Skip to content

Commit 8f1e81c

Browse files
committed
[GR-30957] Implement Module/ModuleLayer substitutions #3445.
PullRequest: graal/9540
2 parents fc38aba + d811e48 commit 8f1e81c

File tree

24 files changed

+1162
-276
lines changed

24 files changed

+1162
-276
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ jobs:
8080
JDK: "labsjdk-ce-11"
8181
GATE: "build,debuginfotest"
8282
PRIMARY: "substratevm"
83+
- env:
84+
JDK: "labsjdk-ce-11"
85+
GATE: "hellomodule"
86+
PRIMARY: "substratevm"
87+
USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM: true
8388
- env:
8489
JDK: "labsjdk-ce-11"
8590
GATE: "style,fullbuild"

substratevm/mx.substratevm/suite.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@
198198
"dependencies": ["com.oracle.svm.core"],
199199
"requires" : [
200200
"java.logging",
201-
"jdk.unsupported"
201+
"jdk.unsupported",
202+
"java.compiler",
202203
],
203204
"requiresConcealed" : {
204205
"java.base" : [
@@ -235,7 +236,10 @@
235236
"com.oracle.svm.core.jdk15": {
236237
"subDir": "src",
237238
"sourceDirs": ["src"],
238-
"dependencies": ["com.oracle.svm.core"],
239+
"dependencies": [
240+
"com.oracle.svm.core",
241+
"com.oracle.svm.core.jdk11"
242+
],
239243
"requiresConcealed" : {
240244
"java.base" : [
241245
"jdk.internal.loader",
@@ -403,6 +407,7 @@
403407
"sourceDirs": ["src"],
404408
"dependencies": [
405409
"com.oracle.svm.hosted",
410+
"com.oracle.svm.core.jdk11"
406411
],
407412
"requires" : ["java.instrument"],
408413
"requiresConcealed" : {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
package com.oracle.svm.core.jdk11;
26+
27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.Platform;
29+
import org.graalvm.nativeimage.Platforms;
30+
31+
public final class BootModuleLayerSupport {
32+
33+
public static BootModuleLayerSupport instance() {
34+
return ImageSingletons.lookup(BootModuleLayerSupport.class);
35+
}
36+
37+
private ModuleLayer bootLayer;
38+
39+
@Platforms(Platform.HOSTED_ONLY.class)
40+
public void setBootLayer(ModuleLayer bootLayer) {
41+
this.bootLayer = bootLayer;
42+
}
43+
44+
public ModuleLayer getBootLayer() {
45+
return bootLayer;
46+
}
47+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
package com.oracle.svm.core.jdk11;
27+
28+
import com.oracle.svm.core.SubstrateUtil;
29+
import com.oracle.svm.core.annotate.Alias;
30+
import com.oracle.svm.core.annotate.Delete;
31+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
32+
import com.oracle.svm.core.annotate.Substitute;
33+
import com.oracle.svm.core.annotate.TargetClass;
34+
import com.oracle.svm.core.hub.ClassForNameSupport;
35+
import com.oracle.svm.core.jdk.JDK11OrLater;
36+
import com.oracle.svm.core.jdk.Target_java_lang_Package;
37+
38+
import java.util.concurrent.ConcurrentHashMap;
39+
import java.util.stream.Stream;
40+
41+
@TargetClass(value = jdk.internal.loader.ClassLoaders.class, onlyWith = JDK11OrLater.class)
42+
final class Target_jdk_internal_loader_ClassLoaders_JDK11OrLater {
43+
@Alias
44+
static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader();
45+
46+
@Alias
47+
public static native ClassLoader platformClassLoader();
48+
}
49+
50+
@TargetClass(value = jdk.internal.loader.BootLoader.class, onlyWith = JDK11OrLater.class)
51+
final class Target_jdk_internal_loader_BootLoader_JDK11OrLater {
52+
53+
@Substitute
54+
static Package getDefinedPackage(String name) {
55+
if (name != null) {
56+
Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null,
57+
null, null, null, null, null);
58+
return SubstrateUtil.cast(pkg, Package.class);
59+
} else {
60+
return null;
61+
}
62+
}
63+
64+
@Substitute
65+
public static Stream<Package> packages() {
66+
Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders_JDK11OrLater.bootLoader();
67+
Target_java_lang_ClassLoader_JDK11OrLater systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader_JDK11OrLater.class);
68+
return systemClassLoader.packages();
69+
}
70+
71+
@Delete("only used by #packages()")
72+
private static native String[] getSystemPackageNames();
73+
74+
@Substitute
75+
private static Class<?> loadClassOrNull(String name) {
76+
return ClassForNameSupport.forNameOrNull(name, null);
77+
}
78+
79+
@SuppressWarnings("unused")
80+
@Substitute
81+
private static Class<?> loadClass(Target_java_lang_Module_JDK11OrLater module, String name) {
82+
/* The module system is not supported for now, therefore the module parameter is ignored. */
83+
return ClassForNameSupport.forNameOrNull(name, null);
84+
}
85+
86+
@Substitute
87+
private static boolean hasClassPath() {
88+
return true;
89+
}
90+
91+
/**
92+
* All ClassLoaderValue are reset at run time for now. See also
93+
* {@link Target_java_lang_ClassLoader_JDK11OrLater#classLoaderValueMap} for resetting of individual class
94+
* loaders.
95+
*/
96+
// Checkstyle: stop
97+
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)//
98+
static ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP;
99+
// Checkstyle: resume
100+
}
101+
102+
/** Dummy class to have a class with the file's name. */
103+
public final class JavaLangSubstitutions_JDK11OrLater {
104+
105+
}

0 commit comments

Comments
 (0)