Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenJDK 15] Removal of nashorn javascript engine breaks build #2365

Closed
jerboaa opened this issue Apr 20, 2020 · 6 comments · Fixed by #2383 or #2455
Closed

[OpenJDK 15] Removal of nashorn javascript engine breaks build #2365

jerboaa opened this issue Apr 20, 2020 · 6 comments · Fixed by #2383 or #2455

Comments

@jerboaa
Copy link
Collaborator

jerboaa commented Apr 20, 2020

In jdk/jdk the nashorn javascript has been removed:
https://openjdk.java.net/jeps/372
https://bugs.openjdk.java.net/browse/JDK-8241749

This breaks the graal VM native image build like this:

/home/jenkins/workspace/jdk-15-gaovm-x86-64_linux/src/graal/graal-ce/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java:33: error: package jdk.nashorn.api.scripting does not exist
import jdk.nashorn.api.scripting.ClassFilter;
                                ^
/home/jenkins/workspace/jdk-15-gaovm-x86-64_linux/src/graal/graal-ce/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java:45: error: cannot find symbol
    private ScriptEngine newEngine(String[] args, ClassLoader appLoader, ClassFilter classFilter) {
                                                                         ^
  symbol:   class ClassFilter
  location: class Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory
/home/jenkins/workspace/jdk-15-gaovm-x86-64_linux/src/graal/graal-ce/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java:35: error: package jdk.nashorn.api.scripting does not exist
@TargetClass(jdk.nashorn.api.scripting.NashornScriptEngineFactory.class)
                                      ^
3 errors

WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.jpackage
Compiling com.oracle.svm.core with javac-daemon(JDK 15) failed
1 build tasks failed

Substrate VM needs to get updated to account for this. I hope to get a fix in for this later in the week.

/cc @bobvandette

@jerboaa
Copy link
Collaborator Author

jerboaa commented Apr 23, 2020

This gets one further (past nashorn removal), but then a slew of errors result

diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java
new file mode 100644
index 00000000000..e04cea2ad38
--- /dev/null
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java
@@ -0,0 +1,7 @@
+package com.oracle.svm.core.jdk;
+
+import com.oracle.svm.core.annotate.TargetClass;
+
+@TargetClass(className = "jdk.nashorn.api.scripting.ClassFilter", onlyWith = JDK14OrEarlier.class)
+public final class Target_jdk_nashorn_api_scripting_ClassFilter {
+}
\ No newline at end of file
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java
index 8ab3fa7bf7b..729ae1d1ef8 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java
@@ -30,9 +30,7 @@ import com.oracle.svm.core.annotate.Substitute;
 import com.oracle.svm.core.annotate.TargetClass;
 import com.oracle.svm.core.util.VMError;
 
-import jdk.nashorn.api.scripting.ClassFilter;
-
-@TargetClass(jdk.nashorn.api.scripting.NashornScriptEngineFactory.class)
+@TargetClass(className = "jdk.nashorn.api.scripting.NashornScriptEngineFactory", onlyWith = JDK14OrEarlier.class)
 public final class Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory {
     @Substitute
     @SuppressWarnings({"unused", "static-method"})
@@ -42,7 +40,7 @@ public final class Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory {
 
     @Substitute
     @SuppressWarnings({"unused", "static-method"})
-    private ScriptEngine newEngine(String[] args, ClassLoader appLoader, ClassFilter classFilter) {
+    private ScriptEngine newEngine(String[] args, ClassLoader appLoader, Target_jdk_nashorn_api_scripting_ClassFilter classFilter) {
         throw VMError.unsupportedFeature(Util.errorMessage);
     }
 }

Error then looks similar to:

[testme-helloworld:200062]    classlist:   2,957.76 ms,  0.96 GB
[testme-helloworld:200062]        (cap):     628.00 ms,  0.96 GB
[testme-helloworld:200062]        setup:   1,941.35 ms,  0.96 GB
[testme-helloworld:200062]     (clinit):     165.06 ms,  1.21 GB
[testme-helloworld:200062]     analysis:   9,573.73 ms,  1.21 GB
Warning: Aborting stand-alone image build due to unsupported features
com.oracle.svm.hosted.FallbackFeature$FallbackImageRequest: Aborting stand-alone image build due to unsupported features
	at com.oracle.svm.hosted.FallbackFeature.reportFallback(FallbackFeature.java:209)
	at com.oracle.svm.hosted.FallbackFeature.reportFallback(FallbackFeature.java:194)
	at com.oracle.svm.hosted.FallbackFeature.afterAnalysis(FallbackFeature.java:274)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:741)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:741)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:538)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:451)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1409)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
