Skip to content

Commit

Permalink
isRegisteredAsParallelCapable
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 18, 2024
1 parent 5236af9 commit 8d1565d
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import xyz.wagyourtail.jvmdg.util.Utils;
import xyz.wagyourtail.jvmdg.version.Modify;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -67,4 +71,21 @@ public static ClassLoader getPlatformClassLoader() {
return ClassLoader.getSystemClassLoader();
}

private static final MethodHandles.Lookup IMPL_LOOKUP = Utils.getImplLookup();
private static final MethodHandle IS_REGISTERED;

static {
try {
Class<?> parallelLoaders = Class.forName("java.lang.ClassLoader$ParallelLoaders");
IS_REGISTERED = IMPL_LOOKUP.findStatic(parallelLoaders, "isRegistered", MethodType.methodType(boolean.class, Class.class));
} catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

@Stub
public final boolean isRegisteredAsParallelCapable(ClassLoader loader) throws Throwable {
return (boolean) IS_REGISTERED.invokeExact(loader.getClass());
}

}

0 comments on commit 8d1565d

Please sign in to comment.