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

[GR-30957] Implement Module/ModuleLayer substitutions #3445

Merged
merged 8 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ jobs:
JDK: "labsjdk-ce-11"
GATE: "build,debuginfotest"
PRIMARY: "substratevm"
- env:
JDK: "labsjdk-ce-11"
GATE: "hellomodule"
PRIMARY: "substratevm"
USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM: true
- env:
JDK: "labsjdk-ce-11"
GATE: "style,fullbuild"
Expand Down
9 changes: 7 additions & 2 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@
"dependencies": ["com.oracle.svm.core"],
"requires" : [
"java.logging",
"jdk.unsupported"
"jdk.unsupported",
"java.compiler",
],
"requiresConcealed" : {
"java.base" : [
Expand Down Expand Up @@ -235,7 +236,10 @@
"com.oracle.svm.core.jdk15": {
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": ["com.oracle.svm.core"],
"dependencies": [
"com.oracle.svm.core",
"com.oracle.svm.core.jdk11"
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.loader",
Expand Down Expand Up @@ -403,6 +407,7 @@
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.hosted",
"com.oracle.svm.core.jdk11"
],
"requires" : ["java.instrument"],
"requiresConcealed" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jdk11;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

public final class BootModuleLayerSupport {

public static BootModuleLayerSupport instance() {
return ImageSingletons.lookup(BootModuleLayerSupport.class);
}

private ModuleLayer bootLayer;

@Platforms(Platform.HOSTED_ONLY.class)
public void setBootLayer(ModuleLayer bootLayer) {
this.bootLayer = bootLayer;
}

public ModuleLayer getBootLayer() {
return bootLayer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jdk11;

import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.hub.ClassForNameSupport;
import com.oracle.svm.core.jdk.JDK11OrLater;
import com.oracle.svm.core.jdk.Target_java_lang_Package;

import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

@TargetClass(value = jdk.internal.loader.ClassLoaders.class, onlyWith = JDK11OrLater.class)
final class Target_jdk_internal_loader_ClassLoaders_JDK11OrLater {
@Alias
static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader();

@Alias
public static native ClassLoader platformClassLoader();
}

@TargetClass(value = jdk.internal.loader.BootLoader.class, onlyWith = JDK11OrLater.class)
final class Target_jdk_internal_loader_BootLoader_JDK11OrLater {

@Substitute
static Package getDefinedPackage(String name) {
if (name != null) {
Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null,
null, null, null, null, null);
return SubstrateUtil.cast(pkg, Package.class);
} else {
return null;
}
}

@Substitute
public static Stream<Package> packages() {
Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders_JDK11OrLater.bootLoader();
Target_java_lang_ClassLoader_JDK11OrLater systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader_JDK11OrLater.class);
return systemClassLoader.packages();
}

@Delete("only used by #packages()")
private static native String[] getSystemPackageNames();

@Substitute
private static Class<?> loadClassOrNull(String name) {
return ClassForNameSupport.forNameOrNull(name, null);
}

@SuppressWarnings("unused")
@Substitute
private static Class<?> loadClass(Target_java_lang_Module_JDK11OrLater module, String name) {
/* The module system is not supported for now, therefore the module parameter is ignored. */
return ClassForNameSupport.forNameOrNull(name, null);
}

@Substitute
private static boolean hasClassPath() {
return true;
}

/**
* All ClassLoaderValue are reset at run time for now. See also
* {@link Target_java_lang_ClassLoader_JDK11OrLater#classLoaderValueMap} for resetting of individual class
* loaders.
*/
// Checkstyle: stop
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)//
static ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP;
// Checkstyle: resume
}

/** Dummy class to have a class with the file's name. */
public final class JavaLangSubstitutions_JDK11OrLater {

}
Loading