diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilationDriver.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilationDriver.java index 466bfb830c5c..e6b38c28dc8d 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilationDriver.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilationDriver.java @@ -159,7 +159,7 @@ public HotSpotGraalRuntimeProvider getGraalRuntime() { * Implemented by * {@code com.oracle.svm.graal.hotspot.libgraal.LibGraalEntryPoints#compileMethod}. */ - public static native long compileMethodInLibgraal(long isolateThread, + public static native long compileMethodInLibgraal(long isolateThreadAddress, long methodHandle, boolean useProfilingInfo, boolean installAsDefault, diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilerTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilerTest.java index ae094cda7b69..89d7aa53fe26 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilerTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilerTest.java @@ -24,13 +24,13 @@ */ package jdk.graal.compiler.hotspot.test; -import jdk.graal.compiler.hotspot.HotSpotGraalServices; import org.junit.Assume; import org.junit.Test; import com.oracle.truffle.runtime.hotspot.libgraal.LibGraal; import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope; +import jdk.graal.compiler.hotspot.HotSpotGraalServices; import jdk.vm.ci.meta.ResolvedJavaType; /** @@ -62,7 +62,7 @@ public class LibGraalCompilerTest extends HotSpotGraalCompilerTest { * Implemented by * {@code com.oracle.svm.graal.hotspot.libgraal.LibGraalEntryPoints#hashConstantOopFields}. * - * @param isolateThread + * @param isolateThreadAddress * @param typeHandle the type whose constant object fields are to be hashed * @param useScope should a {@linkplain HotSpotGraalServices#openLocalCompilationContext(Object) * scope} be used for each iteration. If true, then @@ -71,7 +71,7 @@ public class LibGraalCompilerTest extends HotSpotGraalCompilerTest { * @param iterations number of times to run the hashing loop * @param oopsPerIteration number of oops to process per hashing loop */ - public static native long hashConstantOopFields(long isolateThread, + public static native long hashConstantOopFields(long isolateThreadAddress, long typeHandle, boolean useScope, int iterations, diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/TraceCompilationTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/TraceCompilationTest.java index ccb19144de80..bf036f152573 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/TraceCompilationTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/TraceCompilationTest.java @@ -40,12 +40,6 @@ import java.util.logging.LogRecord; import java.util.regex.Pattern; -import com.oracle.truffle.api.test.SubprocessTestUtils; -import com.oracle.truffle.runtime.OptimizedCallTarget; - -import jdk.graal.compiler.truffle.test.nodes.AbstractTestNode; -import jdk.graal.compiler.truffle.test.nodes.RootTestNode; -import jdk.graal.compiler.serviceprovider.GraalServices; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -55,6 +49,12 @@ import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.api.test.SubprocessTestUtils; +import com.oracle.truffle.runtime.OptimizedCallTarget; + +import jdk.graal.compiler.serviceprovider.GraalServices; +import jdk.graal.compiler.truffle.test.nodes.AbstractTestNode; +import jdk.graal.compiler.truffle.test.nodes.RootTestNode; public class TraceCompilationTest extends TestWithPolyglotOptions { @@ -109,6 +109,14 @@ public void testCompilationFailureTracingDetails() throws Exception { Arrays.asList("opt done")); } + @Test + public void testCompilationId() throws Exception { + testHelper(() -> RootNode.createConstantNode(true), + Collections.singletonMap("engine.TraceCompilation", "true"), + Arrays.asList("CompId "), + Arrays.asList("CompId n/a")); + } + @Test public void testExceptionFromPublish() throws Exception { testHelper( @@ -252,7 +260,7 @@ public synchronized void publish(LogRecord lr) { Pattern p = it.next(); if (p.matcher(lr.getMessage()).matches()) { it.remove(); - return; + break; } } for (Pattern p : unexpected) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/libgraal/truffle/GraalEntryPoints.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/libgraal/truffle/GraalEntryPoints.java index a98a5dac143f..2ffb4549e130 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/libgraal/truffle/GraalEntryPoints.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/libgraal/truffle/GraalEntryPoints.java @@ -24,10 +24,13 @@ */ package jdk.graal.compiler.hotspot.libgraal.truffle; +import java.util.function.Supplier; + import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; + import jdk.graal.compiler.hotspot.CompilationContext; import jdk.graal.compiler.hotspot.HotSpotGraalServices; import jdk.graal.compiler.truffle.TruffleCompilerOptions; @@ -37,8 +40,6 @@ import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; import jdk.vm.ci.meta.ResolvedJavaMethod; -import java.util.function.Supplier; - /** * Guest Graal entry points for Truffle to libgraal calls. */ @@ -126,6 +127,10 @@ public static String[] getNodeTypes(Object graphInfo, boolean simpleNames) { return ((GraphInfo) graphInfo).getNodeTypes(simpleNames); } + public static long getCompilationId(Object compilationResultInfo) { + return ((CompilationResultInfo) compilationResultInfo).getCompilationId(); + } + public static int getTargetCodeSize(Object compilationResultInfo) { return ((CompilationResultInfo) compilationResultInfo).getTargetCodeSize(); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilationIdentifier.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilationIdentifier.java index e5e480242c1c..fdeac5e8268b 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilationIdentifier.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilationIdentifier.java @@ -24,15 +24,18 @@ */ package jdk.graal.compiler.truffle; -import jdk.graal.compiler.core.common.CompilationIdentifier; - import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilationTask; +import jdk.graal.compiler.core.common.CompilationIdentifier; + public interface TruffleCompilationIdentifier extends CompilationIdentifier { TruffleCompilationTask getTask(); TruffleCompilable getCompilable(); + default long getTruffleCompilationId() { + return -1; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilerImpl.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilerImpl.java index 0fa13ddecdb4..328f8ce0e6c9 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilerImpl.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/TruffleCompilerImpl.java @@ -407,8 +407,8 @@ static class CompilationResultInfoImpl implements TruffleCompilerListener.Compil } @Override - public String getCompilationId() { - return compResult.getCompilationId().toString(CompilationIdentifier.Verbosity.ID); + public long getCompilationId() { + return ((TruffleCompilationIdentifier) compResult.getCompilationId()).getTruffleCompilationId(); } @Override diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleCompilationIdentifier.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleCompilationIdentifier.java index 3dfd6a1d9758..d85327bdb454 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleCompilationIdentifier.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleCompilationIdentifier.java @@ -24,12 +24,11 @@ */ package jdk.graal.compiler.truffle.hotspot; -import jdk.graal.compiler.hotspot.HotSpotCompilationIdentifier; -import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; - import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilationTask; +import jdk.graal.compiler.hotspot.HotSpotCompilationIdentifier; +import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; import jdk.vm.ci.hotspot.HotSpotCompilationRequest; /** @@ -71,4 +70,8 @@ protected StringBuilder buildID(StringBuilder sb) { return super.buildID(sb.append("Truffle")); } + @Override + public long getTruffleCompilationId() { + return getRequest().getId(); + } } diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index 75d1af6d1dfb..23a864ca55a5 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -8,6 +8,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f * The short description returned by `PolyglotException#toString` now starts with the qualified name of the metaobject of the guest exception, if the exception represents a guest exception that has a metaobject. Otherwise, it starts with the qualified name of the `PolyglotException` class. * `PolyglotException#printStackTrace` now always starts with the string returned by `PolyglotException#toString()` like for regular Java Throwable objects. * GR-54673 Added the option `engine.MaximumCompilations` to protect against too many repeated compilations of the same call target. The default value is `100`. +* GR-61448 Compilation id (`CompId`) was added to the `opt done` truffle compilation logs. This id matches the compilation id in the output of deoptimization, compilation and code cache logs on HotSpot and SubstrateVM. ## Version 24.2.0 * GR-54905 When using Truffle NFI with the Panama backend, native access must now be granted to the Truffle module instead of the NFI Panama module. Use the `--enable-native-access=org.graalvm.truffle` Java command line option to enable the native access for the NFI Panama backend. diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateCompilationIdentifier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateCompilationIdentifier.java index 6a01e72cacee..0f62e55e9f19 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateCompilationIdentifier.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/code/SubstrateCompilationIdentifier.java @@ -28,14 +28,13 @@ import jdk.graal.compiler.core.common.CompilationIdentifier; import jdk.graal.compiler.debug.GraalError; - import jdk.vm.ci.meta.ResolvedJavaMethod; public class SubstrateCompilationIdentifier implements CompilationIdentifier { private static final AtomicLong uniqueIds = new AtomicLong(); - private final long id; + protected final long id; private final ResolvedJavaMethod method; public SubstrateCompilationIdentifier(ResolvedJavaMethod method) { diff --git a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalEntryPoints.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalEntryPoints.java index c4b3ca421d73..6f8704ffd352 100644 --- a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalEntryPoints.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalEntryPoints.java @@ -42,24 +42,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import com.oracle.svm.core.heap.UnknownObjectField; -import com.oracle.svm.core.option.RuntimeOptionValues; -import com.oracle.svm.core.option.XOptions; -import com.oracle.svm.core.util.VMError; -import com.oracle.svm.graal.hotspot.LibGraalJNIMethodScope; -import com.oracle.svm.util.ClassUtil; -import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; -import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal; -import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id; -import jdk.graal.compiler.hotspot.libgraal.BuildTime; -import jdk.graal.compiler.hotspot.libgraal.RunTime; -import jdk.graal.compiler.options.OptionDescriptor; -import jdk.graal.compiler.options.OptionDescriptors; -import jdk.graal.compiler.options.OptionDescriptorsMap; -import jdk.graal.compiler.options.OptionKey; -import jdk.graal.compiler.options.OptionValues; -import jdk.graal.compiler.options.OptionsParser; -import jdk.graal.compiler.word.Word; import org.graalvm.collections.EconomicMap; import org.graalvm.jniutils.HSObject; import org.graalvm.jniutils.JNI; @@ -89,8 +71,26 @@ import org.graalvm.word.PointerBase; import com.oracle.svm.core.heap.Heap; +import com.oracle.svm.core.heap.UnknownObjectField; +import com.oracle.svm.core.option.RuntimeOptionValues; +import com.oracle.svm.core.option.XOptions; +import com.oracle.svm.core.util.VMError; +import com.oracle.svm.graal.hotspot.LibGraalJNIMethodScope; +import com.oracle.svm.util.ClassUtil; +import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id; import com.sun.management.ThreadMXBean; +import jdk.graal.compiler.hotspot.libgraal.BuildTime; +import jdk.graal.compiler.hotspot.libgraal.RunTime; +import jdk.graal.compiler.options.OptionDescriptor; +import jdk.graal.compiler.options.OptionDescriptors; +import jdk.graal.compiler.options.OptionDescriptorsMap; +import jdk.graal.compiler.options.OptionKey; +import jdk.graal.compiler.options.OptionValues; +import jdk.graal.compiler.options.OptionsParser; +import jdk.graal.compiler.word.Word; import jdk.internal.misc.Unsafe; /** @@ -234,7 +234,7 @@ static void ttyPrintf(String format, Object... args) { @CEntryPoint(name = "Java_jdk_graal_compiler_hotspot_test_LibGraalCompilationDriver_compileMethodInLibgraal", include = LibGraalFeature.IsEnabled.class) private static long compileMethod(JNIEnv jniEnv, PointerBase jclass, - @IsolateThreadContext long isolateThread, + @IsolateThreadContext long isolateThreadAddress, long methodHandle, boolean useProfilingInfo, boolean installAsDefault, @@ -293,7 +293,7 @@ private static long compileMethod(JNIEnv jniEnv, @SuppressWarnings({"unused", "try"}) private static long hashConstantOopFields(JNIEnv jniEnv, PointerBase jclass, - @IsolateThreadContext long isolateThread, + @IsolateThreadContext long isolateThreadAddress, long typeHandle, boolean useScope, int iterations, @@ -370,11 +370,11 @@ final class LibGraalScopeEntryPoints { static native long attachThreadTo(PointerBase env, PointerBase hsClazz, @IsolateContext long isolate); @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_detachThreadFrom", builtin = Builtin.DETACH_THREAD) - static native void detachThreadFrom(PointerBase env, PointerBase hsClazz, @IsolateThreadContext long isolateThread); + static native void detachThreadFrom(PointerBase env, PointerBase hsClazz, @IsolateThreadContext long isolateThreadAddress); @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_getIsolateId") @SuppressWarnings("unused") - public static long getIsolateId(PointerBase env, PointerBase jclass, @IsolateThreadContext long isolateThreadId) { + public static long getIsolateId(PointerBase env, PointerBase jclass, @IsolateThreadContext long isolateThreadAddress) { return ImageSingletons.lookup(IsolateSupport.class).getIsolateID(); } } @@ -404,6 +404,7 @@ final class LibGraalTruffleToLibGraalEntryPoints { private final MethodHandle getSuppliedString = null; private final MethodHandle getNodeCount = null; private final MethodHandle getNodeTypes = null; + private final MethodHandle getCompilationId = null; private final MethodHandle getTargetCodeSize = null; private final MethodHandle getTotalFrameSize = null; private final MethodHandle getExceptionHandlersCount = null; @@ -445,7 +446,7 @@ final class LibGraalTruffleToLibGraalEntryPoints { if (!hostMethodByName.contains(methodName)) { throw VMError.shouldNotReachHere("Missing C entry point method %s.%s corresponding to TruffleToLibGraal.Id.%s. " + "To resolve this, add `@CEntryPoint(\"Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_%s\") " + - "@TruffleToLibGraal(Id.%s) static %s(JNIEnv env, JClass jclass, @IsolateThreadContext long isolateThreadId, " + + "@TruffleToLibGraal(Id.%s) static %s(JNIEnv env, JClass jclass, @IsolateThreadContext long isolateThreadAddress, " + ")` in %s, where the and correspond to TruffleToLibGraalCalls.%s. " + "Use a MethodHandle to delegate to %s.%s.", ClassUtil.getUnqualifiedName(getClass()), methodName, id, methodName, id, methodName, getClass().getName(), methodName, @@ -497,7 +498,7 @@ private static LibGraalTruffleToLibGraalEntryPoints singleton() { @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeIsolate") @TruffleToLibGraal(Id.InitializeIsolate) - public static void initializeIsolate(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, JClass runtimeClass) { + public static void initializeIsolate(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, JClass runtimeClass) { try (JNIMethodScope s = openScope(Id.InitializeIsolate, env)) { TruffleFromLibGraalStartPoints.initializeJNI(runtimeClass); singleton().initializeIsolate.invoke(); @@ -509,7 +510,7 @@ public static void initializeIsolate(JNIEnv env, JClass hsClazz, @IsolateThreadC @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_registerRuntime") @TruffleToLibGraal(Id.RegisterRuntime) - public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, JObject truffleRuntime) { + public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, JObject truffleRuntime) { try (JNIMethodScope s = openScope(Id.RegisterRuntime, env)) { return (boolean) singleton().registerRuntime.invoke(JNIUtil.NewWeakGlobalRef(env, truffleRuntime, "TruffleCompilerRuntime").rawValue()); } catch (Throwable t) { @@ -521,7 +522,7 @@ public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @IsolateThread @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeRuntime") @TruffleToLibGraal(Id.InitializeRuntime) - public static long initializeRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, + public static long initializeRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, JObject truffleRuntime, JClass hsClassLoaderDelegate) { try (JNIMethodScope s = openScope(Id.InitializeRuntime, env)) { HSObject hsHandle = new HSObject(env, truffleRuntime, true, false); @@ -536,7 +537,7 @@ public static long initializeRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadC @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_newCompiler") @TruffleToLibGraal(Id.NewCompiler) - public static long newCompiler(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) { + public static long newCompiler(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long truffleRuntimeHandle) { try (JNIMethodScope s = openScope(Id.NewCompiler, env)) { Object truffleRuntime = LibGraalObjectHandles.resolve(truffleRuntimeHandle, Object.class); Object compiler = singleton().newCompiler.invoke(truffleRuntime); @@ -550,7 +551,7 @@ public static long newCompiler(JNIEnv env, JClass hsClazz, @IsolateThreadContext @SuppressWarnings("unused") @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeCompiler") @TruffleToLibGraal(Id.InitializeRuntime) - public static void initializeCompiler(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long compilerHandle, JObject hsCompilable, + public static void initializeCompiler(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long compilerHandle, JObject hsCompilable, boolean firstInitialization) { try (JNIMethodScope scope = openScope(Id.InitializeCompiler, env)) { Object compiler = LibGraalObjectHandles.resolve(compilerHandle, Object.class); @@ -563,7 +564,7 @@ public static void initializeCompiler(JNIEnv env, JClass hsClazz, @IsolateThread @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerConfigurationFactoryName") @TruffleToLibGraal(Id.GetCompilerConfigurationFactoryName) - public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) { + public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long truffleRuntimeHandle) { try { JNIMethodScope scope = openScope(Id.GetCompilerConfigurationFactoryName, env); try (JNIMethodScope s = scope) { @@ -582,7 +583,7 @@ public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsC @TruffleToLibGraal(Id.DoCompile) public static void doCompile(JNIEnv env, JClass hsClazz, - @IsolateThreadContext long isolateThreadId, + @IsolateThreadContext long isolateThreadAddress, long compilerHandle, JObject hsTask, JObject hsCompilable, @@ -606,7 +607,7 @@ public static void doCompile(JNIEnv env, @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_shutdown") @TruffleToLibGraal(Id.Shutdown) - public static void shutdown(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static void shutdown(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.Shutdown, env)) { Object compiler = LibGraalObjectHandles.resolve(handle, Object.class); singleton().shutdown.invoke(compiler); @@ -618,7 +619,7 @@ public static void shutdown(JNIEnv env, JClass hsClazz, @IsolateThreadContext lo @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleCallBoundaryMethod") @TruffleToLibGraal(Id.InstallTruffleCallBoundaryMethod) - public static void installTruffleCallBoundaryMethod(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle, long methodHandle) { + public static void installTruffleCallBoundaryMethod(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle, long methodHandle) { try (JNIMethodScope s = openScope(Id.InstallTruffleCallBoundaryMethod, env)) { Object compiler = LibGraalObjectHandles.resolve(handle, Object.class); singleton().installTruffleCallBoundaryMethod.invoke(compiler, methodHandle); @@ -630,7 +631,7 @@ public static void installTruffleCallBoundaryMethod(JNIEnv env, JClass hsClazz, @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleReservedOopMethod") @TruffleToLibGraal(Id.InstallTruffleReservedOopMethod) - public static void installTruffleReservedOopMethod(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle, long methodHandle) { + public static void installTruffleReservedOopMethod(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle, long methodHandle) { try (JNIMethodScope s = openScope(Id.InstallTruffleReservedOopMethod, env)) { Object compiler = LibGraalObjectHandles.resolve(handle, Object.class); singleton().installTruffleReservedOopMethod.invoke(compiler, methodHandle); @@ -642,7 +643,7 @@ public static void installTruffleReservedOopMethod(JNIEnv env, JClass hsClazz, @ @SuppressWarnings("unused") @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_pendingTransferToInterpreterOffset") @TruffleToLibGraal(Id.PendingTransferToInterpreterOffset) - public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle, JObject hsCompilable) { + public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle, JObject hsCompilable) { try (JNIMethodScope scope = openScope(Id.PendingTransferToInterpreterOffset, env)) { Object compiler = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().pendingTransferToInterpreterOffset.invoke(compiler, new HSObject(scope, hsCompilable)); @@ -655,7 +656,7 @@ public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getSuppliedString") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetSuppliedString) - public static JString getSuppliedString(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static JString getSuppliedString(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try { JNIMethodScope scope = openScope(Id.GetSuppliedString, env); try (JNIMethodScope s = scope) { @@ -677,7 +678,7 @@ public static JString getSuppliedString(JNIEnv env, JClass hsClazz, @IsolateThre @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeCount") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetNodeCount) - public static int getNodeCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getNodeCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetNodeCount, env)) { Object graphInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getNodeCount.invoke(graphInfo); @@ -690,7 +691,7 @@ public static int getNodeCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeTypes") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetNodeTypes) - public static JObjectArray getNodeTypes(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle, boolean simpleNames) { + public static JObjectArray getNodeTypes(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle, boolean simpleNames) { try { JNIMethodScope scope = openScope(Id.GetNodeTypes, env); try (JNIMethodScope s = scope) { @@ -714,10 +715,26 @@ private static JClass getStringClass(JNIEnv env) { return JNIUtil.NewGlobalRef(env, JNIUtil.findClass(env, "java/lang/String"), "Class"); } + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls2_getCompilationId") + @SuppressWarnings({"unused", "try"}) + @TruffleToLibGraal(Id.GetCompilationId) + public static long getCompilationId(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { + try { + JNIMethodScope scope = openScope(Id.GetCompilationId, env); + try (JNIMethodScope s = scope) { + Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); + return (long) singleton().getCompilationId.invoke(compilationResultInfo); + } + } catch (Throwable t) { + JNIExceptionWrapper.throwInHotSpot(env, t); + return -1; + } + } + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTargetCodeSize") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetTargetCodeSize) - public static int getTargetCodeSize(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getTargetCodeSize(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetTargetCodeSize, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getTargetCodeSize.invoke(compilationResultInfo); @@ -730,7 +747,7 @@ public static int getTargetCodeSize(JNIEnv env, JClass hsClazz, @IsolateThreadCo @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTotalFrameSize") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetTotalFrameSize) - public static int getTotalFrameSize(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getTotalFrameSize(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetTotalFrameSize, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getTotalFrameSize.invoke(compilationResultInfo); @@ -743,7 +760,7 @@ public static int getTotalFrameSize(JNIEnv env, JClass hsClazz, @IsolateThreadCo @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getExceptionHandlersCount") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetExceptionHandlersCount) - public static int getExceptionHandlersCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getExceptionHandlersCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetExceptionHandlersCount, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getExceptionHandlersCount.invoke(compilationResultInfo); @@ -756,7 +773,7 @@ public static int getExceptionHandlersCount(JNIEnv env, JClass hsClazz, @Isolate @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopointsCount") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetInfopointsCount) - public static int getInfopointsCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getInfopointsCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetInfopointsCount, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getInfopointsCount.invoke(compilationResultInfo); @@ -769,7 +786,7 @@ public static int getInfopointsCount(JNIEnv env, JClass hsClazz, @IsolateThreadC @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopoints") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetInfopoints) - public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try { JNIMethodScope scope = openScope(Id.GetInfopoints, env); try (JNIMethodScope s = scope) { @@ -792,7 +809,7 @@ public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @IsolateThr @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getMarksCount") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetMarksCount) - public static int getMarksCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getMarksCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetMarksCount, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getMarksCount.invoke(compilationResultInfo); @@ -805,7 +822,7 @@ public static int getMarksCount(JNIEnv env, JClass hsClazz, @IsolateThreadContex @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getDataPatchesCount") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetDataPatchesCount) - public static int getDataPatchesCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, long handle) { + public static int getDataPatchesCount(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, long handle) { try (JNIMethodScope s = openScope(Id.GetDataPatchesCount, env)) { Object compilationResultInfo = LibGraalObjectHandles.resolve(handle, Object.class); return (int) singleton().getDataPatchesCount.invoke(compilationResultInfo); @@ -818,7 +835,7 @@ public static int getDataPatchesCount(JNIEnv env, JClass hsClazz, @IsolateThread @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_listCompilerOptions") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.ListCompilerOptions) - public static JByteArray listCompilerOptions(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId) { + public static JByteArray listCompilerOptions(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress) { try { JNIMethodScope scope = openScope(Id.ListCompilerOptions, env); try (JNIMethodScope s = scope) { @@ -846,7 +863,7 @@ public static JByteArray listCompilerOptions(JNIEnv env, JClass hsClazz, @Isolat @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_compilerOptionExists") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.CompilerOptionExists) - public static boolean compilerOptionExists(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, JString optionName) { + public static boolean compilerOptionExists(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, JString optionName) { try (JNIMethodScope scope = openScope(Id.CompilerOptionExists, env)) { return (boolean) singleton().compilerOptionExists.invoke(JNIUtil.createString(env, optionName)); } catch (Throwable t) { @@ -858,7 +875,7 @@ public static boolean compilerOptionExists(JNIEnv env, JClass hsClazz, @IsolateT @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_validateCompilerOption") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.ValidateCompilerOption) - public static JString validateCompilerOption(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId, JString optionName, JString optionValue) { + public static JString validateCompilerOption(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadAddress, JString optionName, JString optionValue) { try { JNIMethodScope scope = openScope(Id.ValidateCompilerOption, env); try (JNIMethodScope s = scope) { @@ -875,7 +892,7 @@ public static JString validateCompilerOption(JNIEnv env, JClass hsClazz, @Isolat @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_purgePartialEvaluationCaches") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.PurgePartialEvaluationCaches) - public static void purgePartialEvaluationCaches(JNIEnv env, JClass hsClass, @IsolateThreadContext long isolateThreadId, long compilerHandle) { + public static void purgePartialEvaluationCaches(JNIEnv env, JClass hsClass, @IsolateThreadContext long isolateThreadAddress, long compilerHandle) { try (JNIMethodScope s = openScope(Id.PurgePartialEvaluationCaches, env)) { Object compiler = LibGraalObjectHandles.resolve(compilerHandle, Object.class); if (compiler != null) { @@ -889,7 +906,7 @@ public static void purgePartialEvaluationCaches(JNIEnv env, JClass hsClass, @Iso @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerVersion") @SuppressWarnings({"unused", "try"}) @TruffleToLibGraal(Id.GetCompilerVersion) - public static JString getCompilerVersion(JNIEnv env, JClass hsClass, @IsolateThreadContext long isolateThreadId) { + public static JString getCompilerVersion(JNIEnv env, JClass hsClass, @IsolateThreadContext long isolateThreadAddress) { try { JNIMethodScope scope = openScope(Id.GetCompilerVersion, env); try (JNIMethodScope s = scope) { @@ -905,7 +922,7 @@ public static JString getCompilerVersion(JNIEnv env, JClass hsClass, @IsolateThr @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalObject_releaseHandle") @SuppressWarnings("unused") - public static boolean releaseHandle(JNIEnv jniEnv, JClass jclass, @IsolateThreadContext long isolateThreadId, long handle) { + public static boolean releaseHandle(JNIEnv jniEnv, JClass jclass, @IsolateThreadContext long isolateThreadAddress, long handle) { try { ObjectHandles.getGlobal().destroy(Word.pointer(handle)); return true; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleCompilationIdentifier.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleCompilationIdentifier.java index 36fc6a63a137..6e8c961d17c7 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleCompilationIdentifier.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleCompilationIdentifier.java @@ -24,13 +24,13 @@ */ package com.oracle.svm.truffle; -import jdk.graal.compiler.debug.GraalError; -import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; - import com.oracle.svm.core.graal.code.SubstrateCompilationIdentifier; import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilationTask; +import jdk.graal.compiler.debug.GraalError; +import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; + public final class SubstrateTruffleCompilationIdentifier extends SubstrateCompilationIdentifier implements TruffleCompilationIdentifier { private final TruffleCompilationTask task; @@ -77,4 +77,8 @@ public TruffleCompilable getCompilable() { return compilable; } + @Override + public long getTruffleCompilationId() { + return id; + } } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolateAwareTruffleCompiler.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolateAwareTruffleCompiler.java index 243536523bb7..e10b0f00d721 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolateAwareTruffleCompiler.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolateAwareTruffleCompiler.java @@ -58,11 +58,11 @@ import com.oracle.truffle.compiler.TruffleCompilationTask; import com.oracle.truffle.compiler.TruffleCompilerListener; -import jdk.graal.compiler.core.common.CompilationIdentifier; import jdk.graal.compiler.core.common.SuppressFBWarnings; import jdk.graal.compiler.nodes.PauseNode; import jdk.graal.compiler.truffle.PartialEvaluator; import jdk.graal.compiler.truffle.TruffleCompilation; +import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; import jdk.graal.compiler.truffle.phases.TruffleTier; import jdk.graal.compiler.word.Word; @@ -107,7 +107,7 @@ public void doCompile(TruffleCompilationTask task, TruffleCompilable compilable, if (listener != null) { eventContext = new IsolatedEventContext(listener, compilable, task); } - ClientHandle compilationIdentifier = client.hand(delegate.createCompilationIdentifier(task, compilable)); + ClientHandle compilationIdentifier = client.hand(delegate.createCompilationIdentifier(task, compilable)); ClientHandle thrownException = doCompile0(context, (ClientIsolateThread) CurrentIsolate.getCurrentThread(), ImageHeapObjects.ref(delegate), @@ -186,7 +186,7 @@ private static ClientHandle doCompile0(@SuppressWarnings("unused") @CEnt ImageHeapRef delegateRef, ClientHandle taskHandle, ClientHandle compilableHandle, - ClientHandle compilationIdentifier, + ClientHandle compilationIdentifier, ClientHandle eventContextHandle, boolean firstCompilation) { IsolatedCompileContext.set(new IsolatedCompileContext(client)); diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationIdentifier.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationIdentifier.java index 7358ba3767fc..3549d54c7c2b 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationIdentifier.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationIdentifier.java @@ -24,8 +24,6 @@ */ package com.oracle.svm.truffle.isolated; -import jdk.graal.compiler.core.common.CompilationIdentifier; -import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; import org.graalvm.nativeimage.c.function.CEntryPoint; import com.oracle.svm.graal.isolated.ClientHandle; @@ -37,7 +35,9 @@ import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilationTask; -final class IsolatedTruffleCompilationIdentifier extends IsolatedObjectProxy implements TruffleCompilationIdentifier { +import jdk.graal.compiler.truffle.TruffleCompilationIdentifier; + +final class IsolatedTruffleCompilationIdentifier extends IsolatedObjectProxy implements TruffleCompilationIdentifier { private static final Verbosity[] VERBOSITIES = Verbosity.values(); @@ -45,7 +45,7 @@ final class IsolatedTruffleCompilationIdentifier extends IsolatedObjectProxy handle, TruffleCompilationTask task, TruffleCompilable compilable) { + IsolatedTruffleCompilationIdentifier(ClientHandle handle, TruffleCompilationTask task, TruffleCompilable compilable) { super(handle); this.task = task; this.compilable = compilable; @@ -77,10 +77,20 @@ public String toString(Verbosity verbosity) { } @CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished) - private static CompilerHandle toString0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle idHandle, int verbosityOrdinal) { - CompilationIdentifier id = IsolatedCompileClient.get().unhand(idHandle); + private static CompilerHandle toString0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle idHandle, int verbosityOrdinal) { + TruffleCompilationIdentifier id = IsolatedCompileClient.get().unhand(idHandle); String description = id.toString(VERBOSITIES[verbosityOrdinal]); return IsolatedCompileClient.get().createStringInCompiler(description); } + @Override + public long getTruffleCompilationId() { + return getTruffleCompilationId0(IsolatedCompileContext.get().getClient(), handle); + } + + @CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished) + private static long getTruffleCompilationId0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle idHandle) { + TruffleCompilationIdentifier id = IsolatedCompileClient.get().unhand(idHandle); + return id.getTruffleCompilationId(); + } } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilerEventForwarder.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilerEventForwarder.java index c8ecb1799508..aa988e3554ca 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilerEventForwarder.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilerEventForwarder.java @@ -24,7 +24,8 @@ */ package com.oracle.svm.truffle.isolated; -import com.oracle.svm.graal.isolated.IsolatedHandles; +import java.util.function.Supplier; + import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.struct.RawField; @@ -40,14 +41,13 @@ import com.oracle.svm.graal.isolated.CompilerIsolateThread; import com.oracle.svm.graal.isolated.IsolatedCompileClient; import com.oracle.svm.graal.isolated.IsolatedCompileContext; +import com.oracle.svm.graal.isolated.IsolatedHandles; import com.oracle.truffle.compiler.TruffleCompilable; import com.oracle.truffle.compiler.TruffleCompilationTask; import com.oracle.truffle.compiler.TruffleCompilerListener; import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; -import java.util.function.Supplier; - final class IsolatedTruffleCompilerEventForwarder implements TruffleCompilerListener { private final ClientHandle contextHandle; @@ -69,6 +69,7 @@ public void onTruffleTierFinished(TruffleCompilable compilable, TruffleCompilati public void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task, GraphInfo graph, CompilationResultInfo info, int tier) { IsolatedCompilationResultData data = StackValue.get(IsolatedCompilationResultData.class); data.setOriginalObjectHandle(IsolatedCompileContext.get().hand(info)); + data.setCompilationId(info.getCompilationId()); data.setTargetCodeSize(info.getTargetCodeSize()); data.setTotalFrameSize(info.getTotalFrameSize()); data.setExceptionHandlersCount(info.getExceptionHandlersCount()); @@ -170,6 +171,7 @@ private static ClientHandle getNodeTypes0(@SuppressWarnings("unused") final class IsolatedCompilationResultInfo implements CompilationResultInfo { private CompilerHandle originalObjectHandle; + private final long compilationId; private final int targetCodeSize; private final int totalFrameSize; private final int exceptionHandlersCount; @@ -179,6 +181,7 @@ final class IsolatedCompilationResultInfo implements CompilationResultInfo { IsolatedCompilationResultInfo(IsolatedCompilationResultData data) { originalObjectHandle = data.getOriginalObjectHandle(); + compilationId = data.getCompilationId(); targetCodeSize = data.getTargetCodeSize(); totalFrameSize = data.getTotalFrameSize(); exceptionHandlersCount = data.getExceptionHandlersCount(); @@ -187,6 +190,11 @@ final class IsolatedCompilationResultInfo implements CompilationResultInfo { dataPatchesCount = data.getDataPatchesCount(); } + @Override + public long getCompilationId() { + return compilationId; + } + @Override public int getTargetCodeSize() { return targetCodeSize; @@ -238,6 +246,12 @@ interface IsolatedCompilationResultData extends PointerBase { @RawField void setOriginalObjectHandle(CompilerHandle value); + @RawField + long getCompilationId(); + + @RawField + void setCompilationId(long compilationId); + @RawField int getTargetCodeSize(); diff --git a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/CompilationIdLogTest.java b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/CompilationIdLogTest.java new file mode 100644 index 000000000000..22b7570de5e0 --- /dev/null +++ b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/CompilationIdLogTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.oracle.truffle.api.test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.graalvm.polyglot.Context; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; + +import com.oracle.truffle.tck.tests.TruffleTestAssumptions; + +public class CompilationIdLogTest { + + @Test + public void testCompilationIdAvailable() throws IOException { + /* + * This test runs with jargraal, libgraal, polyglot isolates, and on SVM. + */ + Runtime.Version jdkVersion = Runtime.version(); + Assume.assumeTrue("Not running with optimizing runtime", TruffleTestAssumptions.isOptimizingRuntime()); + Assume.assumeTrue("Too old JDK feature version", jdkVersion.feature() >= 25); + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); + Context context = Context.newBuilder().out(out).err(out).allowExperimentalOptions(true).option("engine.CompileImmediately", "true").option("engine.BackgroundCompilation", + "false").option("engine.TraceCompilation", "true").build()) { + context.eval("instrumentation-test-language", "CONSTANT(true)"); + Pattern compilationIdPattern = Pattern.compile("\\[engine] opt done.*CompId \\d+"); + Matcher compilationIdMatcher = compilationIdPattern.matcher(out.toString()); + Assert.assertTrue(out.toString(), compilationIdMatcher.find()); + } + } +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java index 761bbcafdada..7b4498f60998 100644 --- a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java @@ -70,8 +70,12 @@ interface GraphInfo { * Summary information for the result of a compilation. */ interface CompilationResultInfo { - /** Gets the ID of the compilation. */ - String getCompilationId(); + /** + * Gets the ID of the compilation. + */ + default long getCompilationId() { + return -1; + } /** * Gets the size of the machine code generated. diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleToLibGraal.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleToLibGraal.java index 23babcbdbac3..fb8fefffbaf2 100644 --- a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleToLibGraal.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleToLibGraal.java @@ -73,6 +73,7 @@ enum Id { GetNodeCount, GetNodeTypes, GetSuppliedString, + GetCompilationId, GetTargetCodeSize, GetTotalFrameSize, InitializeIsolate, diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java index 5cd044e8999c..e5e8223a1808 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java @@ -47,7 +47,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; -import com.oracle.truffle.runtime.ModulesSupport; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; @@ -56,6 +55,7 @@ import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; import com.oracle.truffle.runtime.AbstractCompilationTask; import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.ModulesSupport; import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.runtime.OptimizedTruffleRuntime; import com.oracle.truffle.runtime.jfr.CompilationEvent; @@ -171,6 +171,7 @@ public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilation event.setGraalNodeCount(graph.getNodeCount()); event.setPartialEvaluationNodeCount(data.partialEvalNodeCount); event.setPartialEvaluationTime((data.timePartialEvaluationFinished - data.timeCompilationStarted) / 1_000_000); + event.setCompilationId(TraceCompilationListener.getCompilationId(result)); event.publish(); currentCompilation.remove(); } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java index 43885610c1eb..21416d2612ed 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java @@ -40,6 +40,8 @@ */ package com.oracle.truffle.runtime.debug; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; @@ -65,6 +67,17 @@ * for each event. */ public final class TraceCompilationListener extends AbstractGraalTruffleRuntimeListener { + private static final Method GET_COMPILATION_ID_METHOD; + + static { + Method getCompilationIdMethod = null; + try { + getCompilationIdMethod = CompilationResultInfo.class.getMethod("getCompilationId"); + } catch (NoSuchMethodException e) { + // deliberately ignored, getCompilationIdMethod is null in this case + } + GET_COMPILATION_ID_METHOD = getCompilationIdMethod; + } private final ThreadLocal currentCompilation = new ThreadLocal<>(); @@ -77,18 +90,19 @@ public static void install(OptimizedTruffleRuntime runtime) { } public static final String TIER_FORMAT = "Tier %d"; - private static final String QUEUE_FORMAT = "Queue: Size %4d Change %c%-2d Load %5.2f Time %5dus "; - private static final String TARGET_FORMAT = "engine=%-2d TargetId=%-5d %-50s "; + private static final String QUEUE_FORMAT = "Queue: Size %4d Change %c%-2d Load %5.2f Time %5dus "; + private static final String TARGET_FORMAT = "engine=%-2d id=%-5d %-50s "; public static final String COUNT_THRESHOLD_FORMAT = "Count/Thres %9d/%9d"; private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").withZone(ZoneId.of("UTC")); // @formatter:off private static final String QUEUED_FORMAT = "opt queued " + TARGET_FORMAT + "|" + TIER_FORMAT + "|" + COUNT_THRESHOLD_FORMAT + "|" + QUEUE_FORMAT + "|UTC %s|Src %s"; private static final String UNQUEUED_FORMAT = "opt unque. " + TARGET_FORMAT + "|" + TIER_FORMAT + "|" + COUNT_THRESHOLD_FORMAT + "|" + QUEUE_FORMAT + "|UTC %s|Src %s|Reason %s"; private static final String START_FORMAT = "opt start " + TARGET_FORMAT + "|" + TIER_FORMAT + "|Priority %9d|Rate %.6f|" + QUEUE_FORMAT + "|UTC %s|Src %s"; - private static final String DONE_FORMAT = "opt done " + TARGET_FORMAT + "|" + TIER_FORMAT + "|Time %18s|AST %4d|Inlined %3dY %3dN|IR %6d/%6d|CompilationId %s|CodeSize %7d|Addr 0x%012x|UTC %s|Src %s"; + private static final String DONE_FORMAT = "opt done " + TARGET_FORMAT + "|" + TIER_FORMAT + "|Time %18s|AST %4d|Inlined %3dY %3dN|IR %6d/%6d|CodeSize %7d|Addr 0x%012x|CompId %-7s|UTC %s|Src %s"; private static final String FAILED_FORMAT = "opt failed " + TARGET_FORMAT + "|" + TIER_FORMAT + "|Time %18s|Reason: %s|UTC %s|Src %s"; - private static final String INV_FORMAT = "opt inval. " + TARGET_FORMAT + " |UTC %s|Src %s|Reason %s"; - private static final String DEOPT_FORMAT = "opt deopt " + TARGET_FORMAT + "| |UTC %s|Src %s"; + private static final String PADDING = " "; + private static final String INV_FORMAT = "opt inval. " + TARGET_FORMAT + " " + PADDING + "|UTC %s|Src %s|Reason %s"; + private static final String DEOPT_FORMAT = "opt deopt " + TARGET_FORMAT + "|" + PADDING + "|UTC %s|Src %s"; // @formatter:on @Override @@ -243,14 +257,33 @@ public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilation inlinedAndDispatched[1], compilation.nodeCountPartialEval, graph == null ? 0 : graph.getNodeCount(), - result == null ? 0 : result.getCompilationId(), result == null ? 0 : result.getTargetCodeSize(), target.getCodeAddress(), + result == null ? "n/a" : getCompilationId(result), TIME_FORMATTER.format(ZonedDateTime.now()), formatSourceSection(safeSourceSection(target)))); currentCompilation.remove(); } + static String getCompilationId(CompilationResultInfo result) { + /* + * When the CompilationResultInfo class is from GraalVM, the getCompilationId method might + * not be there. + */ + String toRet = "n/a"; + if (GET_COMPILATION_ID_METHOD != null) { + try { + long compilationId = (long) GET_COMPILATION_ID_METHOD.invoke(result); + if (compilationId >= 0) { + toRet = String.valueOf(compilationId); + } + } catch (IllegalAccessException | InvocationTargetException e) { + // deliberately ignored, the compilationId is n/a in this case + } + } + return toRet; + } + private SourceSection safeSourceSection(OptimizedCallTarget target) { try { return target.getRootNode().getSourceSection(); diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java index 946e9e7b3824..ed42c8ebd78a 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java @@ -53,6 +53,11 @@ final class LibGraalCompilationResultInfo extends LibGraalScopedHandle implement super(handle, LibGraalCompilationResultInfo.class); } + @Override + public long getCompilationId() { + return TruffleToLibGraalCalls2.getCompilationId(getIsolateThread(), getHandle()); + } + @Override public int getTargetCodeSize() { return TruffleToLibGraalCalls.getTargetCodeSize(getIsolateThread(), getHandle()); @@ -87,8 +92,4 @@ public int getMarksCount() { public int getDataPatchesCount() { return TruffleToLibGraalCalls.getDataPatchesCount(getIsolateThread(), getHandle()); } - - public String getCompilationId() { - return "LibGraal"; - } } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java index 2311fb04bf23..a4bc3049c362 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java @@ -108,13 +108,13 @@ public long getHandle() { } /** - * Releases {@code handle} in the isolate denoted by {@code isolateThreadId}. + * Releases {@code handle} in the isolate denoted by {@code isolateThreadAddress}. * * @return {@code false} if {@code} is not a valid handle in the isolate */ // Implementation: // com.oracle.svm.graal.hotspot.libgraal.LibGraalTruffleToLibGraalEntryPoints.releaseHandle - static native boolean releaseHandle(long isolateThreadId, long handle); + static native boolean releaseHandle(long isolateThreadAddress, long handle); @Override public String toString() { diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java index 2f8fe98420c1..ae7f4fcca40e 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java @@ -46,8 +46,8 @@ import com.oracle.truffle.compiler.TruffleCompilationSupport; import com.oracle.truffle.compiler.TruffleCompiler; import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; -import com.oracle.truffle.compiler.TruffleCompilerRuntime; import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor.Type; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntime; import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope.DetachAction; @@ -70,6 +70,11 @@ public LibGraalTruffleCompilationSupport() { public static void initializeIsolate(long isolateThreadId) { runtime().registerNativeMethods(TruffleToLibGraalCalls.class); + try { + runtime().registerNativeMethods(TruffleToLibGraalCalls2.class); + } catch (UnsatisfiedLinkError e) { + // deliberately ignored, the entry points might not be there + } TruffleToLibGraalCalls.initializeIsolate(isolateThreadId, LibGraalTruffleCompilationSupport.class); } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java index a1b48781c269..ea178035ad05 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java @@ -79,7 +79,7 @@ final class TruffleToLibGraalCalls { * Invoked first time the isolate is attached. */ @TruffleToLibGraal(Id.InitializeIsolate) - static native boolean initializeIsolate(long isolateThreadId, Class runtimeClass); + static native boolean initializeIsolate(long isolateThreadAddress, Class runtimeClass); /** * Registers a Truffle runtime. Returns true if this was the first runtime @@ -87,81 +87,81 @@ final class TruffleToLibGraalCalls { * {@link #registerRuntime(long, Object)}. */ @TruffleToLibGraal(RegisterRuntime) - static native boolean registerRuntime(long isolateThreadId, Object truffleRuntime); + static native boolean registerRuntime(long isolateThreadAddress, Object truffleRuntime); @TruffleToLibGraal(InitializeRuntime) - static native long initializeRuntime(long isolateThreadId, TruffleCompilerRuntime truffleRuntime, Class classLoaderDelegate); + static native long initializeRuntime(long isolateThreadAddress, TruffleCompilerRuntime truffleRuntime, Class classLoaderDelegate); @TruffleToLibGraal(Id.ListCompilerOptions) - static native byte[] listCompilerOptions(long isolateThreadId); + static native byte[] listCompilerOptions(long isolateThreadAddress); @TruffleToLibGraal(Id.CompilerOptionExists) - static native boolean compilerOptionExists(long isolateThreadId, String optionName); + static native boolean compilerOptionExists(long isolateThreadAddress, String optionName); @TruffleToLibGraal(Id.ValidateCompilerOption) - static native String validateCompilerOption(long isolateThreadId, String optionName, String optionValue); + static native String validateCompilerOption(long isolateThreadAddress, String optionName, String optionValue); @TruffleToLibGraal(GetCompilerConfigurationFactoryName) - static native String getCompilerConfigurationFactoryName(long isolateThreadId, long truffleRuntimeHandle); + static native String getCompilerConfigurationFactoryName(long isolateThreadAddress, long truffleRuntimeHandle); @TruffleToLibGraal(NewCompiler) - static native long newCompiler(long isolateThreadId, long truffleRuntimeHandle); + static native long newCompiler(long isolateThreadAddress, long truffleRuntimeHandle); @TruffleToLibGraal(InitializeCompiler) - static native void initializeCompiler(long isolateThreadId, long compilerHandle, TruffleCompilable compilable, boolean firstInitialization); + static native void initializeCompiler(long isolateThreadAddress, long compilerHandle, TruffleCompilable compilable, boolean firstInitialization); @TruffleToLibGraal(DoCompile) - static native void doCompile(long isolateThreadId, + static native void doCompile(long isolateThreadAddress, long compilerHandle, TruffleCompilationTask task, TruffleCompilable compilable, TruffleCompilerListener listener); @TruffleToLibGraal(InstallTruffleCallBoundaryMethod) - static native void installTruffleCallBoundaryMethod(long isolateThreadId, long handle, long methodHandle); + static native void installTruffleCallBoundaryMethod(long isolateThreadAddress, long handle, long methodHandle); @TruffleToLibGraal(InstallTruffleReservedOopMethod) - static native void installTruffleReservedOopMethod(long isolateThreadId, long handle, long methodHandle); + static native void installTruffleReservedOopMethod(long isolateThreadAddress, long handle, long methodHandle); @TruffleToLibGraal(PendingTransferToInterpreterOffset) - static native int pendingTransferToInterpreterOffset(long isolateThreadId, long handle, TruffleCompilable compilable); + static native int pendingTransferToInterpreterOffset(long isolateThreadAddress, long handle, TruffleCompilable compilable); @TruffleToLibGraal(Shutdown) - static native void shutdown(long isolateThreadId, long handle); + static native void shutdown(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetNodeCount) - static native int getNodeCount(long isolateThreadId, long handle); + static native int getNodeCount(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetNodeTypes) - static native String[] getNodeTypes(long isolateThreadId, long handle, boolean simpleNames); + static native String[] getNodeTypes(long isolateThreadAddress, long handle, boolean simpleNames); @TruffleToLibGraal(GetSuppliedString) - static native String getSuppliedString(long isolateThreadId, long handle); + static native String getSuppliedString(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetTargetCodeSize) - static native int getTargetCodeSize(long isolateThreadId, long handle); + static native int getTargetCodeSize(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetTotalFrameSize) - static native int getTotalFrameSize(long isolateThreadId, long handle); + static native int getTotalFrameSize(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetExceptionHandlersCount) - static native int getExceptionHandlersCount(long isolateThreadId, long handle); + static native int getExceptionHandlersCount(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetInfopointsCount) - static native int getInfopointsCount(long isolateThreadId, long handle); + static native int getInfopointsCount(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetInfopoints) - static native String[] getInfopoints(long isolateThreadId, long handle); + static native String[] getInfopoints(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetMarksCount) - static native int getMarksCount(long isolateThreadId, long handle); + static native int getMarksCount(long isolateThreadAddress, long handle); @TruffleToLibGraal(GetDataPatchesCount) - static native int getDataPatchesCount(long isolateThreadId, long handle); + static native int getDataPatchesCount(long isolateThreadAddress, long handle); @TruffleToLibGraal(PurgePartialEvaluationCaches) - static native void purgePartialEvaluationCaches(long isolateThreadId, long compilerHandle); + static native void purgePartialEvaluationCaches(long isolateThreadAddress, long compilerHandle); @TruffleToLibGraal(GetCompilerVersion) - static native String getCompilerVersion(long isolateThreadId); + static native String getCompilerVersion(long isolateThreadAddress); } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls2.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls2.java new file mode 100644 index 000000000000..b5a1b35d0c15 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls2.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.oracle.truffle.runtime.hotspot.libgraal; + +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetCompilationId; + +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal; + +final class TruffleToLibGraalCalls2 { + + @TruffleToLibGraal(GetCompilationId) + static native long getCompilationId(long isolateThreadAddress, long handle); +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationEvent.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationEvent.java index 1d4895d9cea8..7672e602ca3e 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationEvent.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationEvent.java @@ -66,4 +66,6 @@ public interface CompilationEvent extends RootFunctionEvent { void setPartialEvaluationNodeCount(int count); void setPartialEvaluationTime(long time); + + void setCompilationId(String id); } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java index 63a944a1f5ef..12d22189642b 100644 --- a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java @@ -79,6 +79,8 @@ class CompilationEventImpl extends RootFunctionEventImpl implements CompilationE @Label("Tier") @Description("The Tier of the Truffle Compiler") public int truffleTier; + @Label("Compilation Id") @Description("The VM Id of the Compilation") public String compilationId; + private transient CompilationFailureEventImpl failure; @Override @@ -148,6 +150,11 @@ public void setPartialEvaluationTime(long time) { this.peTime = time; } + @Override + public void setCompilationId(String id) { + this.compilationId = id; + } + @Override public void publish() { super.publish();