I finished a library for Java and I used it to replace java.lang.invoke
package (i.e., add it to the boot class loader prior to normal JVM library). In the package, it dynamically generates bytecodes for method handles. Thanks if you have any information about this class !
Currently, this package runs OK with JRuby with test cases, but it fails when I try to test it with Nashorn (A Java version for JavaScript language). The error message is:
java.lang.NoClassDefFoundError: jdk.nashorn.internal.scripts.JO28P0
at java.lang.invoke.DYNGuardWithTestHandle702.0000000051119BF0.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:88)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
at java.lang.reflect.Constructor.newInstance(Constructor.java:437)
at code.jit.asm.plugins.MethodHandlePlugin.initObject(MethodHandlePlugin.java:208)
at code.jit.asm.backplane.ClassContext.createTransformedObject(ClassContext.java:359)
at code.jit.asm.services.BytecodeGenerator$6.action(BytecodeGenerator.java:211)
at code.jit.asm.services.BytecodeGenerator.run(BytecodeGenerator.java:325)
at code.jit.asm.services.BytecodeGenerator.generate(BytecodeGenerator.java:291)
at code.jit.asm.services.BytecodeGenerator.startGenerating(BytecodeGenerator.java:257)
at code.jit.asm.services.TaskRepositoryService.put(TaskRepositoryService.java:48)
at code.jit.asm.services.BytecodeGenerator.generate(BytecodeGenerator.java:251)
at code.jit.asm.services.BytecodeGenerator.generate(BytecodeGenerator.java:247)
at java.lang.invoke.CallSite.jitMethodHandle(CallSite.java:125)
at java.lang.invoke.MutableCallSite.setTarget(MutableCallSite.java:116)
at jdk.internal.dynalink.ChainedCallSite.relinkInternal(ChainedCallSite.java:209)
at jdk.internal.dynalink.ChainedCallSite.relink(ChainedCallSite.java:161)
at jdk.nashorn.internal.runtime.linker.LinkerCallSite.relink(LinkerCallSite.java:154)
at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:297)
at java.lang.invoke.DirectHandle.invokeExact_thunkArchetype_L(DirectHandle.java:291)
at java.lang.invoke.DYNFoldNonvoidHandle699.00000000525AABE0.inlinedMethod(Unknown Source)
at java.lang.invoke.MutableCallSiteDynamicInvokerHandle.invokeExact_thunkArchetype_X(MutableCallSiteDynamicInvokerHandle.java:56)
at jdk.nashorn.internal.scripts.Script$4$richards.:program(file:/C:/sxu/project/octane/richards.js:515)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:635)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:506)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:405)
at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1236)
at jdk.nashorn.internal.runtime.Context.load(Context.java:849)
at jdk.nashorn.internal.objects.Global.load(Global.java:1544)
For the exception, I can not find any class JO28P0 from nashorn package. I can not get any information for this class via google.
Here the JS is from octane benchmark, in which I comment all tests except the the first two cases:
C:\\sxu\\project\\octane\\run.js
var base_dir = 'C:\\sxu\\project\\octane\\';
load(base_dir + 'base.js');
load(base_dir + 'richards.js');/*
load(base_dir + 'deltablue.js');
...
load(base_dir + 'typescript-compiler.js'); */
And the main Java code to launch the case is:
public static void runOctane(String[] args) {
NashornScriptEngine nashorn = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
CompiledScript scr = nashorn.compile(new String(Files.readAllBytes(
Paths.get("C:\\sxu\\project\\octane\\run.js"))));
scr.eval();
}
One VM argument is -Djit_bytecode=true
. If this argument is true, then will go to my library. Otherwise, the my library would not be effect.
The exception disappears if jit_bytecode
is false.
UPDATE:
My code emits dynamic bytecodes, which contains symbol JO28P0
. The exception was thrown when I am trying to use UNSAFE.defineAnonymousClass()
. So How can I use use the Structure ClassLoader so that the Unsafe.defineAnonymousClass
can succeed?