[testme-helloworld:200168]    classlist:   1,841.80 ms,  0.96 GB
[testme-helloworld:200168]        (cap):     801.21 ms,  0.96 GB
[testme-helloworld:200168]        setup:   2,460.68 ms,  0.96 GB
[testme-helloworld:200168]     (clinit):     182.66 ms,  1.21 GB
[testme-helloworld:200168]   (typeflow):   5,231.14 ms,  1.21 GB
[testme-helloworld:200168]    (objects):   5,130.69 ms,  1.21 GB
[testme-helloworld:200168]   (features):     243.96 ms,  1.21 GB
[testme-helloworld:200168]     analysis:  11,427.63 ms,  1.70 GB
Fatal error: FallbackImageRequest while building fallback image.com.oracle.svm.hosted.FallbackFeature$FallbackImageRequest: Aborting stand-alone image build. Unsupported features in 58 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing com.oracle.svm.core.genscavenge.GCImpl.printGCSummary(GCImpl.java:1752)
Call path from entry point to com.oracle.svm.core.genscavenge.GCImpl.printGCSummary(): 
	at com.oracle.svm.core.genscavenge.GCImpl.printGCSummary(GCImpl.java:1738)
	at com.oracle.svm.core.genscavenge.GCImpl$$Lambda$156/0x00000007c08456d0.run(Unknown Source)
	at com.oracle.svm.core.jdk.RuntimeSupport.executeHooks(RuntimeSupport.java:125)
	at com.oracle.svm.core.jdk.RuntimeSupport.executeStartupHooks(RuntimeSupport.java:75)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:141)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:184)
	at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing com.oracle.svm.core.thread.VMThreads.detachAllThreadsExceptCurrentWithoutCleanupForTearDown(VMThreads.java:425)
