Skip to content

Commit c17a8f4

Browse files
committed
Non-jlinked-build fixes for breakage after cc11ae1
Only perform nashorn substitutions if that module is actulally loaded as it would otherwise affect JDK 9+ builds. cc11ae1 re-ordered arguments passed to the native image generator. Move code to after compiler specific flags get added, which includes -XX:+UnlockExperimentalVMOptions. Add relevant modules to the module path for module-based builds like 'native-image --macro:native-image-agent-library' as not all JDKs have truffle and sdk modules in the default module path. Closes #3778
1 parent cd693b9 commit c17a8f4

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.oracle.svm.core.jdk;
27+
28+
import java.util.function.BooleanSupplier;
29+
30+
public final class NashornSupport {
31+
32+
// Determine if the jdk.scripting.nashorn module (or jar) is available. If it's not,
33+
// the boolean supplier should return false.
34+
static class NashornAvailable implements BooleanSupplier {
35+
36+
private static final String CLASSFILTER_NAME = "jdk.nashorn.api.scripting.ClassFilter";
37+
38+
@Override
39+
public boolean getAsBoolean() {
40+
try {
41+
// Checkstyle: stop
42+
Class.forName(CLASSFILTER_NAME);
43+
// Checkstyle: resume
44+
return true;
45+
} catch (ClassNotFoundException e) {
46+
return false;
47+
}
48+
}
49+
50+
}
51+
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_ClassFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
package com.oracle.svm.core.jdk;
2626

2727
import com.oracle.svm.core.annotate.TargetClass;
28+
import com.oracle.svm.core.jdk.NashornSupport.NashornAvailable;
2829

29-
@TargetClass(className = "jdk.nashorn.api.scripting.ClassFilter", onlyWith = JDK14OrEarlier.class)
30+
@TargetClass(className = "jdk.nashorn.api.scripting.ClassFilter", onlyWith = {JDK14OrEarlier.class, NashornAvailable.class})
3031
public final class Target_jdk_nashorn_api_scripting_ClassFilter {
3132
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929
import com.oracle.svm.core.annotate.Substitute;
3030
import com.oracle.svm.core.annotate.TargetClass;
31+
import com.oracle.svm.core.jdk.NashornSupport.NashornAvailable;
3132
import com.oracle.svm.core.util.VMError;
3233

33-
@TargetClass(className = "jdk.nashorn.api.scripting.NashornScriptEngineFactory", onlyWith = JDK14OrEarlier.class)
34+
@TargetClass(className = "jdk.nashorn.api.scripting.NashornScriptEngineFactory", onlyWith = {JDK14OrEarlier.class, NashornAvailable.class})
3435
public final class Target_jdk_nashorn_api_scripting_NashornScriptEngineFactory {
3536
@Substitute
3637
@SuppressWarnings({"unused", "static-method"})

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,6 @@ public List<String> getBuilderJavaArgs() {
481481
}
482482
}
483483

484-
if (useJVMCINativeLibrary) {
485-
builderJavaArgs.add("-XX:+UseJVMCINativeLibrary");
486-
} else {
487-
builderJavaArgs.add("-XX:-UseJVMCICompiler");
488-
}
489-
490484
String javaVersion = String.valueOf(JavaVersionUtil.JAVA_SPEC);
491485
String[] flagsForVersion = graalCompilerFlags.get(javaVersion);
492486
if (flagsForVersion == null) {
@@ -516,6 +510,12 @@ public List<String> getBuilderJavaArgs() {
516510
}
517511
}
518512

513+
if (useJVMCINativeLibrary) {
514+
builderJavaArgs.add("-XX:+UseJVMCINativeLibrary");
515+
} else {
516+
builderJavaArgs.add("-XX:-UseJVMCICompiler");
517+
}
518+
519519
return builderJavaArgs;
520520
}
521521

@@ -524,11 +524,12 @@ public List<String> getBuilderJavaArgs() {
524524
*/
525525
public List<Path> getBuilderModulePath() {
526526
List<Path> result = new ArrayList<>();
527+
// Non-jlinked JDKs need truffle and graal-sdk on the module path since they
528+
// don't have those modules as part of the JDK.
529+
result.addAll(getJars(rootDir.resolve(Paths.get("lib", "jvmci")), "graal-sdk", "enterprise-graal"));
530+
result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api"));
527531
if (modulePathBuild) {
528532
result.addAll(getJars(rootDir.resolve(Paths.get("lib", "svm", "builder"))));
529-
} else {
530-
result.addAll(getJars(rootDir.resolve(Paths.get("lib", "jvmci")), "graal-sdk", "enterprise-graal"));
531-
result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api"));
532533
}
533534
return result;
534535
}

0 commit comments

Comments
 (0)