Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public HotSpotGraalRuntimeProvider getGraalRuntime() {
private static final Unsafe UNSAFE = Unsafe.getUnsafe();

/**
* Implemented by
* {@code com.oracle.svm.graal.hotspot.libgraal.LibGraalEntryPoints.compileMethod}.
* Implemented by {@code com.oracle.svm.graal.hotspot.guestgraal.GuestGraal#compileMethod}.
*/
public static native long compileMethodInLibgraal(long isolateThread,
long methodHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class LibGraalCompilerTest extends HotSpotGraalCompilerTest {
* Computes a hash based on the static final Object fields in {@code typeHandle}.
*
* Implemented by
* {@code com.oracle.svm.graal.hotspot.libgraal.LibGraalEntryPoints.hashConstantOopFields}.
* {@code com.oracle.svm.graal.hotspot.guestgraal.GuestGraal#hashConstantOopFields}.
*
* @param isolateThread
* @param typeHandle the type whose constant object fields are to be hashed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,6 @@ private static String match(StructuredGraph graph, String methodPattern) {
return label;
}

/**
* Substituted by {@code com.oracle.svm.graal.hotspot.libgraal.
* Target_jdk_graal_compiler_core_GraalCompiler} to optionally test routing fatal error handling
* from libgraal to HotSpot.
*
* @return true if the caller should proceed to throw an exception
*/
@SuppressWarnings("unused")
private static boolean notifyCrash(String crashMessage) {
return true;
}

/**
* Builds the graph, optimizes it.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ protected void onAttachError(InternalError error) {
}

/**
* Substituted by {@code com.oracle.svm.graal.hotspot.libgraal.
* Target_jdk_graal_compiler_core_GraalServiceThread} to attach to the peer runtime if required.
* Substituted by {@code Target_jdk_graal_compiler_core_GraalServiceThread} to attach to the
* peer runtime if required.
*/
private void afterRun() {
}

/**
* Substituted by {@code com.oracle.svm.graal.hotspot.libgraal.
* Target_jdk_graal_compiler_core_GraalServiceThread} to attach to the peer runtime if required.
* Substituted by {@code Target_jdk_graal_compiler_core_GraalServiceThread} to attach to the
* peer runtime if required.
*/
private void beforeRun() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ private Object getLoadedFromLocation(boolean verbose) {

private static String nativeImageLocationQualifier;

/**
* Gets the qualifier for the libgraal library (e.g., "PGO optimized").
*/
public static String getNativeImageLocationQualifier() {
return nativeImageLocationQualifier;
}

/**
* Records a qualifier for the libgraal library (e.g., "PGO optimized").
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ private static String stripPrefix(String name, String prefix) {
}

/**
* Substituted by
* {@code com.oracle.svm.graal.hotspot.libgraal.Target_jdk_graal_compiler_hotspot_HotSpotGraalOptionValues}.
* Substituted by {@code Target_jdk_graal_compiler_hotspot_HotSpotGraalOptionValues}.
*
* @param settings unparsed libgraal option values
*/
Expand All @@ -195,8 +194,7 @@ static void printProperties(OptionValues compilerOptions, PrintStream out) {
}

/**
* Substituted by
* {@code com.oracle.svm.graal.hotspot.libgraal.Target_jdk_graal_compiler_hotspot_HotSpotGraalOptionValues}.
* Substituted by {@code Target_jdk_graal_compiler_hotspot_HotSpotGraalOptionValues}.
*
* @param out where help is to be printed
* @param prefix system property prefix for libgraal VM options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.function.Supplier;

import jdk.graal.compiler.core.ArchitectureSpecific;
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
import org.graalvm.collections.EconomicMap;

import jdk.graal.compiler.core.common.spi.ForeignCallSignature;
Expand Down Expand Up @@ -146,6 +147,7 @@ public static void configureGraalForLibGraal(String arch,
List<Class<?>> guestServiceClasses,
Consumer<Class<?>> registerAsInHeap,
Consumer<List<Class<?>>> hostedGraalSetFoldNodePluginClasses,
String nativeImageLocationQualifier,
String encodedGuestObjects) {
GraalError.guarantee(VALID_LOADER_NAME.equals(LOADER.getName()),
"Only call this method from classloader " + VALID_LOADER_NAME);
Expand All @@ -154,6 +156,8 @@ public static void configureGraalForLibGraal(String arch,
guestServiceClasses.forEach(c -> addProviders(services, arch, c));
GraalServices.setLibgraalServices(services);

CompilerConfigurationFactory.setNativeImageLocationQualifier(nativeImageLocationQualifier);

try {
Field cachedHotSpotJVMCIBackendFactoriesField = ObjectCopier.getField(HotSpotJVMCIRuntime.class, "cachedHotSpotJVMCIBackendFactories");
GraalError.guarantee(cachedHotSpotJVMCIBackendFactoriesField.get(null) == null, "Expect cachedHotSpotJVMCIBackendFactories to be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static long compileMethod(long methodHandle, boolean useProfilingInfo,

HotSpotJVMCIRuntime runtime = HotSpotJVMCIRuntime.runtime();
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
if (methodHandle == 0L) {
return 0L;
}

int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
HotSpotResolvedJavaMethod method = runtime.unhand(HotSpotResolvedJavaMethod.class, methodHandle);
Expand Down
1 change: 0 additions & 1 deletion sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,6 @@ def get_build_args(self):
'-H:APIFunctionPrefix=truffle_isolate_',
] + svm_experimental_options([
'-H:+IgnoreMaxHeapSizeWhileInVMOperation',
'-H:+BuildOutputPrefix',
'-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json'
]) + mx.get_runtime_jvm_args(self.subject.native_image_jar_distributions) + \
project.native_image_config.build_args + project.native_image_config.build_args_enterprise
Expand Down
11 changes: 8 additions & 3 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ def _native_image_launcher_extra_jvm_args():
libgraal_jar_distributions = [
'sdk:NATIVEBRIDGE',
'sdk:JNIUTILS',
'substratevm:GRAAL_HOTSPOT_LIBRARY']
'substratevm:GUESTGRAAL_LIBRARY']

def allow_build_path_in_libgraal():
"""
Expand Down Expand Up @@ -1458,13 +1458,18 @@ def prevent_build_path_in_libgraal():
return ['-H:NativeLinkerOption=-pdbaltpath:%_PDB%']
return []

libgraal_features = [
'com.oracle.svm.graal.hotspot.guestgraal.GuestGraalFeature'
]

libgraal_build_args = [
'--features=' + ','.join(libgraal_features),

## Pass via JVM args opening up of packages needed for image builder early on
'-J--add-exports=jdk.graal.compiler/jdk.graal.compiler.hotspot=ALL-UNNAMED',
'-J--add-exports=jdk.graal.compiler/jdk.graal.compiler.options=ALL-UNNAMED',
'-J--add-exports=jdk.graal.compiler/jdk.graal.compiler.truffle=ALL-UNNAMED',
'-J--add-exports=jdk.graal.compiler/jdk.graal.compiler.truffle.hotspot=ALL-UNNAMED',
'-J--add-exports=org.graalvm.jniutils/org.graalvm.jniutils=ALL-UNNAMED',
'-J--add-exports=org.graalvm.truffle.compiler/com.oracle.truffle.compiler.hotspot.libgraal=ALL-UNNAMED',
'-J--add-exports=org.graalvm.truffle.compiler/com.oracle.truffle.compiler.hotspot=ALL-UNNAMED',
'-J--add-exports=org.graalvm.truffle.compiler/com.oracle.truffle.compiler=ALL-UNNAMED',
Expand Down Expand Up @@ -1537,7 +1542,7 @@ def prevent_build_path_in_libgraal():
destination="<lib:jvmcicompiler>",
jvm_library=True,
jar_distributions=libgraal_jar_distributions,
build_args=libgraal_build_args + ['--features=com.oracle.svm.graal.hotspot.libgraal.LibGraalFeature,com.oracle.svm.graal.hotspot.libgraal.truffle.TruffleLibGraalFeature'],
build_args=libgraal_build_args,
add_to_module='java.base',
headers=False,
home_finder=False,
Expand Down
53 changes: 0 additions & 53 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,39 +1351,6 @@
"jacoco" : "exclude",
},

"com.oracle.svm.graal.hotspot.libgraal" : {
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.graal.hotspot",
"com.oracle.svm.graal",
"compiler:GRAAL",
"sdk:NATIVEBRIDGE",
],
"requires" : [
"jdk.management"
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc",
],
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
"jdk.vm.ci.code",
"jdk.vm.ci.hotspot",
]
},
"checkstyle" : "com.oracle.svm.hosted",
"javaCompliance" : "21+",
"annotationProcessors": [
"truffle:TRUFFLE_LIBGRAAL_PROCESSOR",
"compiler:GRAAL_PROCESSOR",
"SVM_PROCESSOR",
],
"defaultBuild": False,
"jacoco" : "exclude",
},

"com.oracle.svm.configure": {
"subDir": "src",
"sourceDirs": [
Expand Down Expand Up @@ -1853,26 +1820,6 @@
"maven" : False,
},

"GRAAL_HOTSPOT_LIBRARY": {
"subDir": "src",
"description" : "SubstrateVM HotSpot Graal library support",
"javaCompliance" : "21+",
"dependencies": [
"com.oracle.svm.graal.hotspot.libgraal",
],
"overlaps" : [
"LIBRARY_SUPPORT",
"GUESTGRAAL_LIBRARY"
],
"distDependencies": [
"SVM",
"sdk:JNIUTILS",
"sdk:NATIVEBRIDGE",
],
"defaultBuild": False,
"maven": False,
},

"GUESTGRAAL_LIBRARY": {
"subDir": "src",
"description" : "GuestGraal HotSpot Graal library support",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
*/
final class GuestGraal {

/*
* See jdk.graal.compiler.hotspot.guestgraal.BuildTime.getRuntimeHandles to see how these
* handles are initialized and what their target methods are.
*/

private final MethodHandle getJNIEnv;
private final MethodHandle getSavedProperty;
private final MethodHandle ttyPrintf;
Expand Down Expand Up @@ -239,9 +244,6 @@ private static long compileMethod(JNIEnv jniEnv,
long timeAndMemBufferAddress,
long profilePathBufferAddress) {
try (JNIMethodScope jniScope = new JNIMethodScope("compileMethod", jniEnv)) {
if (methodHandle == 0L) {
return 0L;
}
String profileLoadPath;
if (profilePathBufferAddress > 0) {
profileLoadPath = CTypeConversion.toJavaString(WordFactory.pointer(profilePathBufferAddress));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.graal.hotspot.GetCompilerConfig;
import com.oracle.svm.graal.hotspot.GetJNIConfig;
import com.oracle.svm.hosted.FeatureImpl;
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
import jdk.graal.compiler.options.OptionDescriptor;
import jdk.graal.compiler.options.OptionKey;
import jdk.graal.compiler.serviceprovider.LibGraalService;
Expand Down Expand Up @@ -397,13 +397,17 @@ public void beforeAnalysis(BeforeAnalysisAccess baa) {
List<Class<?>> serviceClasses = impl.getImageClassLoader().findAnnotatedClasses(LibGraalService.class, false);
serviceClasses.stream().map(c -> loader.loadClassOrFail(c.getName())).forEach(guestServiceClasses::add);

// Transfer libgraal qualifier (e.g. "PGO optimized") from host to guest.
String nativeImageLocationQualifier = CompilerConfigurationFactory.getNativeImageLocationQualifier();

MethodHandle configureGraalForLibGraal = mhl.findStatic(buildTimeClass,
"configureGraalForLibGraal",
methodType(void.class,
String.class, // arch
List.class, // guestServiceClasses
Consumer.class, // registerAsInHeap
Consumer.class, // hostedGraalSetFoldNodePluginClasses
String.class, // nativeImageLocationQualifier
String.class // encodedGuestObjects
));
GetCompilerConfig.Result configResult = GetCompilerConfig.from(Options.GuestJavaHome.getValue(), bb.getOptions());
Expand All @@ -417,6 +421,7 @@ public void beforeAnalysis(BeforeAnalysisAccess baa) {
guestServiceClasses,
registerAsInHeap,
hostedGraalSetFoldNodePluginClasses,
nativeImageLocationQualifier,
configResult.encodedConfig());

initGraalRuntimeHandles(mhl.findStatic(buildTimeClass, "getRuntimeHandles", methodType(Map.class)));
Expand Down Expand Up @@ -461,7 +466,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
classesPattern("jdk.graal.compiler.options",
"ModifiableOptionValues", "Option.*"),
classesPattern("jdk.graal.compiler.util.json",
"JsonWriter"),
"JsonWriter", "JsonBuilder.*"),
classesPattern("org.graalvm.collections",
"EconomicMap.*", "EmptyMap.*", "Equivalence.*", "Pair"),
classesPattern("jdk.vm.ci.amd64",
Expand Down Expand Up @@ -502,26 +507,12 @@ public void afterAnalysis(AfterAnalysisAccess access) {
}
}
if (!forbiddenReachableTypes.isEmpty()) {
CallTreePrinter.print(bigBang, "reports", "report");
VMError.shouldNotReachHere("GuestGraal build found forbidden hosted types as reachable: %s", String.join(", ", forbiddenReachableTypes));
}
optionCollector.afterAnalysis(access);
}

@Override
public void beforeImageWrite(BeforeImageWriteAccess access) {
if (!Platform.includedIn(Platform.WINDOWS.class)) {
((FeatureImpl.BeforeImageWriteAccessImpl) access).registerLinkerInvocationTransformer(linkerInvocation -> {
Path imageFilePath = linkerInvocation.getOutputFile();
String imageName = imageFilePath.getFileName().toString();
String posixLibraryPrefix = "lib";
assert !imageName.startsWith(posixLibraryPrefix);
String posixImageName = posixLibraryPrefix + imageName;
linkerInvocation.setOutputFile(imageFilePath.getParent().resolve(posixImageName));
return linkerInvocation;
});
}
}

private static Pattern classesPattern(String packageName, String... regexes) {
return Pattern.compile("%s(%s)".formatted(Pattern.quote(packageName + '.'), String.join("|", regexes)));
}
Expand Down
Loading