Call path from entry point to com.oracle.svm.core.thread.VMThreads.detachAllThreadsExceptCurrentWithoutCleanupForTearDown(): 
	at com.oracle.svm.core.thread.VMThreads.detachAllThreadsExceptCurrentWithoutCleanupForTearDown(VMThreads.java:425)
	at com.oracle.svm.core.c.function.CEntryPointNativeFunctions.detachAllThreadsAndTearDownIsolate0(CEntryPointNativeFunctions.java:210)
	at com.oracle.svm.core.c.function.CEntryPointNativeFunctions.detachAllThreadsAndTearDownIsolate(CEntryPointNativeFunctions.java:203)
	at com.oracle.svm.core.code.IsolateEnterStub.CEntryPointNativeFunctions_detachAllThreadsAndTearDownIsolate_803a26f98b4febfb61e3b676ead8b433cc2f21b3(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing com.oracle.svm.jni.functions.JNIInvocationInterface$Support.releaseCurrentThreadOwnedMonitors(JNIInvocationInterface.java:298)
Call path from entry point to com.oracle.svm.jni.functions.JNIInvocationInterface$Support.releaseCurrentThreadOwnedMonitors(): 
	at com.oracle.svm.jni.functions.JNIInvocationInterface$Support.releaseCurrentThreadOwnedMonitors(JNIInvocationInterface.java:298)
	at com.oracle.svm.jni.functions.JNIInvocationInterface.DetachCurrentThread(JNIInvocationInterface.java:213)
	at com.oracle.svm.core.code.IsolateEnterStub.JNIInvocationInterface_DetachCurrentThread_f2242e753d02cfb782eed29e0199d6a979dafc97(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing java.lang.module.ModuleDescriptor.toString(ModuleDescriptor.java:2565)
Call path from entry point to java.lang.module.ModuleDescriptor.toString(Set, String): 
	at java.lang.module.ModuleDescriptor.toString(ModuleDescriptor.java:2565)
	at java.lang.module.ModuleDescriptor$Requires.toString(ModuleDescriptor.java:357)
	at java.lang.String.valueOf(String.java:3364)
	at java.io.PrintStream.println(PrintStream.java:1028)
	at com.oracle.svm.jni.functions.JNIFunctions.ExceptionDescribe(JNIFunctions.java:759)
	at com.oracle.svm.core.code.IsolateEnterStub.JNIFunctions_ExceptionDescribe_b5412f7570bccae90b000bc37855f00408b2ad73(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing java.lang.reflect.Executable.sharedToString(Executable.java:114)
Call path from entry point to java.lang.reflect.Executable.sharedToString(int, boolean, Class[], Class[]): 
	at java.lang.reflect.Executable.sharedToString(Executable.java:110)
	at java.lang.reflect.Constructor.toString(Constructor.java:355)
	at java.lang.String.valueOf(String.java:3364)
	at java.io.PrintStream.println(PrintStream.java:1028)
	at com.oracle.svm.jni.functions.JNIFunctions.ExceptionDescribe(JNIFunctions.java:759)
	at com.oracle.svm.core.code.IsolateEnterStub.JNIFunctions_ExceptionDescribe_b5412f7570bccae90b000bc37855f00408b2ad73(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed.
Trace: 
	at parsing java.nio.charset.CoderResult.malformedForLength(CoderResult.java:222)
Call path from entry point to java.nio.charset.CoderResult.malformedForLength(int): 
	at java.nio.charset.CoderResult.malformedForLength(CoderResult.java:218)
	at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:597)
	at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:401)
	at java.lang.StringCoding.encode(StringCoding.java:444)
	at java.lang.String.getBytes(String.java:959)
	at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST_Nonvirtual:Ljava_lang_String_2_0002egetBytes_00028Ljava_lang_String_2_00029_3B(generated:0)

@bobvandette
Copy link
Contributor

bobvandette commented Apr 23, 2020

I just discovered this issue yesterday. I believe the problem is caused by the introduction of Hidden classes (8238358).

https://hg.openjdk.java.net/jdk/jdk/rev/30ec85283758

A build of JDK15 before and after the Hidden Classes changeset proves that this change is the cause of the UnsupportedFeatureException.

The failure occurs when native-image is trying to process an
Invoke with a Method Handle but the invocation plugin doesn’t handle DynamicNewInstanceNode.

The methodHandleMethod is ...

AnalysisMethod<java.lang.invoke.Invokers$Holder.linkToTargetMethod -> HotSpotMethod<Invokers$Holder.linkToTargetMethod(Object)>>

In IntrinsifyMethodHandlesInvocationPlugin.java

node is 12|DynamicNewInstance

Node singleFunctionality = null;
ReturnNode singleReturn = null;
for (Node node : graph.getNodes()) {
    if (node == graph.start() || node instanceof ParameterNode || node instanceof ConstantNode || node instanceof FrameState) {
        /* Ignore the allowed framework around the nodes we care about. */
    } else if (node instanceof MethodCallTargetNode) {
        /* We check the Invoke, so we can ignore the call target. */
    } else if ((node instanceof Invoke || node instanceof LoadFieldNode || node instanceof StoreFieldNode) && singleFunctionality == null) {
        singleFunctionality = node;
    } else if (node instanceof ReturnNode && singleReturn == null) {
        singleReturn = (ReturnNode) node;
    } else {
        reportUnsupportedFeature(b, methodHandleMethod);  <<<---------
        return;
    }
}

Please go ahead and do a PR for the nashorn removal and I'll open a new issue for the Hidden classes problem.

@jerboaa
Copy link
Collaborator Author

jerboaa commented Apr 23, 2020

OK. #2383

@jerboaa
Copy link
Collaborator Author

jerboaa commented Apr 23, 2020

@bobvandette Please cc me on the hidden classes issue. Thanks!

@bobvandette
Copy link
Contributor

Here is the Hidden Classes issue #2382

@jerboaa
Copy link
Collaborator Author

jerboaa commented Apr 23, 2020

Here is the Hidden Classes issue #2382

Thanks!

bobvandette pushed a commit to bobvandette/graal that referenced this issue May 20, 2020
bobvandette pushed a commit to bobvandette/graal that referenced this issue May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants