diff --git a/compiler/mx.compiler/mx_compiler.py b/compiler/mx.compiler/mx_compiler.py index 1f89925550bf..a4b99da5e641 100644 --- a/compiler/mx.compiler/mx_compiler.py +++ b/compiler/mx.compiler/mx_compiler.py @@ -704,7 +704,11 @@ def _unittest_config_participant(config): # for the junit harness which uses reflection to find @Test methods. In addition, the # tests widely use JVMCI classes so JVMCI needs to also export all its packages to # ALL-UNNAMED. - mainClassArgs.extend(['-JUnitOpenPackages', 'jdk.internal.vm.ci/*=jdk.internal.vm.compiler,ALL-UNNAMED']) + + mainClassArgs.extend(['-JUnitOpenPackages', 'jdk.internal.vm.ci/*=org.graalvm.truffle.runtime,jdk.internal.vm.compiler,ALL-UNNAMED']) + mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.truffle/*=ALL-UNNAMED']) + mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.truffle.compiler/*=ALL-UNNAMED']) + mainClassArgs.extend(['-JUnitOpenPackages', 'org.graalvm.truffle.runtime/*=ALL-UNNAMED']) limited_modules = None for arg in vmArgs: @@ -1294,7 +1298,6 @@ class GraalConfig: def __init__(self): self.jvmci_dists = [] self.jvmci_jars = [] - self.jvmci_parent_dists = [] self.jvmci_parent_jars = [] self.boot_dists = [] self.boot_jars = [] @@ -1312,10 +1315,9 @@ def __init__(self): self.boot_dists.append(d) self.boot_jars.append(d.classpath_repr()) - self.jvmci_parent_dists = [mx.distribution('truffle:TRUFFLE_API')] - self.jvmci_parent_jars = [jar.classpath_repr() for jar in self.jvmci_parent_dists] + self.jvmci_parent_jars = [] - self.dists = self.jvmci_dists + self.jvmci_parent_dists + self.boot_dists + self.dists = self.jvmci_dists + self.boot_dists self.jars = self.jvmci_jars + self.jvmci_parent_jars + self.boot_jars self.dists_dict = {e.suite.name + ':' + e.name : e for e in self.dists} @@ -1328,7 +1330,6 @@ def _jvmci_jars(): return [ 'compiler:GRAAL', 'compiler:GRAAL_MANAGEMENT', - 'compiler:GRAAL_TRUFFLE_JFR_IMPL', ] # The community compiler component diff --git a/compiler/mx.compiler/suite.py b/compiler/mx.compiler/suite.py index b000c64bf1c2..8fdd27012b18 100644 --- a/compiler/mx.compiler/suite.py +++ b/compiler/mx.compiler/suite.py @@ -163,7 +163,7 @@ "sourceDirs" : ["src"], "dependencies" : [ "sdk:GRAAL_SDK", - "truffle:TRUFFLE_API", + "truffle:TRUFFLE_COMPILER", ], "requires" : [ "jdk.internal.vm.ci", @@ -192,11 +192,8 @@ "org.graalvm.compiler.core.common.CompilerProfiler", "org.graalvm.compiler.truffle.compiler.substitutions.GraphBuilderInvocationPluginProvider", "org.graalvm.compiler.truffle.compiler.phases.inlining.InliningPolicyProvider", - "org.graalvm.compiler.truffle.jfr.EventFactory.Provider", - "org.graalvm.compiler.truffle.runtime.FloodControlHandler", ], "annotationProcessors" : [ - "truffle:TRUFFLE_DSL_PROCESSOR", "GRAAL_PROCESSOR" ], "checkPackagePrefix": "false", @@ -209,7 +206,6 @@ "org.graalvm.libgraal.jni", "org.graalvm.compiler.replacements", "org.graalvm.compiler.hotspot.test", - "org.graalvm.nativebridge.processor.test", "org.graalvm.compiler.replacements.test", "org.graalvm.compiler.api.directives.test", "org.graalvm.compiler.test", @@ -218,31 +214,10 @@ "org.graalvm.compiler.loop.test", "org.graalvm.compiler.core.aarch64.test", "org.graalvm.compiler.jtt", - "org.graalvm.compiler.truffle.options", - "org.graalvm.compiler.truffle.jfr", - "org.graalvm.compiler.truffle.jfr.impl", - "org.graalvm.compiler.truffle.runtime", "org.graalvm.compiler.truffle.test", - "org.graalvm.compiler.truffle.common.hotspot.libgraal", - "org.graalvm.compiler.truffle.compiler.hotspot.libgraal", ], }, - "jdk.internal.vm.compiler.truffle.jfr" : { - "subDir" : "src", - "sourceDirs" : ["src"], - "dependencies" : [ - "jdk.internal.vm.compiler", - ], - "requires" : [ - "jdk.jfr" - ], - "checkPackagePrefix": "false", - "checkstyle" : "jdk.internal.vm.compiler", - "javaCompliance" : "17+", - "jacoco" : "exclude", - }, - "jdk.internal.vm.compiler.processor" : { "subDir" : "src", "sourceDirs" : ["src"], @@ -265,6 +240,7 @@ "JAVA_ALLOCATION_INSTRUMENTER", "truffle:TRUFFLE_SL_TEST", "truffle:TRUFFLE_TEST", + "truffle:TRUFFLE_RUNTIME", ], "requires" : [ "jdk.unsupported", @@ -272,7 +248,7 @@ "java.logging", "java.instrument", "java.management", - "jdk.jfr" + "jdk.jfr", ], "requiresConcealed" : { "java.base" : [ @@ -306,39 +282,6 @@ "jacoco" : "exclude", }, - "org.graalvm.nativebridge.processor" : { - "subDir" : "src", - "sourceDirs" : ["src"], - "dependencies" : [ - "jdk.internal.vm.compiler.processor", - ], - "requires" : [ - "java.compiler" - ], - "annotationProcessors" : [ - ], - "checkstyle" : "jdk.internal.vm.compiler", - "javaCompliance" : "17+", - "workingSets" : "API,Graal", - }, - - "org.graalvm.nativebridge.processor.test" : { - "subDir" : "src", - "sourceDirs" : ["src"], - "dependencies" : [ - "jdk.internal.vm.compiler", - "mx:JUNIT", - ], - "annotationProcessors" : [ - "GRAAL_NATIVEBRIDGE_PROCESSOR", - ], - "checkstyle" : "jdk.internal.vm.compiler", - "javaCompliance" : "17+", - "workingSets" : "Graal,Test", - "jacoco" : "exclude", - "testProject" : True, - }, - "org.graalvm.compiler.management" : { "subDir" : "src", "sourceDirs" : ["src"], @@ -436,56 +379,6 @@ # ------------- GraalTruffle ------------- - "org.graalvm.compiler.truffle.compiler.hotspot.libgraal" : { - "subDir" : "src", - "sourceDirs" : ["src"], - "dependencies" : [ - "jdk.internal.vm.compiler", - ], - "requiresConcealed" : { - "jdk.internal.vm.ci" : [ - "jdk.vm.ci.meta", - "jdk.vm.ci.code", - "jdk.vm.ci.runtime", - "jdk.vm.ci.hotspot", - ], - }, - "jacoco" : "exclude", # GR-13965 - "checkstyle" : "jdk.internal.vm.compiler", - "javaCompliance" : "17+", - "annotationProcessors" : [ - "GRAAL_PROCESSOR", - ], - }, - - "org.graalvm.compiler.truffle.libgraal.truffleattach" : { - "subDir" : "src", - "native" : "shared_lib", - "deliverable" : "truffleattach", - "use_jdk_headers" : True, - "buildDependencies" : [ - ], - "os_arch" : { - "windows" : { - "" : { - "cflags" : ["--std=c++11"] - } - }, - "linux" : { - "" : { - "cflags" : ["--std=c++11", "-g", "-Wall", "-Werror", "-D_GNU_SOURCE"], - "ldlibs" : ["-ldl"], - }, - }, - "" : { - "" : { - "cflags" : ["--std=c++11", "-g", "-Wall", "-Werror"], - "ldlibs" : ["-ldl"], - }, - }, - }, - }, - "org.graalvm.compiler.truffle.test.jdk21" : { "subDir" : "src", "sourceDirs" : ["src"], @@ -552,7 +445,6 @@ "subDir" : "src", "dependencies" : [ "jdk.internal.vm.compiler.test", - "org.graalvm.nativebridge.processor.test", "org.graalvm.compiler.hotspot.jdk20.test", "org.graalvm.compiler.hotspot.jdk21.test", ], @@ -560,6 +452,8 @@ "GRAAL", "truffle:TRUFFLE_SL_TEST", "truffle:TRUFFLE_TEST", + "truffle:TRUFFLE_COMPILER", + "truffle:TRUFFLE_RUNTIME", "regex:TREGEX" ], "exclude" : [ @@ -570,34 +464,6 @@ "maven": False, }, - "GRAAL_TRUFFLE_JFR_IMPL" : { - # This distribution defines a module. - "moduleInfo" : { - "name" : "jdk.internal.vm.compiler.truffle.jfr", - }, - "subDir" : "src", - "dependencies" : [ - "jdk.internal.vm.compiler.truffle.jfr", - ], - "distDependencies" : [ - "GRAAL", - ], - "maven": False, - }, - - "GRAAL_TRUFFLE_COMPILER_LIBGRAAL": { - "subDir" : "src", - "dependencies" : [ - "org.graalvm.compiler.truffle.compiler.hotspot.libgraal", - ], - - "distDependencies" : [ - "GRAAL", - ], - "maven": False, - "javaCompliance" : "17+", - }, - "GRAAL_PROCESSOR" : { "subDir": "src", "dependencies" : [ @@ -606,15 +472,6 @@ "maven": False, }, - "GRAAL_NATIVEBRIDGE_PROCESSOR" : { - "subDir" : "src", - "dependencies" : [ - "org.graalvm.nativebridge.processor" - ], - "distDependencies" : ["GRAAL_PROCESSOR"], - "maven": False, - }, - "GRAAL" : { # This distribution defines a module. "moduleInfo" : { @@ -632,12 +489,9 @@ "org.graalvm.compiler.options to org.graalvm.nativeimage.driver,org.graalvm.nativeimage.junitsupport", "org.graalvm.compiler.phases.common to org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure", "org.graalvm.compiler.serviceprovider to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.diagnostics", - "org.graalvm.compiler.truffle.jfr to jdk.internal.vm.compiler.truffle.jfr", "org.graalvm.util.json to org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure,org.graalvm.nativeimage.driver", ], "uses" : [ - "com.oracle.truffle.api.impl.TruffleLocator", - "com.oracle.truffle.api.object.LayoutFactory", "org.graalvm.compiler.code.DisassemblerProvider", "org.graalvm.compiler.core.match.MatchStatementSet", "org.graalvm.compiler.debug.DebugHandlersFactory", @@ -651,10 +505,6 @@ "org.graalvm.compiler.serviceprovider.JMXService", "org.graalvm.compiler.truffle.compiler.hotspot.TruffleCallBoundaryInstrumentationFactory", "org.graalvm.compiler.truffle.compiler.substitutions.GraphBuilderInvocationPluginProvider", - "org.graalvm.compiler.truffle.runtime.LoopNodeFactory", - "org.graalvm.compiler.truffle.runtime.TruffleTypes", - "org.graalvm.compiler.truffle.runtime.EngineCacheSupport", - "org.graalvm.home.HomeFinder", ], }, "subDir" : "src", @@ -663,7 +513,7 @@ ], "distDependencies" : [ "sdk:GRAAL_SDK", - "truffle:TRUFFLE_API" + "truffle:TRUFFLE_COMPILER", ], "allowsJavadocWarnings": True, "description": "The GraalVM compiler and the Graal-truffle optimizer.", @@ -740,33 +590,6 @@ }, }, - "TRUFFLE_LIBGRAAL_TRUFFLEATTACH" : { - "native" : True, - "platformDependent" : True, - "platforms" : [ - "linux-amd64", - "linux-aarch64", - "darwin-amd64", - "darwin-aarch64", - "windows-amd64", - ], - "layout" : { - "bin/" : "dependency:org.graalvm.compiler.truffle.libgraal.truffleattach", - }, - "description" : "Contains a library to attach Truffle runtime to jvmci runtime.", - "maven": True, - }, - - "TRUFFLE_LIBGRAAL_TRUFFLEATTACH_GRAALVM_SUPPORT" : { - "native" : True, - "platformDependent" : True, - "layout" : { - "./" : ["dependency:org.graalvm.compiler.truffle.libgraal.truffleattach"], - }, - "description" : "Truffle attach library support distribution for the GraalVM", - "maven" : False, - }, - "GRAAL_PROFDIFF": { "subDir" : "src", "dependencies" : [ diff --git a/compiler/src/jdk.internal.vm.compiler.processor/src/META-INF/services/javax.annotation.processing.Processor b/compiler/src/jdk.internal.vm.compiler.processor/src/META-INF/services/javax.annotation.processing.Processor index 36e6d452cdfb..3bdbb17e6012 100644 --- a/compiler/src/jdk.internal.vm.compiler.processor/src/META-INF/services/javax.annotation.processing.Processor +++ b/compiler/src/jdk.internal.vm.compiler.processor/src/META-INF/services/javax.annotation.processing.Processor @@ -2,7 +2,6 @@ org.graalvm.compiler.replacements.processor.ReplacementsAnnotationProcessor org.graalvm.compiler.nodeinfo.processor.GraphNodeProcessor org.graalvm.compiler.lir.processor.IntrinsicStubProcessor org.graalvm.compiler.lir.processor.StubPortProcessor -org.graalvm.compiler.truffle.compiler.hotspot.libgraal.processor.TruffleFromLibGraalProcessor org.graalvm.compiler.core.match.processor.MatchProcessor org.graalvm.compiler.options.processor.OptionProcessor org.graalvm.compiler.serviceprovider.processor.ServiceProviderProcessor diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsage.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsage.java index 87a931dcaa9c..6e532341187f 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsage.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyBailoutUsage.java @@ -52,11 +52,11 @@ private static String getPackageName(Class c) { getPackageName(PermanentBailoutException.class), "jdk.vm.ci", - // Allows GraalTruffleRuntime.handleAnnotationFailure to throw - // a BailoutException since the org.graalvm.compiler.truffle.runtime + // Allows OptimizedTruffleRuntime.handleAnnotationFailure to throw + // a BailoutException since the com.oracle.truffle.runtime // project can not see the PermanentBailoutException or // RetryableBailoutException types. - "org.graalvm.compiler.truffle.runtime" + "com.oracle.truffle.runtime" }; } catch (Throwable t) { throw new GraalError(t); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifySystemPropertyUsage.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifySystemPropertyUsage.java index 1563511ef72a..854976b2df4a 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifySystemPropertyUsage.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifySystemPropertyUsage.java @@ -88,7 +88,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) { // The main method in JVMCIVersionCheck is only called from the shell return; } else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.polyglot") || - packageName.startsWith("org.graalvm.home") || packageName.equals("org.graalvm.compiler.truffle.runtime.hotspot")) { + packageName.startsWith("org.graalvm.home") || packageName.equals("com.oracle.truffle.runtime.hotspot")) { // Truffle, SDK and Truffle runtime do not depend on JVMCI so they cannot use // Services.getSavedProperties() return; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyUnsafeAccess.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyUnsafeAccess.java index 11009e0bb763..fe46883700ca 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyUnsafeAccess.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/core/test/VerifyUnsafeAccess.java @@ -62,8 +62,8 @@ protected void verify(StructuredGraph graph, CoreProviders context) { caller.getName().equals("initUnsafe")) { // This is the blessed way access Unsafe in Graal and JVMCI return; - } else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("org.graalvm.compiler.truffle.runtime")) { - // Truffle and GraalTruffleRuntime do not depend on Graal and so cannot use + } else if (packageName.startsWith("com.oracle.truffle") || packageName.startsWith("com.oracle.truffle.runtime")) { + // Truffle and OptimizedTruffleRuntime do not depend on Graal and so cannot use // GraalUnsafeAccess return; } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java index 8bbfe78573b4..e3bb85a7c0ff 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/CompileTheWorld.java @@ -113,11 +113,12 @@ import org.graalvm.compiler.options.OptionsParser; import org.graalvm.compiler.serviceprovider.GraalServices; import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.LibGraalIsolate; -import org.graalvm.libgraal.LibGraalScope; import org.graalvm.util.OptionsEncoder; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraal; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalIsolate; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope; + import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; import jdk.vm.ci.hotspot.HotSpotCompilationRequest; import jdk.vm.ci.hotspot.HotSpotInstalledCode; @@ -138,6 +139,8 @@ public final class CompileTheWorld { static { ModuleSupport.exportAndOpenAllPackagesToUnnamed("jdk.internal.vm.compiler"); + ModuleSupport.exportAndOpenAllPackagesToUnnamed("org.graalvm.truffle"); + ModuleSupport.exportAndOpenAllPackagesToUnnamed("org.graalvm.truffle.runtime"); } /** diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/LibGraalCompilerTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/LibGraalCompilerTest.java index 042f3d38dca2..1cbf88e21789 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/LibGraalCompilerTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/hotspot/test/LibGraalCompilerTest.java @@ -25,11 +25,12 @@ package org.graalvm.compiler.hotspot.test; import org.graalvm.compiler.hotspot.HotSpotGraalServices; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.LibGraalScope; 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.vm.ci.meta.ResolvedJavaType; /** diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AOTSupportCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AOTSupportCompilationTest.java index 79dae2f2db64..526898b28951 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AOTSupportCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AOTSupportCompilationTest.java @@ -26,7 +26,6 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.java.MethodCallTargetNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Test; import org.openjdk.jmh.annotations.TearDown; @@ -43,6 +42,7 @@ import com.oracle.truffle.api.dsl.test.AOTSupportTestFactory.AOTManualLibrarySingleLimitNodeGen; import com.oracle.truffle.api.dsl.test.AOTSupportTestFactory.TestNodeGen; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class AOTSupportCompilationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AbstractSplittingStrategyTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AbstractSplittingStrategyTest.java index c17f6cf54a55..8f8b945a6667 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AbstractSplittingStrategyTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AbstractSplittingStrategyTest.java @@ -26,10 +26,6 @@ import java.lang.reflect.Field; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -42,10 +38,14 @@ import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.ReflectionUtils; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; public class AbstractSplittingStrategyTest extends TestWithPolyglotOptions { - protected static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + protected static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); static final Object[] noArguments = {}; protected SplitCountingListener listener; @@ -170,7 +170,7 @@ public void removeListener() { runtime.removeListener(listener); } - static class SplitCountingListener implements GraalTruffleRuntimeListener { + static class SplitCountingListener implements OptimizedTruffleRuntimeListener { int splitCount = 0; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AgnosticInliningPhaseTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AgnosticInliningPhaseTest.java index e74e0b103ede..bef852090be0 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AgnosticInliningPhaseTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AgnosticInliningPhaseTest.java @@ -26,14 +26,11 @@ import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PostPartialEvaluationSuite; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; import org.graalvm.compiler.truffle.compiler.phases.inlining.AgnosticInliningPhase; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.polyglot.Context; import org.junit.Before; @@ -42,6 +39,9 @@ import com.oracle.truffle.api.TruffleRuntime; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; public class AgnosticInliningPhaseTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AllocationReporterPartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AllocationReporterPartialEvaluationTest.java index 4900670233d9..45f7669ff2f0 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AllocationReporterPartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AllocationReporterPartialEvaluationTest.java @@ -28,7 +28,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.PolyglotAccess; import org.junit.Test; @@ -43,6 +42,7 @@ import com.oracle.truffle.api.instrumentation.TruffleInstrument; import com.oracle.truffle.api.nodes.LanguageInfo; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; /** * Test of consistent behavior of AllocationReporter when individual calls are optimized or diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumedValuePartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumedValuePartialEvaluationTest.java index 46ce97d04eff..24764dde6da0 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumedValuePartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumedValuePartialEvaluationTest.java @@ -25,7 +25,6 @@ package org.graalvm.compiler.truffle.test; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.junit.Assert; @@ -34,6 +33,7 @@ import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.utilities.AssumedValue; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class AssumedValuePartialEvaluationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumptionPartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumptionPartialEvaluationTest.java index 80d87c9090e6..c82983f659f4 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumptionPartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/AssumptionPartialEvaluationTest.java @@ -26,9 +26,6 @@ import java.lang.ref.WeakReference; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.runtime.OptimizedAssumption; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.AssumptionCutsBranchTestNode; import org.graalvm.compiler.truffle.test.nodes.ConstantWithAssumptionTestNode; @@ -46,6 +43,9 @@ import com.oracle.truffle.api.nodes.InvalidAssumptionException; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.runtime.OptimizedAssumption; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class AssumptionPartialEvaluationTest extends PartialEvaluationTest { public static Object constant42() { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BeginNodeOptimizationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BeginNodeOptimizationTest.java index 5ad002f9b789..b770c0460d46 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BeginNodeOptimizationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BeginNodeOptimizationTest.java @@ -29,7 +29,6 @@ import org.graalvm.compiler.graph.Graph; import org.graalvm.compiler.nodes.BeginNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -39,6 +38,7 @@ import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class BeginNodeOptimizationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BytecodeOSRNodeTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BytecodeOSRNodeTest.java index 045050942869..3c602db3cf5c 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BytecodeOSRNodeTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/BytecodeOSRNodeTest.java @@ -29,10 +29,11 @@ import java.util.concurrent.TimeUnit; import com.oracle.truffle.api.test.SubprocessTestUtils; +import com.oracle.truffle.runtime.BytecodeOSRMetadata; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; + import org.graalvm.compiler.test.GraalTest; -import org.graalvm.compiler.truffle.runtime.BytecodeOSRMetadata; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Before; @@ -60,7 +61,7 @@ public class BytecodeOSRNodeTest extends TestWithSynchronousCompiling { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); @Rule public TestRule timeout = GraalTest.createTimeout(30, TimeUnit.SECONDS); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CastExactPartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CastExactPartialEvaluationTest.java index 1b02ee9ec5cb..ab22fbba6362 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CastExactPartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CastExactPartialEvaluationTest.java @@ -30,7 +30,6 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.java.MethodCallTargetNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.junit.Assert; @@ -44,6 +43,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.profiles.ValueProfile; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class CastExactPartialEvaluationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CodeInvalidationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CodeInvalidationTest.java index 3423f7bbd649..42b51267d7cc 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CodeInvalidationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CodeInvalidationTest.java @@ -32,8 +32,6 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.PolyglotException; import org.graalvm.polyglot.Source; @@ -56,6 +54,8 @@ import com.oracle.truffle.api.test.CompileImmediatelyCheck; import com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedOSRLoopNode; public class CodeInvalidationTest extends AbstractPolyglotTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationFinalWeakReferencePartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationFinalWeakReferencePartialEvaluationTest.java index 5e609aee305e..e197be134770 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationFinalWeakReferencePartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationFinalWeakReferencePartialEvaluationTest.java @@ -28,7 +28,6 @@ import java.util.function.IntSupplier; import java.util.stream.IntStream; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.junit.Assert; @@ -39,6 +38,7 @@ 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.runtime.OptimizedCallTarget; public class CompilationFinalWeakReferencePartialEvaluationTest extends PartialEvaluationTest { public static Object constant42() { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationMemoryTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationMemoryTest.java index a5d900a879b9..29abca34d896 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationMemoryTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilationMemoryTest.java @@ -29,11 +29,6 @@ import java.util.Arrays; import java.util.concurrent.FutureTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -41,6 +36,11 @@ import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.GCUtils; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class CompilationMemoryTest extends TestWithPolyglotOptions { @@ -54,13 +54,13 @@ public void testFieldsFreedAfterCompilation() throws InterruptedException { TestObject expected = new TestObject(); OptimizedCallTarget callTarget = (OptimizedCallTarget) RootNode.createConstantNode(expected).getCallTarget(); GraalTruffleRuntimeListenerImpl listener = new GraalTruffleRuntimeListenerImpl(callTarget); - GraalTruffleRuntime.getRuntime().addListener(listener); + OptimizedTruffleRuntime.getRuntime().addListener(listener); try { Assert.assertEquals(expected, callTarget.call()); Assert.assertEquals(expected, callTarget.call()); Assert.assertTrue(callTarget.isValid()); } finally { - GraalTruffleRuntime.getRuntime().removeListener(listener); + OptimizedTruffleRuntime.getRuntime().removeListener(listener); } Thread compilerTread = listener.thread; Assert.assertNotNull("Calltarget was not successfully compiled", compilerTread); @@ -88,7 +88,7 @@ private static boolean awaitDone(Thread t, long timeout) throws InterruptedExcep return false; } - private static final class GraalTruffleRuntimeListenerImpl implements GraalTruffleRuntimeListener { + private static final class GraalTruffleRuntimeListenerImpl implements OptimizedTruffleRuntimeListener { private volatile OptimizedCallTarget callTarget; volatile Thread thread; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerInitializationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerInitializationTest.java index fbc0fc7e4717..9d94c90e5ada 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerInitializationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerInitializationTest.java @@ -30,7 +30,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; import org.graalvm.polyglot.Context; import org.junit.Assume; import org.junit.Before; @@ -40,6 +39,7 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage; import com.oracle.truffle.api.test.ReflectionUtils; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; public class CompilerInitializationTest { @@ -102,7 +102,7 @@ public static void assertTruffleCompilerInitialized(boolean expected) throws Exc } private static Field compilerField() throws NoSuchFieldException { - Field f = GraalTruffleRuntime.class.getDeclaredField("truffleCompiler"); + Field f = OptimizedTruffleRuntime.class.getDeclaredField("truffleCompiler"); ReflectionUtils.setAccessible(f, true); return f; } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerLoggingTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerLoggingTest.java index 3b8dc1f66897..9927096d591a 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerLoggingTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/CompilerLoggingTest.java @@ -36,19 +36,19 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.frame.VirtualFrame; import org.graalvm.compiler.debug.TTY; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -63,13 +63,13 @@ public class CompilerLoggingTest extends TestWithPolyglotOptions { @Test public void testLogging() throws IOException { if (!TruffleOptions.AOT) { - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); TruffleCompiler compiler = runtime.newTruffleCompiler(); Assume.assumeTrue("Not supported in isolated compiler.", compiler instanceof TruffleCompilerImpl); } try (ByteArrayOutputStream logOut = new ByteArrayOutputStream()) { setupContext(Context.newBuilder().logHandler(logOut).option("engine.CompileImmediately", "true").option("engine.MultiTier", "false").option("engine.BackgroundCompilation", "false")); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); TestListener listener = new TestListener(); try { runtime.addListener(listener); @@ -84,7 +84,7 @@ public void testLogging() throws IOException { } } - private static final class TestListener implements GraalTruffleRuntimeListener { + private static final class TestListener implements OptimizedTruffleRuntimeListener { @Override public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilationTask task, TruffleCompilerListener.GraphInfo graph, @@ -127,8 +127,8 @@ public void testGR46391() throws InterruptedException, BrokenBarrierException, T private void testGR46391Impl(String testName, Context.Builder builder) throws InterruptedException, BrokenBarrierException, TimeoutException { CyclicBarrier barrier = new CyclicBarrier(2); String rootName = String.format("%s.%s", TestRootNode.class.getName(), testName); - GraalTruffleRuntimeListener listener = new LogAfterEngineClose(rootName, barrier); - var runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntimeListener listener = new LogAfterEngineClose(rootName, barrier); + var runtime = OptimizedTruffleRuntime.getRuntime(); runtime.addListener(listener); try { builder.option("engine.CompileImmediately", "true"); @@ -169,7 +169,7 @@ public Object execute(VirtualFrame frame) { } } - private static final class LogAfterEngineClose implements GraalTruffleRuntimeListener { + private static final class LogAfterEngineClose implements OptimizedTruffleRuntimeListener { private static final String BEFORE_CLOSE = String.format("%s#BEFORE CLOSE", LogAfterEngineClose.class.getSimpleName()); private static final String AFTER_CLOSE = String.format("%s#AFTER CLOSE", LogAfterEngineClose.class.getSimpleName()); private final String expectedRootName; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ContextLookupCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ContextLookupCompilationTest.java index b7ea5aeb9c7f..bbc580aa67fd 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ContextLookupCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ContextLookupCompilationTest.java @@ -38,8 +38,6 @@ import org.graalvm.compiler.nodes.FieldLocationIdentity; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.memory.ReadNode; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Engine; import org.graalvm.word.LocationIdentity; @@ -62,6 +60,8 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.meta.ResolvedJavaField; @@ -96,12 +96,12 @@ private static Context createContext(Engine engine, String... languages) { } /* - * This test verifies that JVMCI has all the features it needs for a GraalTruffleRuntime. + * This test verifies that JVMCI has all the features it needs for a OptimizedTruffleRuntime. */ @Test public void testJVMCIIsLatest() { - Assume.assumeTrue(Truffle.getRuntime() instanceof GraalTruffleRuntime); - GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + Assume.assumeTrue(Truffle.getRuntime() instanceof OptimizedTruffleRuntime); + OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); assertTrue(runtime.isLatestJVMCI()); } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DFAPartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DFAPartialEvaluationTest.java index 064a409cc661..52fd5af2b280 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DFAPartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DFAPartialEvaluationTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Test; @@ -36,6 +35,7 @@ import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class DFAPartialEvaluationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DeoptInvalidateListener.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DeoptInvalidateListener.java index 91d1550dc140..52b00cb1b89b 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DeoptInvalidateListener.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DeoptInvalidateListener.java @@ -25,9 +25,10 @@ package org.graalvm.compiler.truffle.test; import com.oracle.truffle.api.frame.Frame; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; + import org.junit.Assert; public class DeoptInvalidateListener extends AbstractGraalTruffleRuntimeListener implements AutoCloseable { @@ -37,7 +38,7 @@ public class DeoptInvalidateListener extends AbstractGraalTruffleRuntimeListener boolean invalidated = false; @SuppressWarnings("this-escape") - protected DeoptInvalidateListener(GraalTruffleRuntime runtime, OptimizedCallTarget focus) { + protected DeoptInvalidateListener(OptimizedTruffleRuntime runtime, OptimizedCallTarget focus) { super(runtime); this.focus = focus; runtime.addListener(this); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DynamicObjectPartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DynamicObjectPartialEvaluationTest.java index 7c7d9fb5b8a3..977224ffadbc 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DynamicObjectPartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/DynamicObjectPartialEvaluationTest.java @@ -34,7 +34,6 @@ import org.graalvm.compiler.nodes.java.LoadFieldNode; import org.graalvm.compiler.nodes.java.StoreFieldNode; import org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.junit.Assert; @@ -49,6 +48,7 @@ import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.object.Shape; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.meta.JavaKind; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/EncodedGraphCacheTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/EncodedGraphCacheTest.java index 960220832dfb..20063c60ba0d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/EncodedGraphCacheTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/EncodedGraphCacheTest.java @@ -32,13 +32,9 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.nodes.EncodedGraph; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.graalvm.polyglot.Context; @@ -49,6 +45,10 @@ 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.compiler.TruffleCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -96,7 +96,7 @@ static void runWithBooleanFlag(TruffleCompilerImpl truffleCompiler, BiFunction verifier, Supplier { try { var cond = new NotifyCompilation(); - GraalTruffleRuntime.getRuntime().addListener(cond); + OptimizedTruffleRuntime.getRuntime().addListener(cond); setupContext("engine.CompileImmediately", "true", "engine.CompilationFailureAction", "ExitVM"); OptimizedCallTarget callTarget = (OptimizedCallTarget) RootNode.createConstantNode(42).getCallTarget(); callTarget.call(); @@ -67,7 +68,7 @@ public void testExit() throws IOException, InterruptedException { } } - private static final class NotifyCompilation implements GraalTruffleRuntimeListener { + private static final class NotifyCompilation implements OptimizedTruffleRuntimeListener { private final CountDownLatch signal = new CountDownLatch(1); @Override diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ExplodeLoopBlockDuplicationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ExplodeLoopBlockDuplicationTest.java index b153223b0879..e3ce5495c1e4 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ExplodeLoopBlockDuplicationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ExplodeLoopBlockDuplicationTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerDirectives; @@ -33,6 +32,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FlushEngineQueueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FlushEngineQueueTest.java index 5e7c00cf9bec..12e5e2f52067 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FlushEngineQueueTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FlushEngineQueueTest.java @@ -26,12 +26,12 @@ import static org.junit.Assert.assertNotEquals; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Test; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; @SuppressWarnings("try") public class FlushEngineQueueTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameAccessVerificationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameAccessVerificationTest.java index 571c28b32c74..0e3ea5006820 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameAccessVerificationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameAccessVerificationTest.java @@ -38,7 +38,6 @@ import org.graalvm.compiler.nodes.java.AbstractNewObjectNode; import org.graalvm.compiler.nodes.java.ExceptionObjectNode; import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; @@ -51,6 +50,7 @@ import com.oracle.truffle.api.frame.FrameSlotTypeException; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.meta.SpeculationLog; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameDescriptorTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameDescriptorTest.java index 62a14b122cc5..0da3943f1386 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameDescriptorTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/FrameDescriptorTest.java @@ -27,7 +27,6 @@ import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.ReturnNode; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Test; @@ -38,6 +37,7 @@ import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class FrameDescriptorTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GenerateInlineCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GenerateInlineCompilationTest.java index 977f915bbe8d..b7546e4c0a1d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GenerateInlineCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GenerateInlineCompilationTest.java @@ -25,7 +25,6 @@ package org.graalvm.compiler.truffle.test; import org.graalvm.compiler.nodes.ReturnNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.GenerateInlineCompilationTestFactory.CustomNodeGen; import org.graalvm.compiler.truffle.test.GenerateInlineCompilationTestFactory.TestChildrenNodeGen; import org.graalvm.compiler.truffle.test.GenerateInlineCompilationTestFactory.TestDimensionsRootNodeGen; @@ -49,6 +48,7 @@ import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import com.oracle.truffle.api.profiles.InlinedConditionProfile; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class GenerateInlineCompilationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GetRootNodeCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GetRootNodeCompilationTest.java index 3a292ec2d79f..112f9fde5fc0 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GetRootNodeCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GetRootNodeCompilationTest.java @@ -34,7 +34,6 @@ import org.graalvm.compiler.core.common.PermanentBailoutException; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Before; @@ -47,6 +46,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeUtil; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; /** * Tests compilation of {@link Node#getRootNode()} and the getRootNodeImpl() intrinsic. diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GraalTruffleRuntimeListenerTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GraalTruffleRuntimeListenerTest.java index 298a6decd2d5..12bc13bd4411 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GraalTruffleRuntimeListenerTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/GraalTruffleRuntimeListenerTest.java @@ -39,11 +39,12 @@ import java.util.List; import com.oracle.truffle.api.test.SubprocessTestUtils; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; + import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.graalvm.polyglot.Context; import org.junit.Test; @@ -65,7 +66,7 @@ protected Context.Builder newContextBuilder() { @Test public void testCompilationSuccess() { setupContext("engine.CompileImmediately", "true", "engine.BackgroundCompilation", "false"); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) RootNode.createConstantNode(true).getCallTarget(); TestListener listener = new TestListener(compilable); try { @@ -90,7 +91,7 @@ public void testCompilationFailure() throws IOException, InterruptedException { builder.option("engine.CompileImmediately", "true"); builder.option("engine.BackgroundCompilation", "false"); setupContext(builder); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) createFailureNode().getCallTarget(); TestListener listener = new TestListener(compilable); try { @@ -115,7 +116,7 @@ public void testCompilationFailureRetry() throws IOException, InterruptedExcepti public void write(int b) throws IOException { } }).allowExperimentalOptions(true).option("engine.CompileImmediately", "true").option("engine.BackgroundCompilation", "false").option("engine.CompilationFailureAction", "Diagnose")); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) createFailureNode().getCallTarget(); TestListener listener = new TestListener(compilable); try { @@ -139,7 +140,7 @@ public void testBlockCompilation() { setupContext("engine.CompileImmediately", "true", "engine.BackgroundCompilation", "false", "engine.PartialBlockCompilationSize", "1"); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) createBlocks().getCallTarget(); compilable.computeBlockCompilations(); TestListener listener = new TestListener(compilable); @@ -177,7 +178,7 @@ public void testBlockCompilationLargeBlocks() { "engine.BackgroundCompilation", "false", "engine.PartialBlockCompilationSize", "1", "engine.PartialBlockMaximumSize", "0"); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) createBlocks().getCallTarget(); compilable.computeBlockCompilations(); TestListener listener = new TestListener(compilable); @@ -211,7 +212,7 @@ public void testBlockCompilationMaximumGraalGraphSize() { "engine.BackgroundCompilation", "false", "engine.PartialBlockCompilationSize", String.valueOf(blockSize), "compiler.MaximumGraalGraphSize", "20000"); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); AbstractTestNode[] children = new AbstractTestNode[nodeCount]; for (int i = 0; i < children.length; i++) { children[i] = new ExpensiveTestNode(); @@ -360,7 +361,7 @@ private enum EventType { DEQUEUED, } - private static final class TestListener implements GraalTruffleRuntimeListener { + private static final class TestListener implements OptimizedTruffleRuntimeListener { private static final long TIMEOUT = 10_000; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HashCodeIntrinsicTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HashCodeIntrinsicTest.java index 2c689e02a382..16b7b4f4ba68 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HashCodeIntrinsicTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HashCodeIntrinsicTest.java @@ -25,13 +25,13 @@ package org.graalvm.compiler.truffle.test; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Test; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class HashCodeIntrinsicTest extends PartialEvaluationTest { @TruffleBoundary diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java index 3fdaca98527a..779c12eab85c 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/HostInliningTest.java @@ -56,8 +56,6 @@ import org.graalvm.compiler.phases.common.CanonicalizerPhase; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.truffle.compiler.host.HostInliningPhase; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.compiler.truffle.test.HostInliningTestFactory.IfNodeGen; import org.graalvm.polyglot.Context; import org.junit.Assert; @@ -82,6 +80,8 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.profiles.InlinedCountingConditionProfile; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/IndirectCallSiteTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/IndirectCallSiteTest.java index 0493faeebeb7..d0c4bfbd0b5c 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/IndirectCallSiteTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/IndirectCallSiteTest.java @@ -24,11 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; -import org.graalvm.compiler.truffle.runtime.OptimizedIndirectCallNode; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -39,11 +34,16 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.IndirectCallNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; +import com.oracle.truffle.runtime.OptimizedIndirectCallNode; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; @SuppressWarnings("try") public class IndirectCallSiteTest extends TestWithSynchronousCompiling { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); @Before @Override @@ -134,7 +134,7 @@ class DirectlyCallsTargetWithArguments extends DeoptimizeAwareRootNode { DirectlyCallsTargetWithArguments(OptimizedCallTarget target, Object[] arguments) { super(); - this.directCallNode = (OptimizedDirectCallNode) GraalTruffleRuntime.getRuntime().createDirectCallNode(target); + this.directCallNode = (OptimizedDirectCallNode) OptimizedTruffleRuntime.getRuntime().createDirectCallNode(target); this.arguments = arguments; } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/InstrumentBranchesPhaseTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/InstrumentBranchesPhaseTest.java index 4f0b433314c0..2f0973e05126 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/InstrumentBranchesPhaseTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/InstrumentBranchesPhaseTest.java @@ -30,7 +30,6 @@ import org.graalvm.compiler.api.directives.GraalDirectives; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.graalvm.polyglot.Context; @@ -41,6 +40,7 @@ import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.test.ReflectionUtils; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class InstrumentBranchesPhaseTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LanguageContextFreedTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LanguageContextFreedTest.java index 39efc1db20fb..dfbbb38f013c 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LanguageContextFreedTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LanguageContextFreedTest.java @@ -33,9 +33,10 @@ import java.util.function.Supplier; import com.oracle.truffle.api.test.SubprocessTestUtils; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; + import org.graalvm.collections.Pair; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Engine; import org.graalvm.polyglot.Source; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LazyClassLoadingTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LazyClassLoadingTest.java index 645c42ffd363..65d2a6c37ff2 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LazyClassLoadingTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LazyClassLoadingTest.java @@ -24,9 +24,9 @@ */ package org.graalvm.compiler.truffle.test; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompileImmediately; import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine; import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompileImmediately; import java.io.IOException; import java.util.ArrayList; @@ -49,12 +49,12 @@ import org.graalvm.compiler.options.OptionsParser; import org.graalvm.compiler.test.SubprocessUtil; import org.graalvm.compiler.test.SubprocessUtil.Subprocess; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.runtime.JVMCICompilerFactory; import jdk.vm.ci.services.JVMCIServiceLocator; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibraryCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibraryCompilationTest.java index e6fb5c8860ad..103889e87531 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibraryCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibraryCompilationTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerAsserts; @@ -36,6 +35,7 @@ import com.oracle.truffle.api.library.Library; import com.oracle.truffle.api.library.LibraryFactory; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.BailoutException; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibrarySplittingStrategyTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibrarySplittingStrategyTest.java index 8a215f7762d9..e43e1cb7fb14 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibrarySplittingStrategyTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LibrarySplittingStrategyTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Before; import org.junit.Test; @@ -45,6 +44,7 @@ import com.oracle.truffle.api.library.Library; import com.oracle.truffle.api.object.DynamicObject; import com.oracle.truffle.api.object.Shape; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class LibrarySplittingStrategyTest extends AbstractSplittingStrategyTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodeOSRTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodeOSRTest.java index 7642da4d925f..047c16ad0d8a 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodeOSRTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodeOSRTest.java @@ -26,8 +26,6 @@ import java.util.stream.IntStream; -import org.graalvm.compiler.truffle.runtime.BytecodeOSRMetadata; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Test; @@ -43,6 +41,8 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.BytecodeOSRMetadata; +import com.oracle.truffle.runtime.OptimizedCallTarget; @SuppressWarnings("deprecation") public class LoopNodeOSRTest extends TestWithSynchronousCompiling { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodePartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodePartialEvaluationTest.java index 3796130670fc..bba78a82b30d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodePartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/LoopNodePartialEvaluationTest.java @@ -32,7 +32,6 @@ import org.graalvm.compiler.nodes.ProfileData.ProfileSource; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.cfg.ControlFlowGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -45,6 +44,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class LoopNodePartialEvaluationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MaterializedFrameTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MaterializedFrameTest.java index e87a5935e761..1f7edc447da8 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MaterializedFrameTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MaterializedFrameTest.java @@ -36,7 +36,6 @@ import org.graalvm.compiler.nodes.calc.IsNullNode; import org.graalvm.compiler.nodes.java.LoadFieldNode; import org.graalvm.compiler.nodes.java.MethodCallTargetNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerDirectives; @@ -48,6 +47,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.profiles.ValueProfile; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class MaterializedFrameTest extends PartialEvaluationTest { private static RootNode createRootNode() { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MergeExplodeProxyTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MergeExplodeProxyTest.java index 2978b4dc33eb..dae4019dec0a 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MergeExplodeProxyTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MergeExplodeProxyTest.java @@ -28,7 +28,6 @@ import org.graalvm.compiler.nodes.ProxyNode; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.phases.util.GraphOrder; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -44,6 +43,7 @@ import com.oracle.truffle.api.nodes.DirectCallNode; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.api.nodes.RootNode; /** diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierAssumptionInvalidationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierAssumptionInvalidationTest.java index 487d3290ad30..c53897c1e89b 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierAssumptionInvalidationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierAssumptionInvalidationTest.java @@ -28,7 +28,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assume; import org.junit.Test; @@ -39,6 +38,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.CompileImmediatelyCheck; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class MultiTierAssumptionInvalidationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierCompilationTest.java index f75abcdef8a5..f6eed1e6c0be 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/MultiTierCompilationTest.java @@ -24,10 +24,9 @@ */ package org.graalvm.compiler.truffle.test; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.FirstTierCompilationThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.LastTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.FirstTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.LastTierCompilationThreshold; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -41,6 +40,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class MultiTierCompilationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeLimitTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeLimitTest.java index 3aab74159c72..ac4bf235e78f 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeLimitTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeLimitTest.java @@ -30,8 +30,6 @@ import org.graalvm.compiler.core.common.PermanentBailoutException; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.phases.contract.NodeCostUtil; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Assume; @@ -43,6 +41,8 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; public class NodeLimitTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeSplittingStrategyTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeSplittingStrategyTest.java index 7d35b5963481..8962c59b1a81 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeSplittingStrategyTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/NodeSplittingStrategyTest.java @@ -24,9 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Before; @@ -46,6 +43,9 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; public class NodeSplittingStrategyTest extends AbstractSplittingStrategyTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedBlockNodeTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedBlockNodeTest.java index 12d47c4381a6..bc965e8e9d69 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedBlockNodeTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedBlockNodeTest.java @@ -39,9 +39,6 @@ import com.oracle.truffle.sl.runtime.SLStrings; import org.graalvm.compiler.test.SubprocessUtil; -import org.graalvm.compiler.truffle.runtime.OptimizedBlockNode; -import org.graalvm.compiler.truffle.runtime.OptimizedBlockNode.PartialBlocks; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Value; import org.junit.After; @@ -64,6 +61,9 @@ import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedBlockNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedBlockNode.PartialBlocks; import com.oracle.truffle.sl.runtime.SLContext; public class OptimizedBlockNodeTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedCallTargetTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedCallTargetTest.java index b7ff06d5f6a0..32ef40671f32 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedCallTargetTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedCallTargetTest.java @@ -36,10 +36,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.ConstantTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; @@ -58,10 +54,14 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedOSRLoopNode; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; @SuppressWarnings("try") public class OptimizedCallTargetTest extends TestWithSynchronousCompiling { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); private static final Field nodeRewritingAssumptionField; static { try { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedOSRLoopNodeTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedOSRLoopNodeTest.java index a23999f849c6..a0510040f601 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedOSRLoopNodeTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OptimizedOSRLoopNodeTest.java @@ -24,9 +24,9 @@ */ package org.graalvm.compiler.truffle.test; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.MinInvokeThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.OSRCompilationThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.MinInvokeThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.OSRCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -38,10 +38,6 @@ import java.util.function.Function; import java.util.stream.IntStream; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; -import org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Before; @@ -71,11 +67,15 @@ import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; +import com.oracle.truffle.runtime.OptimizedOSRLoopNode; @RunWith(Theories.class) public class OptimizedOSRLoopNodeTest extends TestWithSynchronousCompiling { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); @DataPoint public static final OSRLoopFactory DEFAULT = (threshold, repeating) -> (OptimizedOSRLoopNode) OptimizedOSRLoopNode.create(repeating); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OverrideOptionsTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OverrideOptionsTest.java index 2fdad2c9e848..482b23d3c037 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OverrideOptionsTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/OverrideOptionsTest.java @@ -24,14 +24,14 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.options.OptionValues; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; public class OverrideOptionsTest extends TruffleCompilerImplTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PartialEvaluationTest.java index c62c8c1f08e8..6002bd21cc3e 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PartialEvaluationTest.java @@ -44,7 +44,6 @@ import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase; import org.graalvm.compiler.phases.tiers.HighTierContext; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; @@ -52,8 +51,6 @@ import org.graalvm.compiler.truffle.compiler.TruffleDebugJavaMethod; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; import org.graalvm.compiler.truffle.compiler.phases.TruffleTier; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import com.oracle.truffle.api.CallTarget; @@ -61,6 +58,9 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ControlFlowException; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.meta.Constant; @@ -113,7 +113,7 @@ protected OptimizedCallTarget compileHelper(String methodName, RootNode root, Ob } // Ensure the invoke stub is installed - GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); runtime.bypassedInstalledCode(compilable); return compilable; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PerformanceWarningTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PerformanceWarningTest.java index 3d64074fc180..b9eb9bef92f7 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PerformanceWarningTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PerformanceWarningTest.java @@ -30,12 +30,8 @@ import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.DebugContext.Builder; import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Before; @@ -46,6 +42,10 @@ import com.oracle.truffle.api.frame.FrameSlotKind; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; public class PerformanceWarningTest extends TruffleCompilerImplTest { @@ -429,7 +429,7 @@ protected class TrivialCallsInnerNode extends RootNode { public TrivialCallsInnerNode() { super(null); - this.callNode = (OptimizedDirectCallNode) GraalTruffleRuntime.getRuntime().createDirectCallNode(new RootNode(null) { + this.callNode = (OptimizedDirectCallNode) OptimizedTruffleRuntime.getRuntime().createDirectCallNode(new RootNode(null) { @Override public Object execute(VirtualFrame frame) { return 0; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PolyglotEngineOptionsTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PolyglotEngineOptionsTest.java index 76f7ee34c322..5ebec2955489 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PolyglotEngineOptionsTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PolyglotEngineOptionsTest.java @@ -25,8 +25,7 @@ package org.graalvm.compiler.truffle.test; import com.oracle.truffle.sl.runtime.SLStrings; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; + import org.graalvm.options.OptionDescriptor; import org.graalvm.options.OptionStability; import org.graalvm.polyglot.Context; @@ -35,6 +34,8 @@ import org.junit.Test; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; import com.oracle.truffle.sl.runtime.SLContext; import com.oracle.truffle.sl.runtime.SLFunction; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PropagateHotnessToLexicalSingleCallerTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PropagateHotnessToLexicalSingleCallerTest.java index c1245100eecd..c6db218df1f2 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PropagateHotnessToLexicalSingleCallerTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/PropagateHotnessToLexicalSingleCallerTest.java @@ -26,8 +26,6 @@ import java.util.function.Function; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -41,6 +39,8 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RepeatingNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class PropagateHotnessToLexicalSingleCallerTest extends TestWithSynchronousCompiling { @@ -86,7 +86,7 @@ public FrameDescriptor getParentFrameDescriptor() { static class RootNodeWithLoop extends NamedRootNode { - @Child LoopNode loopNode = GraalTruffleRuntime.getRuntime().createLoopNode(new SimpleLoopNode()); + @Child LoopNode loopNode = OptimizedTruffleRuntime.getRuntime().createLoopNode(new SimpleLoopNode()); protected RootNodeWithLoop(String name, FrameDescriptor parentFrameDescriptor) { super(name, parentFrameDescriptor); @@ -122,7 +122,7 @@ public Object execute(VirtualFrame frame) { @CompilerDirectives.TruffleBoundary private void createCallNode(FrameDescriptor frameDescriptor) { target = (OptimizedCallTarget) rootNodeFactory.apply(frameDescriptor).getCallTarget(); - callNode = insert(GraalTruffleRuntime.getRuntime().createDirectCallNode(target)); + callNode = insert(OptimizedTruffleRuntime.getRuntime().createDirectCallNode(target)); } } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ResourceLimitsCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ResourceLimitsCompilationTest.java index 981e10c626e5..890180f8cc2a 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ResourceLimitsCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ResourceLimitsCompilationTest.java @@ -37,7 +37,6 @@ import org.graalvm.compiler.nodes.java.MethodCallTargetNode; import org.graalvm.compiler.nodes.memory.ReadNode; import org.graalvm.compiler.nodes.memory.WriteNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Engine; import org.graalvm.polyglot.ResourceLimits; @@ -46,6 +45,7 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class ResourceLimitsCompilationTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/RewriteDuringCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/RewriteDuringCompilationTest.java index a678116718f2..fd8f7542460d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/RewriteDuringCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/RewriteDuringCompilationTest.java @@ -36,8 +36,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Source; import org.junit.Assert; @@ -59,6 +57,8 @@ import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest; import com.oracle.truffle.api.test.polyglot.ProxyLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedOSRLoopNode; public class RewriteDuringCompilationTest extends AbstractPolyglotTest { abstract static class BaseNode extends Node { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SafepointRethrowDeoptPETest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SafepointRethrowDeoptPETest.java index 835cf85ba258..a7c17147eb05 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SafepointRethrowDeoptPETest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SafepointRethrowDeoptPETest.java @@ -27,7 +27,6 @@ import java.util.concurrent.CountDownLatch; import org.graalvm.compiler.core.common.GraalOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; @@ -35,6 +34,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class SafepointRethrowDeoptPETest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SimplePartialEvaluationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SimplePartialEvaluationTest.java index 8170c6340293..878c8fb073d6 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SimplePartialEvaluationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/SimplePartialEvaluationTest.java @@ -31,7 +31,6 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.replacements.PEGraphDecoder; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.AddTestNode; import org.graalvm.compiler.truffle.test.nodes.BlockTestNode; @@ -69,6 +68,7 @@ import com.oracle.truffle.api.frame.FrameSlotKind; import com.oracle.truffle.api.impl.FrameWithoutBoxing; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.BailoutException; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/StringNodeInliningCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/StringNodeInliningCompilationTest.java index dbddc6858d56..e60eab932975 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/StringNodeInliningCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/StringNodeInliningCompilationTest.java @@ -26,7 +26,6 @@ import static org.junit.Assume.assumeFalse; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Test; @@ -35,6 +34,7 @@ import com.oracle.truffle.api.strings.TruffleString; import com.oracle.truffle.api.strings.TruffleString.Encoding; import com.oracle.truffle.api.test.CompileImmediatelyCheck; +import com.oracle.truffle.runtime.OptimizedCallTarget; /** * Basic smoke test to ensure TruffleString inlined nodes compile cleanly. diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TestWithSynchronousCompiling.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TestWithSynchronousCompiling.java index 6848fe5ac999..63501e0604a3 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TestWithSynchronousCompiling.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TestWithSynchronousCompiling.java @@ -28,10 +28,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context.Builder; import org.junit.Before; +import com.oracle.truffle.runtime.OptimizedCallTarget; + /** * Base class for Truffle unit tests that require that there be no background compilation. * diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ThreadsActivationCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ThreadsActivationCompilationTest.java index e314195051bf..1ec41cf25011 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ThreadsActivationCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/ThreadsActivationCompilationTest.java @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicReference; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Test; @@ -42,6 +41,7 @@ import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest; import com.oracle.truffle.api.test.polyglot.ProxyLanguage.LanguageContext; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class ThreadsActivationCompilationTest extends AbstractPolyglotTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TraceCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TraceCompilationTest.java index 8becdd99cc3f..e0b9150f7990 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TraceCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TraceCompilationTest.java @@ -41,8 +41,9 @@ import java.util.regex.Pattern; import com.oracle.truffle.api.test.SubprocessTestUtils; +import com.oracle.truffle.runtime.OptimizedCallTarget; + import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.nodes.AbstractTestNode; import org.graalvm.compiler.truffle.test.nodes.RootTestNode; import org.graalvm.polyglot.Context; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TransferToInterpreterTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TransferToInterpreterTest.java index 880566c6dc6e..5495aa68947f 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TransferToInterpreterTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TransferToInterpreterTest.java @@ -24,10 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -35,6 +31,10 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class TransferToInterpreterTest extends TestWithPolyglotOptions { @@ -46,7 +46,7 @@ public void setup() { @Test public void test() { RootNode rootNode = new TestRootNode(); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget(); target.call(0); Assert.assertFalse(target.isValid()); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryExceptionsTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryExceptionsTest.java index c6946ee60711..c0b8314a3f3d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryExceptionsTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryExceptionsTest.java @@ -24,15 +24,10 @@ */ package org.graalvm.compiler.truffle.test; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Before; import org.junit.Test; @@ -40,10 +35,15 @@ import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; public class TruffleBoundaryExceptionsTest extends TestWithSynchronousCompiling { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); @Override @Before @@ -87,7 +87,7 @@ public void throwExceptionBoundary() { } } final int[] compilationCount = {0}; - GraalTruffleRuntimeListener listener = new GraalTruffleRuntimeListener() { + OptimizedTruffleRuntimeListener listener = new OptimizedTruffleRuntimeListener() { @Override public void onCompilationStarted(OptimizedCallTarget target, AbstractCompilationTask task) { compilationCount[0]++; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryInliningTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryInliningTest.java index 6fd0d4435e93..945ea6518995 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryInliningTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleBoundaryInliningTest.java @@ -28,7 +28,6 @@ import org.graalvm.compiler.nodes.Invoke; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerAsserts; @@ -36,6 +35,7 @@ import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class TruffleBoundaryInliningTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleCompilerImplTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleCompilerImplTest.java index 5fb813fb2a82..baae27b6cbdb 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleCompilerImplTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleCompilerImplTest.java @@ -30,12 +30,9 @@ import org.graalvm.compiler.core.target.Backend; import org.graalvm.compiler.core.test.GraalCompilerTest; import org.graalvm.compiler.phases.util.Providers; -import org.graalvm.compiler.truffle.common.TruffleCompiler; import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.After; import org.junit.Assume; @@ -43,6 +40,9 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; public abstract class TruffleCompilerImplTest extends GraalCompilerTest { @@ -52,7 +52,7 @@ public abstract class TruffleCompilerImplTest extends GraalCompilerTest { protected TruffleCompilerImplTest() { if (!TruffleOptions.AOT) { - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); TruffleCompiler compiler = runtime.newTruffleCompiler(); Assume.assumeTrue("cannot get whitebox interface to Truffle compiler", compiler instanceof TruffleCompilerImpl); this.truffleCompiler = (TruffleCompilerImpl) compiler; @@ -62,7 +62,7 @@ protected TruffleCompilerImplTest() { @Before public void onlyWhiteBox() { if (TruffleOptions.AOT) { - TruffleCompiler compiler = GraalTruffleRuntime.getRuntime().getTruffleCompiler(getInitCallTarget()); + TruffleCompiler compiler = OptimizedTruffleRuntime.getRuntime().getTruffleCompiler(getInitCallTarget()); Assume.assumeTrue("cannot get whitebox interface to Truffle compiler", compiler instanceof TruffleCompilerImpl); this.truffleCompiler = (TruffleCompilerImpl) compiler; } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleContextCompilationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleContextCompilationTest.java index bfd05151dd14..d52b22a7443b 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleContextCompilationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleContextCompilationTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerDirectives; @@ -36,6 +35,7 @@ import com.oracle.truffle.api.TruffleLanguage.Registration; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.BailoutException; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleReturnBoxedParameterTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleReturnBoxedParameterTest.java index 21edbeb5be44..0a75468e0e3e 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleReturnBoxedParameterTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleReturnBoxedParameterTest.java @@ -30,7 +30,6 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.extended.ForeignCallNode; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.TruffleReturnBoxedParameterTestFactory.IntNodeFactory; import org.junit.Test; @@ -42,6 +41,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.nodes.UnexpectedResultException; +import com.oracle.truffle.runtime.OptimizedCallTarget; /** * A simple test to verify that a truffle compilation unit returning a parameter re-uses the boxed diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleRuntimeTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleRuntimeTest.java index 78c3b9702a99..344218e98c70 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleRuntimeTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleRuntimeTest.java @@ -61,7 +61,7 @@ public void testGetTVMCI() { TruffleRuntime runtime = Truffle.getRuntime(); TVMCI tvmci = runtime.getCapability(TVMCI.class); assertNotNull("Truffle Virtual Machine Compiler Interface not found", tvmci); - assertEquals("GraalTVMCI", tvmci.getClass().getSimpleName()); + assertEquals("OptimizedTVMCI", tvmci.getClass().getSimpleName()); abstract class TVMCISubclass extends TVMCI { } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleToTruffleCallExceptionHandlerTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleToTruffleCallExceptionHandlerTest.java index d5454b626491..c7c413de695c 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleToTruffleCallExceptionHandlerTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/TruffleToTruffleCallExceptionHandlerTest.java @@ -26,8 +26,6 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.UnwindNode; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.polyglot.Context; import org.junit.Assert; import org.junit.Test; @@ -36,6 +34,8 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.DirectCallNode; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; /** * A simple test class verifying that a truffle-2-truffle call never results in the compilation of @@ -43,7 +43,7 @@ */ public class TruffleToTruffleCallExceptionHandlerTest extends PartialEvaluationTest { - private static final GraalTruffleRuntime runtime = (GraalTruffleRuntime) Truffle.getRuntime(); + private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime(); private static final class Compilables { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/UnrollLoopBlockDuplicationTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/UnrollLoopBlockDuplicationTest.java index ad74eb976dcf..4e1c45a6ae95 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/UnrollLoopBlockDuplicationTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/UnrollLoopBlockDuplicationTest.java @@ -24,7 +24,6 @@ */ package org.graalvm.compiler.truffle.test; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.junit.Test; import com.oracle.truffle.api.CompilerDirectives; @@ -33,6 +32,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java index 0a26c0ec4818..21a99980d20d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java @@ -24,13 +24,12 @@ */ package org.graalvm.compiler.truffle.test.builtins; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.IndirectCallNode; import com.oracle.truffle.api.nodes.NodeInfo; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.sl.runtime.SLFunction; import com.oracle.truffle.sl.runtime.SLNull; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLDisableSplittingBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLDisableSplittingBuiltin.java index 0a815b6d2a81..de0a6995d622 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLDisableSplittingBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLDisableSplittingBuiltin.java @@ -25,13 +25,11 @@ package org.graalvm.compiler.truffle.test.builtins; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; - -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.sl.nodes.SLRootNode; import com.oracle.truffle.sl.runtime.SLFunction; import com.oracle.truffle.sl.runtime.SLNull; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGetOptionBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGetOptionBuiltin.java index 9a99fa0465f0..94ca268257cf 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGetOptionBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGetOptionBuiltin.java @@ -24,8 +24,6 @@ */ package org.graalvm.compiler.truffle.test.builtins; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.options.OptionDescriptor; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -33,6 +31,8 @@ import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.strings.TruffleString; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; /** * Looks up the value of an option in {@link OptimizedRuntimeOptions}. In the future this builtin diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGraalRuntimeBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGraalRuntimeBuiltin.java index 567d9b1cd320..6a3237886ba5 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGraalRuntimeBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLGraalRuntimeBuiltin.java @@ -27,9 +27,6 @@ import java.util.HashSet; import java.util.Set; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - import com.oracle.truffle.api.CallTarget; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.Truffle; @@ -37,12 +34,14 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeVisitor; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.sl.builtins.SLBuiltinNode; public abstract class SLGraalRuntimeBuiltin extends SLBuiltinNode { protected SLGraalRuntimeBuiltin() { - if (!(Truffle.getRuntime() instanceof GraalTruffleRuntime)) { + if (!(Truffle.getRuntime() instanceof OptimizedTruffleRuntime)) { throw new AssertionError("Graal runtime builtins can only be used inside of a Graal runtime."); } } diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLIsOptimizedBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLIsOptimizedBuiltin.java index 8376c52cb592..de3a8898d506 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLIsOptimizedBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLIsOptimizedBuiltin.java @@ -24,11 +24,10 @@ */ package org.graalvm.compiler.truffle.test.builtins; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.NodeInfo; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.sl.runtime.SLFunction; /** diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLWaitForOptimizationBuiltin.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLWaitForOptimizationBuiltin.java index 58d3e0b02e80..003b62e5f52d 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLWaitForOptimizationBuiltin.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/builtins/SLWaitForOptimizationBuiltin.java @@ -27,12 +27,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.NodeInfo; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; import com.oracle.truffle.sl.runtime.SLFunction; import com.oracle.truffle.sl.runtime.SLNull; @@ -46,7 +45,7 @@ public abstract class SLWaitForOptimizationBuiltin extends SLGraalRuntimeBuiltin @Specialization public SLFunction waitForOptimization(SLFunction function, long timeout) { OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget(); - GraalTruffleRuntime runtime = ((GraalTruffleRuntime) Truffle.getRuntime()); + OptimizedTruffleRuntime runtime = ((OptimizedTruffleRuntime) Truffle.getRuntime()); try { runtime.waitForCompilation(target, timeout); } catch (ExecutionException | TimeoutException e) { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/BTreeQueueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/BTreeQueueTest.java index 94ebfd5202a1..bcd2c1cf4844 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/BTreeQueueTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/BTreeQueueTest.java @@ -24,10 +24,11 @@ */ package org.graalvm.compiler.truffle.test.collection; -import org.graalvm.compiler.truffle.runtime.collection.BTreeQueue; import org.junit.Assert; import org.junit.Test; +import com.oracle.truffle.runtime.collection.BTreeQueue; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/DelegatingBlockingQueueTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/DelegatingBlockingQueueTest.java index 12b7414ff4f5..ab5a952b5c64 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/DelegatingBlockingQueueTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/collection/DelegatingBlockingQueueTest.java @@ -24,11 +24,12 @@ */ package org.graalvm.compiler.truffle.test.collection; -import org.graalvm.compiler.truffle.runtime.collection.ArrayQueue; -import org.graalvm.compiler.truffle.runtime.collection.DelegatingBlockingQueue; import org.junit.Assert; import org.junit.Test; +import com.oracle.truffle.runtime.collection.ArrayQueue; +import com.oracle.truffle.runtime.collection.DelegatingBlockingQueue; + import java.util.ArrayList; public class DelegatingBlockingQueueTest { diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/libgraal/JNIExceptionWrapperTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/libgraal/JNIExceptionWrapperTest.java index 1a03fb270bf7..46a724e8f6ba 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/libgraal/JNIExceptionWrapperTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/libgraal/JNIExceptionWrapperTest.java @@ -36,17 +36,17 @@ import org.graalvm.compiler.core.CompilationWrapper; import org.graalvm.compiler.core.GraalCompilerOptions; import org.graalvm.compiler.test.SubprocessUtil; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.TestWithPolyglotOptions; import org.junit.Test; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class JNIExceptionWrapperTest extends TestWithPolyglotOptions { @@ -85,7 +85,7 @@ private static List makeSilent(List vmArgs) { private void testMergedStackTraceImpl() throws Exception { setupContext("engine.CompilationFailureAction", "Throw", "engine.BackgroundCompilation", Boolean.FALSE.toString()); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); OptimizedCallTarget compilable = (OptimizedCallTarget) RootNode.createConstantNode(42).getCallTarget(); TruffleCompiler compiler = runtime.getTruffleCompiler(compilable); TestTruffleCompilationTask task = new TestTruffleCompilationTask(); diff --git a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/strings/TStringConstantFoldingTest.java b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/strings/TStringConstantFoldingTest.java index bd5aca403586..cd3ba2453c37 100644 --- a/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/strings/TStringConstantFoldingTest.java +++ b/compiler/src/jdk.internal.vm.compiler.test/src/org/graalvm/compiler/truffle/test/strings/TStringConstantFoldingTest.java @@ -30,7 +30,6 @@ import org.graalvm.compiler.core.common.GraalOptions; import org.graalvm.compiler.nodes.ReturnNode; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.compiler.truffle.test.PartialEvaluationTest; import org.junit.Assert; import org.junit.Assume; @@ -39,6 +38,7 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.strings.TruffleString; +import com.oracle.truffle.runtime.OptimizedCallTarget; public class TStringConstantFoldingTest extends PartialEvaluationTest { diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/META-INF/services/org.graalvm.compiler.truffle.jfr.EventFactory$Provider b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/META-INF/services/org.graalvm.compiler.truffle.jfr.EventFactory$Provider deleted file mode 100644 index d4d957ce2d5f..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/META-INF/services/org.graalvm.compiler.truffle.jfr.EventFactory$Provider +++ /dev/null @@ -1 +0,0 @@ -org.graalvm.compiler.truffle.jfr.impl.ProviderImpl diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationFailureEventImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationFailureEventImpl.java deleted file mode 100644 index 2653c351a510..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationFailureEventImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import jdk.jfr.BooleanFlag; -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.Label; -import jdk.jfr.Name; -import jdk.jfr.StackTrace; - -@Name("org.graalvm.compiler.truffle.CompilationFailure") -@Category("Truffle Compiler") -@Label("Compilation Failure") -@Description("Truffe Compilation Failures") -@StackTrace(false) -class CompilationFailureEventImpl extends RootFunctionEventImpl { - - @Label("Permanent Failure") @Description("Permanent Failure") @BooleanFlag public boolean permanentFailure; - - @Label("Failure Reason") @Description("Failure Reason") public String failureReason; - - CompilationFailureEventImpl(String source, String language, String rootFunction, boolean permanent, CharSequence reason) { - super(source, language, rootFunction); - this.permanentFailure = permanent; - this.failureReason = reason == null ? null : reason.toString(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationStatisticsEventImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationStatisticsEventImpl.java deleted file mode 100644 index 6e42229b61e7..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationStatisticsEventImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.DataAmount; -import jdk.jfr.Event; -import jdk.jfr.Label; -import jdk.jfr.Name; -import jdk.jfr.Period; -import jdk.jfr.StackTrace; -import jdk.jfr.Timespan; -import jdk.jfr.Unsigned; -import org.graalvm.compiler.truffle.jfr.CompilationStatisticsEvent; - -@Name("org.graalvm.compiler.truffle.CompilerStatistics") -@Category("Truffle Compiler") -@Label("Compiler Statistics") -@Description("Truffe Compiler Statistics") -@Period("1s") -@StackTrace(false) -class CompilationStatisticsEventImpl extends Event implements CompilationStatisticsEvent { - - @Label("Compiled Methods") @Description("Compiled Methods") @Unsigned public long compiledMethods; - - @Label("Bailouts") @Description("Bailouts") @Unsigned public long bailouts; - - @Label("Invalidated Compilations") @Description("Invalidated Compilations") @Unsigned public long invalidations; - - @Label("Compilation Resulting Size") @Description("Compilation Resulting Size") @DataAmount @Unsigned public long compiledCodeSize; - - @Label("Total Time") @Description("Total Time") @Timespan(Timespan.MILLISECONDS) public long totalTime; - - @Label("Peak Time") @Description("Peak Time") @Timespan(Timespan.MILLISECONDS) public long peakTime; - - @Override - public void setCompiledMethods(long compiledMethodsCount) { - this.compiledMethods = compiledMethodsCount; - } - - @Override - public void setBailouts(long bailoutsCount) { - this.bailouts = bailoutsCount; - } - - @Override - public void setInvalidations(long invalidationsCount) { - this.invalidations = invalidationsCount; - } - - @Override - public void setCompiledCodeSize(long codeSize) { - this.compiledCodeSize = codeSize; - } - - @Override - public void setTotalTime(long time) { - this.totalTime = time; - } - - @Override - public void setPeakTime(long time) { - this.peakTime = time; - } - - @Override - public void publish() { - commit(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/DeoptimizationEventImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/DeoptimizationEventImpl.java deleted file mode 100644 index 2cd90ec367cd..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/DeoptimizationEventImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.Label; -import jdk.jfr.Name; -import jdk.jfr.StackTrace; -import org.graalvm.compiler.truffle.jfr.DeoptimizationEvent; - -@Name("org.graalvm.compiler.truffle.Deoptimization") -@Category("Truffle Compiler") -@Label("Deoptimization") -@Description("Truffle Call Target Deoptimization") -@StackTrace(false) -class DeoptimizationEventImpl extends RootFunctionEventImpl implements DeoptimizationEvent { - -} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/InvalidationEventImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/InvalidationEventImpl.java deleted file mode 100644 index 081612d3cf73..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/InvalidationEventImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.Label; -import jdk.jfr.Name; -import jdk.jfr.StackTrace; -import org.graalvm.compiler.truffle.jfr.InvalidationEvent; - -@Name("org.graalvm.compiler.truffle.AssumptionInvalidation") -@Category("Truffle Compiler") -@Label("Assumption Invalidation") -@Description("Truffle Assumption Invalidation") -@StackTrace(true) -class InvalidationEventImpl extends RootFunctionEventImpl implements InvalidationEvent { - - @Label("Reason") @Description("Invalidation Reason") public String reason; - - @Override - public void setReason(CharSequence invalidationReason) { - this.reason = invalidationReason == null ? null : invalidationReason.toString(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/ProviderImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/ProviderImpl.java deleted file mode 100644 index b08b59fc50c9..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/ProviderImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import jdk.jfr.FlightRecorder; -import org.graalvm.compiler.truffle.jfr.EventFactory; - -public final class ProviderImpl implements EventFactory.Provider { - @Override - public EventFactory getEventFactory() { - return FlightRecorder.isAvailable() ? new EventFactoryImpl() : null; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/RootFunctionEventImpl.java b/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/RootFunctionEventImpl.java deleted file mode 100644 index 2c2d998d5d52..000000000000 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/RootFunctionEventImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr.impl; - -import com.oracle.truffle.api.nodes.LanguageInfo; -import jdk.jfr.Event; -import jdk.jfr.Label; -import jdk.jfr.Description; -import com.oracle.truffle.api.RootCallTarget; -import com.oracle.truffle.api.source.SourceSection; -import com.oracle.truffle.api.nodes.RootNode; -import org.graalvm.compiler.truffle.jfr.RootFunctionEvent; - -abstract class RootFunctionEventImpl extends Event implements RootFunctionEvent { - - @Label("Source") @Description("Compiled Source") public String source; - @Label("Language") @Description("Guest Language") public String language; - @Label("Root Function") @Description("Root Function") public String rootFunction; - - RootFunctionEventImpl() { - } - - RootFunctionEventImpl(String source, String language, String rootFunction) { - this.source = source; - this.language = language; - this.rootFunction = rootFunction; - } - - @Override - public void setRootFunction(RootCallTarget target) { - RootNode rootNode = target.getRootNode(); - this.source = targetName(rootNode); - LanguageInfo languageInfo = rootNode.getLanguageInfo(); - this.language = languageInfo != null ? languageInfo.getId() : null; - this.rootFunction = rootNode.getName(); - if (this.rootFunction == null) { - this.rootFunction = rootNode.toString(); - } - } - - @Override - public void publish() { - commit(); - } - - private static String targetName(RootNode rootNode) { - SourceSection sourceSection = rootNode.getSourceSection(); - if (sourceSection != null && sourceSection.getSource() != null) { - return sourceSection.getSource().getName() + ":" + sourceSection.getStartLine(); - } - return null; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess b/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess deleted file mode 100644 index 3a087fe78a10..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess +++ /dev/null @@ -1 +0,0 @@ -org.graalvm.compiler.truffle.runtime.hotspot.libgraal.LibGraalTruffleRuntimeAccess diff --git a/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/org.graalvm.compiler.truffle.runtime.LoopNodeFactory b/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/org.graalvm.compiler.truffle.runtime.LoopNodeFactory deleted file mode 100644 index dc9422d0a2e1..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/META-INF/services/org.graalvm.compiler.truffle.runtime.LoopNodeFactory +++ /dev/null @@ -1 +0,0 @@ -org.graalvm.compiler.truffle.runtime.DefaultLoopNodeFactory diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java index ab49c5e66dd2..43312ec7447d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java @@ -280,8 +280,8 @@ private static void registerTrufflePlugins(InvocationPlugins plugins, WordTypes // cannot install intrinsics without return; } - - Registration tl = new Registration(plugins, "org.graalvm.compiler.truffle.runtime.hotspot.HotSpotFastThreadLocal"); + plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/runtime/hotspot/HotSpotFastThreadLocal;")); + Registration tl = new Registration(plugins, "com.oracle.truffle.runtime.hotspot.HotSpotFastThreadLocal"); tl.register(new InvocationPlugin("get", Receiver.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/HostMethodInfo.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/HostMethodInfo.java deleted file mode 100644 index da9582480586..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/HostMethodInfo.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.compiler.truffle.common; - -/** - * TODO GR-44222 as soon as the annotation API is available in libgraal this can be moved to the - * compiler implementation side. - * - * @param isTruffleBoundary specifies if the method is annotated by {@code TruffleBoundary} - * @param isBytecodeInterpreterSwitch specifies if the method is annotated by - * {@code BytecodeInterpreterSwitch}. - * @param isBytecodeInterpreterSwitchBoundary specifies if the method is annotated by - * {@code BytecodeInterpreterSwitchBoundary} - * @param isInliningCutoff specifies if the method is annotated by {@code InliningCutoff} - */ -public record HostMethodInfo( - boolean isTruffleBoundary, - boolean isBytecodeInterpreterSwitch, - boolean isBytecodeInterpreterSwitchBoundary, - boolean isInliningCutoff) { - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/OptimizedAssumptionDependency.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/OptimizedAssumptionDependency.java deleted file mode 100644 index 026cd0e2c106..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/OptimizedAssumptionDependency.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.common; - -/** - * Represents some machine code whose validity depends on an assumption. Valid machine code can - * still be executed. - */ -public interface OptimizedAssumptionDependency { - - /** - * Called when a depended-on assumption is invalidated, with the intention to invalidate the - * machine code referenced by this object. - */ - void onAssumptionInvalidated(Object source, CharSequence reason); - - /** - * Determines if the machine code referenced by this object is valid. - */ - boolean isAlive(); - - /** - * Gets the Truffle AST whose machine code is represented by this object. May be {@code null}. - */ - default TruffleCompilable getCompilable() { - return null; - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/PartialEvaluationMethodInfo.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/PartialEvaluationMethodInfo.java deleted file mode 100644 index 31082cbf61ac..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/PartialEvaluationMethodInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.compiler.truffle.common; - -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime.InlineKind; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime.LoopExplosionKind; - -/** - * TODO GR-44222 as soon as the annotation API is available in libgraal this can be moved to the - * compiler implementation side. - * - * @param loopExplosion Queries how loops in {@code method} with constant number of invocations - * should be unrolled. - * @param inlineForPartialEvaluation Gets an object describing whether and how a method can be - * inlined based on Truffle directives during partial evaluation - * @param inlineForTruffleBoundary Gets an object describing whether and how a method can be inlined - * based on Truffle directives after partial evaluation e.g. during later inlining - * phases. - * @param isInlineable Determines if {@code method} can be inlined by the runtime (independently - * from Truffle). - * @param isSpecializationMethod Determines if {@code method} is annotated by - * {@code Specialization}. - */ -public record PartialEvaluationMethodInfo( - LoopExplosionKind loopExplosion, - InlineKind inlineForPartialEvaluation, - InlineKind inlineForTruffleBoundary, - boolean isInlineable, - boolean isSpecializationMethod) { - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationSupport.java deleted file mode 100644 index 5210938b8f97..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationSupport.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.compiler.truffle.common; - -/** - * Represents entry points for Truffle runtime implementations to Truffle compilation. - */ -public interface TruffleCompilationSupport { - - /** - * Registers a runtime instance after it was fully initialized. - */ - void registerRuntime(TruffleCompilerRuntime runtime); - - /** - * Creates a new compiler handle for compilation. A runtime must be - * {@link #registerRuntime(TruffleCompilerRuntime) registered} prior to calling this method. - * Only one compiler instance should be created per Truffle runtime instance. - */ - TruffleCompiler createCompiler(TruffleCompilerRuntime runtime); - - /** - * Lists all compiler options available, including deprecated options. - */ - TruffleCompilerOptionDescriptor[] listCompilerOptions(); - - /** - * Returns true if a compilation key exists, else false. - */ - boolean compilerOptionExists(String key); - - /** - * Validates a compiler option and returns null if the option is null. An error - * message otherwise. - */ - String validateCompilerOption(String key, String value); - - /** - * Returns a compiler configuration name that will be used. - */ - String getCompilerConfigurationName(TruffleCompilerRuntime runtime); - - /** - * Opens a compiler thread scope for compilation threads. Use with try-with-resourcce. - */ - default AutoCloseable openCompilerThreadScope() { - return null; - } - - default boolean isSuppressedCompilationFailure(@SuppressWarnings("unused") Throwable throwable) { - return false; - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompiler.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompiler.java deleted file mode 100644 index f8221f08b7a4..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompiler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 org.graalvm.compiler.truffle.common; - -/** - * A compiler that partially evaluates and compiles a {@link TruffleCompilable} to machine code. - */ -public interface TruffleCompiler { - - String FIRST_TIER_COMPILATION_SUFFIX = "#1"; - String SECOND_TIER_COMPILATION_SUFFIX = "#2"; - - /** - * Initializes the compiler before the first compilation. - * - * @param compilable the Truffle AST that triggered the initialization - * @param firstInitialization first initialization. For a multi-isolate compiler the - * {@code firstInitialization} must be {@code true} for an initialization in the - * first isolate and {@code false} for an initialization in the following isolates. - * - * @since 20.0.0 - */ - void initialize(TruffleCompilable compilable, boolean firstInitialization); - - /** - * Compiles {@code compilable} to machine code. - * - * @param listener a listener receiving events about compilation success or failure - */ - void doCompile(TruffleCompilationTask task, TruffleCompilable compilable, TruffleCompilerListener listener); - - /** - * Notifies this object that it will no longer being used and should thus perform all relevant - * finalization tasks. This is typically performed when the process exits. - */ - void shutdown(); - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerOptionDescriptor.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerOptionDescriptor.java deleted file mode 100644 index 4e19fab2e63b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerOptionDescriptor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 org.graalvm.compiler.truffle.common; - -import org.graalvm.compiler.options.OptionDescriptor; - -/** - * Represents the description of a Truffle compiler options. - */ -public record TruffleCompilerOptionDescriptor(String name, Type type, boolean deprecated, String help, String deprecationMessage) { - - public TruffleCompilerOptionDescriptor(OptionDescriptor d) { - this(d.getName(), matchGraalOptionType(d), d.isDeprecated(), d.getHelp(), d.getDeprecationMessage()); - } - - static Type matchGraalOptionType(OptionDescriptor d) { - switch (d.getOptionType()) { - case User: - return Type.USER; - case Expert: - return Type.EXPERT; - case Debug: - return Type.DEBUG; - default: - return Type.DEBUG; - } - } - - public enum Type { - /** - * An option common for users to apply. - */ - USER, - - /** - * An option only relevant in corner cases and for fine-tuning. - */ - EXPERT, - - /** - * An option only relevant when debugging the compiler. - */ - DEBUG - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleSourceLanguagePosition.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleSourceLanguagePosition.java deleted file mode 100644 index 8f66e0ea0f39..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleSourceLanguagePosition.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.common; - -import java.net.URI; - -public interface TruffleSourceLanguagePosition { - - String getDescription(); - - int getOffsetEnd(); - - int getOffsetStart(); - - int getLineNumber(); - - URI getURI(); - - String getLanguage(); - - int getNodeId(); - - String getNodeClassName(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/HotSpotTruffleCompiler.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/HotSpotTruffleCompiler.java deleted file mode 100644 index 0c3264f03c59..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/HotSpotTruffleCompiler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2013, 2022, 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 org.graalvm.compiler.truffle.common.hotspot; - -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompiler; - -import jdk.vm.ci.meta.ResolvedJavaMethod; - -public interface HotSpotTruffleCompiler extends TruffleCompiler { - - /** - * Compiles and installs special code for truffle call boundary methods. The passed method must - * have compilation and inlining disabled in HotSpot. - */ - void installTruffleCallBoundaryMethod(ResolvedJavaMethod method, TruffleCompilable compilable); - - /** - * Compiles and installs special code fast thread local object access. The passed method must - * have compilation and inlining disabled in HotSpot. - */ - void installTruffleReservedOopMethod(ResolvedJavaMethod method, TruffleCompilable compilable); - - int pendingTransferToInterpreterOffset(TruffleCompilable compilable); - - /** - * Releases caches used for PE/compilation. - */ - void purgePartialEvaluationCaches(); - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraalRepeated.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraalRepeated.java deleted file mode 100644 index d260df1897dc..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraalRepeated.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.common.hotspot.libgraal; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Container for repeated {@link TruffleFromLibGraal} annotations. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface TruffleFromLibGraalRepeated { - TruffleFromLibGraal[] value(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleToLibGraal.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleToLibGraal.java deleted file mode 100644 index 18e338eacde0..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleToLibGraal.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2013, 2022, 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 org.graalvm.compiler.truffle.common.hotspot.libgraal; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotates methods associated with both ends of a HotSpot to libgraal call. This annotation - * simplifies navigating between these methods in an IDE. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface TruffleToLibGraal { - /** - * Gets the token identifying a call from HotSpot to libgraal. - */ - Id value(); - - /** - * Identifier for a call from HotSpot to libgraal. - */ - // Please keep sorted - enum Id { - DoCompile, - GetCompilerConfigurationFactoryName, - GetDataPatchesCount, - GetExceptionHandlersCount, - GetInfopoints, - GetInfopointsCount, - GetMarksCount, - GetNodeCount, - GetNodeTypes, - GetSuppliedString, - GetTargetCodeSize, - GetTotalFrameSize, - InitializeCompiler, - RegisterRuntime, - ListCompilerOptions, - CompilerOptionExists, - ValidateCompilerOption, - InitializeRuntime, - InstallTruffleCallBoundaryMethod, - InstallTruffleReservedOopMethod, - NewCompiler, - PendingTransferToInterpreterOffset, - PurgePartialEvaluationCaches, - Shutdown; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractKnownTruffleTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractKnownTruffleTypes.java index 4ea90103a842..72ff0ae5c2fd 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractKnownTruffleTypes.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractKnownTruffleTypes.java @@ -32,7 +32,8 @@ import java.util.Map; import org.graalvm.compiler.debug.GraalError; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; + +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.MetaAccessProvider; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractTruffleCompilationSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractTruffleCompilationSupport.java index 2bc35c34d900..d0aebf3c8b12 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractTruffleCompilationSupport.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/AbstractTruffleCompilationSupport.java @@ -24,8 +24,8 @@ */ package org.graalvm.compiler.truffle.compiler; -import org.graalvm.compiler.truffle.common.TruffleCompilationSupport; -import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor; +import com.oracle.truffle.compiler.TruffleCompilationSupport; +import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; public abstract class AbstractTruffleCompilationSupport implements TruffleCompilationSupport { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/ExpansionStatistics.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/ExpansionStatistics.java index 833f9c136e4f..b358a5150a5c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/ExpansionStatistics.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/ExpansionStatistics.java @@ -52,9 +52,10 @@ import org.graalvm.compiler.nodes.spi.VirtualizableAllocation; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.schedule.SchedulePhase; -import org.graalvm.compiler.truffle.common.TruffleCompilable; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.CompilationTier; +import com.oracle.truffle.compiler.TruffleCompilable; + import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/KnownTruffleTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/KnownTruffleTypes.java index 025ff97ec3a8..6f2ca4bcfa9e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/KnownTruffleTypes.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/KnownTruffleTypes.java @@ -36,7 +36,7 @@ import java.util.Objects; import java.util.Set; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; @@ -149,11 +149,11 @@ public class KnownTruffleTypes extends AbstractKnownTruffleTypes { public final ResolvedJavaField AbstractAssumption_isValid = findField(AbstractAssumption, "isValid"); // truffle.runtime - public final ResolvedJavaType BaseOSRRootNode = lookupTypeCached("org.graalvm.compiler.truffle.runtime.BaseOSRRootNode"); + public final ResolvedJavaType BaseOSRRootNode = lookupTypeCached("com.oracle.truffle.runtime.BaseOSRRootNode"); public final ResolvedJavaField BaseOSRRootNode_loopNode = findField(BaseOSRRootNode, "loopNode"); - public final ResolvedJavaType CompilationState = lookupType("org.graalvm.compiler.truffle.runtime.CompilationState"); + public final ResolvedJavaType CompilationState = lookupType("com.oracle.truffle.runtime.CompilationState"); - public final ResolvedJavaType OptimizedCallTarget = lookupTypeCached("org.graalvm.compiler.truffle.runtime.OptimizedCallTarget"); + public final ResolvedJavaType OptimizedCallTarget = lookupTypeCached("com.oracle.truffle.runtime.OptimizedCallTarget"); public final ResolvedJavaMethod OptimizedCallTarget_callDirect = findMethod(OptimizedCallTarget, "callDirect", Node, Object_Array); public final ResolvedJavaMethod OptimizedCallTarget_callInlined = findMethod(OptimizedCallTarget, "callInlined", Node, Object_Array); public final ResolvedJavaMethod OptimizedCallTarget_callIndirect = findMethod(OptimizedCallTarget, "callIndirect", Node, Object_Array); @@ -164,12 +164,12 @@ public class KnownTruffleTypes extends AbstractKnownTruffleTypes { public final ResolvedJavaField OptimizedCallTarget_validRootAssumption = findField(OptimizedCallTarget, "validRootAssumption"); public final ResolvedJavaField OptimizedCallTarget_rootNode = findField(OptimizedCallTarget, "rootNode"); - public final ResolvedJavaType OptimizedDirectCallNode = lookupTypeCached("org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode"); + public final ResolvedJavaType OptimizedDirectCallNode = lookupTypeCached("com.oracle.truffle.runtime.OptimizedDirectCallNode"); public final ResolvedJavaField OptimizedDirectCallNode_currentCallTarget = findField(OptimizedDirectCallNode, "currentCallTarget"); public final ResolvedJavaField OptimizedDirectCallNode_inliningForced = findField(OptimizedDirectCallNode, "inliningForced"); public final ResolvedJavaField OptimizedDirectCallNode_callCount = findField(OptimizedDirectCallNode, "callCount"); - public final ResolvedJavaType OptimizedAssumption = lookupType("org.graalvm.compiler.truffle.runtime.OptimizedAssumption"); + public final ResolvedJavaType OptimizedAssumption = lookupType("com.oracle.truffle.runtime.OptimizedAssumption"); public final ResolvedJavaType[] skippedExceptionTypes = createSkippedExceptionTypes(); // Checkstyle: resume field name check diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PartialEvaluator.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PartialEvaluator.java index 61cd0d95b46e..5e90bdd2e9d5 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PartialEvaluator.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PartialEvaluator.java @@ -66,18 +66,19 @@ import org.graalvm.compiler.serviceprovider.GraalServices; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime.InlineKind; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; import org.graalvm.compiler.truffle.compiler.phases.DeoptimizeOnExceptionPhase; import org.graalvm.compiler.truffle.compiler.phases.InstrumentPhase; import org.graalvm.compiler.truffle.compiler.substitutions.GraphBuilderInvocationPluginProvider; import org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; +import com.oracle.truffle.compiler.TruffleCompilerRuntime.InlineKind; + import jdk.vm.ci.meta.DeoptimizationAction; import jdk.vm.ci.meta.DeoptimizationReason; import jdk.vm.ci.meta.JavaConstant; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PerformanceInformationHandler.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PerformanceInformationHandler.java index 39646f41002a..8cb5316cefc6 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PerformanceInformationHandler.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/PerformanceInformationHandler.java @@ -53,10 +53,11 @@ import org.graalvm.compiler.nodes.java.MethodCallTargetNode; import org.graalvm.compiler.nodes.util.GraphUtil; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.PerformanceWarningKind; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleAST.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleAST.java index 2fba436c5932..7e5d297497aa 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleAST.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleAST.java @@ -36,10 +36,6 @@ import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; import org.graalvm.compiler.truffle.compiler.PartialEvaluator.SourceLanguagePositionImpl; import org.graalvm.compiler.truffle.compiler.phases.inlining.CallNode; import org.graalvm.compiler.truffle.compiler.phases.inlining.CallNode.State; @@ -47,6 +43,11 @@ import org.graalvm.graphio.GraphBlocks; import org.graalvm.graphio.GraphStructure; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; + import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilation.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilation.java index 0bf149d65174..1cee2c3f0dee 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilation.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilation.java @@ -29,9 +29,10 @@ import org.graalvm.compiler.debug.LogStream; import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; /** * Represents a truffle compilation bundling compilable and task into a single object. Also installs diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilationIdentifier.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilationIdentifier.java index 05c547b73f4c..c8aa4d7929e6 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilationIdentifier.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilationIdentifier.java @@ -25,8 +25,9 @@ package org.graalvm.compiler.truffle.compiler; import org.graalvm.compiler.core.common.CompilationIdentifier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; public interface TruffleCompilationIdentifier extends CompilationIdentifier { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerConfiguration.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerConfiguration.java index 6414686e7621..c24610873306 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerConfiguration.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerConfiguration.java @@ -31,7 +31,8 @@ import org.graalvm.compiler.core.target.Backend; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import org.graalvm.compiler.phases.tiers.Suites; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; + +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.code.Architecture; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java index bfbfd90818a9..515a7bb0a835 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerImpl.java @@ -85,13 +85,6 @@ import org.graalvm.compiler.phases.tiers.Suites; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerAssumptionDependency; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleCompilation.TTYToPolyglotLoggerBridge; import org.graalvm.compiler.truffle.compiler.nodes.AnyExtendNode; import org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption; @@ -99,6 +92,14 @@ import org.graalvm.compiler.truffle.compiler.phases.InstrumentationSuite; import org.graalvm.compiler.truffle.compiler.phases.TruffleTier; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.TruffleCompilerAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.code.CompilationRequest; import jdk.vm.ci.code.InstalledCode; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerOptions.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerOptions.java index 9dbac51eeb03..e407f7d81981 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerOptions.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleCompilerOptions.java @@ -39,7 +39,9 @@ import org.graalvm.compiler.options.OptionType; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.options.OptionsParser; -import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor; + +import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; +import com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor.Type; /* * Do not refer to any compiler classes here to guarantee lazy class loading. @@ -316,11 +318,28 @@ public static TruffleCompilerOptionDescriptor[] listOptions() { List convertedDescriptors = new ArrayList<>(); for (org.graalvm.compiler.options.OptionDescriptor descriptor : TruffleCompilerImpl.OPTION_DESCRIPTORS) { - convertedDescriptors.add(new TruffleCompilerOptionDescriptor(descriptor)); + convertedDescriptors.add(createCompilerOptionDescriptor(descriptor)); } return convertedDescriptors.toArray(new TruffleCompilerOptionDescriptor[convertedDescriptors.size()]); } + private static TruffleCompilerOptionDescriptor createCompilerOptionDescriptor(OptionDescriptor d) { + return new TruffleCompilerOptionDescriptor(d.getName(), matchGraalOptionType(d), d.isDeprecated(), d.getHelp(), d.getDeprecationMessage()); + } + + private static Type matchGraalOptionType(OptionDescriptor d) { + switch (d.getOptionType()) { + case User: + return Type.USER; + case Expert: + return Type.EXPERT; + case Debug: + return Type.DEBUG; + default: + return Type.DEBUG; + } + } + static Object parseCustom(OptionDescriptor descriptor, String uncheckedValue) { Class type = descriptor.getOptionValueType(); if (type == PerformanceWarnings.class) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleConstantFieldProvider.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleConstantFieldProvider.java index 967d45fcaf66..4d2c1d7d280b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleConstantFieldProvider.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleConstantFieldProvider.java @@ -25,7 +25,8 @@ package org.graalvm.compiler.truffle.compiler; import org.graalvm.compiler.core.common.spi.ConstantFieldProvider; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; + +import com.oracle.truffle.compiler.ConstantFieldInfo; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleDebugJavaMethod.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleDebugJavaMethod.java index 90e93c5f5dbd..c834c9b0201d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleDebugJavaMethod.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleDebugJavaMethod.java @@ -24,8 +24,8 @@ */ package org.graalvm.compiler.truffle.compiler; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleTierContext.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleTierContext.java index dde0bae0ceb7..9eead2621437 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleTierContext.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/TruffleTierContext.java @@ -36,11 +36,12 @@ import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.phases.util.Providers; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java index ff498e8e47a5..7648a02bfab0 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/HostInliningPhase.java @@ -78,11 +78,10 @@ import org.graalvm.compiler.phases.common.inlining.InliningUtil; import org.graalvm.compiler.phases.contract.NodeCostUtil; import org.graalvm.compiler.phases.tiers.HighTierContext; -import org.graalvm.compiler.truffle.common.HostMethodInfo; +import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.compiler.HostMethodInfo; import jdk.vm.ci.meta.JavaTypeProfile; import jdk.vm.ci.meta.ProfilingInfo; @@ -397,9 +396,10 @@ private static boolean isInBudget(CallTree call, int graphSize, int sizeLimit) { *

* This method follows the same rules as the {@link PartialEvaluator} for recursive exploration. * For example, methods dominated by a call to - * {@link CompilerDirectives#transferToInterpreterAndInvalidate()} are not inlined or explored. - * The same applies to calls protected by {@link CompilerDirectives#inInterpreter()} or methods - * annotated by {@link TruffleBoundary}. + * {@link KnownTruffleTypes#CompilerDirectives}#transferToInterpreterAndInvalidate() not inlined + * or explored. The same applies to calls protected by + * {@link KnownTruffleTypes#CompilerDirectives}#inInterpreter() or methods annotated by + * TruffleBoundary. */ private List exploreGraph(InliningPhaseContext context, CallTree caller, StructuredGraph graph, int exploreRound) { caller.exploredIndex = exploreRound; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleHostEnvironment.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleHostEnvironment.java index 00c177746769..1b96b1db947e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleHostEnvironment.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleHostEnvironment.java @@ -26,12 +26,13 @@ import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java index e1f0121165b0..3d0e364b03c4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/host/TruffleKnownHostTypes.java @@ -24,10 +24,11 @@ */ package org.graalvm.compiler.truffle.compiler.host; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.AbstractKnownTruffleTypes; import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -42,7 +43,7 @@ public final class TruffleKnownHostTypes extends AbstractKnownTruffleTypes { // truffle.api.impl public final ResolvedJavaType FrameWithoutBoxing = lookupType("com.oracle.truffle.api.impl.FrameWithoutBoxing"); - public final ResolvedJavaType OptimizedCallTarget = lookupTypeCached("org.graalvm.compiler.truffle.runtime.OptimizedCallTarget"); + public final ResolvedJavaType OptimizedCallTarget = lookupTypeCached("com.oracle.truffle.runtime.OptimizedCallTarget"); public final ResolvedJavaMethod OptimizedCallTarget_call = findMethod(OptimizedCallTarget, "call", lookupType(Object[].class)); // truffle.api diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotKnownTruffleTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotKnownTruffleTypes.java index ac1ff8c2b752..8c170711ced4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotKnownTruffleTypes.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotKnownTruffleTypes.java @@ -27,9 +27,10 @@ import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; @@ -49,10 +50,10 @@ public final class HotSpotKnownTruffleTypes extends KnownTruffleTypes { public final ResolvedJavaField InstalledCode_entryPoint = findField(InstalledCode, "entryPoint"); // truffle.runtime.hotspot - public final ResolvedJavaType HotSpotThreadLocalHandshake = lookupTypeCached("org.graalvm.compiler.truffle.runtime.hotspot.HotSpotThreadLocalHandshake"); + public final ResolvedJavaType HotSpotThreadLocalHandshake = lookupTypeCached("com.oracle.truffle.runtime.hotspot.HotSpotThreadLocalHandshake"); public final ResolvedJavaMethod HotSpotThreadLocalHandshake_doHandshake = findMethod(HotSpotThreadLocalHandshake, "doHandshake", java_lang_Object); - public final ResolvedJavaType HotSpotOptimizedCallTarget = lookupTypeCached("org.graalvm.compiler.truffle.runtime.hotspot.HotSpotOptimizedCallTarget"); + public final ResolvedJavaType HotSpotOptimizedCallTarget = lookupTypeCached("com.oracle.truffle.runtime.hotspot.HotSpotOptimizedCallTarget"); public final ResolvedJavaField HotSpotOptimizedCallTarget_installedCode = findField(HotSpotOptimizedCallTarget, "installedCode"); public HotSpotKnownTruffleTypes(TruffleCompilerRuntime runtime, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotPartialEvaluator.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotPartialEvaluator.java index 8200464817b6..41963f1f8d22 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotPartialEvaluator.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotPartialEvaluator.java @@ -37,12 +37,13 @@ import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleElementCache; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; + import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationIdentifier.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationIdentifier.java index 6542e3cf9bd4..35b7f255e04a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationIdentifier.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationIdentifier.java @@ -25,10 +25,11 @@ package org.graalvm.compiler.truffle.compiler.hotspot; import org.graalvm.compiler.hotspot.HotSpotCompilationIdentifier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; + import jdk.vm.ci.hotspot.HotSpotCompilationRequest; /** diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationSupport.java index b1dcf71e31eb..2f346e4c7cde 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationSupport.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilationSupport.java @@ -27,11 +27,11 @@ import org.graalvm.compiler.hotspot.CompilerConfigurationFactory; import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.AbstractTruffleCompilationSupport; import org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl.Options; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; + +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; @@ -69,7 +69,7 @@ public TruffleCompiler createCompiler(TruffleCompilerRuntime runtime) { @Override public void registerRuntime(TruffleCompilerRuntime runtime) { - HotSpotTruffleHostEnvironmentLookup.registerRuntime((HotSpotTruffleRuntime) runtime); + HotSpotTruffleHostEnvironmentLookup.registerRuntime(runtime); } } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilerImpl.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilerImpl.java index 32c7c2d68e89..babb5ea576c9 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilerImpl.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleCompilerImpl.java @@ -80,10 +80,6 @@ import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.printer.GraalDebugHandlersFactory; import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.common.hotspot.HotSpotTruffleCompiler; import org.graalvm.compiler.truffle.compiler.PartialEvaluatorConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; @@ -92,6 +88,11 @@ import org.graalvm.compiler.truffle.compiler.host.HostInliningPhase; import org.graalvm.compiler.truffle.compiler.host.InjectImmutableFrameFieldsPhase; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.hotspot.HotSpotTruffleCompiler; + import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.CompiledCode; import jdk.vm.ci.code.InstalledCode; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleGraphBuilderPlugins.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleGraphBuilderPlugins.java index 75939af45345..f073af38d9f4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleGraphBuilderPlugins.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleGraphBuilderPlugins.java @@ -72,7 +72,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec static void registerHotspotThreadLocalStubPlugins(InvocationPlugins plugins, WordTypes wordTypes, int jvmciReservedReference0Offset) { GraalError.guarantee(jvmciReservedReference0Offset != -1, "jvmciReservedReference0Offset is not available but used."); - InvocationPlugins.Registration tl = new InvocationPlugins.Registration(plugins, "org.graalvm.compiler.truffle.runtime.hotspot.HotSpotFastThreadLocal"); + InvocationPlugins.Registration tl = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.runtime.hotspot.HotSpotFastThreadLocal"); tl.register(new RequiredInvocationPlugin("getJVMCIReservedReference") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironment.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironment.java index a5725eecafd9..c72c3faf20b9 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironment.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironment.java @@ -24,13 +24,14 @@ */ package org.graalvm.compiler.truffle.compiler.hotspot; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; +import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.compiler.truffle.compiler.TruffleElementCache; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; + +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -54,7 +55,12 @@ protected TruffleCompilerImpl createCompiler(TruffleCompilable compilable) { /* * If we directly compile in the host, we can just lookup the host compiler. */ - return (TruffleCompilerImpl) ((HotSpotTruffleRuntime) runtime()).getTruffleCompiler(compilable); + TruffleCompilerRuntime runtime = runtime(); + try { + return (TruffleCompilerImpl) runtime.getClass().getMethod("getTruffleCompiler", TruffleCompilable.class).invoke(runtime, compilable); + } catch (ReflectiveOperationException e) { + throw GraalError.shouldNotReachHere(e); + } } final class HostMethodInfoCache extends TruffleElementCache { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironmentLookup.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironmentLookup.java index 9147416e1c36..c4de7b41528e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironmentLookup.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleHostEnvironmentLookup.java @@ -28,7 +28,8 @@ import org.graalvm.compiler.serviceprovider.ServiceProvider; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; + +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.meta.ResolvedJavaType; @@ -41,12 +42,12 @@ @ServiceProvider(TruffleHostEnvironment.Lookup.class) public final class HotSpotTruffleHostEnvironmentLookup implements TruffleHostEnvironment.Lookup { - private static final AtomicReference RUNTIME = new AtomicReference<>(); + private static final AtomicReference RUNTIME = new AtomicReference<>(); private TruffleHostEnvironment environment; @Override public TruffleHostEnvironment lookup(ResolvedJavaType forType) { - HotSpotTruffleRuntime runtime = RUNTIME.get(); + TruffleCompilerRuntime runtime = RUNTIME.get(); if (runtime == null) { // fast-path non truffle return null; @@ -69,7 +70,7 @@ public TruffleHostEnvironment lookup(ResolvedJavaType forType) { return env; } - public static boolean registerRuntime(HotSpotTruffleRuntime runtime) { + public static boolean registerRuntime(TruffleCompilerRuntime runtime) { return RUNTIME.compareAndSet(null, runtime); } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleSafepointLoweringSnippet.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleSafepointLoweringSnippet.java index 3a8e08713937..4e889819c1e7 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleSafepointLoweringSnippet.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/HotSpotTruffleSafepointLoweringSnippet.java @@ -70,8 +70,8 @@ public final class HotSpotTruffleSafepointLoweringSnippet implements Snippets { /** * Description for a call to - * {@code org.graalvm.compiler.truffle.runtime.hotspot.HotSpotThreadLocalHandshake.doHandshake()} - * via a stub. + * {@code com.oracle.truffle.runtime.hotspot.HotSpotThreadLocalHandshake.doHandshake()} via a + * stub. */ static final HotSpotForeignCallDescriptor THREAD_LOCAL_HANDSHAKE = new HotSpotForeignCallDescriptor( SAFEPOINT, @@ -84,7 +84,7 @@ public final class HotSpotTruffleSafepointLoweringSnippet implements Snippets { /** * Snippet that does the same as - * {@code org.graalvm.compiler.truffle.runtime.hotspot.HotSpotThreadLocalHandshake.poll()}. + * {@code com.oracle.truffle.runtime.hotspot.HotSpotThreadLocalHandshake.poll()}. * * This condition cannot be hoisted out of loops as it is introduced in a phase late enough. See * {@link TruffleSafepointInsertionPhase}. diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCallBoundaryInstrumentationFactory.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCallBoundaryInstrumentationFactory.java index 277650982b6e..95a475577e8c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCallBoundaryInstrumentationFactory.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCallBoundaryInstrumentationFactory.java @@ -30,10 +30,12 @@ import org.graalvm.compiler.lir.asm.EntryPointDecorator; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; +import com.oracle.truffle.compiler.TruffleCompilable; + /** * A service for creating a specialized {@link CompilationResultBuilder} used to inject code into * the beginning of a - * {@linkplain HotSpotTruffleCompilerImpl#installTruffleCallBoundaryMethod(jdk.vm.ci.meta.ResolvedJavaMethod, org.graalvm.compiler.truffle.common.TruffleCompilable) + * {@linkplain HotSpotTruffleCompilerImpl#installTruffleCallBoundaryMethod(jdk.vm.ci.meta.ResolvedJavaMethod, TruffleCompilable) * call boundary method}. The injected code tests the {@code entryPoint} field of the * {@code installedCode} field of the receiver and tail calls it if it is non-zero: * diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCommunityCompilerConfiguration.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCommunityCompilerConfiguration.java index feec26d2c070..b9dd70a07f0d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCommunityCompilerConfiguration.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleCommunityCompilerConfiguration.java @@ -29,11 +29,12 @@ import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import org.graalvm.compiler.nodes.spi.Replacements; import org.graalvm.compiler.options.OptionValues; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.host.HostInliningPhase; import org.graalvm.compiler.truffle.compiler.host.InjectImmutableFrameFieldsPhase; import org.graalvm.compiler.truffle.compiler.substitutions.TruffleInvocationPlugins; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.code.Architecture; /** diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleEntryPointDecorator.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleEntryPointDecorator.java index f8b9b0bcdafd..0f6df4dd438a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleEntryPointDecorator.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/hotspot/TruffleEntryPointDecorator.java @@ -39,7 +39,7 @@ /** * Mechanism for injecting special code into - * {@linkplain HotSpotTruffleCompilerImpl#installTruffleCallBoundaryMethod(jdk.vm.ci.meta.ResolvedJavaMethod, org.graalvm.compiler.truffle.common.TruffleCompilable) + * {@linkplain HotSpotTruffleCompilerImpl#installTruffleCallBoundaryMethod(jdk.vm.ci.meta.ResolvedJavaMethod, com.oracle.truffle.compiler.TruffleCompilable) * call boundary methods}. */ public abstract class TruffleEntryPointDecorator implements EntryPointDecorator { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/FrameAccessVerificationPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/FrameAccessVerificationPhase.java index 72770f02b306..181b10b43cf2 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/FrameAccessVerificationPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/FrameAccessVerificationPhase.java @@ -54,7 +54,6 @@ import org.graalvm.compiler.phases.graph.ReentrantNodeIterator; import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.LoopInfo; import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure; -import org.graalvm.compiler.truffle.common.TruffleCompilable; import org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.PerformanceWarningKind; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; @@ -64,6 +63,8 @@ import org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameAccessVerificationNode; import org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode; +import com.oracle.truffle.compiler.TruffleCompilable; + import jdk.vm.ci.meta.DeoptimizationAction; import jdk.vm.ci.meta.DeoptimizationReason; import jdk.vm.ci.meta.SpeculationLog.Speculation; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InliningAcrossTruffleBoundaryPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InliningAcrossTruffleBoundaryPhase.java index ca26d908c1d5..65de31ee72aa 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InliningAcrossTruffleBoundaryPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InliningAcrossTruffleBoundaryPhase.java @@ -27,9 +27,10 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.java.MethodCallTargetNode; import org.graalvm.compiler.phases.BasePhase; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + public final class InliningAcrossTruffleBoundaryPhase extends BasePhase { @Override protected void run(StructuredGraph graph, TruffleTierContext context) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentPhase.java index 4d3c9aca84b4..21f5358fb3b0 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentPhase.java @@ -85,10 +85,10 @@ private static String asStackPattern(String declaringClassName, String methodNam } private static final String[] OMITTED_STACK_PATTERNS = new String[]{ - asStackPattern("org.graalvm.compiler.truffle.runtime.OptimizedCallTarget", "executeRootNode"), - asStackPattern("org.graalvm.compiler.truffle.runtime.OptimizedCallTarget", "profiledPERoot"), - asStackPattern("org.graalvm.compiler.truffle.runtime.OptimizedCallTarget", "callDirect"), - asStackPattern("org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode", "call"), + asStackPattern("com.oracle.truffle.runtime.OptimizedCallTarget", "executeRootNode"), + asStackPattern("com.oracle.truffle.runtime.OptimizedCallTarget", "profiledPERoot"), + asStackPattern("com.oracle.truffle.runtime.OptimizedCallTarget", "callDirect"), + asStackPattern("com.oracle.truffle.runtime.OptimizedDirectCallNode", "call"), }; private final Instrumentation instrumentation; protected final SnippetReflectionProvider snippetReflection; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentTruffleBoundariesPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentTruffleBoundariesPhase.java index e1a13d2b95d5..76e9c74376db 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentTruffleBoundariesPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/InstrumentTruffleBoundariesPhase.java @@ -31,9 +31,10 @@ import org.graalvm.compiler.nodes.FixedWithNextNode; import org.graalvm.compiler.nodes.Invoke; import org.graalvm.compiler.nodes.StructuredGraph; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime.InlineKind; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; +import com.oracle.truffle.compiler.TruffleCompilerRuntime.InlineKind; + import jdk.vm.ci.meta.JavaConstant; /** diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/SetIdentityForValueTypesPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/SetIdentityForValueTypesPhase.java index 50dc54cee7e1..faa762d36a8a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/SetIdentityForValueTypesPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/SetIdentityForValueTypesPhase.java @@ -28,9 +28,10 @@ import org.graalvm.compiler.nodes.virtual.VirtualInstanceNode; import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; import org.graalvm.compiler.phases.BasePhase; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.ResolvedJavaType; public final class SetIdentityForValueTypesPhase extends BasePhase { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/TruffleSafepointInsertionPhase.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/TruffleSafepointInsertionPhase.java index c1be891c47e9..66d24978044a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/TruffleSafepointInsertionPhase.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/TruffleSafepointInsertionPhase.java @@ -47,8 +47,6 @@ import org.graalvm.compiler.truffle.compiler.TruffleCompilation; import org.graalvm.compiler.truffle.compiler.nodes.TruffleSafepointNode; -import com.oracle.truffle.api.TruffleSafepoint; - import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -57,8 +55,8 @@ /** * Adds Truffle safepoints to loops and methods ends. * - * Invocations of {@link TruffleSafepoint#poll(com.oracle.truffle.api.nodes.Node)} are removed - * during PE. This phase ensures that they are efficiently added again at method and loop ends. + * Invocations of TruffleSafepoint.poll are removed during PE. This phase ensures that they are + * efficiently added again at method and loop ends. */ public final class TruffleSafepointInsertionPhase extends Phase { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallNode.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallNode.java index d8408770e79e..e37c852c0b58 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallNode.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallNode.java @@ -48,10 +48,12 @@ import org.graalvm.compiler.phases.common.inlining.InliningUtil; import org.graalvm.compiler.phases.common.inlining.InliningUtil.InlineeReturnAction; import org.graalvm.compiler.phases.contract.NodeCostUtil; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions.PerformanceWarningKind; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; + import org.graalvm.compiler.truffle.compiler.TruffleTierContext; import jdk.vm.ci.meta.JavaConstant; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallTree.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallTree.java index 46f050f24ac9..03dcba628f3c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallTree.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/CallTree.java @@ -26,13 +26,14 @@ import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.graph.Graph; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PostPartialEvaluationSuite; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions; import org.graalvm.compiler.truffle.compiler.TruffleTierContext; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + public final class CallTree extends Graph { private final InliningPolicy policy; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/GraphManager.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/GraphManager.java index 8792bb107ba3..979d0aa40f3e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/GraphManager.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/phases/inlining/GraphManager.java @@ -42,7 +42,6 @@ import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin; import org.graalvm.compiler.phases.common.inlining.InliningUtil; import org.graalvm.compiler.phases.contract.NodeCostUtil; -import org.graalvm.compiler.truffle.common.TruffleCompilable; import org.graalvm.compiler.truffle.compiler.PEAgnosticInlineInvokePlugin; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PostPartialEvaluationSuite; @@ -51,6 +50,8 @@ import org.graalvm.compiler.truffle.compiler.TruffleTierContext; import org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption; +import com.oracle.truffle.compiler.TruffleCompilable; + import jdk.vm.ci.meta.ResolvedJavaMethod; final class GraphManager { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleGraphBuilderPlugins.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleGraphBuilderPlugins.java index f76f4ff26e6f..a102383cff68 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleGraphBuilderPlugins.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleGraphBuilderPlugins.java @@ -97,7 +97,6 @@ import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.replacements.nodes.arithmetic.UnsignedMulHighNode; import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; import org.graalvm.compiler.truffle.compiler.PerformanceInformationHandler; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; @@ -123,6 +122,8 @@ import org.graalvm.compiler.truffle.compiler.phases.TruffleSafepointInsertionPhase; import org.graalvm.word.LocationIdentity; +import com.oracle.truffle.compiler.TruffleCompilationTask; + import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.DeoptimizationAction; @@ -170,7 +171,7 @@ public static void registerInvocationPlugins(InvocationPlugins plugins, KnownTru private static void registerTruffleSafepointPlugins(InvocationPlugins plugins, KnownTruffleTypes types, boolean canDelayIntrinsification) { final ResolvedJavaType truffleSafepoint = types.TruffleSafepoint; Registration r = new Registration(plugins, new ResolvedJavaSymbol(truffleSafepoint)); - r.register(new RequiredInvocationPlugin("poll", com.oracle.truffle.api.nodes.Node.class) { + r.register(new RequiredInvocationPlugin("poll", new ResolvedJavaSymbol(types.Node)) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { if (!TruffleSafepointInsertionPhase.allowsSafepoints(b.getGraph())) { @@ -926,9 +927,6 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - /** - * @see com.oracle.truffle.api.nodes.Node - */ public static void registerNodePlugins(InvocationPlugins plugins, KnownTruffleTypes types, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, ConstantReflectionProvider constantReflection) { Registration r = new Registration(plugins, new ResolvedJavaSymbol(types.Node)); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleInvocationPlugins.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleInvocationPlugins.java index 8bad07545a10..61fcd7a3860f 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleInvocationPlugins.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/compiler/substitutions/TruffleInvocationPlugins.java @@ -45,6 +45,7 @@ import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; +import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.OptionalLazySymbol; import org.graalvm.compiler.nodes.spi.Replacements; import org.graalvm.compiler.replacements.nodes.ArrayCopyWithConversionsNode; import org.graalvm.compiler.replacements.nodes.ArrayIndexOfMacroNode; @@ -55,8 +56,6 @@ import org.graalvm.compiler.replacements.nodes.MacroNode; import org.graalvm.word.LocationIdentity; -import com.oracle.truffle.api.nodes.Node; - import jdk.vm.ci.aarch64.AArch64; import jdk.vm.ci.amd64.AMD64; import jdk.vm.ci.code.Architecture; @@ -268,28 +267,30 @@ private static void registerTStringPlugins(InvocationPlugins plugins, Replacemen plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/strings/TStringOps;")); InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.strings.TStringOps", replacements); - r.register(new InlineOnlyInvocationPlugin("runIndexOfAny1", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class) { + OptionalLazySymbol nodeType = new OptionalLazySymbol("com.oracle.truffle.api.nodes.Node"); + + r.register(new InlineOnlyInvocationPlugin("runIndexOfAny1", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0) { return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchAny, location, array, offset, length, stride, isNative, fromIndex, v0); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfAny2", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOfAny2", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0, ValueNode v1) { return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchAny, location, array, offset, length, stride, isNative, fromIndex, v0, v1); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfAny3", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOfAny3", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0, ValueNode v1, ValueNode v2) { return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchAny, location, array, offset, length, stride, isNative, fromIndex, v0, v1, v2); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfAny4", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOfAny4", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0, ValueNode v1, ValueNode v2, @@ -297,14 +298,14 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchAny, location, array, offset, length, stride, isNative, fromIndex, v0, v1, v2, v3); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfRange1", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOfRange1", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0, ValueNode v1) { return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchRange, location, array, offset, length, stride, isNative, fromIndex, v0, v1); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfRange2", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class, + r.register(new InlineOnlyInvocationPlugin("runIndexOfRange2", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, @@ -313,14 +314,14 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.MatchRange, location, array, offset, length, stride, isNative, fromIndex, v0, v1, v2, v3); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOfTable", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, byte[].class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOfTable", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, byte[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode tables) { return applyIndexOf(b, targetMethod, ArrayIndexOfVariant.Table, location, array, offset, length, stride, isNative, fromIndex, tables); } }); - r.register(new InlineOnlyInvocationPlugin("runIndexOf2ConsecutiveWithStride", Node.class, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runIndexOf2ConsecutiveWithStride", nodeType, byte[].class, long.class, int.class, int.class, boolean.class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode stride, ValueNode isNative, ValueNode fromIndex, ValueNode v0, ValueNode v1) { @@ -328,7 +329,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); - r.register(new InlineOnlyInvocationPlugin("runRegionEqualsWithStride", Node.class, + r.register(new InlineOnlyInvocationPlugin("runRegionEqualsWithStride", nodeType, byte[].class, long.class, boolean.class, byte[].class, long.class, boolean.class, int.class, int.class) { @Override @@ -348,7 +349,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runMemCmp", Node.class, + r.register(new InlineOnlyInvocationPlugin("runMemCmp", nodeType, byte[].class, long.class, boolean.class, byte[].class, long.class, boolean.class, int.class, int.class) { @Override @@ -368,7 +369,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runArrayCopy", Node.class, + r.register(new InlineOnlyInvocationPlugin("runArrayCopy", nodeType, byte[].class, long.class, boolean.class, byte[].class, long.class, boolean.class, int.class, int.class) { @Override @@ -378,7 +379,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return applyArrayCopy(b, arrayA, offsetA, arrayB, offsetB, length, dynamicStrides); } }); - r.register(new InlineOnlyInvocationPlugin("runArrayCopy", Node.class, + r.register(new InlineOnlyInvocationPlugin("runArrayCopy", nodeType, char[].class, long.class, byte[].class, long.class, int.class, int.class) { @Override @@ -388,7 +389,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return applyArrayCopy(b, arrayA, offsetA, arrayB, offsetB, length, dynamicStrides); } }); - r.register(new InlineOnlyInvocationPlugin("runArrayCopy", Node.class, + r.register(new InlineOnlyInvocationPlugin("runArrayCopy", nodeType, int[].class, long.class, byte[].class, long.class, int.class, int.class) { @Override @@ -398,7 +399,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return applyArrayCopy(b, arrayA, offsetA, arrayB, offsetB, length, dynamicStrides); } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesLatin1", Node.class, byte[].class, long.class, int.class, boolean.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesLatin1", nodeType, byte[].class, long.class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode isNative) { @@ -407,7 +408,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesBMP", Node.class, byte[].class, long.class, int.class, boolean.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesBMP", nodeType, byte[].class, long.class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode isNative) { @@ -416,7 +417,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF8", Node.class, byte[].class, long.class, int.class, boolean.class, boolean.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF8", nodeType, byte[].class, long.class, int.class, boolean.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode isNative, ValueNode assumeValid) { @@ -425,7 +426,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF16", Node.class, byte[].class, long.class, int.class, boolean.class, boolean.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF16", nodeType, byte[].class, long.class, int.class, boolean.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode isNative, ValueNode assumeValid) { @@ -434,7 +435,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF16C", Node.class, char[].class, long.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF16C", nodeType, char[].class, long.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length) { @@ -443,7 +444,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF32", Node.class, byte[].class, long.class, int.class, boolean.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF32", nodeType, byte[].class, long.class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length, ValueNode isNative) { @@ -452,7 +453,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF32I", Node.class, int[].class, long.class, int.class) { + r.register(new InlineOnlyInvocationPlugin("runCalcStringAttributesUTF32I", nodeType, int[].class, long.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, ValueNode array, ValueNode offset, ValueNode length) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationEvent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationEvent.java deleted file mode 100644 index 072ff73a23b4..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -/** - * The JFR event describing a Truffle compilation. - */ -public interface CompilationEvent extends RootFunctionEvent { - - void compilationStarted(); - - void failed(boolean permanent, CharSequence reason); - - void succeeded(); - - void setCompiledCodeSize(int size); - - void setCompiledCodeAddress(long addr); - - void setInlinedCalls(int count); - - void setDispatchedCalls(int count); - - void setGraalNodeCount(int count); - - void setPartialEvaluationNodeCount(int count); - - void setPartialEvaluationTime(long time); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationStatisticsEvent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationStatisticsEvent.java deleted file mode 100644 index 675f453c7afb..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/CompilationStatisticsEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -public interface CompilationStatisticsEvent extends Event { - - void setCompiledMethods(long compiledMethods); - - void setBailouts(long bailouts); - - void setInvalidations(long invalidations); - - void setCompiledCodeSize(long size); - - void setTotalTime(long time); - - void setPeakTime(long time); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/DeoptimizationEvent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/DeoptimizationEvent.java deleted file mode 100644 index 3819a7e7297e..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/DeoptimizationEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -public interface DeoptimizationEvent extends RootFunctionEvent { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/Event.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/Event.java deleted file mode 100644 index 71ed6d802d77..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/Event.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -public interface Event { - - boolean isEnabled(); - - void publish(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/EventFactory.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/EventFactory.java deleted file mode 100644 index 1a7d2b3f2f4f..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/EventFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -import java.lang.annotation.Annotation; - -public interface EventFactory { - - Class getRequiredAnnotation(); - - boolean isInitialized(); - - void addInitializationListener(Runnable listener); - - CompilationEvent createCompilationEvent(); - - DeoptimizationEvent createDeoptimizationEvent(); - - InvalidationEvent createInvalidationEvent(); - - CompilationStatisticsEvent createCompilationStatisticsEvent(); - - void addPeriodicEvent(Class event, Runnable producer); - - void removePeriodicEvent(Class event, Runnable producer); - - interface Provider { - EventFactory getEventFactory(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/InvalidationEvent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/InvalidationEvent.java deleted file mode 100644 index 621980e75cef..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/InvalidationEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -public interface InvalidationEvent extends RootFunctionEvent { - - void setReason(CharSequence invalidationReason); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/RootFunctionEvent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/RootFunctionEvent.java deleted file mode 100644 index 9edf3a9ad643..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/jfr/RootFunctionEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.jfr; - -import com.oracle.truffle.api.RootCallTarget; - -public interface RootFunctionEvent extends Event { - - void setRootFunction(RootCallTarget target); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractGraalTruffleRuntimeListener.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractGraalTruffleRuntimeListener.java deleted file mode 100644 index bd8132b8b91c..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractGraalTruffleRuntimeListener.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.runtime; - -public abstract class AbstractGraalTruffleRuntimeListener implements GraalTruffleRuntimeListener { - - protected final GraalTruffleRuntime runtime; - - protected AbstractGraalTruffleRuntimeListener(GraalTruffleRuntime runtime) { - this.runtime = runtime; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractOptimizedLoopNode.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractOptimizedLoopNode.java deleted file mode 100644 index b45b1f05378c..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractOptimizedLoopNode.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.compiler.truffle.runtime; - -import java.util.Objects; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.RepeatingNode; - -abstract class AbstractOptimizedLoopNode extends LoopNode { - - @Child protected RepeatingNode repeatingNode; - - @CompilationFinal private long trueCount; // long for long running loops. - @CompilationFinal private int falseCount; - - protected AbstractOptimizedLoopNode(RepeatingNode repeatingNode) { - this.repeatingNode = Objects.requireNonNull(repeatingNode); - } - - @Override - public final RepeatingNode getRepeatingNode() { - return repeatingNode; - } - - protected final void profileCounted(long iterations) { - if (CompilerDirectives.inInterpreter()) { - long trueCountLocal = trueCount + iterations; - if (trueCountLocal >= 0) { // don't write overflow values - trueCount = trueCountLocal; - int falseCountLocal = falseCount; - if (falseCountLocal < Integer.MAX_VALUE) { - falseCount = falseCountLocal + 1; - } - } - } - } - - protected final boolean inject(boolean condition) { - if (CompilerDirectives.inCompiledCode()) { - return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); - } else { - return condition; - } - } - - private static double calculateProbability(long trueCountLocal, int falseCountLocal) { - if (falseCountLocal == 0 && trueCountLocal == 0) { - // Avoid division by zero and assume default probability for AOT. - return 0.5; - } else { - return (double) trueCountLocal / (double) (trueCountLocal + falseCountLocal); - } - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BaseOSRRootNode.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BaseOSRRootNode.java deleted file mode 100644 index d13e34f9db99..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BaseOSRRootNode.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2015, 2022, 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 org.graalvm.compiler.truffle.runtime; - -import java.lang.ref.Reference; - -import com.oracle.truffle.api.TruffleLanguage; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.NodeInterface; -import com.oracle.truffle.api.nodes.RootNode; - -/** - * Base class for on-stack replaced (OSR) root nodes. - */ -public abstract class BaseOSRRootNode extends RootNode { - - /** - * Not adopted by the OSRRootNode; belongs to another RootNode. OptimizedCallTarget treats - * OSRRootNodes specially, skipping adoption of child nodes. - * - * This loop node instance is also used by the compiler to find the real root node e.g. for the - * truffle guest safepoint location. See TruffleSafepointInsertionPhase#skipOSRRoot. - */ - @Child protected NodeInterface loopNode; - - protected BaseOSRRootNode(TruffleLanguage language, FrameDescriptor frameDescriptor, NodeInterface loopNode) { - super(language, frameDescriptor); - this.loopNode = loopNode; - } - - @Override - public final Object execute(VirtualFrame frame) { - try { - return executeOSR(frame); - } finally { - // reachability fence is needed to keep the values from being cleared as non-live locals - Reference.reachabilityFence(frame); - Reference.reachabilityFence(this); - } - } - - /** - * Entrypoint for OSR root nodes. - */ - protected abstract Object executeOSR(VirtualFrame frame); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationState.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationState.java deleted file mode 100644 index 161b4e168853..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationState.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.CompilerDirectives; - -public enum CompilationState { - - INTERPRETED, - - FIRST_TIER_ROOT, - LAST_TIER_ROOT, - - FIRST_TIER_INLINED, - LAST_TIER_INLINED; - - boolean isCompilationRoot() { - return this == FIRST_TIER_ROOT || this == LAST_TIER_ROOT; - } - - boolean isCompiled() { - return this != INTERPRETED; - } - - int getTier() { - switch (this) { - case INTERPRETED: - return 0; - case FIRST_TIER_INLINED: - case FIRST_TIER_ROOT: - return 1; - case LAST_TIER_INLINED: - case LAST_TIER_ROOT: - return 2; - default: - throw CompilerDirectives.shouldNotReachHere("invalid state"); - } - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DefaultLoopNodeFactory.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DefaultLoopNodeFactory.java deleted file mode 100644 index 0956e81f3de4..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DefaultLoopNodeFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015, 2018, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.RepeatingNode; - -public class DefaultLoopNodeFactory implements LoopNodeFactory { - - @Override - public LoopNode create(RepeatingNode repeatingNode) { - return OptimizedOSRLoopNode.create(repeatingNode); - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineCacheSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineCacheSupport.java deleted file mode 100644 index 6d1bddec934b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineCacheSupport.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.runtime; - -import java.util.function.Function; - -import org.graalvm.options.OptionDescriptors; -import org.graalvm.options.OptionValues; - -import com.oracle.truffle.api.TruffleLogger; - -public interface EngineCacheSupport extends GraalRuntimeServiceProvider { - - void onEngineCreated(EngineData e); - - void onEnginePatch(EngineData e); - - boolean onEngineClosing(EngineData e); - - void onEngineClosed(EngineData e); - - boolean isStoreEnabled(OptionValues options); - - Object tryLoadingCachedEngine(OptionValues options, Function loggerFactory); - - final class Disabled implements EngineCacheSupport { - - @Override - public void onEngineCreated(EngineData e) { - } - - @Override - public void onEnginePatch(EngineData e) { - } - - @Override - public Object tryLoadingCachedEngine(OptionValues options, Function loggerFactory) { - return null; - } - - @Override - public boolean onEngineClosing(EngineData e) { - return false; - } - - @Override - public boolean isStoreEnabled(OptionValues options) { - return false; - } - - @Override - public void onEngineClosed(EngineData e) { - } - - @Override - public int getPriority() { - // only last resort - return Integer.MIN_VALUE; - } - - @Override - public OptionDescriptors getEngineOptions() { - return OptionDescriptors.EMPTY; - } - - } - - static EngineCacheSupport get() { - return GraalTruffleRuntime.getRuntime().getEngineCacheSupport(); - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FixedPointMath.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FixedPointMath.java deleted file mode 100644 index cf012173dbeb..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FixedPointMath.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2013, 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 org.graalvm.compiler.truffle.runtime; - -public final class FixedPointMath { - private static final int SCALE = 4; - - /** - * should not be instantiated. - */ - private FixedPointMath() { - throw new IllegalStateException("Should not instantiate " + this.getClass().getName()); - } - - public static int toFixedPoint(double x) { - return (int) (x * (1 << SCALE)); - } - - public static int multiply(int fixedPointValue, int anInteger) { - return (fixedPointValue * anInteger) >> SCALE; - } - - public static double toDouble(int fixedPointValue) { - return ((double) fixedPointValue) / (1 << SCALE); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FloodControlHandler.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FloodControlHandler.java deleted file mode 100644 index aee11df1e110..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/FloodControlHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.compiler.truffle.runtime; - -import java.util.function.Supplier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; - -/** - * Support for an embedder to impose control over logging and dumping during Truffle compilation - * failure handling. - */ -public interface FloodControlHandler extends GraalRuntimeServiceProvider { - - /** - * Return {@code true} to suppress logging and dumping of a given exception. - */ - boolean isSuppressedFailure(TruffleCompilable compilable, Supplier serializedException); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFastThreadLocal.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFastThreadLocal.java deleted file mode 100644 index 75f5fe09b0a3..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFastThreadLocal.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.compiler.truffle.runtime; - -import static com.oracle.truffle.api.CompilerAsserts.partialEvaluationConstant; -import static com.oracle.truffle.api.CompilerDirectives.inCompiledCode; -import static org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.castArrayFixedLength; -import static org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.unsafeCast; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.impl.AbstractFastThreadLocal; - -public abstract class GraalFastThreadLocal extends AbstractFastThreadLocal { - - protected GraalFastThreadLocal() { - } - - @Override - public abstract void set(Object[] data); - - @Override - public abstract Object[] get(); - - @Override - @SuppressWarnings("unchecked") - public final C fastGet(int index, Class castType, boolean invalidateOnNull) { - Object[] data; - if (inCompiledCode()) { - partialEvaluationConstant(index); - partialEvaluationConstant(castType); - Object[] array = get(); - if (array == null) { - if (invalidateOnNull) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - } - return null; - } - Object v = castArrayFixedLength(array, index + 1)[index]; - C result = unsafeCast(v, castType, true, false, true); - return result; - } else { - data = get(); - if (data == null) { - return null; - } - C result = (C) data[index]; - assert castType == null || result == null || result.getClass() == castType : "Invalid exact type returned"; - return result; - } - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalOSRFrameInstance.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalOSRFrameInstance.java deleted file mode 100644 index d597132758eb..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalOSRFrameInstance.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.nodes.RootNode; - -import jdk.vm.ci.code.stack.InspectedFrame; - -/** - * Represents a Truffle {@link com.oracle.truffle.api.frame.FrameInstance} where OSR occurred. - * - * Contains a separate field for the {@link InspectedFrame} containing the most up-to-date Frame. - */ -public final class GraalOSRFrameInstance extends GraalFrameInstance { - private final InspectedFrame osrFrame; - - GraalOSRFrameInstance(InspectedFrame callTargetFrame, InspectedFrame callNodeFrame, InspectedFrame osrFrame) { - super(callTargetFrame, callNodeFrame); - this.osrFrame = osrFrame; - } - - @TruffleBoundary - @Override - public Frame getFrame(FrameAccess access) { - Frame materializedOSRFrame = getFrameFrom(osrFrame, access); - if (getOSRRootNode() instanceof OptimizedOSRLoopNode.LoopOSRRootNode) { - return (Frame) materializedOSRFrame.getArguments()[0]; - } - return materializedOSRFrame; - } - - private RootNode getOSRRootNode() { - return ((OptimizedCallTarget) osrFrame.getLocal(GraalFrameInstance.CALL_TARGET_INDEX)).getRootNode(); - } - - @TruffleBoundary - @Override - public boolean isVirtualFrame() { - return osrFrame.isVirtual(FRAME_INDEX); - } - - @TruffleBoundary - @Override - public int getCompilationTier() { - return ((CompilationState) osrFrame.getLocal(OPTIMIZATION_TIER_FRAME_INDEX)).getTier(); - } - - @TruffleBoundary - @Override - public boolean isCompilationRoot() { - return ((CompilationState) osrFrame.getLocal(OPTIMIZATION_TIER_FRAME_INDEX)).isCompilationRoot(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeAccessor.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeAccessor.java deleted file mode 100644 index 5dd3cf7b4503..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeAccessor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2019, 2022, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.impl.Accessor; - -final class GraalRuntimeAccessor extends Accessor { - - static final GraalRuntimeAccessor ACCESSOR = new GraalRuntimeAccessor(); - - static final NodeSupport NODES = ACCESSOR.nodeSupport(); - static final SourceSupport SOURCE = ACCESSOR.sourceSupport(); - static final InstrumentSupport INSTRUMENT = ACCESSOR.instrumentSupport(); - static final LanguageSupport LANGUAGE = ACCESSOR.languageSupport(); - static final EngineSupport ENGINE = ACCESSOR.engineSupport(); - static final InteropSupport INTEROP = ACCESSOR.interopSupport(); - static final FrameSupport FRAME = ACCESSOR.framesSupport(); - - private GraalRuntimeAccessor() { - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeServiceProvider.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeServiceProvider.java deleted file mode 100644 index 2c2108d0b308..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalRuntimeServiceProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015, 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 org.graalvm.compiler.truffle.runtime; - -import org.graalvm.options.OptionDescriptors; - -public interface GraalRuntimeServiceProvider { - - default int getPriority() { - return 0; - } - - default OptionDescriptors getEngineOptions() { - return null; - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTVMCI.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTVMCI.java deleted file mode 100644 index 95b55e78d0ee..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTVMCI.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2014, 2022, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.impl.Accessor.EngineSupport; -import com.oracle.truffle.api.impl.Accessor.RuntimeSupport; -import com.oracle.truffle.api.impl.TVMCI; -import com.oracle.truffle.api.nodes.RootNode; - -public final class GraalTVMCI extends TVMCI { - - @Override - protected RuntimeSupport createRuntimeSupport(Object permission) { - return new GraalRuntimeSupport(permission); - } - - static EngineData getEngineData(RootNode rootNode) { - final EngineSupport engineAccess = GraalRuntimeAccessor.ENGINE; - final Object layer; - if (rootNode == null) { - layer = engineAccess.getCurrentSharingLayer(); - } else { - layer = GraalRuntimeAccessor.NODES.getSharingLayer(rootNode); - } - return engineAccess.getOrCreateRuntimeData(layer); - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTestTVMCI.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTestTVMCI.java deleted file mode 100644 index a0fd1e0e90f4..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTestTVMCI.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2017, 2022, 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 org.graalvm.compiler.truffle.runtime; - -import java.io.Closeable; -import java.io.IOException; - -import org.graalvm.compiler.truffle.runtime.GraalTestTVMCI.GraalTestContext; - -import com.oracle.truffle.api.impl.TVMCI; -import com.oracle.truffle.api.nodes.RootNode; - -final class GraalTestTVMCI extends TVMCI.Test { - - static final class GraalTestContext implements Closeable { - - @Override - public synchronized void close() throws IOException { - } - } - - @Override - protected GraalTestContext createTestContext(String testName) { - return new GraalTestContext(); - } - - @Override - public OptimizedCallTarget createTestCallTarget(GraalTestContext testContext, RootNode testNode) { - return (OptimizedCallTarget) testNode.getCallTarget(); - } - - @SuppressWarnings("try") - @Override - public void finishWarmup(GraalTestContext testContext, OptimizedCallTarget callTarget) { - callTarget.compile(true); - callTarget.waitForCompilation(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/LoopNodeFactory.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/LoopNodeFactory.java deleted file mode 100644 index 56f72b63a7ec..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/LoopNodeFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.RepeatingNode; - -public interface LoopNodeFactory extends GraalRuntimeServiceProvider { - - LoopNode create(RepeatingNode repeatingNode); - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/ModuleUtil.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/ModuleUtil.java deleted file mode 100644 index b8f84b6acdb7..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/ModuleUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.compiler.truffle.runtime; - -import java.util.Set; - -public final class ModuleUtil { - - public static void exportTo(Class client) { - Module truffleModule = ModuleUtil.class.getModule(); - exportFromTo(truffleModule, client.getModule()); - } - - private static void exportFromTo(Module truffleModule, Module clientModule) { - if (truffleModule != clientModule) { - Set packages = truffleModule.getPackages(); - for (String pkg : packages) { - boolean exported = truffleModule.isExported(pkg, clientModule); - if (!exported) { - truffleModule.addExports(pkg, clientModule); - } - } - } - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedIndirectCallNode.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedIndirectCallNode.java deleted file mode 100644 index 3ac4530fc388..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedIndirectCallNode.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2013, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.CallTarget; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.IndirectCallNode; -import com.oracle.truffle.api.nodes.NodeInfo; - -/** - * A call node with a dynamic {@link CallTarget} that can be optimized by Graal. - */ -@NodeInfo -public final class OptimizedIndirectCallNode extends IndirectCallNode { - - @CompilationFinal private Class exceptionProfile; - - /* - * Should be instantiated with the runtime. - */ - OptimizedIndirectCallNode() { - } - - @Override - public Object call(CallTarget target, Object... arguments) { - try { - OptimizedCallTarget optimizedTarget = ((OptimizedCallTarget) target); - return optimizedTarget.callIndirect(this, arguments); - } catch (Throwable t) { - throw handleException(t); - } - } - - private RuntimeException handleException(Throwable t) { - Throwable profiledT = profileExceptionType(t); - GraalRuntimeAccessor.LANGUAGE.addStackFrameInfo(this, null, profiledT, null); - throw OptimizedCallTarget.rethrow(profiledT); - } - - @SuppressWarnings("unchecked") - private T profileExceptionType(T value) { - Class clazz = exceptionProfile; - if (clazz != Throwable.class) { - if (clazz != null && value.getClass() == clazz) { - if (CompilerDirectives.inInterpreter()) { - return value; - } else { - return (T) CompilerDirectives.castExact(value, clazz); - } - } else { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (clazz == null) { - exceptionProfile = value.getClass(); - } else { - exceptionProfile = Throwable.class; - } - } - } - return value; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedLoopNode.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedLoopNode.java deleted file mode 100644 index c2ff38144a7c..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedLoopNode.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014, 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 org.graalvm.compiler.truffle.runtime; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.TruffleSafepoint; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.RepeatingNode; - -public final class OptimizedLoopNode extends AbstractOptimizedLoopNode { - - OptimizedLoopNode(RepeatingNode repeatingNode) { - super(repeatingNode); - } - - @Override - public Object execute(VirtualFrame frame) { - Object status; - long loopCount = 0; - try { - while (inject(repeatingNode.shouldContinue(status = repeatingNode.executeRepeatingWithValue(frame)))) { - if (CompilerDirectives.hasNextTier()) { - loopCount++; - } - TruffleSafepoint.poll(this); - } - return status; - } finally { - profileCounted(loopCount); - reportLoopCount(this, OptimizedOSRLoopNode.toIntOrMaxInt(loopCount)); - } - } - - static LoopNode create(RepeatingNode repeatingNode) { - return new OptimizedLoopNode(repeatingNode); - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/SuppressFBWarnings.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/SuppressFBWarnings.java deleted file mode 100644 index 4052161953e2..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/SuppressFBWarnings.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016, 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 org.graalvm.compiler.truffle.runtime; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Used to suppress SpotBugs warnings. - */ -@Retention(RetentionPolicy.CLASS) -@interface SuppressFBWarnings { - /** - * @see "https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html" - */ - String[] value(); - - /** - * Reason why the warning is suppressed. Use a SpotBugs issue id where appropriate. - */ - String justification(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleCallBoundary.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleCallBoundary.java deleted file mode 100644 index fad539de8274..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleCallBoundary.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2014, 2018, 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 org.graalvm.compiler.truffle.runtime; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Denotes methods for which Truffle compiled code may be available. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface TruffleCallBoundary { - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleInlining.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleInlining.java deleted file mode 100644 index 17f20c9c9fce..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleInlining.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2013, 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 org.graalvm.compiler.truffle.runtime; - -import org.graalvm.compiler.truffle.common.TruffleCompilable; - -/** - * @deprecated this class is schedule for removal. Use {@link AbstractCompilationTask} instead. - */ -@Deprecated -public class TruffleInlining { - - private final AbstractCompilationTask task; - - public TruffleInlining(AbstractCompilationTask task) { - this.task = task; - } - - public int countCalls() { - return task.countCalls(); - } - - public int countInlinedCalls() { - return task.countInlinedCalls(); - } - - public TruffleCompilable[] inlinedTargets() { - return task.inlinedTargets(); - } - - public void addInlinedTarget(TruffleCompilable target) { - task.addInlinedTarget(target); - } - - public void setCallCounts(int total, int inlined) { - task.setCallCounts(total, inlined); - } - - public void addTargetToDequeue(TruffleCompilable target) { - task.addTargetToDequeue(target); - } - - public void dequeueTargets() { - task.dequeueTargets(); - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleTypes.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleTypes.java deleted file mode 100644 index eb09694160ff..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleTypes.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015, 2018, 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 org.graalvm.compiler.truffle.runtime; - -/** - * A service for getting types that can be resolved by - * {@link GraalTruffleRuntime#resolveType(jdk.vm.ci.meta.MetaAccessProvider, String, boolean)}. - */ -public interface TruffleTypes { - - /** - * Gets the types supplied by this supplier. - */ - Class[] getTypes(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/SerialQueue.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/SerialQueue.java deleted file mode 100644 index ad9b1b7e6018..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/SerialQueue.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.compiler.truffle.runtime.collection; - -interface SerialQueue { - void add(E x); - - @SuppressWarnings("unused") - default int addIndexOf(E x) { - throw new UnsupportedOperationException(); - } - - /** - * Returns the position in the pool, or -1 if the element is not present. - */ - @SuppressWarnings("unused") - default int indexOf(E x) { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unchecked") - E poll(); - - @SuppressWarnings("unchecked") - E peek(); - - void clear(); - - int size(); - - Object[] toArray(); - - @SuppressWarnings("unchecked") - T[] toArray(T[] a); - - int internalCapacity(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceASTCompilationListener.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceASTCompilationListener.java deleted file mode 100644 index 7b36473fa58b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceASTCompilationListener.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2014, 2020, 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 org.graalvm.compiler.truffle.runtime.debug; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; - -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.NodeUtil; -import com.oracle.truffle.api.nodes.NodeVisitor; - -/** - * Traces all polymorphic and generic nodes after each successful Truffle compilation. - */ -public final class TraceASTCompilationListener extends AbstractGraalTruffleRuntimeListener { - - private TraceASTCompilationListener(GraalTruffleRuntime runtime) { - super(runtime); - } - - public static void install(GraalTruffleRuntime runtime) { - runtime.addListener(new TraceASTCompilationListener(runtime)); - } - - @Override - public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilationTask task, GraphInfo graphInfo, CompilationResultInfo compilationResultInfo) { - if (target.getOptionValue(OptimizedRuntimeOptions.TraceCompilationAST)) { - StringWriter logMessage = new StringWriter(); - try (PrintWriter out = new PrintWriter(logMessage)) { - printCompactTree(out, target); - } - runtime.logEvent(target, 0, "opt AST", target.toString(), target.getDebugProperties(), logMessage.toString()); - } - } - - private static void printCompactTree(PrintWriter out, OptimizedCallTarget target) { - target.accept(new NodeVisitor() { - private boolean newLine = false; - - @Override - public boolean visit(Node node) { - if (node == null) { - return true; - } - Node parent = node.getParent(); - if (newLine) { - out.println(); - } else { - newLine = true; - } - if (parent == null) { - out.printf("%s", node.getClass().getSimpleName()); - } else { - String fieldName = NodeUtil.findChildFieldName(parent, node); - out.printf("%s = %s", fieldName, node.getClass().getSimpleName()); - } - return true; - } - - }); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationPolymorphismListener.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationPolymorphismListener.java deleted file mode 100644 index eef40afec3f6..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationPolymorphismListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2014, 2020, 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 org.graalvm.compiler.truffle.runtime.debug; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; - -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.NodeCost; -import com.oracle.truffle.api.nodes.NodeUtil; -import com.oracle.truffle.api.nodes.NodeVisitor; - -public final class TraceCompilationPolymorphismListener extends AbstractGraalTruffleRuntimeListener { - - private TraceCompilationPolymorphismListener(GraalTruffleRuntime runtime) { - super(runtime); - } - - public static void install(GraalTruffleRuntime runtime) { - runtime.addListener(new TraceCompilationPolymorphismListener(runtime)); - } - - @Override - public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilationTask task, GraphInfo graph, CompilationResultInfo result) { - if (target.getOptionValue(OptimizedRuntimeOptions.TraceCompilationPolymorphism)) { - target.accept(new NodeVisitor() { - @Override - public boolean visit(Node node) { - if (node != null && (node.getCost() == NodeCost.MEGAMORPHIC || node.getCost() == NodeCost.POLYMORPHIC)) { - NodeCost cost = node.getCost(); - Map props = new LinkedHashMap<>(); - props.put("simpleName", node.getClass().getSimpleName()); - props.put("subtree", "\n" + NodeUtil.printCompactTreeToString(node)); - String msg = cost == NodeCost.MEGAMORPHIC ? "megamorphic" : "polymorphic"; - runtime.logEvent(target, 0, msg, node.toString(), props, null); - } - return true; - } - }); - } - } - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/AbstractHotSpotTruffleRuntimeAccess.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/AbstractHotSpotTruffleRuntimeAccess.java deleted file mode 100644 index d80ab7ebddf7..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/AbstractHotSpotTruffleRuntimeAccess.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2013, 2018, 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 org.graalvm.compiler.truffle.runtime.hotspot; - -import com.oracle.truffle.api.TruffleRuntime; -import com.oracle.truffle.api.TruffleRuntimeAccess; -import com.oracle.truffle.api.impl.DefaultTruffleRuntime; -import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; -import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; -import jdk.vm.ci.runtime.JVMCI; -import jdk.vm.ci.services.Services; - -public abstract class AbstractHotSpotTruffleRuntimeAccess implements TruffleRuntimeAccess { - - private final boolean hasOpenJVMCI; - - protected AbstractHotSpotTruffleRuntimeAccess() { - hasOpenJVMCI = JVMCIOpenSupport.openJVMCI(); - } - - @Override - public final TruffleRuntime getRuntime() { - if (hasOpenJVMCI) { - // initialize JVMCI to make sure the TruffleCompiler option is parsed - Services.initializeJVMCI(); - HotSpotJVMCIRuntime hsRuntime = (HotSpotJVMCIRuntime) JVMCI.getRuntime(); - HotSpotVMConfigAccess config = new HotSpotVMConfigAccess(hsRuntime.getConfigStore()); - boolean useCompiler = config.getFlag("UseCompiler", Boolean.class); - if (useCompiler) { - return createRuntime(); - } - } - return new DefaultTruffleRuntime(); - } - - @Override - public final int getPriority() { - if (hasOpenJVMCI) { - return calculatePriority(); - } else { - return Integer.MIN_VALUE; - } - } - - protected abstract TruffleRuntime createRuntime(); - - protected abstract int calculatePriority(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java deleted file mode 100644 index 5bd664cb7b73..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2019, 2023, 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 org.graalvm.compiler.truffle.runtime.hotspot; - -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; - -import jdk.vm.ci.hotspot.HotSpotSpeculationLog; -import jdk.vm.ci.meta.SpeculationLog; - -/** - * JDK versioned functionality used by the HotSpot Truffle runtime. - * - * This version is for JDK 17+. - */ -class HotSpotTruffleRuntimeServices { - - /** - * A wrapper that holds a strong reference to another speculation log that - * {@linkplain HotSpotSpeculationLog#managesFailedSpeculations() manages} the failed - * speculations list. - */ - static class CompilationSpeculationLog extends HotSpotSpeculationLog { - private final HotSpotSpeculationLog wrappedLog; - - CompilationSpeculationLog(HotSpotSpeculationLog wrappedLog) { - super(wrappedLog.getFailedSpeculationsAddress()); - this.wrappedLog = wrappedLog; - } - - @Override - public String toString() { - return wrappedLog.toString(); - } - } - - /** - * Gets a speculation log to be used for compiling {@code callTarget}. - */ - public static SpeculationLog getCompilationSpeculationLog(OptimizedCallTarget callTarget) { - HotSpotSpeculationLog wrappedLog = (HotSpotSpeculationLog) callTarget.getSpeculationLog(); - CompilationSpeculationLog compilationSpeculationLog = new CompilationSpeculationLog(wrappedLog); - compilationSpeculationLog.collectFailedSpeculations(); - return compilationSpeculationLog; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/JVMCIOpenSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/JVMCIOpenSupport.java deleted file mode 100644 index 72ae35bd43a8..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/JVMCIOpenSupport.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.compiler.truffle.runtime.hotspot; - -final class JVMCIOpenSupport { - - private static final Module truffleRuntimeModule; - private static final Module jvmciModule; - private static final boolean truffleAttachLibraryAvailable; - static { - truffleRuntimeModule = JVMCIOpenSupport.class.getModule(); - jvmciModule = truffleRuntimeModule.getLayer().findModule("jdk.internal.vm.ci").orElse(null); - truffleAttachLibraryAvailable = jvmciModule != null && loadTruffleAttachLibrary(); - } - - private JVMCIOpenSupport() { - } - - static boolean hasOpenJVMCI() { - return jvmciModule != null && isJVMCIExportedOrOpenedToTruffleRuntime(); - } - - static boolean openJVMCI() { - if (jvmciModule == null) { - return false; - } - if (isJVMCIExportedOrOpenedToTruffleRuntime()) { - return true; - } - if (truffleAttachLibraryAvailable) { - truffleRuntimeModule.addReads(jvmciModule); - openJVMCITo0(truffleRuntimeModule); - return true; - } - return false; - } - - private static boolean isJVMCIExportedOrOpenedToTruffleRuntime() { - return jvmciModule.isExported("jdk.vm.ci.hotspot", truffleRuntimeModule); - } - - private static boolean loadTruffleAttachLibrary() { - /* - * Support for unittests. Unittests are passing path to the truffleattach library using - * truffle.attach.library system property. - */ - String attachLib = System.getProperty("truffle.attach.library"); - try { - if (attachLib == null) { - try { - System.loadLibrary("truffleattach"); - } catch (UnsatisfiedLinkError invalidLibrary) { - return false; - } - } else { - System.load(attachLib); - } - return true; - } catch (Throwable throwable) { - throw new InternalError(throwable); - } - } - - private static native void openJVMCITo0(Module toModule); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/java/HotSpotTruffleRuntimeAccess.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/java/HotSpotTruffleRuntimeAccess.java deleted file mode 100644 index 6f32c4cd11ba..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/java/HotSpotTruffleRuntimeAccess.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2015, 2018, 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 org.graalvm.compiler.truffle.runtime.hotspot.java; - -import org.graalvm.compiler.serviceprovider.ServiceProvider; -import org.graalvm.compiler.truffle.common.TruffleCompilationSupport; -import org.graalvm.compiler.truffle.runtime.hotspot.AbstractHotSpotTruffleRuntimeAccess; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; - -import com.oracle.truffle.api.TruffleRuntime; -import com.oracle.truffle.api.TruffleRuntimeAccess; - -@ServiceProvider(TruffleRuntimeAccess.class) -public final class HotSpotTruffleRuntimeAccess extends AbstractHotSpotTruffleRuntimeAccess { - - @Override - protected TruffleRuntime createRuntime() { - try { - Class hotspotCompilationSupport = Class.forName("org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilationSupport"); - TruffleCompilationSupport compilationSupport = (TruffleCompilationSupport) hotspotCompilationSupport.getConstructor().newInstance(); - HotSpotTruffleRuntime rt = new HotSpotTruffleRuntime(compilationSupport); - compilationSupport.registerRuntime(rt); - return rt; - } catch (ReflectiveOperationException e) { - throw new InternalError(e); - } - } - - @Override - protected int calculatePriority() { - return 0; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java deleted file mode 100644 index 5f18e812310a..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -import static org.graalvm.libgraal.LibGraalScope.getIsolateThread; - -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; - -/** - * Encapsulates a handle to a {@code CompilationResultInfo} object in the libgraal heap. - */ -final class LibGraalCompilationResultInfo extends LibGraalScopedHandle implements TruffleCompilerListener.CompilationResultInfo { - - LibGraalCompilationResultInfo(long handle) { - super(handle, LibGraalCompilationResultInfo.class); - } - - @Override - public int getTargetCodeSize() { - return TruffleToLibGraalCalls.getTargetCodeSize(getIsolateThread(), getHandle()); - } - - @Override - public int getTotalFrameSize() { - return TruffleToLibGraalCalls.getTotalFrameSize(getIsolateThread(), getHandle()); - } - - @Override - public int getExceptionHandlersCount() { - return TruffleToLibGraalCalls.getExceptionHandlersCount(getIsolateThread(), getHandle()); - } - - @Override - public int getInfopointsCount() { - return TruffleToLibGraalCalls.getInfopointsCount(getIsolateThread(), getHandle()); - } - - @Override - public String[] getInfopoints() { - return TruffleToLibGraalCalls.getInfopoints(getIsolateThread(), getHandle()); - } - - @Override - public int getMarksCount() { - return TruffleToLibGraalCalls.getMarksCount(getIsolateThread(), getHandle()); - } - - @Override - public int getDataPatchesCount() { - return TruffleToLibGraalCalls.getDataPatchesCount(getIsolateThread(), getHandle()); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java deleted file mode 100644 index 537afb12f468..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -import static org.graalvm.libgraal.LibGraalScope.getIsolateThread; - -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; - -/** - * Encapsulates a handle to a {@link GraphInfo} object in the libgraal heap. - */ -final class LibGraalGraphInfo extends LibGraalScopedHandle implements TruffleCompilerListener.GraphInfo { - - LibGraalGraphInfo(long handle) { - super(handle, LibGraalGraphInfo.class); - } - - @Override - public int getNodeCount() { - return TruffleToLibGraalCalls.getNodeCount(getIsolateThread(), getHandle()); - } - - @Override - public String[] getNodeTypes(boolean simpleNames) { - return TruffleToLibGraalCalls.getNodeTypes(getIsolateThread(), getHandle(), simpleNames); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java deleted file mode 100644 index 093651e60b62..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -/** - * Encapsulates a handle to an object in the libgraal heap where the handle is only valid within the - * scope of a {@link TruffleFromLibGraalEntryPoints} method. - */ -class LibGraalScopedHandle implements AutoCloseable { - - /** - * Handle to a libgraal object. - */ - private long handle; - - private final Class handleType; - - /** - * Creates a new {@link LibGraalScopedHandle}. - * - * @param handle handle to a libgraal object - */ - LibGraalScopedHandle(long handle, Class handleType) { - this.handle = handle; - this.handleType = handleType; - } - - long getHandle() { - if (handle == 0L) { - throw new IllegalStateException("Using invalid handle to " + handleType.getName() + " object in libgraal heap"); - } - return handle; - } - - @Override - public void close() { - handle = 0L; - } - - @Override - public String toString() { - return String.format("%s@0x%x", handleType.getName(), handle); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java deleted file mode 100644 index 13cc2d9a0bc6..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, 2020, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -import static org.graalvm.libgraal.LibGraalScope.getIsolateThread; - -import java.util.function.Supplier; - -import org.graalvm.libgraal.LibGraalObject; - -/** - * Encapsulates a handle to a {@link Supplier} object in the libgraal heap. - */ -final class LibGraalStringSupplier extends LibGraalObject implements Supplier { - - LibGraalStringSupplier(long handle) { - super(handle); - } - - @Override - public String get() { - return TruffleToLibGraalCalls.getSuppliedString(getIsolateThread(), getHandle()); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleRuntimeAccess.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleRuntimeAccess.java deleted file mode 100644 index f51ba6d1976c..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleRuntimeAccess.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018, 2019, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -import org.graalvm.compiler.truffle.runtime.hotspot.AbstractHotSpotTruffleRuntimeAccess; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; -import org.graalvm.libgraal.LibGraal; - -import com.oracle.truffle.api.TruffleRuntime; - -/** - * Access to a {@link TruffleRuntime} that uses libgraal for compilation. - */ -public final class LibGraalTruffleRuntimeAccess extends AbstractHotSpotTruffleRuntimeAccess { - - @Override - protected TruffleRuntime createRuntime() { - LibGraalTruffleCompilationSupport compilationSupport = new LibGraalTruffleCompilationSupport(); - HotSpotTruffleRuntime runtime = new HotSpotTruffleRuntime(compilationSupport); - compilationSupport.registerRuntime(runtime); - return runtime; - } - - @Override - protected int calculatePriority() { - if (LibGraal.isAvailable()) { - return Integer.MAX_VALUE; - } - return Integer.MIN_VALUE; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java deleted file mode 100644 index d4dcdaeae5bc..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.DoCompile; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetCompilerConfigurationFactoryName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetDataPatchesCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetExceptionHandlersCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopoints; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopointsCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetMarksCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeTypes; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetTargetCodeSize; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetTotalFrameSize; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InitializeCompiler; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InitializeRuntime; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleCallBoundaryMethod; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleReservedOopMethod; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.NewCompiler; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.PendingTransferToInterpreterOffset; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.PurgePartialEvaluationCaches; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.RegisterRuntime; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.Shutdown; - -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id; - -/** - * Native methods linked to libgraal entry points. - */ -final class TruffleToLibGraalCalls { - - @TruffleToLibGraal(InitializeRuntime) - static native long initializeRuntime(long isolateThreadId, TruffleCompilerRuntime truffleRuntime, Class classLoaderDelegate); - - /** - * Registers a Truffle runtime. Returns true if this was the first runtime - * registered and false if there were previous calls to - * {@link #registerRuntime(long, Object)}. - */ - @TruffleToLibGraal(RegisterRuntime) - static native boolean registerRuntime(long isolateThreadId, Object truffleRuntime); - - @TruffleToLibGraal(Id.ListCompilerOptions) - static native byte[] listCompilerOptions(long isolateThreadId); - - @TruffleToLibGraal(Id.CompilerOptionExists) - static native boolean compilerOptionExists(long isolateThreadId, String optionName); - - @TruffleToLibGraal(Id.ValidateCompilerOption) - static native String validateCompilerOption(long isolateThreadId, String optionName, String optionValue); - - @TruffleToLibGraal(GetCompilerConfigurationFactoryName) - static native String getCompilerConfigurationFactoryName(long isolateThreadId, long truffleRuntimeHandle); - - @TruffleToLibGraal(NewCompiler) - static native long newCompiler(long isolateThreadId, long truffleRuntimeHandle); - - @TruffleToLibGraal(InitializeCompiler) - static native void initializeCompiler(long isolateThreadId, long compilerHandle, TruffleCompilable compilable, boolean firstInitialization); - - @TruffleToLibGraal(DoCompile) - static native void doCompile(long isolateThreadId, - long compilerHandle, - TruffleCompilationTask task, - TruffleCompilable compilable, - TruffleCompilerListener listener); - - @TruffleToLibGraal(InstallTruffleCallBoundaryMethod) - static native void installTruffleCallBoundaryMethod(long isolateThreadId, long handle, long methodHandle); - - @TruffleToLibGraal(InstallTruffleReservedOopMethod) - static native void installTruffleReservedOopMethod(long isolateThreadId, long handle, long methodHandle); - - @TruffleToLibGraal(PendingTransferToInterpreterOffset) - static native int pendingTransferToInterpreterOffset(long isolateThreadId, long handle, TruffleCompilable compilable); - - @TruffleToLibGraal(Shutdown) - static native void shutdown(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetNodeCount) - static native int getNodeCount(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetNodeTypes) - static native String[] getNodeTypes(long isolateThreadId, long handle, boolean simpleNames); - - @TruffleToLibGraal(GetSuppliedString) - static native String getSuppliedString(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetTargetCodeSize) - static native int getTargetCodeSize(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetTotalFrameSize) - static native int getTotalFrameSize(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetExceptionHandlersCount) - static native int getExceptionHandlersCount(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetInfopointsCount) - static native int getInfopointsCount(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetInfopoints) - static native String[] getInfopoints(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetMarksCount) - static native int getMarksCount(long isolateThreadId, long handle); - - @TruffleToLibGraal(GetDataPatchesCount) - static native int getDataPatchesCount(long isolateThreadId, long handle); - - @TruffleToLibGraal(PurgePartialEvaluationCaches) - static native void purgePartialEvaluationCaches(long isolateThreadId, long compilerHandle); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/serviceprovider/TruffleRuntimeServices.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/serviceprovider/TruffleRuntimeServices.java deleted file mode 100644 index 9eb208e072e9..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/serviceprovider/TruffleRuntimeServices.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 org.graalvm.compiler.truffle.runtime.serviceprovider; - -import java.util.ServiceLoader; - -/** - * A subset of the methods defined in {@code org.graalvm.compiler.serviceprovider.GraalServices}. - */ -public final class TruffleRuntimeServices { - - /** - * Gets an {@link Iterable} of the providers available for a given service. - * - * @param service the service whose provider is being requested - */ - public static Iterable load(Class service) { - Class lookupClass = TruffleRuntimeServices.class; - ModuleLayer moduleLayer = lookupClass.getModule().getLayer(); - Iterable services; - if (moduleLayer != null) { - services = ServiceLoader.load(moduleLayer, service); - } else { - services = ServiceLoader.load(service, lookupClass.getClassLoader()); - } - if (!services.iterator().hasNext()) { - services = ServiceLoader.load(service); - } - return services; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIEntryPoint.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIEntryPoint.java deleted file mode 100644 index 76e33a44e24a..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIEntryPoint.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, 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 org.graalvm.jniutils; - -import org.graalvm.nativeimage.hosted.Feature; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation used to mark methods called by the JNI native interface. The annotation can be used - * by {@link Feature}s to register the annotated methods as JNI accessed. - */ -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@Retention(RetentionPolicy.RUNTIME) -public @interface JNIEntryPoint { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/NativeBridgeSupport.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/NativeBridgeSupport.java deleted file mode 100644 index eaefa2507742..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/NativeBridgeSupport.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.jniutils; - -import org.graalvm.nativeimage.ImageSingletons; - -/** - * Services used by the {@code org.graalvm.jniutils} module. To enable the - * {@code org.graalvm.jniutils} module a {@code NativeBridgeSupport} instance must be registered in - * the {@link ImageSingletons}. - */ -public interface NativeBridgeSupport { - - /** - * Returns the name of a feature using {@code org.graalvm.jniutils} module. The feature name is - * used in the logging output. - */ - String getFeatureName(); - - /** - * Checks if logging at given level is enabled. - */ - boolean isTracingEnabled(int level); - - /** - * Logs the message. - */ - void trace(String message); - - /** - * Returns a {@code NativeBridgeSupport} instance registered in the {@link ImageSingletons}. - */ - static NativeBridgeSupport getInstance() { - return ImageSingletons.lookup(NativeBridgeSupport.class); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/DestroyedIsolateException.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/DestroyedIsolateException.java deleted file mode 100644 index a3143dd9b930..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/DestroyedIsolateException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.libgraal; - -/** - * Exception thrown when a {@link LibGraalObject} associated with a destroyed isolate context is - * used. - */ -public final class DestroyedIsolateException extends IllegalArgumentException { - - private static final long serialVersionUID = 1L; - - private final boolean vmExit; - - DestroyedIsolateException(String message, boolean vmExit) { - super(message); - this.vmExit = vmExit; - } - - /** - * Returns {@code true} if this exception was thrown during VM exit. - */ - public boolean isVmExit() { - return vmExit; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalEntryPointsResolver.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalEntryPointsResolver.java deleted file mode 100644 index b7e766b72438..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalEntryPointsResolver.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.libgraal.jni.annotation; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PACKAGE; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to generate the {@code FromLibGraalCalls} for given id type. The annotation can be - * applied to packages, types and methods. When applied to method the generated - * {@code FromLibGraalCalls} subclass delegates to the annotated method. The annotated method must - * be static and its return type must be {@code JClass}. When applied to package or type the - * {@link #entryPointsClassName} is used to resolve the {@code JClass}. - */ -@Retention(RetentionPolicy.SOURCE) -@Target({PACKAGE, TYPE, METHOD}) -public @interface FromLibGraalEntryPointsResolver { - /** - * The id class. It has to implement the {@link FromLibGraalId}. - */ - Class> value(); - - /** - * The fully qualified name of the entry points class on the HotSpot side. The - * {@code entryPointsClassName} is mandatory when the annotation is present on package or type - * element. - */ - String entryPointsClassName() default ""; -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalId.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalId.java deleted file mode 100644 index c7dda824a9c4..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/FromLibGraalId.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.libgraal.jni.annotation; - -public interface FromLibGraalId { - - String getName(); - - String getSignature(); - - String getMethodName(); - - Class[] getParameterTypes(); - - Class getReturnType(); - - /** - * Creates a JVM method signature as specified in the Sections 4.3.3 of the JVM Specification. - */ - static String encodeMethodSignature(Class returnType, Class... parameterTypes) { - StringBuilder builder = new StringBuilder("("); - for (Class type : parameterTypes) { - Utilities.encodeType(type, builder); - } - builder.append(")"); - Utilities.encodeType(returnType, builder); - return builder.toString(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/Utilities.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/Utilities.java deleted file mode 100644 index af6ce4a20137..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/annotation/Utilities.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2020, 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 org.graalvm.libgraal.jni.annotation; - -final class Utilities { - - private Utilities() { - } - - static void encodeType(Class type, StringBuilder buf) { - String desc; - if (type == boolean.class) { - desc = "Z"; - } else if (type == byte.class) { - desc = "B"; - } else if (type == char.class) { - desc = "C"; - } else if (type == short.class) { - desc = "S"; - } else if (type == int.class) { - desc = "I"; - } else if (type == long.class) { - desc = "J"; - } else if (type == float.class) { - desc = "F"; - } else if (type == double.class) { - desc = "D"; - } else if (type == void.class) { - desc = "V"; - } else if (type.isArray()) { - buf.append('['); - encodeType(type.getComponentType(), buf); - return; - } else { - desc = "L" + type.getName().replace('.', '/') + ";"; - } - buf.append(desc); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReference.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReference.java deleted file mode 100644 index c6e208d45264..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReference.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation configuring a type as a by reference parameter in the whole annotated compilation - * unit. For classes that have many methods using {@link ByReference} parameters, using this - * annotation is more convenient. Instead of overriding these methods and specifying - * {@link ByReference} in each method, the whole class can be annotated with - * {@link AlwaysByReference}. It is always possible to override {@link AlwaysByReference} - * configuration with {@link ByReference} annotation on a particular method or parameter. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.SOURCE) -@Repeatable(AlwaysByReferenceRepeated.class) -public @interface AlwaysByReference { - /** - * Method parameter or return type that should always be handled as a {@link ByReference} in the - * annotated compilation unit. - * - * @see ByReference - */ - Class type(); - - /** - * The class to instantiate for a foreign handle. - * - * @see ByReference#value() for the start point class requirements. - */ - Class startPointClass(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java deleted file mode 100644 index 541dae806891..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Container for repeated {@link AlwaysByReference} annotations. - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.SOURCE) -public @interface AlwaysByReferenceRepeated { - AlwaysByReference[] value(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchAccessor.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchAccessor.java deleted file mode 100644 index 824d2be664a9..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchAccessor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks a method as a custom dispatch accessor. In the class with a custom dispatch, the method is - * used to translate the API object to the dispatch class handling the operation. The method - * annotated by {@link CustomDispatchAccessor} must be a non-private static method with a single - * parameter returning the bridged type. - * - * @see CustomReceiverAccessor - * @see CustomDispatchFactory - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface CustomDispatchAccessor { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchFactory.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchFactory.java deleted file mode 100644 index 2cdfd453bfcb..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomDispatchFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks a method as a factory for custom dispatch API objects. In the class with a custom dispatch, - * the method is used to create a custom dispatch API object from a receiver transferred by a - * reference. The method annotated by {@link CustomDispatchFactory} must be a non-private static - * method taking a receiver parameter and returning the custom dispatch API object. - * - * @see CustomDispatchAccessor - * @see CustomReceiverAccessor - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface CustomDispatchFactory { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomReceiverAccessor.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomReceiverAccessor.java deleted file mode 100644 index 000bcb790c94..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/CustomReceiverAccessor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks a method as a custom receiver accessor. In the class with a custom dispatch, the method is - * used to translate the API object to the receiver. The method annotated by - * {@link CustomReceiverAccessor} must be a non-private static method with a single parameter - * returning the receiver. - * - * @see CustomDispatchAccessor - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface CustomReceiverAccessor { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java deleted file mode 100644 index d0a2855ba1be..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -final class DefaultStackTraceMarshaller implements BinaryMarshaller { - - static final DefaultStackTraceMarshaller INSTANCE = new DefaultStackTraceMarshaller(); - - private DefaultStackTraceMarshaller() { - } - - @Override - public StackTraceElement[] read(BinaryInput in) { - int len = in.readInt(); - StackTraceElement[] res = new StackTraceElement[len]; - for (int i = 0; i < len; i++) { - res[i] = StackTraceElementMarshaller.INSTANCE.read(in); - } - return res; - } - - @Override - public void write(BinaryOutput out, StackTraceElement[] stack) { - out.writeInt(stack.length); - for (StackTraceElement stackTraceElement : stack) { - StackTraceElementMarshaller.INSTANCE.write(out, stackTraceElement); - } - } - - @Override - public int inferSize(StackTraceElement[] object) { - return object.length == 0 ? 0 : object.length * StackTraceElementMarshaller.INSTANCE.inferSize(object[0]); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java deleted file mode 100644 index 85ec099b0ad2..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -final class DefaultThrowableMarshaller implements BinaryMarshaller { - - private static final int THROWABLE_SIZE_ESTIMATE = 1024; - private final DefaultStackTraceMarshaller stackTraceMarshaller = DefaultStackTraceMarshaller.INSTANCE; - - @Override - public Throwable read(BinaryInput in) { - String foreignExceptionClassName = in.readUTF(); - String foreignExceptionMessage = (String) in.readTypedValue(); - StackTraceElement[] foreignExceptionStack = stackTraceMarshaller.read(in); - return new MarshalledException(foreignExceptionClassName, foreignExceptionMessage, ForeignException.mergeStackTrace(foreignExceptionStack)); - } - - @Override - public void write(BinaryOutput out, Throwable object) { - out.writeUTF(object instanceof MarshalledException ? ((MarshalledException) object).getForeignExceptionClassName() : object.getClass().getName()); - out.writeTypedValue(object.getMessage()); - stackTraceMarshaller.write(out, object.getStackTrace()); - } - - @Override - public int inferSize(Throwable object) { - // We don't use Throwable#getStackTrace as it allocates. - return THROWABLE_SIZE_ESTIMATE; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/EndPointHandle.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/EndPointHandle.java deleted file mode 100644 index 7c3dcaecab5a..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/EndPointHandle.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import org.graalvm.jniutils.HSObject; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks a bridge class field as a foreign reference handle. - * - * When the bridged type is a class, the handle to a foreign object has to be stored in a - * non-private field annotated by the {@link EndPointHandle}. Annotation processor uses this field - * to obtain the foreign object reference. For HotSpot to native calls, the field type must be - * assignable to {@link NativeObject}. For native to HotSpot calls, the field type must be - * assignable to {@link HSObject}. - * - * Example: - * - *

- * @GenerateHotSpotToNativeBridge(jniConfig = ExampleJNIConfig.class)
- * abstract class NativeCalculator extends Calculator {
- *
- *     @EndPointHandle final NativeObject delegate;
- *
- *     NativeCalculator(NativeObject delegate) {
- *         this.delegate = delegate;
- *     }
- * }
- * 
- */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.FIELD) -public @interface EndPointHandle { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java deleted file mode 100644 index a464cdb0eaaf..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -import org.graalvm.jniutils.JNIEntryPoint; - -final class ForeignExceptionEndPoints { - - private ForeignExceptionEndPoints() { - } - - /** - * Called by JNI to create a {@link ForeignException} used to throw native exception into Java - * code. - * - * @param rawValue marshalled original exception - * @return a {@link ForeignException} instance - */ - @JNIEntryPoint - static Throwable createForeignException(byte[] rawValue) { - return ForeignException.create(rawValue, ForeignException.HOST_TO_GUEST); - } - - /** - * Called by JNI to return a marshalled exception transferred by the {@code exception}. - */ - @JNIEntryPoint - static byte[] toByteArray(ForeignException exception) { - return exception.toByteArray(); - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java deleted file mode 100644 index c173e7deba3b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import org.graalvm.nativeimage.c.function.CEntryPoint.AlwaysIncluded; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.function.BooleanSupplier; - -/** - * Generates a HotSpot to native bridge. For the annotated class, the processor generates a bridge - * delegating calls to the object in a native image heap. Further information can be found in the - * native bridge - * tutorial. - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.TYPE) -public @interface GenerateHotSpotToNativeBridge { - - /** - * If the supplier returns {@code true}, the bridge entry points are added automatically when - * building a shared library. This means the bridge entry points are root methods for - * compilation, and everything reachable from them is compiled too. The provided class must have - * a nullary constructor, which is used to instantiate the class. The - * {@link BooleanSupplier#getAsBoolean()}} function is called on the newly instantiated - * instance. - */ - Class include() default AlwaysIncluded.class; - - /** - * The native bridge configuration. The returned class must have an accessible static - * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned - * {@link JNIConfig} instance is used for marshallers' lookup. - */ - Class jniConfig(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java deleted file mode 100644 index be865151c6cf..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Generate a native to HotSpot bridge for an annotated class. For the annotated class, the - * processor generates a bridge delegating calls to the object in a HotSpot heap. Further - * information can be found in the native bridge - * tutorial. - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.TYPE) -public @interface GenerateNativeToHotSpotBridge { - - /** - * The native bridge configuration. The returned class must have an accessible static - * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned - * {@link JNIConfig} instance is used for marshallers' lookup. - */ - Class jniConfig(); - -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java deleted file mode 100644 index fbcd41a9cac6..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -import org.graalvm.nativeimage.c.function.CEntryPoint; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.function.BooleanSupplier; - -/** - * Generates a native to native bridge. For the annotated class, the processor generates a bridge - * delegating calls to the object in a native image heap. Further information can be found in the - * native bridge - * tutorial. - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.TYPE) -public @interface GenerateNativeToNativeBridge { - /** - * If the supplier returns {@code true}, the bridge entry points are added automatically when - * building a shared library. This means the bridge entry points are root methods for - * compilation, and everything reachable from them is compiled too. The provided class must have - * a nullary constructor, which is used to instantiate the class. The - * {@link BooleanSupplier#getAsBoolean()}} function is called on the newly instantiated - * instance. - */ - Class include() default CEntryPoint.AlwaysIncluded.class; - - /** - * The native bridge configuration. The returned class must have an accessible static - * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned - * {@link JNIConfig} instance is used for marshallers' lookup. - */ - Class jniConfig(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Idempotent.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Idempotent.java deleted file mode 100644 index 5ad8eb9ba2c2..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Idempotent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Enables the return value caching. The annotated method is called only once, the returned value is - * cached and the successive calls return the cached value. The annotated method must have a - * non-void return type. - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD, ElementType.TYPE}) -public @interface Idempotent { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/In.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/In.java deleted file mode 100644 index 3d9acf75a76b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/In.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Configures an array parameter as an in-parameter. For an in-parameter, the array value is copied - * over the boundary into a called method. The {@link In} is the default behavior. It's needed only - * in combination with {@link Out} for in-out parameters. - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.PARAMETER) -public @interface In { - - /** - * Copy only a part of the array starting at the offset given by the - * {@code arrayOffsetParameter} method parameter. By default, the whole array is copied. The - * {@code arrayOffsetParameter} can be used to improve the performance and copy only a part of - * the array over the boundary. - */ - String arrayOffsetParameter() default ""; - - /** - * Limits copying only to many of the elements given by the {@code arrayLengthParameter} - * parameter. By default, the whole array is copied. The {@code arrayLengthParameter} can be - * used to improve the performance and copy only a part of the array over the boundary. - */ - String arrayLengthParameter() default ""; -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshalledException.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshalledException.java deleted file mode 100644 index 57676688e18b..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshalledException.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -/** - * An exception representing an exception thrown over the isolate boundary. - */ -@SuppressWarnings("serial") -public final class MarshalledException extends RuntimeException { - - private final String foreignExceptionClassName; - - /** - * Creates a {@link MarshalledException} for foreign exception of the - * {@code foreignExceptionClassName} type with the {@code foreignExceptionMessage} message. - * - * @param foreignExceptionClassName the foreign exception class name - * @param foreignExceptionMessage the foreign exception message - * @param stackTrace the merged stack trace. - */ - public MarshalledException(String foreignExceptionClassName, String foreignExceptionMessage, StackTraceElement[] stackTrace) { - super(foreignExceptionMessage); - this.foreignExceptionClassName = foreignExceptionClassName; - setStackTrace(stackTrace); - } - - /** - * Returns the foreign exception class name. - */ - public String getForeignExceptionClassName() { - return foreignExceptionClassName; - } - - @Override - @SuppressWarnings("sync-override") - public Throwable fillInStackTrace() { - return this; - } - - @Override - public String toString() { - String message = getLocalizedMessage(); - return (message != null) ? (foreignExceptionClassName + ": " + message) : foreignExceptionClassName; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshallerAnnotation.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshallerAnnotation.java deleted file mode 100644 index 19389c4a97de..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/MarshallerAnnotation.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Meta-annotation that marks an annotation to be used for marshaller lookup. An annotation intended - * for {@link JNIConfig#lookupMarshaller(Class, Class[]) marshaller lookup} must be annotated by - * this annotation. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface MarshallerAnnotation { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Out.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Out.java deleted file mode 100644 index fa2dc1c84e91..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/Out.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Configures an array parameter as an out-parameter. For an out-parameter, the array value is - * copied over the boundary from a called method. It may be combined with {@link In} for in-out - * parameters. Example showing the configuration for - * {@link java.io.OutputStream#write(byte[], int, int)}. - * - *
- * @Override
- * public abstract int read(@Out(arrayOffsetParameter = "off", arrayLengthParameter = "len", trimToResult = true) byte[] b, int off, int len);
- * 
- */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.PARAMETER) -public @interface Out { - - /** - * Copy only a part of the array starting at offset given by the {@code arrayOffsetParameter} - * method parameter. By default, the whole array is copied. The {@code arrayOffsetParameter} can - * be used to improve the performance and copy only a part of the array over the boundary. - */ - String arrayOffsetParameter() default ""; - - /** - * Limits copying only to many of the elements given by the {@code arrayLengthParameter} - * parameter. By default, the whole array is copied. The {@code arrayLengthParameter} can be - * used to improve the performance and copy only a part of the array over the boundary. - */ - String arrayLengthParameter() default ""; - - /** - * Limits copying only to method result number of elements. It can be used to further limit the - * number of copied elements in addition to {@link #arrayLengthParameter}. When used, it's still - * good to specify {@link #arrayLengthParameter} as an upper bound to limit allocated array - * size. - */ - boolean trimToResult() default false; -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/RawReference.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/RawReference.java deleted file mode 100644 index cb66d8077726..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/RawReference.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Instruments the native bridge processor to marshall annotated method return type or method - * parameter as a pointer value stored as Java {@code long} type. The annotated parameter must have - * {@link Object} type. - */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.PARAMETER, ElementType.METHOD}) -public @interface RawReference { -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ReceiverMethod.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ReceiverMethod.java deleted file mode 100644 index b1f21a3e05ad..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ReceiverMethod.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 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 org.graalvm.nativebridge; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The {@link ReceiverMethod} allows you to provide a custom method implementation in the generated - * type but still generate the over the boundary call. It's useful when pre-code or post-code is - * needed before or after over the boundary call. The annotated method must have the same parameter - * types as the receiver method. - * - * Example showing a method {@code execute} with custom pre-code and post-code. - * - *
- * @Override
- * public final boolean execute() {
- *     preCode();
- *     boolean result = executeImpl();
- *     postCode();
- *     return result;
- * }
- *
- * @ReceiverMethod("execute")
- * abstract boolean executeImpl();
- * 
- * - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface ReceiverMethod { - String value(); -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java deleted file mode 100644 index 143087950aba..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge; - -final class StackTraceElementMarshaller implements BinaryMarshaller { - - static final StackTraceElementMarshaller INSTANCE = new StackTraceElementMarshaller(); - - private StackTraceElementMarshaller() { - } - - private static final int STACK_TRACE_ELEMENT_SIZE_ESTIMATE = 100; - - @Override - public StackTraceElement read(BinaryInput in) { - String className = in.readUTF(); - String methodName = in.readUTF(); - String fileName = in.readUTF(); - fileName = fileName.isEmpty() ? null : fileName; - int lineNumber = in.readInt(); - return new StackTraceElement(className, methodName, fileName, lineNumber); - } - - @Override - public void write(BinaryOutput out, StackTraceElement stackTraceElement) { - out.writeUTF(stackTraceElement.getClassName()); - out.writeUTF(stackTraceElement.getMethodName()); - String fileName = stackTraceElement.getFileName(); - out.writeUTF(fileName == null ? "" : fileName); - out.writeInt(stackTraceElement.getLineNumber()); - } - - @Override - public int inferSize(StackTraceElement object) { - return STACK_TRACE_ELEMENT_SIZE_ESTIMATE; - } -} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StringMarshaller.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StringMarshaller.java deleted file mode 100644 index 41f721b837cb..000000000000 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/StringMarshaller.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge; - -/** - * BinaryMarshaller used to marshall string array components. - */ -final class StringMarshaller implements BinaryMarshaller { - - private static final int STRING_SIZE_ESTIMATE = 32; - - @Override - public String read(BinaryInput in) { - return in.readUTF(); - } - - @Override - public void write(BinaryOutput out, String str) { - out.writeUTF(str); - } - - @Override - public int inferSize(String object) { - return STRING_SIZE_ESTIMATE; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java deleted file mode 100644 index ca66998c984c..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -public abstract class AbstractService { - - public abstract boolean execute(); - - @SuppressWarnings({"unused", "static-method"}) - private boolean executePrivate(long value) { - return true; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java deleted file mode 100644 index cc4e42d9eff5..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge.processor.test; - -import java.time.Duration; -import java.util.List; -import java.util.Map; - -public interface CustomMarshallerService { - - Map createMap(List keys, List values); - - Map getProperties(); - - Duration[] getDurations(); - - void setDurations(Duration[] durations); - - Duration[] getSetDurations(Duration[] durations); - - void fillDurations(Duration[] durations); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java deleted file mode 100644 index d95498926c34..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -public abstract class CustomReceiverService { - - public abstract boolean execute(Object receiver); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java deleted file mode 100644 index fc101ef5a91a..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) -public @interface ExpectError { - String[] value(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java deleted file mode 100644 index ed2b5ae164ef..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge.processor.test; - -import java.util.List; -import java.util.Map; - -public interface OutParameterService { - - void singleOutParameterVoid(List p1); - - int singleOutParameterPrimitive(List p1); - - int[] singleOutParameterArray(List p1); - - Map singleOutParameterCustom(List p1); - - void multipleOutParametersVoid(List p1, List p2); - - int multipleOutParametersPrimitive(List p1, List p2); - - int[] multipleOutParametersArray(List p1, List p2); - - Map multipleOutParametersCustom(List p1, List p2); - - void mixedParametersVoid(List p1, List p2, List p3, List p4); - - int mixedParametersPrimitive(List p1, List p2, List p3, List p4); - - int[] mixedParametersArray(List p1, List p2, List p3, List p4); - - Map mixedParametersCustom(List p1, List p2, List p3, List p4); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java deleted file mode 100644 index c1220c6ba133..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -public interface Service { - boolean execute(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java deleted file mode 100644 index ea10125753dc..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -public final class ServiceAPI { - - public final CustomReceiverService dispatch; - - public final Object receiver; - - public ServiceAPI(CustomReceiverService dispatch, Object receiver) { - this.dispatch = dispatch; - this.receiver = receiver; - } - - public boolean execute() { - return dispatch.execute(receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java deleted file mode 100644 index 2635c1e12aac..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test; - -import org.graalvm.nativebridge.BinaryInput; -import org.graalvm.nativebridge.BinaryMarshaller; -import org.graalvm.nativebridge.BinaryOutput; -import org.graalvm.nativebridge.JNIConfig; -import org.graalvm.polyglot.TypeLiteral; - -import java.time.Duration; -import java.util.List; -import java.util.Map; - -public final class TestJNIConfig { - - private static final BinaryMarshaller UNSUPPORTED = new BinaryMarshaller() { - @Override - public Object read(BinaryInput input) { - throw new UnsupportedOperationException(); - } - - @Override - public void write(BinaryOutput output, Object object) { - throw new UnsupportedOperationException(); - } - }; - - private static final JNIConfig INSTANCE = createJNIConfig(); - - public static JNIConfig getInstance() { - return INSTANCE; - } - - private static JNIConfig createJNIConfig() { - TypeLiteral> stringList = new TypeLiteral<>() { - }; - TypeLiteral> stringMap = new TypeLiteral<>() { - }; - return JNIConfig.newBuilder().registerMarshaller(Duration.class, unsupportedMarshaller()).registerMarshaller(stringList, unsupportedMarshaller()).registerMarshaller(stringMap, - unsupportedMarshaller()).build(); - } - - @SuppressWarnings("unchecked") - private static BinaryMarshaller unsupportedMarshaller() { - return (BinaryMarshaller) UNSUPPORTED; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java deleted file mode 100644 index 7a3e2b3ac18e..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -final class InnerClassTest { - - @ExpectError("Annotation is supported only on top-level types.%n" + - "To fix this make the `ServiceImpl` a top-level class.") - @GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) - abstract static class ServiceImpl extends NativeObject implements Service { - - ServiceImpl(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java deleted file mode 100644 index 4bbef538ab4b..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + - "To fix this implement the bridged interface or extend the bridged class.") -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class InvalidBaseType1Test extends NativeObject { - - InvalidBaseType1Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java deleted file mode 100644 index 7304b9cb208f..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + - "To fix this introduce a new bridged interface extending `Service`, `Runnable` and implement it.") -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class InvalidBaseType2Test extends NativeObject implements Service, Runnable { - - InvalidBaseType2Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java deleted file mode 100644 index 6f1f9e3ab2ff..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + - "To fix this introduce a new bridged base class extending `AbstractService` and implementing `Service` and extend it.") -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class InvalidBaseType3Test extends AbstractService implements Service { - - InvalidBaseType3Test() { - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java deleted file mode 100644 index bf77e8b93ddd..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -@ExpectError("The annotated type must have a single constructor.%n" + - "Fix the ambiguity by removing constructor overloads.") -abstract class InvalidConstructorTest extends CustomReceiverService { - - @SuppressWarnings("unused") - InvalidConstructorTest(int num) { - } - - @SuppressWarnings("unused") - InvalidConstructorTest(Object obj) { - } - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java deleted file mode 100644 index ba7f1c2df8dd..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor1Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch1(ServiceAPI receiver) { - return receiver.dispatch; - } - - @ExpectError("Only a single method can be annotated by the `CustomDispatchAccessor`.%n" + - "Fix the ambiguity by removing the `static CustomReceiverService getDispatch1(ServiceAPI receiver)` method or the `static CustomReceiverService getDispatch2(ServiceAPI receiver)` method.") - @CustomDispatchAccessor - static CustomReceiverService getDispatch2(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java deleted file mode 100644 index 71bd89d472f7..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor2Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + - "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") - @SuppressWarnings("static-method") - final CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java deleted file mode 100644 index 2a235900dd99..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor3Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + - "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") - private static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java deleted file mode 100644 index b83f3e35c2bc..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor4Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + - "To fix this change the signature to `static CustomReceiverService getDispatch(Object receiver)`.") - static CustomReceiverService getDispatch() { - return null; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java deleted file mode 100644 index e5ee3e69a2c0..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor5Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + - "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") - @SuppressWarnings("unused") - static CustomReceiverService getDispatch(ServiceAPI receiver, Object foo) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java deleted file mode 100644 index 0ac95e2ce0a4..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor6Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + - "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") - static Object getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java deleted file mode 100644 index 1c8670572320..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchAccessor7Test extends CustomReceiverService { - - @CustomDispatchAccessor - @ExpectError("Classes with a custom dispatch accessor must also provide a custom receiver accessor.%n" + - "To fix this add the `@CustomReceiverAccessor static Object resolveReceiver(ServiceAPI receiver)` method.") - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java deleted file mode 100644 index d7731bbaebb6..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory1Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - static ServiceAPI create1(Object receiver) { - return new ServiceAPI(null, receiver); - } - - @CustomDispatchFactory - @ExpectError("Only a single method can be annotated by the `CustomDispatchFactory`.%n" + - "Fix the ambiguity by removing the `static ServiceAPI create1(Object receiver)` method or the `static ServiceAPI create2(Object receiver)` method.") - static ServiceAPI create2(Object receiver) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java deleted file mode 100644 index 4491b70bbe61..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory2Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - @SuppressWarnings("static-method") - final ServiceAPI create(Object receiver) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java deleted file mode 100644 index 7d48810cc511..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory3Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - private static ServiceAPI create(Object receiver) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java deleted file mode 100644 index b3a5209189e1..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory4Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - static ServiceAPI create() { - return null; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java deleted file mode 100644 index 167375bb9989..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory5Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - @SuppressWarnings("unused") - static ServiceAPI create(Object receiver, Object foo) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java deleted file mode 100644 index b7b94f9dffd3..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory6Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - @SuppressWarnings("unused") - static int create(Object receiver) { - return 42; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java deleted file mode 100644 index 89af7013ca04..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory7Test extends CustomReceiverService { - - @CustomReceiverAccessor - @ExpectError("Class with a custom receiver accessor must also provide a custom dispatch accessor.%n" + - "To fix this add the `@CustomDispatchAccessor static CustomReceiverService resolveDispatch(ServiceAPI receiver)` method.") - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` is allowed only for classes with a custom dispatch.%n" + - "To fix this add a custom dispatch accessor method annotated by `CustomDispatchAccessor` and a custom receiver accessor method annotated by `CustomReceiverAccessor`.") - static ServiceAPI create(Object receiver) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java deleted file mode 100644 index 471d0ee39702..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomDispatchFactory8Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomDispatchFactory - @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + - "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") - static Object create(Object receiver) { - return new ServiceAPI(null, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java deleted file mode 100644 index 77ac0f522010..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor1Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver1(ServiceAPI receiver) { - return receiver.receiver; - } - - @CustomReceiverAccessor - @ExpectError("Only a single method can be annotated by the `CustomReceiverAccessor`.%n" + - "Fix the ambiguity by removing the `static Object getReceiver1(ServiceAPI receiver)` method or the `static Object getReceiver2(ServiceAPI receiver)` method.") - static Object getReceiver2(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java deleted file mode 100644 index 169aad173cc1..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor2Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + - "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") - @SuppressWarnings("static-method") - final Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java deleted file mode 100644 index 7548a8056904..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor3Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + - "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") - private static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java deleted file mode 100644 index 3288fa533ee7..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor4Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + - "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") - static Object getReceiver() { - return null; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java deleted file mode 100644 index 106944fbc237..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor5Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + - "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") - @SuppressWarnings("unused") - static Object getReceiver(ServiceAPI receiver, Object foo) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java deleted file mode 100644 index 591a9b65235e..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor6Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + - "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") - @SuppressWarnings("unused") - static int getReceiver(ServiceAPI receiver) { - return 42; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java deleted file mode 100644 index 24a9f217142e..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor7Test extends CustomReceiverService { - - @CustomReceiverAccessor - @ExpectError("Class with a custom receiver accessor must also provide a custom dispatch accessor.%n" + - "To fix this add the `@CustomDispatchAccessor static CustomReceiverService resolveDispatch(ServiceAPI receiver)` method.") - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java deleted file mode 100644 index ddc098cde7b1..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidCustomReceiverAccessor8Test extends CustomReceiverService { - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - @ExpectError("The custom receiver accessor must have the same parameter type as the custom dispatch accessor.") - static Object getReceiver(Object receiver) { - return receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java deleted file mode 100644 index e0710bc56077..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidEndPointHandle1Test extends AbstractService { - - @EndPointHandle final HSObject delegate1; - - @ExpectError("Only a single field can be annotated by the `EndPointHandle`.%n" + - "Fix the ambiguity by removing the `final HSObject delegate1` field or the `final HSObject delegate2` field.") @EndPointHandle final HSObject delegate2; - - InvalidEndPointHandle1Test(HSObject delegate) { - this.delegate1 = delegate; - this.delegate2 = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java deleted file mode 100644 index 9c7e4aa0e961..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidEndPointHandle2Test extends AbstractService { - - @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `HSObject` type.%n" + - "To fix this change the signature to `final HSObject delegate`.") @EndPointHandle private final HSObject delegate; - - InvalidEndPointHandle2Test(HSObject delegate) { - this.delegate = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java deleted file mode 100644 index 7d065bbe5d1d..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.Idempotent; -import org.graalvm.nativebridge.Out; -import org.graalvm.nativebridge.processor.test.CustomMarshallerService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -import java.time.Duration; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidIdempotentTest extends HSObject implements CustomMarshallerService { - - InvalidIdempotentTest(JNIEnv env, JObject handle) { - super(env, handle); - } - - @ExpectError("A method with a cached return value cannot have an `Out` parameter.%n" + - "To fix this, remove the `Idempotent` annotation.") - @Override - @Idempotent - public abstract Duration[] getSetDurations(@Out Duration[] durations); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java deleted file mode 100644 index 10e2dcce021b..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + - "The `getInstance` method is used by the generated code to look up marshallers.%n" + - "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") -@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig1Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) -abstract class InvalidJNIConfig1Test extends NativeObject implements Service { - - InvalidJNIConfig1Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - static final class JNIConfigProvider { - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java deleted file mode 100644 index 3d34ac2f9d34..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.JNIConfig; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + - "The `getInstance` method is used by the generated code to look up marshallers.%n" + - "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") -@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig2Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) -abstract class InvalidJNIConfig2Test extends NativeObject implements Service { - - InvalidJNIConfig2Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - static final class JNIConfigProvider { - static JNIConfig getInstance(@SuppressWarnings("unused") Object param) { - return null; - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java deleted file mode 100644 index 2db1f95bce52..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + - "The `getInstance` method is used by the generated code to look up marshallers.%n" + - "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") -@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig3Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) -abstract class InvalidJNIConfig3Test extends NativeObject implements Service { - - InvalidJNIConfig3Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - static final class JNIConfigProvider { - static Object getInstance() { - return null; - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java deleted file mode 100644 index a10daa5bf8b3..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.JNIConfig; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + - "The `getInstance` method is used by the generated code to look up marshallers.%n" + - "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") -@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig4Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) -abstract class InvalidJNIConfig4Test extends NativeObject implements Service { - - InvalidJNIConfig4Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - static final class JNIConfigProvider { - @SuppressWarnings("static-method") - JNIConfig getInstance() { - return null; - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java deleted file mode 100644 index 80d4b5747b1c..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + - "The `getInstance` method is used by the generated code to look up marshallers.%n" + - "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") -@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig5Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) -abstract class InvalidJNIConfig5Test extends NativeObject implements Service { - - InvalidJNIConfig5Test(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - static final class JNIConfigProvider { - @SuppressWarnings("unused") - private static Object getInstance() { - return null; - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java deleted file mode 100644 index 463f304a0f3e..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidMethod1Test extends HSObject implements Service { - - InvalidMethod1Test(JNIEnv env, JObject handle) { - super(env, handle); - } - - @ExpectError("Should be `final` to prevent override in the generated class or `abstract` to be generated.%n" + - "To fix this add a `final` modifier or remove implementation in the `InvalidMethod1Test`.") - public void invalid() { - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java deleted file mode 100644 index 4471788959db..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidMethod2Test extends InvalidExplicitReceiverService { - - @ExpectError("In a class with a custom dispatch, the first method parameter must be the receiver.%n" + - "For a class with a custom dispatch, make the method `final` to prevent its generation.%n" + - "For a class that has no custom dispatch, remove methods annotated by `CustomDispatchAccessor` and `CustomReceiverAccessor`.") - @Override - abstract boolean isValid(); - - @CustomDispatchAccessor - static InvalidExplicitReceiverService getDispatch(Object receiver) { - return (InvalidExplicitReceiverService) receiver; - } - - @CustomReceiverAccessor - static Object getReceiver(Object receiver) { - return receiver; - } -} - -abstract class InvalidExplicitReceiverService { - abstract boolean execute(Object receiver); - - abstract boolean isValid(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java deleted file mode 100644 index da99b0283aef..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.Idempotent; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidMethod3Test extends HSObject implements InvalidService { - - InvalidMethod3Test(JNIEnv env, JObject handle) { - super(env, handle); - } - - @Idempotent - @ExpectError("A method with a cached return value must have a non-void return type.%n" + - "To fix this remove the `Idempotent` annotation or change the return type.") - @Override - public abstract void execute(); - -} - -interface InvalidService { - void execute(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java deleted file mode 100644 index 5cd14dae48fc..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.ReceiverMethod; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidMethod4Test extends HSObject implements Service { - - InvalidMethod4Test(JNIEnv env, JObject handle) { - super(env, handle); - } - - @Override - public final boolean execute() { - return executeImpl(42L); - } - - @ReceiverMethod("execute") - @ExpectError("A method `execute(long)` is not found in the `Service`. " + - "The receiver method must have the same arguments as the annotated method and must exist in the bridged type.") - abstract boolean executeImpl(long p0); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java deleted file mode 100644 index bc7352e71f00..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.ReceiverMethod; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class InvalidMethod5Test extends AbstractService { - - @EndPointHandle final HSObject delegate; - - InvalidMethod5Test(HSObject delegate) { - this.delegate = delegate; - } - - @Override - public final boolean execute() { - return executeImpl(42L); - } - - @ReceiverMethod("executePrivate") - @ExpectError("The receiver method `executePrivate` must be a non-private instance method.") - abstract boolean executeImpl(long value); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java deleted file mode 100644 index 71bdc1ded699..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.METHOD) -@interface TestAnnotation1 { -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java deleted file mode 100644 index efee75e9aa00..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.common; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.METHOD) -@interface TestAnnotation2 { -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java deleted file mode 100644 index 02fe29590663..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeClassImlTest extends AbstractService { - - @EndPointHandle final NativeObject delegate; - - NativeClassImlTest(NativeObject delegate) { - this.delegate = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java deleted file mode 100644 index ae2e76896e86..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.Idempotent; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.Out; -import org.graalvm.nativebridge.processor.test.CustomMarshallerService; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint; - -import java.time.Duration; -import java.util.Map; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = CEntryPoint.NotIncludedAutomatically.class) -abstract class NativeCustomMarshallerTest extends NativeObject implements CustomMarshallerService { - - NativeCustomMarshallerTest(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - @Idempotent - @Override - public abstract Map getProperties(); - - @Override - public abstract void fillDurations(@Out Duration[] durations); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java deleted file mode 100644 index d7cfdd4d8358..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeCustomReceiverImplTest extends CustomReceiverService { - - NativeCustomReceiverImplTest() { - } - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java deleted file mode 100644 index bb78676482c7..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeInterfaceImplTest extends NativeObject implements Service { - - NativeInterfaceImplTest(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java deleted file mode 100644 index ad5e816eaf2b..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -@ExpectError("The annotated type must extend `NativeObject`, have a field annotated by `EndPointHandle` or a custom dispatch.%n" + - "To bridge an interface extend `NativeObject` and implement the interface.%n" + - "To bridge a class extend the class, add the `@EndPointHandle final NativeObject delegate` field and initialize it in the constructor.%n" + - "To bridge a class with a custom dispatch add `@CustomDispatchAccessor static Service resolveDispatch(Object receiver)` and `@CustomReceiverAccessor static Object resolveReceiver(Object receiver)` methods.") -abstract class NativeInvalidBaseTypeTest extends Object implements Service { - - @SuppressWarnings("unused") - NativeInvalidBaseTypeTest(NativeIsolate isolate, long handle) { - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java deleted file mode 100644 index 08cf62d69614..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -@ExpectError("The annotated type must have a single constructor with a `(NativeIsolate, long,...)` signature.%n" + - "To fix this add the `NativeInvalidConstructor1Test(NativeIsolate p0, long p1)` constructor into `NativeInvalidConstructor1Test`.") -abstract class NativeInvalidConstructor1Test extends NativeObject implements Service { - - @SuppressWarnings("unused") - NativeInvalidConstructor1Test(int a, NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java deleted file mode 100644 index 57b1275a186b..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -@ExpectError("The annotated type must have a single constructor with a `(NativeObject,...)` signature.%n" + - "To fix this add the `NativeInvalidConstructor2Test(NativeObject p0)` constructor into `NativeInvalidConstructor2Test`.") -abstract class NativeInvalidConstructor2Test extends AbstractService { - - @EndPointHandle final NativeObject delegate; - - @SuppressWarnings("unused") - NativeInvalidConstructor2Test(NativeIsolate isolate, long handle) { - delegate = null; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java deleted file mode 100644 index 03f809a55561..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.hstonative; - -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeInvalidEndPointHandleTest extends AbstractService { - - @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `NativeObject` type.%n" + - "To fix this change the signature to `final NativeObject delegate`.") @EndPointHandle final Object delegate; - - NativeInvalidEndPointHandleTest(NativeObject delegate) { - this.delegate = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java deleted file mode 100644 index 39e8df9ab24c..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSClassImplTest extends AbstractService { - - @EndPointHandle final HSObject delegate; - - HSClassImplTest(HSObject delegate) { - this.delegate = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java deleted file mode 100644 index 0d6b88c3a8e3..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.Idempotent; -import org.graalvm.nativebridge.Out; -import org.graalvm.nativebridge.processor.test.CustomMarshallerService; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -import java.time.Duration; -import java.util.Map; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSCustomMarshallerTest extends HSObject implements CustomMarshallerService { - - HSCustomMarshallerTest(JNIEnv env, JObject handle) { - super(env, handle); - } - - @Idempotent - @Override - public abstract Map getProperties(); - - @Override - public abstract void fillDurations(@Out Duration[] durations); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java deleted file mode 100644 index 9aed018013d6..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.processor.test.CustomReceiverService; -import org.graalvm.nativebridge.processor.test.ServiceAPI; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSCustomReceiverImplTest extends CustomReceiverService { - - HSCustomReceiverImplTest() { - } - - @CustomDispatchAccessor - static CustomReceiverService getDispatch(ServiceAPI receiver) { - return receiver.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(ServiceAPI receiver) { - return receiver.receiver; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java deleted file mode 100644 index 7239324d08f3..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSInterfaceImplTest extends HSObject implements Service { - - HSInterfaceImplTest(JNIEnv env, JObject delegate) { - super(env, delegate); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java deleted file mode 100644 index 648f9cd25782..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -@ExpectError("The annotated type must extend `HSObject`, have a field annotated by `EndPointHandle` or a custom dispatch.%n" + - "To bridge an interface extend `HSObject` and implement the interface.%n" + - "To bridge a class extend the class, add the `@EndPointHandle final HSObject delegate` field and initialize it in the constructor.%n" + - "To bridge a class with a custom dispatch add `@CustomDispatchAccessor static Service resolveDispatch(Object receiver)` and `@CustomReceiverAccessor static Object resolveReceiver(Object receiver)` methods.") -abstract class HSInvalidBaseTypeTest extends Object implements Service { - - @SuppressWarnings("unused") - HSInvalidBaseTypeTest(JNIEnv env, JObject handle) { - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java deleted file mode 100644 index eab397fd9e2f..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -@ExpectError("The annotated type must have a single constructor with a `(JNIEnv, JObject,...)` signature.%n" + - "To fix this add the `HSInvalidConstructor1Test(JNIEnv p0, JObject p1)` constructor into `HSInvalidConstructor1Test`.") -abstract class HSInvalidConstructor1Test extends HSObject implements Service { - - @SuppressWarnings("unused") - HSInvalidConstructor1Test(int a, JNIEnv env, JObject ref) { - super(env, ref); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java deleted file mode 100644 index cd637715b689..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -@ExpectError("The annotated type must have a single constructor with one of the following signatures `(HSObject,...)`, `(HSObject, JNIEnv,...)`.%n" + - "To fix this add the `HSInvalidConstructor2Test(HSObject p0)` constructor into `HSInvalidConstructor2Test`.") -abstract class HSInvalidConstructor2Test extends AbstractService { - - @EndPointHandle final HSObject delegate; - - @SuppressWarnings("unused") - HSInvalidConstructor2Test(JNIEnv env, JObject ref) { - delegate = null; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java deleted file mode 100644 index cb0706f43642..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetohs; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.EndPointHandle; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.AbstractService; -import org.graalvm.nativebridge.processor.test.ExpectError; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSInvalidEndPointHandleTest extends AbstractService { - - @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `HSObject` type.%n" + - "To fix this change the signature to `final HSObject delegate`.") @EndPointHandle final Object delegate; - - HSInvalidEndPointHandleTest(HSObject delegate) { - this.delegate = delegate; - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java deleted file mode 100644 index 41efc8ecc393..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.GenerateNativeToNativeBridge; -import org.graalvm.nativebridge.JNIConfig; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -@GenerateNativeToNativeBridge(jniConfig = MixedNativeToNativeServiceDifferentConfigs.OtherJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class MixedNativeToNativeServiceDifferentConfigs extends NativeObject implements Service { - - MixedNativeToNativeServiceDifferentConfigs(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - public static final class OtherJNIConfig { - - private static final JNIConfig INSTANCE = createJNIConfig(); - - public static JNIConfig getInstance() { - return INSTANCE; - } - - private static JNIConfig createJNIConfig() { - return JNIConfig.newBuilder().build(); - } - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java deleted file mode 100644 index 4df0a07e4000..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetonative; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.GenerateNativeToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -@GenerateNativeToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class MixedNativeToNativeServiceSameConfig extends NativeObject implements Service { - - MixedNativeToNativeServiceSameConfig(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java deleted file mode 100644 index 8780d7b04899..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.nativetonative; - -import org.graalvm.nativebridge.GenerateNativeToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.Service; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateNativeToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class PureNativeToNativeService extends NativeObject implements Service { - - PureNativeToNativeService(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java deleted file mode 100644 index c05d5c331f97..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.nativebridge.ByReference; - -interface Context { - - Handler getHandler(); - - void close(); - - @ByReference(NativeCustomLanguageDispatch.class) - LanguageAPI getLanguage(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java deleted file mode 100644 index 0f3d77aca45a..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -abstract class CustomLanguageDispatch { - - abstract String getId(Object receiver); - - abstract String getName(Object receiver); - - abstract String getVersion(Object receiver); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java deleted file mode 100644 index 435326428b26..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.AlwaysByReference; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -@AlwaysByReference(type = Context.class, startPointClass = NativeContext.class) -@AlwaysByReference(type = LanguageAPI.class, startPointClass = NativeCustomLanguageDispatch.class) -@AlwaysByReference(type = Record.class, startPointClass = NativeRecord.class) -abstract class HSAlwaysByReferenceHandler extends HSObject implements Handler { - HSAlwaysByReferenceHandler(JNIEnv env, JObject handle) { - super(env, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java deleted file mode 100644 index 165a97f96919..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNI.JObject; -import org.graalvm.nativebridge.ByReference; -import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; - -@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) -abstract class HSHandler extends HSObject implements Handler { - - HSHandler(JNIEnv env, JObject handle) { - super(env, handle); - } - - @Override - public abstract void publish(@ByReference(NativeCustomLanguageDispatch.class) LanguageAPI language, - @ByReference(NativeRecord.class) Record record); - - @Override - @ByReference(NativeContext.class) - public abstract Context getContext(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java deleted file mode 100644 index 75d46da708c9..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -interface Handler { - - void publish(LanguageAPI language, Record record); - - Context getContext(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java deleted file mode 100644 index 8fd270c7e3a0..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.jniutils.HSObject; -import org.graalvm.nativebridge.ByReference; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeContext extends NativeObject implements Context { - - NativeContext(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - @Override - @ByReference(HSObject.class) - public abstract Handler getHandler(); - -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java deleted file mode 100644 index 90a728fa555a..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.nativebridge.CustomDispatchAccessor; -import org.graalvm.nativebridge.CustomDispatchFactory; -import org.graalvm.nativebridge.CustomReceiverAccessor; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeCustomLanguageDispatch extends CustomLanguageDispatch { - - private static final NativeCustomLanguageDispatch INSTANCE = NativeCustomLanguageDispatchGen.createHSToNative(); - - @CustomDispatchAccessor - static CustomLanguageDispatch getDispatch(LanguageAPI api) { - return api.dispatch; - } - - @CustomReceiverAccessor - static Object getReceiver(LanguageAPI api) { - return api.receiver; - } - - @CustomDispatchFactory - static LanguageAPI createLanguage(Object receiver) { - return new LanguageAPI(INSTANCE, receiver); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java deleted file mode 100644 index 88b9a4931faf..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeRecord extends NativeObject implements Record { - - NativeRecord(NativeIsolate isolate, long handle) { - super(isolate, handle); - } -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java deleted file mode 100644 index be7a68065819..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import org.graalvm.nativebridge.ByReference; -import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; -import org.graalvm.nativebridge.NativeIsolate; -import org.graalvm.nativebridge.NativeObject; -import org.graalvm.nativebridge.processor.test.TestJNIConfig; -import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; - -@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) -abstract class NativeService extends NativeObject implements Service { - - NativeService(NativeIsolate isolate, long handle) { - super(isolate, handle); - } - - @Override - @ByReference(NativeContext.class) - public abstract Context open(@ByReference(HSHandler.class) Handler handler); - - @Override - public abstract void execute(@ByReference(NativeObject.class) Context context); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java deleted file mode 100644 index 738465ecf768..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -public interface Record { - int getLevel(); - - String getMessage(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java deleted file mode 100644 index b329723ce17f..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -import java.util.List; - -public interface ReferenceArrayOperations { - - void acceptHost(Handler[] handlers); - - void acceptHostSubArray(Handler[] handlers, int offset, int length); - - void fillHost(Handler[] handlers); - - int fillHostSubArray(Handler[] handlers, int offset, int length); - - void exchangeHost(Handler[] handlers); - - int exchangeHostSubArray(Handler[] handlers, int offset, int length); - - Handler[] getHostObjects(); - - void acceptGuest(Record[] records); - - void acceptGuestWithMarshalledParameter(Record[] records, List list); - - void acceptGuestSubArray(Record[] records, int offset, int length); - - void fillGuest(Record[] records); - - void fillGuestWithMarshalledParameter(Record[] records, List list); - - List fillGuestWithMarshalledResult(Record[] records); - - List fillGuestWithMarshalledResultAndParameter(Record[] records, List list); - - int fillGuestSubArray(Record[] records, int offset, int length); - - List fillGuestSubArrayWithMarshalledResult(Record[] records, int offset, int length); - - void exchangeGuest(Record[] records); - - void exchangeGuestWithMarshalledParameter(Record[] records, List list); - - List exchangeGuestWithMarshalledResult(Record[] records); - - List exchangeGuestWithMarshalledResultAndParameter(Record[] records, List list); - - int exchangeGuestSubArray(Record[] records, int offset, int length); - - List exchangeGuestSubArrayWithMarshalledResult(Record[] records, int offset, int length); - - Record[] getGuestObjects(); -} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java b/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java deleted file mode 100644 index f6510447e95e..000000000000 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022, 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 org.graalvm.nativebridge.processor.test.references; - -interface Service { - Context open(Handler handler); - - void execute(Context context); -} diff --git a/sdk/mx.sdk/mx_sdk.py b/sdk/mx.sdk/mx_sdk.py index 8a7cd57efdd6..be7352460438 100644 --- a/sdk/mx.sdk/mx_sdk.py +++ b/sdk/mx.sdk/mx_sdk.py @@ -115,11 +115,10 @@ def upx(args): third_party_license_files=[], dependencies=[], jar_distributions=[], - boot_jars=['sdk:GRAAL_SDK'], + boot_jars=['sdk:GRAAL_SDK', 'sdk:JNIUTILS', 'sdk:NATIVEBRIDGE'], stability="supported", )) - mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent( suite=_suite, name='GraalVM Launcher Common', @@ -133,7 +132,6 @@ def upx(args): stability="supported", )) - mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent( suite=_suite, name='LLVM.org toolchain', @@ -148,7 +146,6 @@ def upx(args): stability="supported", )) - def mx_register_dynamic_suite_constituents(register_project, register_distribution): mx_sdk_vm_impl.mx_register_dynamic_suite_constituents(register_project, register_distribution) diff --git a/sdk/mx.sdk/mx_sdk_vm.py b/sdk/mx.sdk/mx_sdk_vm.py index 39806c0dd9fb..a08aa3a4dfa2 100644 --- a/sdk/mx.sdk/mx_sdk_vm.py +++ b/sdk/mx.sdk/mx_sdk_vm.py @@ -668,11 +668,21 @@ def _patch_default_security_policy(build_dir, jmods_dir, dst_jdk_dir): grant codeBase "jrt:/org.graalvm.truffle" { permission java.security.AllPermission; }; - grant codeBase "jrt:/org.graalvm.sdk" { permission java.security.AllPermission; }; - + grant codeBase "jrt:/org.graalvm.truffle.runtime" { + permission java.security.AllPermission; + }; + grant codeBase "jrt:/org.graalvm.truffle.compiler" { + permission java.security.AllPermission; + }; + grant codeBase "jrt:/org.graalvm.nativebridge" { + permission java.security.AllPermission; + }; + grant codeBase "jrt:/org.graalvm.jniutils" { + permission java.security.AllPermission; + }; grant codeBase "jrt:/org.graalvm.locator" { permission java.io.FilePermission "<>", "read"; permission java.util.PropertyPermission "*", "read,write"; diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index 3ad81153d087..f22c2949af3c 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -346,6 +346,58 @@ "javaCompliance" : "17+", "workingSets" : "API,SDK", }, + "org.graalvm.jniutils" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + "GRAAL_SDK", + ], + "requires" : [ + ], + "checkstyle" : "org.graalvm.word", + "javaCompliance" : "17+", + }, + "org.graalvm.nativebridge" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + "JNIUTILS" + ], + "requires" : [ + ], + "checkstyle" : "org.graalvm.word", + "javaCompliance" : "17+", + }, + "org.graalvm.nativebridge.processor" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + ], + "requires" : [ + "java.compiler" + ], + "annotationProcessors" : [ + ], + "checkstyle" : "org.graalvm.word", + "javaCompliance" : "17+", + "workingSets" : "API,Graal", + }, + "org.graalvm.nativebridge.processor.test" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + "mx:JUNIT", + "NATIVEBRIDGE", + ], + "annotationProcessors" : [ + "NATIVEBRIDGE_PROCESSOR", + ], + "checkstyle" : "org.graalvm.word", + "javaCompliance" : "17+", + "workingSets" : "Graal,Test", + "jacoco" : "exclude", + "testProject" : True, + }, "org.graalvm.toolchain.test" : { "class" : "ToolchainTestProject", "subDir" : "src", @@ -409,7 +461,7 @@ "org.graalvm.polyglot", "org.graalvm.options", "org.graalvm.word", - "org.graalvm.polyglot.impl to org.graalvm.truffle, com.oracle.graal.graal_enterprise", + "org.graalvm.polyglot.impl to org.graalvm.truffle, com.oracle.truffle.enterprise", "org.graalvm.word.impl to jdk.internal.vm.compiler", "org.graalvm.nativeimage.impl to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.configure,com.oracle.svm.svm_enterprise,org.graalvm.extraimage.builder", "org.graalvm.nativeimage.impl.clinit to org.graalvm.nativeimage.builder", @@ -471,6 +523,54 @@ "javadocType": "api", "description" : """GraalVM TCK SPI""", }, + "JNIUTILS" : { + "moduleInfo" : { + "name" : "org.graalvm.jniutils", + "exports" : [ + "org.graalvm.jniutils", + ], + }, + "subDir" : "src", + "dependencies" : ["org.graalvm.jniutils"], + "distDependencies" : ["GRAAL_SDK"], + "description" : "Utilities for JNI calls from within native-image.", + "allowsJavadocWarnings": True, + }, + "NATIVEBRIDGE" : { + "moduleInfo" : { + "name" : "org.graalvm.nativebridge", + "exports" : [ + "org.graalvm.nativebridge", + ], + }, + "subDir" : "src", + "dependencies" : ["org.graalvm.nativebridge"], + "distDependencies" : ["JNIUTILS"], + "description" : "API and utility classes for nativebridge.", + "allowsJavadocWarnings": True, + }, + "NATIVEBRIDGE_PROCESSOR" : { + "subDir" : "src", + "dependencies" : [ + "org.graalvm.nativebridge.processor" + ], + "distDependencies" : [], + "maven": False, + }, + "NATIVEBRIDGE_PROCESSOR_TEST" : { + "subDir" : "src", + "dependencies" : [ + "org.graalvm.nativebridge.processor.test" + ], + "requiresConcealed": { + "jdk.internal.vm.ci": [ + "jdk.vm.ci.services", + ], + }, + "distDependencies" : ["NATIVEBRIDGE"], + "maven": False, + "testDistribution" : True, + }, "LLVM_TOOLCHAIN": { "native": True, "description": "LLVM with general purpose patches used by Sulong and Native Image", diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/HSObject.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/HSObject.java similarity index 78% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/HSObject.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/HSObject.java index ff53282ee728..2219d3a0a562 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/HSObject.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/HSObject.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNI.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNI.java similarity index 94% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNI.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNI.java index ad8153cedd7e..8bd81b37cf75 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNI.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNI.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; @@ -35,9 +51,9 @@ import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.CContext; +import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.c.function.CFunctionPointer; import org.graalvm.nativeimage.c.function.InvokeCFunctionPointer; -import org.graalvm.nativeimage.c.function.CFunction.Transition; import org.graalvm.nativeimage.c.struct.CField; import org.graalvm.nativeimage.c.struct.CPointerTo; import org.graalvm.nativeimage.c.struct.CStruct; @@ -50,8 +66,6 @@ import org.graalvm.nativeimage.c.type.VoidPointer; import org.graalvm.word.PointerBase; -import jdk.vm.ci.services.Services; - public final class JNI { public static final int JNI_OK = 0; @@ -1082,7 +1096,7 @@ public List getHeaderFiles() { } private static Path[] findJNIHeaders() { - Path javaHome = Paths.get(Services.getSavedProperties().get("java.home")); + Path javaHome = Paths.get(System.getProperty("java.home")); Path includeFolder = javaHome.resolve("include"); if (!Files.exists(includeFolder)) { Path parent = javaHome.getParent(); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNICalls.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNICalls.java similarity index 86% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNICalls.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNICalls.java index daab397a4e8d..bad6bfe74adb 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNICalls.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNICalls.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; diff --git a/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIEntryPoint.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIEntryPoint.java new file mode 100644 index 000000000000..0ff61e23a86b --- /dev/null +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIEntryPoint.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, 2023, 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 org.graalvm.jniutils; + +import org.graalvm.nativeimage.hosted.Feature; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An annotation used to mark methods called by the JNI native interface. The annotation can be used + * by {@link Feature}s to register the annotated methods as JNI accessed. + */ +@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) +@Retention(RetentionPolicy.RUNTIME) +public @interface JNIEntryPoint { +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapper.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapper.java similarity index 93% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapper.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapper.java index 113ba75b3881..bf1fbb3d543f 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapper.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapper.java @@ -2,25 +2,41 @@ * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java similarity index 60% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java index b4c45c2f8ee8..e7211d1c559c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIExceptionWrapperEntryPoints.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIMethodScope.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java similarity index 68% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIMethodScope.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java index ce2fd4481c37..ad3e157debca 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIMethodScope.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIMethodScope.java @@ -1,36 +1,52 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; import static org.graalvm.jniutils.JNIUtil.getFeatureName; +import java.util.Objects; + import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNI.JObject; -import java.util.Objects; - /** * Scope of a call from HotSpot to native method. This also provides access to the {@link JNIEnv} * value for the current thread within the native method call. @@ -147,7 +163,7 @@ public void close() { } } - int depth() { + public final int depth() { int depth = 0; JNIMethodScope ancestor = parent; while (ancestor != null) { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIUtil.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIUtil.java similarity index 94% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIUtil.java rename to sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIUtil.java index 1ebe5c566b3f..bc09cf84c21e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/jniutils/JNIUtil.java +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/JNIUtil.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.jniutils; @@ -32,7 +48,6 @@ import java.io.PrintWriter; import java.io.StringWriter; -import org.graalvm.compiler.serviceprovider.IsolateUtil; import org.graalvm.jniutils.JNI.JArray; import org.graalvm.jniutils.JNI.JBooleanArray; import org.graalvm.jniutils.JNI.JByteArray; @@ -1090,6 +1105,19 @@ public static JObject getJVMCIClassLoader(JNIEnv env) { return env.getFunctions().getCallStaticObjectMethodA().call(env, clazz, getClassLoaderId, nullPointer()); } + public static JObject getClassLoader(JNIEnv env, JClass clazz) { + if (clazz.isNull()) { + throw new NullPointerException(); + } + // Class + JClass classClass = GetObjectClass(env, clazz); // Class + JNI.JMethodID getClassLoader = JNIUtil.findMethod(env, classClass, false, "getClassLoader", "()Ljava/lang/ClassLoader;"); + if (getClassLoader.isNull()) { + throw new NullPointerException("getClassLoader() not found"); + } + return env.getFunctions().getCallObjectMethodA().call(env, clazz, getClassLoader, nullPointer()); + } + /** * Returns the {@link ClassLoader#getSystemClassLoader()}. */ @@ -1162,13 +1190,7 @@ public static boolean tracingAt(int level) { */ public static void trace(int level, String format, Object... args) { if (tracingAt(level)) { - StringBuilder sb = new StringBuilder(); - sb.append('[').append(IsolateUtil.getIsolateID()).append(':').append(Thread.currentThread().getName()).append(']'); - JNIMethodScope scope = JNIMethodScope.scopeOrNull(); - if (scope != null) { - sb.append(new String(new char[2 + (scope.depth() * 2)]).replace('\0', ' ')); - } - NativeBridgeSupport.getInstance().trace(sb.append(String.format(format, args)).toString()); + NativeBridgeSupport.getInstance().trace(String.format(format, args)); } } diff --git a/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/NativeBridgeSupport.java b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/NativeBridgeSupport.java new file mode 100644 index 000000000000..5e8424e92754 --- /dev/null +++ b/sdk/src/org.graalvm.jniutils/src/org/graalvm/jniutils/NativeBridgeSupport.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.jniutils; + +import org.graalvm.nativeimage.ImageSingletons; + +/** + * Services used by the {@code org.graalvm.jniutils} module. To enable the + * {@code org.graalvm.jniutils} module a {@code NativeBridgeSupport} instance must be registered in + * the {@link ImageSingletons}. + */ +public interface NativeBridgeSupport { + + /** + * Returns the name of a feature using {@code org.graalvm.jniutils} module. The feature name is + * used in the logging output. + */ + String getFeatureName(); + + /** + * Checks if logging at given level is enabled. + */ + boolean isTracingEnabled(int level); + + /** + * Logs the message. + */ + void trace(String message); + + /** + * Returns a {@code NativeBridgeSupport} instance registered in the {@link ImageSingletons}. + */ + static NativeBridgeSupport getInstance() { + return ImageSingletons.lookup(NativeBridgeSupport.class); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java new file mode 100644 index 000000000000..02c50e7ee0e7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/AbstractService.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +public abstract class AbstractService { + + public abstract boolean execute(); + + @SuppressWarnings({"unused", "static-method"}) + private boolean executePrivate(long value) { + return true; + } +} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java similarity index 88% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java rename to sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java index 120999b66446..3e17308536db 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/BinaryOutputTest.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor.test; diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java new file mode 100644 index 000000000000..c5b6393e4b61 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomMarshallerService.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +import java.time.Duration; +import java.util.List; +import java.util.Map; + +public interface CustomMarshallerService { + + Map createMap(List keys, List values); + + Map getProperties(); + + Duration[] getDurations(); + + void setDurations(Duration[] durations); + + Duration[] getSetDurations(Duration[] durations); + + void fillDurations(Duration[] durations); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java new file mode 100644 index 000000000000..e971cf93d986 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/CustomReceiverService.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +public abstract class CustomReceiverService { + + public abstract boolean execute(Object receiver); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java new file mode 100644 index 000000000000..19f7bae2f2dc --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ExpectError.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) +public @interface ExpectError { + String[] value(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java new file mode 100644 index 000000000000..fc11ae2997e8 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/OutParameterService.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +import java.util.List; +import java.util.Map; + +public interface OutParameterService { + + void singleOutParameterVoid(List p1); + + int singleOutParameterPrimitive(List p1); + + int[] singleOutParameterArray(List p1); + + Map singleOutParameterCustom(List p1); + + void multipleOutParametersVoid(List p1, List p2); + + int multipleOutParametersPrimitive(List p1, List p2); + + int[] multipleOutParametersArray(List p1, List p2); + + Map multipleOutParametersCustom(List p1, List p2); + + void mixedParametersVoid(List p1, List p2, List p3, List p4); + + int mixedParametersPrimitive(List p1, List p2, List p3, List p4); + + int[] mixedParametersArray(List p1, List p2, List p3, List p4); + + Map mixedParametersCustom(List p1, List p2, List p3, List p4); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java new file mode 100644 index 000000000000..085d03a177bf --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/Service.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +public interface Service { + boolean execute(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java new file mode 100644 index 000000000000..a047f0d85902 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/ServiceAPI.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +public final class ServiceAPI { + + public final CustomReceiverService dispatch; + + public final Object receiver; + + public ServiceAPI(CustomReceiverService dispatch, Object receiver) { + this.dispatch = dispatch; + this.receiver = receiver; + } + + public boolean execute() { + return dispatch.execute(receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java new file mode 100644 index 000000000000..a8301d659d58 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/TestJNIConfig.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test; + +import org.graalvm.nativebridge.BinaryInput; +import org.graalvm.nativebridge.BinaryMarshaller; +import org.graalvm.nativebridge.BinaryOutput; +import org.graalvm.nativebridge.JNIConfig; +import org.graalvm.polyglot.TypeLiteral; + +import java.time.Duration; +import java.util.List; +import java.util.Map; + +public final class TestJNIConfig { + + private static final BinaryMarshaller UNSUPPORTED = new BinaryMarshaller() { + @Override + public Object read(BinaryInput input) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(BinaryOutput output, Object object) { + throw new UnsupportedOperationException(); + } + }; + + private static final JNIConfig INSTANCE = createJNIConfig(); + + public static JNIConfig getInstance() { + return INSTANCE; + } + + private static JNIConfig createJNIConfig() { + TypeLiteral> stringList = new TypeLiteral<>() { + }; + TypeLiteral> stringMap = new TypeLiteral<>() { + }; + return JNIConfig.newBuilder().registerMarshaller(Duration.class, unsupportedMarshaller()).registerMarshaller(stringList, unsupportedMarshaller()).registerMarshaller(stringMap, + unsupportedMarshaller()).build(); + } + + @SuppressWarnings("unchecked") + private static BinaryMarshaller unsupportedMarshaller() { + return (BinaryMarshaller) UNSUPPORTED; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java new file mode 100644 index 000000000000..c3063b26bcc7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InnerClassTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +final class InnerClassTest { + + @ExpectError("Annotation is supported only on top-level types.%n" + + "To fix this make the `ServiceImpl` a top-level class.") + @GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) + abstract static class ServiceImpl extends NativeObject implements Service { + + ServiceImpl(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java new file mode 100644 index 000000000000..03e14490db7e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType1Test.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + + "To fix this implement the bridged interface or extend the bridged class.") +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class InvalidBaseType1Test extends NativeObject { + + InvalidBaseType1Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java new file mode 100644 index 000000000000..2143768ae6f4 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType2Test.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + + "To fix this introduce a new bridged interface extending `Service`, `Runnable` and implement it.") +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class InvalidBaseType2Test extends NativeObject implements Service, Runnable { + + InvalidBaseType2Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java new file mode 100644 index 000000000000..eb82a9e1193d --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidBaseType3Test.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("The annotated type must have a non `Object` superclass or implement a single interface.%n" + + "To fix this introduce a new bridged base class extending `AbstractService` and implementing `Service` and extend it.") +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class InvalidBaseType3Test extends AbstractService implements Service { + + InvalidBaseType3Test() { + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java new file mode 100644 index 000000000000..a58e6c7bdc96 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidConstructorTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +@ExpectError("The annotated type must have a single constructor.%n" + + "Fix the ambiguity by removing constructor overloads.") +abstract class InvalidConstructorTest extends CustomReceiverService { + + @SuppressWarnings("unused") + InvalidConstructorTest(int num) { + } + + @SuppressWarnings("unused") + InvalidConstructorTest(Object obj) { + } + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java new file mode 100644 index 000000000000..3dc100513bdf --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor1Test.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor1Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch1(ServiceAPI receiver) { + return receiver.dispatch; + } + + @ExpectError("Only a single method can be annotated by the `CustomDispatchAccessor`.%n" + + "Fix the ambiguity by removing the `static CustomReceiverService getDispatch1(ServiceAPI receiver)` method or the `static CustomReceiverService getDispatch2(ServiceAPI receiver)` method.") + @CustomDispatchAccessor + static CustomReceiverService getDispatch2(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java new file mode 100644 index 000000000000..94558c509bc0 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor2Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor2Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + + "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") + @SuppressWarnings("static-method") + final CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java new file mode 100644 index 000000000000..13a3ff5da8a3 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor3Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor3Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + + "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") + private static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java new file mode 100644 index 000000000000..673f88024af8 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor4Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor4Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + + "To fix this change the signature to `static CustomReceiverService getDispatch(Object receiver)`.") + static CustomReceiverService getDispatch() { + return null; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java new file mode 100644 index 000000000000..667f9f9480db --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor5Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor5Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + + "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") + @SuppressWarnings("unused") + static CustomReceiverService getDispatch(ServiceAPI receiver, Object foo) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java new file mode 100644 index 000000000000..d963bab8c224 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor6Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor6Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("A method annotated by `CustomDispatchAccessor` must be a non-private static method with a single parameter and `CustomReceiverService` return type.%n" + + "To fix this change the signature to `static CustomReceiverService getDispatch(ServiceAPI receiver)`.") + static Object getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java new file mode 100644 index 000000000000..8e65ba7b3bdc --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchAccessor7Test.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchAccessor7Test extends CustomReceiverService { + + @CustomDispatchAccessor + @ExpectError("Classes with a custom dispatch accessor must also provide a custom receiver accessor.%n" + + "To fix this add the `@CustomReceiverAccessor static Object resolveReceiver(ServiceAPI receiver)` method.") + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java new file mode 100644 index 000000000000..0720ff86b516 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory1Test.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory1Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + static ServiceAPI create1(Object receiver) { + return new ServiceAPI(null, receiver); + } + + @CustomDispatchFactory + @ExpectError("Only a single method can be annotated by the `CustomDispatchFactory`.%n" + + "Fix the ambiguity by removing the `static ServiceAPI create1(Object receiver)` method or the `static ServiceAPI create2(Object receiver)` method.") + static ServiceAPI create2(Object receiver) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java new file mode 100644 index 000000000000..65f31d8b5818 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory2Test.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory2Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + @SuppressWarnings("static-method") + final ServiceAPI create(Object receiver) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java new file mode 100644 index 000000000000..c59c30865412 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory3Test.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory3Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + private static ServiceAPI create(Object receiver) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java new file mode 100644 index 000000000000..96e64549903c --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory4Test.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory4Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + static ServiceAPI create() { + return null; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java new file mode 100644 index 000000000000..2be887a7bfb5 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory5Test.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory5Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + @SuppressWarnings("unused") + static ServiceAPI create(Object receiver, Object foo) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java new file mode 100644 index 000000000000..5af2c6c4b1e8 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory6Test.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory6Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + @SuppressWarnings("unused") + static int create(Object receiver) { + return 42; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java new file mode 100644 index 000000000000..4ae336c36fab --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory7Test.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory7Test extends CustomReceiverService { + + @CustomReceiverAccessor + @ExpectError("Class with a custom receiver accessor must also provide a custom dispatch accessor.%n" + + "To fix this add the `@CustomDispatchAccessor static CustomReceiverService resolveDispatch(ServiceAPI receiver)` method.") + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` is allowed only for classes with a custom dispatch.%n" + + "To fix this add a custom dispatch accessor method annotated by `CustomDispatchAccessor` and a custom receiver accessor method annotated by `CustomReceiverAccessor`.") + static ServiceAPI create(Object receiver) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java new file mode 100644 index 000000000000..b5980dd3f589 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomDispatchFactory8Test.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomDispatchFactory8Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomDispatchFactory + @ExpectError("A method annotated by `CustomDispatchFactory` must be a non-private static method with a single object parameter and `ServiceAPI` return type.%n" + + "To fix this change the signature to `static ServiceAPI create(Object receiver)`.") + static Object create(Object receiver) { + return new ServiceAPI(null, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java new file mode 100644 index 000000000000..500d90cf1888 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor1Test.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor1Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver1(ServiceAPI receiver) { + return receiver.receiver; + } + + @CustomReceiverAccessor + @ExpectError("Only a single method can be annotated by the `CustomReceiverAccessor`.%n" + + "Fix the ambiguity by removing the `static Object getReceiver1(ServiceAPI receiver)` method or the `static Object getReceiver2(ServiceAPI receiver)` method.") + static Object getReceiver2(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java new file mode 100644 index 000000000000..cf91d2310412 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor2Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor2Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + + "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") + @SuppressWarnings("static-method") + final Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java new file mode 100644 index 000000000000..17bff1802a48 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor3Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor3Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + + "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") + private static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java new file mode 100644 index 000000000000..dc1a787fcea4 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor4Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor4Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + + "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") + static Object getReceiver() { + return null; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java new file mode 100644 index 000000000000..42090f06e207 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor5Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor5Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + + "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") + @SuppressWarnings("unused") + static Object getReceiver(ServiceAPI receiver, Object foo) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java new file mode 100644 index 000000000000..7eb995b4a9e1 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor6Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor6Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("A method annotated by `CustomReceiverAccessor` must be a non-private non-void static method with a single parameter.%n" + + "To fix this change the signature to `static Object getReceiver(ServiceAPI receiver)`.") + @SuppressWarnings("unused") + static int getReceiver(ServiceAPI receiver) { + return 42; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java new file mode 100644 index 000000000000..5591b215ad08 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor7Test.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor7Test extends CustomReceiverService { + + @CustomReceiverAccessor + @ExpectError("Class with a custom receiver accessor must also provide a custom dispatch accessor.%n" + + "To fix this add the `@CustomDispatchAccessor static CustomReceiverService resolveDispatch(ServiceAPI receiver)` method.") + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java new file mode 100644 index 000000000000..5d2a2ea9ee3b --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidCustomReceiverAccessor8Test.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidCustomReceiverAccessor8Test extends CustomReceiverService { + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + @ExpectError("The custom receiver accessor must have the same parameter type as the custom dispatch accessor.") + static Object getReceiver(Object receiver) { + return receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java new file mode 100644 index 000000000000..ef79fae6438f --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle1Test.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidEndPointHandle1Test extends AbstractService { + + @EndPointHandle final HSObject delegate1; + + @ExpectError("Only a single field can be annotated by the `EndPointHandle`.%n" + + "Fix the ambiguity by removing the `final HSObject delegate1` field or the `final HSObject delegate2` field.") @EndPointHandle final HSObject delegate2; + + InvalidEndPointHandle1Test(HSObject delegate) { + this.delegate1 = delegate; + this.delegate2 = delegate; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java new file mode 100644 index 000000000000..954d1a652ecc --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidEndPointHandle2Test.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidEndPointHandle2Test extends AbstractService { + + @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `HSObject` type.%n" + + "To fix this change the signature to `final HSObject delegate`.") @EndPointHandle private final HSObject delegate; + + InvalidEndPointHandle2Test(HSObject delegate) { + this.delegate = delegate; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java new file mode 100644 index 000000000000..406104020b05 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidIdempotentTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.Idempotent; +import org.graalvm.nativebridge.Out; +import org.graalvm.nativebridge.processor.test.CustomMarshallerService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +import java.time.Duration; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidIdempotentTest extends HSObject implements CustomMarshallerService { + + InvalidIdempotentTest(JNIEnv env, JObject handle) { + super(env, handle); + } + + @ExpectError("A method with a cached return value cannot have an `Out` parameter.%n" + + "To fix this, remove the `Idempotent` annotation.") + @Override + @Idempotent + public abstract Duration[] getSetDurations(@Out Duration[] durations); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java new file mode 100644 index 000000000000..a641109bb917 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig1Test.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + + "The `getInstance` method is used by the generated code to look up marshallers.%n" + + "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") +@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig1Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) +abstract class InvalidJNIConfig1Test extends NativeObject implements Service { + + InvalidJNIConfig1Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + static final class JNIConfigProvider { + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java new file mode 100644 index 000000000000..ca6afb302209 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig2Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.JNIConfig; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + + "The `getInstance` method is used by the generated code to look up marshallers.%n" + + "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") +@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig2Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) +abstract class InvalidJNIConfig2Test extends NativeObject implements Service { + + InvalidJNIConfig2Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + static final class JNIConfigProvider { + static JNIConfig getInstance(@SuppressWarnings("unused") Object param) { + return null; + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java new file mode 100644 index 000000000000..fbe66afcccf7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig3Test.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + + "The `getInstance` method is used by the generated code to look up marshallers.%n" + + "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") +@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig3Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) +abstract class InvalidJNIConfig3Test extends NativeObject implements Service { + + InvalidJNIConfig3Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + static final class JNIConfigProvider { + static Object getInstance() { + return null; + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java new file mode 100644 index 000000000000..466cafecefa0 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig4Test.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.JNIConfig; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + + "The `getInstance` method is used by the generated code to look up marshallers.%n" + + "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") +@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig4Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) +abstract class InvalidJNIConfig4Test extends NativeObject implements Service { + + InvalidJNIConfig4Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + static final class JNIConfigProvider { + @SuppressWarnings("static-method") + JNIConfig getInstance() { + return null; + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java new file mode 100644 index 000000000000..8542bbf140db --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidJNIConfig5Test.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@ExpectError("JNI config must have a non-private static `getInstance()` method returning `JNIConfig`.%n" + + "The `getInstance` method is used by the generated code to look up marshallers.%n" + + "To fix this add `static JNIConfig getInstance() { return INSTANCE;}` into `JNIConfigProvider`.") +@GenerateHotSpotToNativeBridge(jniConfig = InvalidJNIConfig5Test.JNIConfigProvider.class, include = NotIncludedAutomatically.class) +abstract class InvalidJNIConfig5Test extends NativeObject implements Service { + + InvalidJNIConfig5Test(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + static final class JNIConfigProvider { + @SuppressWarnings("unused") + private static Object getInstance() { + return null; + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java new file mode 100644 index 000000000000..fcc67ced0d13 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod1Test.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidMethod1Test extends HSObject implements Service { + + InvalidMethod1Test(JNIEnv env, JObject handle) { + super(env, handle); + } + + @ExpectError("Should be `final` to prevent override in the generated class or `abstract` to be generated.%n" + + "To fix this add a `final` modifier or remove implementation in the `InvalidMethod1Test`.") + public void invalid() { + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java new file mode 100644 index 000000000000..ad5d3e85ef51 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod2Test.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidMethod2Test extends InvalidExplicitReceiverService { + + @ExpectError("In a class with a custom dispatch, the first method parameter must be the receiver.%n" + + "For a class with a custom dispatch, make the method `final` to prevent its generation.%n" + + "For a class that has no custom dispatch, remove methods annotated by `CustomDispatchAccessor` and `CustomReceiverAccessor`.") + @Override + abstract boolean isValid(); + + @CustomDispatchAccessor + static InvalidExplicitReceiverService getDispatch(Object receiver) { + return (InvalidExplicitReceiverService) receiver; + } + + @CustomReceiverAccessor + static Object getReceiver(Object receiver) { + return receiver; + } +} + +abstract class InvalidExplicitReceiverService { + abstract boolean execute(Object receiver); + + abstract boolean isValid(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java new file mode 100644 index 000000000000..885c15ff76a3 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod3Test.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.Idempotent; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidMethod3Test extends HSObject implements InvalidService { + + InvalidMethod3Test(JNIEnv env, JObject handle) { + super(env, handle); + } + + @Idempotent + @ExpectError("A method with a cached return value must have a non-void return type.%n" + + "To fix this remove the `Idempotent` annotation or change the return type.") + @Override + public abstract void execute(); + +} + +interface InvalidService { + void execute(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java new file mode 100644 index 000000000000..580ec91ba139 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod4Test.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.ReceiverMethod; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidMethod4Test extends HSObject implements Service { + + InvalidMethod4Test(JNIEnv env, JObject handle) { + super(env, handle); + } + + @Override + public final boolean execute() { + return executeImpl(42L); + } + + @ReceiverMethod("execute") + @ExpectError("A method `execute(long)` is not found in the `Service`. " + + "The receiver method must have the same arguments as the annotated method and must exist in the bridged type.") + abstract boolean executeImpl(long p0); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java new file mode 100644 index 000000000000..a0ee2e635ed3 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/InvalidMethod5Test.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.ReceiverMethod; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class InvalidMethod5Test extends AbstractService { + + @EndPointHandle final HSObject delegate; + + InvalidMethod5Test(HSObject delegate) { + this.delegate = delegate; + } + + @Override + public final boolean execute() { + return executeImpl(42L); + } + + @ReceiverMethod("executePrivate") + @ExpectError("The receiver method `executePrivate` must be a non-private instance method.") + abstract boolean executeImpl(long value); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java new file mode 100644 index 000000000000..4d377a1d6bb8 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation1.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.METHOD) +@interface TestAnnotation1 { +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java new file mode 100644 index 000000000000..01a3da0a69ab --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/common/TestAnnotation2.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.common; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.METHOD) +@interface TestAnnotation2 { +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java new file mode 100644 index 000000000000..eba86345c51e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeClassImlTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeClassImlTest extends AbstractService { + + @EndPointHandle final NativeObject delegate; + + NativeClassImlTest(NativeObject delegate) { + this.delegate = delegate; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java new file mode 100644 index 000000000000..e828eac28d85 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomMarshallerTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.Idempotent; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.Out; +import org.graalvm.nativebridge.processor.test.CustomMarshallerService; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint; + +import java.time.Duration; +import java.util.Map; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = CEntryPoint.NotIncludedAutomatically.class) +abstract class NativeCustomMarshallerTest extends NativeObject implements CustomMarshallerService { + + NativeCustomMarshallerTest(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + @Idempotent + @Override + public abstract Map getProperties(); + + @Override + public abstract void fillDurations(@Out Duration[] durations); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java new file mode 100644 index 000000000000..81b3f120e236 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeCustomReceiverImplTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeCustomReceiverImplTest extends CustomReceiverService { + + NativeCustomReceiverImplTest() { + } + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java new file mode 100644 index 000000000000..6e3f7f47e726 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInterfaceImplTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeInterfaceImplTest extends NativeObject implements Service { + + NativeInterfaceImplTest(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java new file mode 100644 index 000000000000..955a19caf8c7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidBaseTypeTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +@ExpectError("The annotated type must extend `NativeObject`, have a field annotated by `EndPointHandle` or a custom dispatch.%n" + + "To bridge an interface extend `NativeObject` and implement the interface.%n" + + "To bridge a class extend the class, add the `@EndPointHandle final NativeObject delegate` field and initialize it in the constructor.%n" + + "To bridge a class with a custom dispatch add `@CustomDispatchAccessor static Service resolveDispatch(Object receiver)` and `@CustomReceiverAccessor static Object resolveReceiver(Object receiver)` methods.") +abstract class NativeInvalidBaseTypeTest extends Object implements Service { + + @SuppressWarnings("unused") + NativeInvalidBaseTypeTest(NativeIsolate isolate, long handle) { + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java new file mode 100644 index 000000000000..ea3fbb34eff9 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor1Test.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +@ExpectError("The annotated type must have a single constructor with a `(NativeIsolate, long,...)` signature.%n" + + "To fix this add the `NativeInvalidConstructor1Test(NativeIsolate p0, long p1)` constructor into `NativeInvalidConstructor1Test`.") +abstract class NativeInvalidConstructor1Test extends NativeObject implements Service { + + @SuppressWarnings("unused") + NativeInvalidConstructor1Test(int a, NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java new file mode 100644 index 000000000000..8c3bbfa9abf9 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidConstructor2Test.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +@ExpectError("The annotated type must have a single constructor with a `(NativeObject,...)` signature.%n" + + "To fix this add the `NativeInvalidConstructor2Test(NativeObject p0)` constructor into `NativeInvalidConstructor2Test`.") +abstract class NativeInvalidConstructor2Test extends AbstractService { + + @EndPointHandle final NativeObject delegate; + + @SuppressWarnings("unused") + NativeInvalidConstructor2Test(NativeIsolate isolate, long handle) { + delegate = null; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java new file mode 100644 index 000000000000..8cfb31b99326 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeInvalidEndPointHandleTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.hstonative; + +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeInvalidEndPointHandleTest extends AbstractService { + + @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `NativeObject` type.%n" + + "To fix this change the signature to `final NativeObject delegate`.") @EndPointHandle final Object delegate; + + NativeInvalidEndPointHandleTest(NativeObject delegate) { + this.delegate = delegate; + } +} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java similarity index 54% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java rename to sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java index 211a496ebb47..0e726e1f6467 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/hstonative/NativeOutParameterService.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor.test.hstonative; diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java new file mode 100644 index 000000000000..05a4a59abc2a --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSClassImplTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSClassImplTest extends AbstractService { + + @EndPointHandle final HSObject delegate; + + HSClassImplTest(HSObject delegate) { + this.delegate = delegate; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java new file mode 100644 index 000000000000..ffafe3c9cbd7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomMarshallerTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.Idempotent; +import org.graalvm.nativebridge.Out; +import org.graalvm.nativebridge.processor.test.CustomMarshallerService; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +import java.time.Duration; +import java.util.Map; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSCustomMarshallerTest extends HSObject implements CustomMarshallerService { + + HSCustomMarshallerTest(JNIEnv env, JObject handle) { + super(env, handle); + } + + @Idempotent + @Override + public abstract Map getProperties(); + + @Override + public abstract void fillDurations(@Out Duration[] durations); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java new file mode 100644 index 000000000000..794f3e02d412 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSCustomReceiverImplTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.processor.test.CustomReceiverService; +import org.graalvm.nativebridge.processor.test.ServiceAPI; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSCustomReceiverImplTest extends CustomReceiverService { + + HSCustomReceiverImplTest() { + } + + @CustomDispatchAccessor + static CustomReceiverService getDispatch(ServiceAPI receiver) { + return receiver.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(ServiceAPI receiver) { + return receiver.receiver; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java new file mode 100644 index 000000000000..86e2f7c612b9 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInterfaceImplTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSInterfaceImplTest extends HSObject implements Service { + + HSInterfaceImplTest(JNIEnv env, JObject delegate) { + super(env, delegate); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java new file mode 100644 index 000000000000..12a22fbb3f5a --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidBaseTypeTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +@ExpectError("The annotated type must extend `HSObject`, have a field annotated by `EndPointHandle` or a custom dispatch.%n" + + "To bridge an interface extend `HSObject` and implement the interface.%n" + + "To bridge a class extend the class, add the `@EndPointHandle final HSObject delegate` field and initialize it in the constructor.%n" + + "To bridge a class with a custom dispatch add `@CustomDispatchAccessor static Service resolveDispatch(Object receiver)` and `@CustomReceiverAccessor static Object resolveReceiver(Object receiver)` methods.") +abstract class HSInvalidBaseTypeTest extends Object implements Service { + + @SuppressWarnings("unused") + HSInvalidBaseTypeTest(JNIEnv env, JObject handle) { + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java new file mode 100644 index 000000000000..ecf47d8d8327 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor1Test.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +@ExpectError("The annotated type must have a single constructor with a `(JNIEnv, JObject,...)` signature.%n" + + "To fix this add the `HSInvalidConstructor1Test(JNIEnv p0, JObject p1)` constructor into `HSInvalidConstructor1Test`.") +abstract class HSInvalidConstructor1Test extends HSObject implements Service { + + @SuppressWarnings("unused") + HSInvalidConstructor1Test(int a, JNIEnv env, JObject ref) { + super(env, ref); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java new file mode 100644 index 000000000000..f6d2c0328fe9 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidConstructor2Test.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +@ExpectError("The annotated type must have a single constructor with one of the following signatures `(HSObject,...)`, `(HSObject, JNIEnv,...)`.%n" + + "To fix this add the `HSInvalidConstructor2Test(HSObject p0)` constructor into `HSInvalidConstructor2Test`.") +abstract class HSInvalidConstructor2Test extends AbstractService { + + @EndPointHandle final HSObject delegate; + + @SuppressWarnings("unused") + HSInvalidConstructor2Test(JNIEnv env, JObject ref) { + delegate = null; + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java new file mode 100644 index 000000000000..accc93291a02 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSInvalidEndPointHandleTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetohs; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.EndPointHandle; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.AbstractService; +import org.graalvm.nativebridge.processor.test.ExpectError; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSInvalidEndPointHandleTest extends AbstractService { + + @ExpectError("A field annotated by `EndPointHandle` must be a non-private field of `HSObject` type.%n" + + "To fix this change the signature to `final HSObject delegate`.") @EndPointHandle final Object delegate; + + HSInvalidEndPointHandleTest(HSObject delegate) { + this.delegate = delegate; + } +} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java similarity index 53% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java rename to sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java index dab37e46b801..e3be073a95b5 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetohs/HSOutParameterService.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor.test.nativetohs; diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java new file mode 100644 index 000000000000..ea20f3f688ff --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceDifferentConfigs.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.GenerateNativeToNativeBridge; +import org.graalvm.nativebridge.JNIConfig; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +@GenerateNativeToNativeBridge(jniConfig = MixedNativeToNativeServiceDifferentConfigs.OtherJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class MixedNativeToNativeServiceDifferentConfigs extends NativeObject implements Service { + + MixedNativeToNativeServiceDifferentConfigs(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + public static final class OtherJNIConfig { + + private static final JNIConfig INSTANCE = createJNIConfig(); + + public static JNIConfig getInstance() { + return INSTANCE; + } + + private static JNIConfig createJNIConfig() { + return JNIConfig.newBuilder().build(); + } + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java new file mode 100644 index 000000000000..f9934282d1ce --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/MixedNativeToNativeServiceSameConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetonative; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.GenerateNativeToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +@GenerateNativeToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class MixedNativeToNativeServiceSameConfig extends NativeObject implements Service { + + MixedNativeToNativeServiceSameConfig(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java new file mode 100644 index 000000000000..21dcbed7d960 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/nativetonative/PureNativeToNativeService.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.nativetonative; + +import org.graalvm.nativebridge.GenerateNativeToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.Service; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateNativeToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class PureNativeToNativeService extends NativeObject implements Service { + + PureNativeToNativeService(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java new file mode 100644 index 000000000000..981614b95405 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Context.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.nativebridge.ByReference; + +interface Context { + + Handler getHandler(); + + void close(); + + @ByReference(NativeCustomLanguageDispatch.class) + LanguageAPI getLanguage(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java new file mode 100644 index 000000000000..47e4e222fe9e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/CustomLanguageDispatch.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +abstract class CustomLanguageDispatch { + + abstract String getId(Object receiver); + + abstract String getName(Object receiver); + + abstract String getVersion(Object receiver); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java new file mode 100644 index 000000000000..f74653d9f9a1 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSAlwaysByReferenceHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.AlwaysByReference; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +@AlwaysByReference(type = Context.class, startPointClass = NativeContext.class) +@AlwaysByReference(type = LanguageAPI.class, startPointClass = NativeCustomLanguageDispatch.class) +@AlwaysByReference(type = Record.class, startPointClass = NativeRecord.class) +abstract class HSAlwaysByReferenceHandler extends HSObject implements Handler { + HSAlwaysByReferenceHandler(JNIEnv env, JObject handle) { + super(env, handle); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java new file mode 100644 index 000000000000..e1cafbaa6b60 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSHandler.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JObject; +import org.graalvm.nativebridge.ByReference; +import org.graalvm.nativebridge.GenerateNativeToHotSpotBridge; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; + +@GenerateNativeToHotSpotBridge(jniConfig = TestJNIConfig.class) +abstract class HSHandler extends HSObject implements Handler { + + HSHandler(JNIEnv env, JObject handle) { + super(env, handle); + } + + @Override + public abstract void publish(@ByReference(NativeCustomLanguageDispatch.class) LanguageAPI language, + @ByReference(NativeRecord.class) Record record); + + @Override + @ByReference(NativeContext.class) + public abstract Context getContext(); +} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java similarity index 71% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java rename to sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java index 29f13099f867..b1dee08c293b 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/HSReferenceArrayOperations.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor.test.references; diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java new file mode 100644 index 000000000000..86fe8a95de17 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Handler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +interface Handler { + + void publish(LanguageAPI language, Record record); + + Context getContext(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java new file mode 100644 index 000000000000..f8dbfd501883 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import java.util.Objects; + +final class LanguageAPI { + + final CustomLanguageDispatch dispatch; + final Object receiver; + + LanguageAPI(CustomLanguageDispatch dispatch, Object receiver) { + this.dispatch = Objects.requireNonNull(dispatch); + this.receiver = Objects.requireNonNull(receiver); + } + + String getId() { + return dispatch.getId(receiver); + } + + String getName() { + return dispatch.getName(receiver); + } + + String getVersion() { + return dispatch.getVersion(receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java new file mode 100644 index 000000000000..d98dcb55ff0c --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeContext.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.jniutils.HSObject; +import org.graalvm.nativebridge.ByReference; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeContext extends NativeObject implements Context { + + NativeContext(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + @Override + @ByReference(HSObject.class) + public abstract Handler getHandler(); + +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java new file mode 100644 index 000000000000..59dd558c4673 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeCustomLanguageDispatch.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.nativebridge.CustomDispatchAccessor; +import org.graalvm.nativebridge.CustomDispatchFactory; +import org.graalvm.nativebridge.CustomReceiverAccessor; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeCustomLanguageDispatch extends CustomLanguageDispatch { + + private static final NativeCustomLanguageDispatch INSTANCE = NativeCustomLanguageDispatchGen.createHSToNative(); + + @CustomDispatchAccessor + static CustomLanguageDispatch getDispatch(LanguageAPI api) { + return api.dispatch; + } + + @CustomReceiverAccessor + static Object getReceiver(LanguageAPI api) { + return api.receiver; + } + + @CustomDispatchFactory + static LanguageAPI createLanguage(Object receiver) { + return new LanguageAPI(INSTANCE, receiver); + } +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java new file mode 100644 index 000000000000..5dae4e63f7c5 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeRecord.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeRecord extends NativeObject implements Record { + + NativeRecord(NativeIsolate isolate, long handle) { + super(isolate, handle); + } +} diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java similarity index 71% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java rename to sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java index fd99fbe7d291..4facd035e5eb 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeReferenceArrayOperations.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor.test.references; diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java new file mode 100644 index 000000000000..bf598928cb72 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/NativeService.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import org.graalvm.nativebridge.ByReference; +import org.graalvm.nativebridge.GenerateHotSpotToNativeBridge; +import org.graalvm.nativebridge.NativeIsolate; +import org.graalvm.nativebridge.NativeObject; +import org.graalvm.nativebridge.processor.test.TestJNIConfig; +import org.graalvm.nativeimage.c.function.CEntryPoint.NotIncludedAutomatically; + +@GenerateHotSpotToNativeBridge(jniConfig = TestJNIConfig.class, include = NotIncludedAutomatically.class) +abstract class NativeService extends NativeObject implements Service { + + NativeService(NativeIsolate isolate, long handle) { + super(isolate, handle); + } + + @Override + @ByReference(NativeContext.class) + public abstract Context open(@ByReference(HSHandler.class) Handler handler); + + @Override + public abstract void execute(@ByReference(NativeObject.class) Context context); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java new file mode 100644 index 000000000000..cf58076f0e32 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Record.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +public interface Record { + int getLevel(); + + String getMessage(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java new file mode 100644 index 000000000000..c9504c071e66 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/ReferenceArrayOperations.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +import java.util.List; + +public interface ReferenceArrayOperations { + + void acceptHost(Handler[] handlers); + + void acceptHostSubArray(Handler[] handlers, int offset, int length); + + void fillHost(Handler[] handlers); + + int fillHostSubArray(Handler[] handlers, int offset, int length); + + void exchangeHost(Handler[] handlers); + + int exchangeHostSubArray(Handler[] handlers, int offset, int length); + + Handler[] getHostObjects(); + + void acceptGuest(Record[] records); + + void acceptGuestWithMarshalledParameter(Record[] records, List list); + + void acceptGuestSubArray(Record[] records, int offset, int length); + + void fillGuest(Record[] records); + + void fillGuestWithMarshalledParameter(Record[] records, List list); + + List fillGuestWithMarshalledResult(Record[] records); + + List fillGuestWithMarshalledResultAndParameter(Record[] records, List list); + + int fillGuestSubArray(Record[] records, int offset, int length); + + List fillGuestSubArrayWithMarshalledResult(Record[] records, int offset, int length); + + void exchangeGuest(Record[] records); + + void exchangeGuestWithMarshalledParameter(Record[] records, List list); + + List exchangeGuestWithMarshalledResult(Record[] records); + + List exchangeGuestWithMarshalledResultAndParameter(Record[] records, List list); + + int exchangeGuestSubArray(Record[] records, int offset, int length); + + List exchangeGuestSubArrayWithMarshalledResult(Record[] records, int offset, int length); + + Record[] getGuestObjects(); +} diff --git a/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java new file mode 100644 index 000000000000..66626f597bda --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/Service.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor.test.references; + +interface Service { + Context open(Handler handler); + + void execute(Context context); +} diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/META-INF/services/javax.annotation.processing.Processor b/sdk/src/org.graalvm.nativebridge.processor/src/META-INF/services/javax.annotation.processing.Processor similarity index 100% rename from compiler/src/org.graalvm.nativebridge.processor/src/META-INF/services/javax.annotation.processing.Processor rename to sdk/src/org.graalvm.nativebridge.processor/src/META-INF/services/javax.annotation.processing.Processor diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java similarity index 95% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java index 034ef789dd31..1afa15b7f24b 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeGenerator.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; @@ -98,7 +114,7 @@ final FactoryMethodInfo resolveFactoryMethod(CharSequence factoryMethodName, Cha abstract void generateImpl(CodeBuilder builder, CharSequence targetClassSimpleName); - abstract MarshallerSnippets marshallerSnippets(MarshallerData marshallerData); + abstract MarshallerSnippet marshallerSnippets(MarshallerData marshallerData); void configureMultipleDefinitions(@SuppressWarnings("unused") List otherDefinitions) { } @@ -136,11 +152,11 @@ final void generateMarshallerLookups(CodeBuilder builder) { } } - final CacheSnippets cacheSnippets() { + final CacheSnippet cacheSnippets() { if (definitionData.hasCustomDispatch()) { - return CacheSnippets.customDispatch(types, parser.typeCache); + return CacheSnippet.customDispatch(types, parser.typeCache); } else { - return CacheSnippets.standardDispatch(types, parser.typeCache); + return CacheSnippet.standardDispatch(types, parser.typeCache); } } @@ -246,7 +262,7 @@ void generateMarshallerFields(CodeBuilder builder, Modifier... modifiers) { } } - void generateCacheFields(CodeBuilder builder, HotSpotToNativeBridgeGenerator.CacheSnippets cacheSnippets) { + void generateCacheFields(CodeBuilder builder, HotSpotToNativeBridgeGenerator.CacheSnippet cacheSnippets) { for (AbstractBridgeParser.MethodData methodData : definitionData.toGenerate) { AbstractBridgeParser.CacheData cacheData = methodData.cachedData; if (cacheData != null) { @@ -257,7 +273,7 @@ void generateCacheFields(CodeBuilder builder, HotSpotToNativeBridgeGenerator.Cac } } - void generateCacheFieldsInit(CodeBuilder builder, CacheSnippets cacheSnippets) { + void generateCacheFieldsInit(CodeBuilder builder, CacheSnippet cacheSnippets) { for (AbstractBridgeParser.MethodData methodData : definitionData.toGenerate) { AbstractBridgeParser.CacheData cacheData = methodData.cachedData; if (cacheData != null) { @@ -421,7 +437,7 @@ boolean isOutParameter(MarshallerData marshaller, TypeMirror type, boolean hostT return isBinaryMarshallable(marshaller, type, hostToIsolate) && marshaller.out != null; } - abstract static class MarshallerSnippets { + abstract static class MarshallerSnippet { private final NativeBridgeProcessor processor; private final AbstractTypeCache cache; @@ -429,7 +445,7 @@ abstract static class MarshallerSnippets { final MarshallerData marshallerData; final Types types; - MarshallerSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, AbstractTypeCache cache, BinaryNameCache binaryNameCache) { + MarshallerSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, AbstractTypeCache cache, BinaryNameCache binaryNameCache) { this.processor = processor; this.marshallerData = marshallerData; this.types = types; @@ -889,12 +905,12 @@ final void generateReadNativeObjectArray(CodeBuilder currentBuilder, CharSequenc } } - abstract static class CacheSnippets { + abstract static class CacheSnippet { final Types types; final AbstractTypeCache cache; - CacheSnippets(Types type, AbstractTypeCache cache) { + CacheSnippet(Types type, AbstractTypeCache cache) { this.types = type; this.cache = cache; } @@ -909,15 +925,15 @@ abstract static class CacheSnippets { abstract CharSequence writeCache(CodeBuilder currentBuilder, CharSequence cacheField, CharSequence receiver, CharSequence value); - static CacheSnippets standardDispatch(Types types, AbstractTypeCache cache) { + static CacheSnippet standardDispatch(Types types, AbstractTypeCache cache) { return new StandardDispatch(types, cache); } - static CacheSnippets customDispatch(Types types, AbstractTypeCache cache) { + static CacheSnippet customDispatch(Types types, AbstractTypeCache cache) { return new CustomDispatch(types, cache); } - private static final class StandardDispatch extends CacheSnippets { + private static final class StandardDispatch extends CacheSnippet { StandardDispatch(Types types, AbstractTypeCache cache) { super(types, cache); @@ -949,7 +965,7 @@ CharSequence writeCache(CodeBuilder currentBuilder, CharSequence cacheField, Cha } } - private static final class CustomDispatch extends CacheSnippets { + private static final class CustomDispatch extends CacheSnippet { CustomDispatch(Types type, AbstractTypeCache cache) { super(type, cache); diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java similarity index 97% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java index 668c9f85c5c6..7a9027adf90e 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractBridgeParser.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractProcessor.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractProcessor.java new file mode 100644 index 000000000000..6234a079df1d --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/AbstractProcessor.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.processing.Filer; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.tools.Diagnostic.Kind; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; + +/** + * {@link javax.annotation.processing.AbstractProcessor} subclass that provides extra functionality. + */ +@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", // + justification = "We want this type to be found when someone is writing a new Graal annotation processor") +public abstract class AbstractProcessor extends javax.annotation.processing.AbstractProcessor { + + /** + * Gets the processing environment available to this processor. + */ + public ProcessingEnvironment env() { + return processingEnv; + } + + @Override + public final SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return doProcess(annotations, roundEnv); + } + + protected abstract boolean doProcess(Set annotations, RoundEnvironment roundEnv); + + private final Map types = new HashMap<>(); + + /** + * Gets the {@link TypeMirror} for a given class name. + * + * @throws NoClassDefFoundError if the class cannot be resolved + */ + public TypeMirror getType(String className) { + return getTypeElement(className).asType(); + } + + public TypeMirror getType(Class element) { + if (element.isArray()) { + return processingEnv.getTypeUtils().getArrayType(getType(element.getComponentType())); + } + if (element.isPrimitive()) { + if (element == void.class) { + return processingEnv.getTypeUtils().getNoType(TypeKind.VOID); + } + TypeKind typeKind; + if (element == boolean.class) { + typeKind = TypeKind.BOOLEAN; + } else if (element == byte.class) { + typeKind = TypeKind.BYTE; + } else if (element == short.class) { + typeKind = TypeKind.SHORT; + } else if (element == char.class) { + typeKind = TypeKind.CHAR; + } else if (element == int.class) { + typeKind = TypeKind.INT; + } else if (element == long.class) { + typeKind = TypeKind.LONG; + } else if (element == float.class) { + typeKind = TypeKind.FLOAT; + } else if (element == double.class) { + typeKind = TypeKind.DOUBLE; + } else { + assert false; + return null; + } + return processingEnv.getTypeUtils().getPrimitiveType(typeKind); + } else { + TypeElement typeElement = getTypeElement(element.getCanonicalName()); + if (typeElement == null) { + return null; + } + return processingEnv.getTypeUtils().erasure(typeElement.asType()); + } + } + + /** + * Gets the {@link TypeMirror} for a given class name. + * + * @return {@code null} if the class cannot be resolved + */ + public TypeMirror getTypeOrNull(String className) { + TypeElement element = getTypeElementOrNull(className); + if (element == null) { + return null; + } + return element.asType(); + } + + /** + * Gets the {@link TypeElement} for a given class name. + * + * @throws NoClassDefFoundError if the class cannot be resolved + */ + public TypeElement getTypeElement(String className) { + TypeElement type = getTypeElementOrNull(className); + if (type == null) { + throw new NoClassDefFoundError(className); + } + return type; + } + + /** + * Gets the {@link TypeElement} for a given class name. + * + * @returns {@code null} if the class cannot be resolved + */ + public TypeElement getTypeElementOrNull(String className) { + TypeElement type = types.get(className); + if (type == null) { + type = processingEnv.getElementUtils().getTypeElement(className); + if (type == null) { + return null; + } + types.put(className, type); + } + return type; + } + + /** + * Converts a given {@link TypeMirror} to a {@link TypeElement}. + * + * @throws ClassCastException if type cannot be converted to a {@link TypeElement} + */ + public TypeElement asTypeElement(TypeMirror type) { + Element element = processingEnv.getTypeUtils().asElement(type); + if (element == null) { + throw new ClassCastException(type + " cannot be converted to a " + TypeElement.class.getName()); + } + return (TypeElement) element; + } + + /** + * Regular expression for a qualified class name that assumes package names start with lowercase + * and non-package components start with uppercase. + */ + private static final Pattern QUALIFIED_CLASS_NAME_RE = Pattern.compile("(?:[a-z]\\w*\\.)+([A-Z].*)"); + + /** + * Gets the non-package component of a qualified class name. + * + * @throws IllegalArgumentException if {@code className} does not match + * {@link #QUALIFIED_CLASS_NAME_RE} + */ + public static String getSimpleName(String className) { + Matcher m = QUALIFIED_CLASS_NAME_RE.matcher(className); + if (m.matches()) { + return m.group(1); + } + throw new IllegalArgumentException("Class name \"" + className + "\" does not match pattern " + QUALIFIED_CLASS_NAME_RE); + } + + /** + * Gets the package component of a qualified class name. + * + * @throws IllegalArgumentException if {@code className} does not match + * {@link #QUALIFIED_CLASS_NAME_RE} + */ + public static String getPackageName(String className) { + String simpleName = getSimpleName(className); + return className.substring(0, className.length() - simpleName.length() - 1); + } + + /** + * Gets the annotation of type {@code annotationType} directly present on {@code element}. + * + * @return {@code null} if an annotation of type {@code annotationType} is not on + * {@code element} + */ + public AnnotationMirror getAnnotation(Element element, TypeMirror annotationType) { + List mirrors = getAnnotations(element, annotationType); + return mirrors.isEmpty() ? null : mirrors.get(0); + } + + /** + * Gets all annotations directly present on {@code element}. + */ + public List getAnnotations(Element element, TypeMirror typeMirror) { + List result = new ArrayList<>(); + for (AnnotationMirror mirror : element.getAnnotationMirrors()) { + if (processingEnv.getTypeUtils().isSameType(mirror.getAnnotationType(), typeMirror)) { + result.add(mirror); + } + } + return result; + } + + /** + * Gets the value of the {@code name} element of {@code annotation} and converts it to a value + * of type {@code type}. + * + * @param type the expected type of the element value. This must be a subclass of one of the + * types described by {@link AnnotationValue}. + * @throws NoSuchElementException if {@code annotation} has no element named {@code name} + * @throws ClassCastException if the value of the specified element cannot be converted to + * {@code type} + */ + public static T getAnnotationValue(AnnotationMirror annotation, String name, Class type) { + ExecutableElement valueMethod = null; + for (ExecutableElement method : ElementFilter.methodsIn(annotation.getAnnotationType().asElement().getEnclosedElements())) { + if (method.getSimpleName().toString().equals(name)) { + valueMethod = method; + break; + } + } + + if (valueMethod == null) { + return null; + } + + AnnotationValue value = annotation.getElementValues().get(valueMethod); + if (value == null) { + value = valueMethod.getDefaultValue(); + } + + return type.cast(value.getValue()); + } + + /** + * Gets the value of the {@code name} array-typed element of {@code annotation} and converts it + * to list of values of type {@code type}. + * + * @param componentType the expected component type of the element value. This must be a + * subclass of one of the types described by {@link AnnotationValue}. + * @throws NoSuchElementException if {@code annotation} has no element named {@code name} + * @throws ClassCastException if the value of the specified element is not an array whose + * components cannot be converted to {@code componentType} + */ + @SuppressWarnings("unchecked") + public static List getAnnotationValueList(AnnotationMirror annotation, String name, Class componentType) { + List values = getAnnotationValue(annotation, name, List.class); + List result = new ArrayList<>(); + + if (values != null) { + for (AnnotationValue value : values) { + result.add(componentType.cast(value.getValue())); + } + } + return result; + } + + public static PackageElement getPackage(Element element) { + Element e = element.getEnclosingElement(); + while (e != null && e.getKind() != ElementKind.PACKAGE) { + e = e.getEnclosingElement(); + } + return (PackageElement) e; + } + + public static PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { + try { + /* Ensure Unix line endings to comply with code style guide checked by Checkstyle. */ + String className = pkg + "." + relativeName; + JavaFileObject sourceFile = filer.createSourceFile(className, originatingElements); + return new PrintWriter(sourceFile.openWriter()) { + @Override + public void println() { + print("\n"); + } + }; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Creates a {@code META-INF/providers/} file whose contents are a single + * line containing {@code serviceClassName}. + */ + public void createProviderFile(String providerClassName, String serviceClassName, Element... originatingElements) { + assert originatingElements.length > 0; + String filename = "META-INF/providers/" + providerClassName; + try { + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + writer.println(serviceClassName); + writer.close(); + } catch (IOException e) { + processingEnv.getMessager().printMessage(isBug367599(e) ? Kind.NOTE : Kind.ERROR, e.getMessage(), originatingElements[0]); + } + } + + /** + * Determines if a given exception is (most likely) caused by + * Bug 367599. + */ + private static boolean isBug367599(Throwable t) { + if (t instanceof FilerException) { + for (StackTraceElement ste : t.getStackTrace()) { + if (ste.toString().contains("org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.create")) { + // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599 + return true; + } + } + } + return t.getCause() != null && isBug367599(t.getCause()); + } +} diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java similarity index 91% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java index 04a2283e8af4..527d46b9abd5 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/CodeBuilder.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java similarity index 57% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java index 87e782bffc9c..72611089ee3f 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/ExpectError.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java similarity index 94% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java index edecffd5b5ee..962d91a5c43d 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeGenerator.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; @@ -115,14 +131,14 @@ void generateImpl(CodeBuilder builder, CharSequence targetClassSimpleName) { } @Override - HotSpotToNativeMarshallerSnippets marshallerSnippets(MarshallerData marshallerData) { - return HotSpotToNativeMarshallerSnippets.forData(parser.processor, definitionData, marshallerData, types, typeCache, binaryNameCache); + HotSpotToNativeMarshallerSnippet marshallerSnippets(MarshallerData marshallerData) { + return HotSpotToNativeMarshallerSnippet.forData(parser.processor, definitionData, marshallerData, types, typeCache, binaryNameCache); } private void generateHSToNativeStartPoint(CodeBuilder builder, FactoryMethodInfo factoryMethodInfo) { HotSpotToNativeDefinitionData hsData = ((HotSpotToNativeDefinitionData) definitionData); - CacheSnippets cacheSnippets = cacheSnippets(); + CacheSnippet cacheSnippets = cacheSnippets(); builder.classStart(EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL), factoryMethod.startPointSimpleName, definitionData.annotatedType, Collections.emptyList()); builder.indent(); @@ -162,7 +178,7 @@ private void generateHSToNativeStartPoint(CodeBuilder builder, FactoryMethodInfo builder.classEnd(); } - private void generateHSToNativeStartMethod(CodeBuilder builder, CacheSnippets cacheSnippets, MethodData methodData) { + private void generateHSToNativeStartMethod(CodeBuilder builder, CacheSnippet cacheSnippets, MethodData methodData) { builder.line(""); overrideMethod(builder, methodData); builder.indent(); @@ -239,7 +255,7 @@ private void generateHSToNativeStartMethod(CodeBuilder builder, CacheSnippets ca boolean needsPostMarshallParameters = generatePreMarshallParameters(builder, allParameters, marshalledParametersOutput, overrides); CharSequence nativeCall = generateMarshallParameters(builder, nativeMethodName, allParameters, marshalledParametersOutput, syntheticPrependParameters, syntheticAppendParameters, overrides); - MarshallerSnippets marshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); + MarshallerSnippet marshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); PreUnmarshallResult preUnmarshallResult = generatePreUnmarshallResult(builder, marshallerSnippets, returnType, nativeCall, receiverNativeObject, hasBinaryMarshalledResult); CharSequence value = marshallerSnippets.unmarshallResult(builder, returnType, preUnmarshallResult.result, receiverNativeObject, preUnmarshallResult.binaryInput, null); builder.lineStart().write(resFieldName).write(" = ").write(value).lineEnd(";"); @@ -263,12 +279,12 @@ private void generateHSToNativeStartMethod(CodeBuilder builder, CacheSnippets ca boolean needsPostMarshallParameters = generatePreMarshallParameters(builder, allParameters, marshalledParametersOutput, overrides); CharSequence nativeCall = generateMarshallParameters(builder, nativeMethodName, allParameters, marshalledParametersOutput, syntheticPrependParameters, syntheticAppendParameters, overrides); - MarshallerSnippets resultMarshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); + MarshallerSnippet resultMarshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); boolean voidReturnType = returnType.getKind() == TypeKind.VOID; CharSequence resultVariable = null; PreUnmarshallResult preUnmarshallResult; if (firstOutMarshalledParameter != null) { - MarshallerSnippets customMarshalledSnippets = marshallerSnippets(firstOutMarshalledParameter); + MarshallerSnippet customMarshalledSnippets = marshallerSnippets(firstOutMarshalledParameter); CharSequence resultInput = generateBinaryInputForResult(builder, customMarshalledSnippets, returnType, nativeCall); preUnmarshallResult = new PreUnmarshallResult(HOTSPOT_RESULT_VARIABLE, null, resultInput, false); if (!voidReturnType) { @@ -328,7 +344,7 @@ private boolean generatePreMarshallParameters(CodeBuilder builder, List parameterValueOverrides) { boolean needsPostMarshall = false; for (MarshalledParameter marshalledParameter : marshalledParameters) { - MarshallerSnippets snippets = marshallerSnippets(marshalledParameter.marshallerData); + MarshallerSnippet snippets = marshallerSnippets(marshalledParameter.marshallerData); needsPostMarshall |= snippets.preMarshallParameter(builder, marshalledParameter.parameterType, marshalledParameter.parameterName, marshalledParametersOutput, null, parameterValueOverrides); } @@ -341,7 +357,7 @@ private CharSequence generateMarshallParameters(CodeBuilder builder, CharSequenc for (MarshalledParameter marshalledParameter : marshalledParameters) { CharSequence override = parameterValueOverrides.get(marshalledParameter.parameterName.toString()); CharSequence useValue = override != null ? override : marshalledParameter.parameterName; - MarshallerSnippets snippets = marshallerSnippets(marshalledParameter.marshallerData); + MarshallerSnippet snippets = marshallerSnippets(marshalledParameter.marshallerData); CharSequence expr = snippets.marshallParameter(builder, marshalledParameter.parameterType, useValue, marshalledParametersOutput, null); if (expr != null) { actualParameters.add(expr); @@ -360,12 +376,12 @@ private void generatePostMarshallParameters(CodeBuilder builder, List "L" + Utilities.cSymbol(te.getQualifiedName().toString()) + "_2"); } - private abstract static class HotSpotToNativeMarshallerSnippets extends MarshallerSnippets { + private abstract static class HotSpotToNativeMarshallerSnippet extends MarshallerSnippet { final TypeCache cache; - HotSpotToNativeMarshallerSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { + HotSpotToNativeMarshallerSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, typeCache, binaryNameCache); this.cache = typeCache; } - static HotSpotToNativeMarshallerSnippets forData(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, + static HotSpotToNativeMarshallerSnippet forData(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { switch (marshallerData.kind) { case VALUE: - return new DirectSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new DirectSnippet(processor, marshallerData, types, typeCache, binaryNameCache); case REFERENCE: - return new ReferenceSnippets(processor, data, marshallerData, types, typeCache, binaryNameCache); + return new ReferenceSnippet(processor, data, marshallerData, types, typeCache, binaryNameCache); case RAW_REFERENCE: - return new RawReferenceSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new RawReferenceSnippet(processor, marshallerData, types, typeCache, binaryNameCache); case CUSTOM: - return new CustomSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new CustomSnippet(processor, marshallerData, types, typeCache, binaryNameCache); default: throw new IllegalArgumentException(String.valueOf(marshallerData.kind)); } } - private static final class DirectSnippets extends HotSpotToNativeMarshallerSnippets { + private static final class DirectSnippet extends HotSpotToNativeMarshallerSnippet { - DirectSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + DirectSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } @@ -990,11 +1006,11 @@ void read(CodeBuilder currentBuilder, TypeMirror resultType, CharSequence result } } - private static final class ReferenceSnippets extends HotSpotToNativeMarshallerSnippets { + private static final class ReferenceSnippet extends HotSpotToNativeMarshallerSnippet { private final DefinitionData data; - ReferenceSnippets(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + ReferenceSnippet(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); this.data = data; } @@ -1370,9 +1386,9 @@ void read(CodeBuilder currentBuilder, TypeMirror resultType, CharSequence result } } - private static final class RawReferenceSnippets extends HotSpotToNativeMarshallerSnippets { + private static final class RawReferenceSnippet extends HotSpotToNativeMarshallerSnippet { - RawReferenceSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + RawReferenceSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } @@ -1414,9 +1430,9 @@ void read(CodeBuilder currentBuilder, TypeMirror resultType, CharSequence result } } - private static final class CustomSnippets extends HotSpotToNativeMarshallerSnippets { + private static final class CustomSnippet extends HotSpotToNativeMarshallerSnippet { - CustomSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + CustomSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java similarity index 69% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java index 855d9eeb88ac..26e3cc8c91c5 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/HotSpotToNativeBridgeParser.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java similarity index 74% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java index 31290220b279..5fe71befd53b 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeBridgeProcessor.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; @@ -45,7 +61,6 @@ import javax.tools.Diagnostic; import javax.tools.JavaFileObject; -import org.graalvm.compiler.processor.AbstractProcessor; import org.graalvm.nativebridge.processor.AbstractBridgeParser.AbstractTypeCache; import org.graalvm.nativebridge.processor.AbstractBridgeParser.DefinitionData; diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java similarity index 95% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java index c1c1e80241e3..7c643c752094 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeGenerator.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; @@ -82,12 +98,12 @@ void generateImpl(CodeBuilder builder, CharSequence targetClassSimpleName) { } @Override - MarshallerSnippets marshallerSnippets(MarshallerData marshallerData) { - return NativeToHotSpotMarshallerSnippets.forData(parser.processor, definitionData, marshallerData, types, typeCache, binaryNameCache); + MarshallerSnippet marshallerSnippets(MarshallerData marshallerData) { + return NativeToHotSpotMarshallerSnippet.forData(parser.processor, definitionData, marshallerData, types, typeCache, binaryNameCache); } private void generateNativeToHSStartPoint(CodeBuilder builder, FactoryMethodInfo factoryMethodInfo) { - CacheSnippets cacheSnippets = cacheSnippets(); + CacheSnippet cacheSnippets = cacheSnippets(); builder.classStart(EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL), START_POINT_SIMPLE_NAME, definitionData.annotatedType, Collections.emptyList()); builder.indent(); @@ -220,7 +236,7 @@ private void generateJNIFieldsInit(CodeBuilder builder, CodeBuilder.Parameter jn } } - private void generateNativeToHSStartMethod(CodeBuilder builder, CacheSnippets cacheSnippets, MethodData methodData) { + private void generateNativeToHSStartMethod(CodeBuilder builder, CacheSnippet cacheSnippets, MethodData methodData) { builder.line(""); overrideMethod(builder, methodData); builder.indent(); @@ -255,7 +271,7 @@ private void generateNativeToHSStartMethod(CodeBuilder builder, CacheSnippets ca CharSequence env; TypeMirror returnType = methodData.type.getReturnType(); boolean voidMethod = returnType.getKind() == TypeKind.VOID; - MarshallerSnippets resultMarshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); + MarshallerSnippet resultMarshallerSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); if (cacheData != null) { if (hasOutParameters) { throw new IllegalStateException("Idempotent cannot be used with Out parameters."); @@ -331,7 +347,7 @@ private void generateNativeToHSStartMethod(CodeBuilder builder, CacheSnippets ca Map.Entry binaryUnmarshallVars = null; if (firstOutMarshalledParameter != null) { hasPostMarshall = true; - MarshallerSnippets customMarshalledSnippets = marshallerSnippets(firstOutMarshalledParameter); + MarshallerSnippet customMarshalledSnippets = marshallerSnippets(firstOutMarshalledParameter); CharSequence jniCall = callHotSpot(builder, methodData, env, args, customMarshalledSnippets); CharSequence endPointResult = generateStoreEndPointResult(builder, customMarshalledSnippets, returnType, jniCall, env); binaryUnmarshallVars = generateCreateBinaryInputForJByteArray(builder, binaryMarshallVars, endPointResult, "marshalledResultInput", env, staticMarshallBufferVar, staticBufferSize); @@ -387,11 +403,11 @@ private void generateNativeToHSStartMethod(CodeBuilder builder, CacheSnippets ca builder.line("}"); } - private static CharSequence generateStoreEndPointResult(CodeBuilder builder, MarshallerSnippets snippets, TypeMirror returnType, CharSequence nativeCall, CharSequence jniEnvFieldName) { + private static CharSequence generateStoreEndPointResult(CodeBuilder builder, MarshallerSnippet snippets, TypeMirror returnType, CharSequence nativeCall, CharSequence jniEnvFieldName) { return snippets.storeRawResult(builder, returnType, nativeCall, jniEnvFieldName); } - private PreUnmarshallResult generatePreUnmarshallResult(CodeBuilder builder, MarshallerSnippets snippets, BinaryMarshallVariables binaryMarshallVars, TypeMirror returnType, + private PreUnmarshallResult generatePreUnmarshallResult(CodeBuilder builder, MarshallerSnippet snippets, BinaryMarshallVariables binaryMarshallVars, TypeMirror returnType, CharSequence nativeCall, CharSequence receiver, CharSequence jniEnvFieldName, boolean hasBinaryMarshalledResult, CharSequence staticMarshallBufferVar, int staticBufferSize) { CharSequence result = nativeCall; @@ -588,7 +604,7 @@ private CharSequence generatePushArgs(CodeBuilder builder, MethodData methodData CharSequence parameterName = formalParameters.get(i).getSimpleName(); CharSequence parameterValueOverride = parameterValueOverrides.get(parameterName.toString()); MarshallerData marshaller = methodData.getParameterMarshaller(i); - MarshallerSnippets marshallerSnippets = marshallerSnippets(marshaller); + MarshallerSnippet marshallerSnippets = marshallerSnippets(marshaller); if (parameterValueOverride != null) { value = parameterValueOverride; } else { @@ -658,7 +674,7 @@ private CharSequence jValueSetterName(TypeMirror type) { } } - private CharSequence callHotSpot(CodeBuilder builder, MethodData methodData, CharSequence jniEnv, CharSequence args, MarshallerSnippets marshallerSnippets) { + private CharSequence callHotSpot(CodeBuilder builder, MethodData methodData, CharSequence jniEnv, CharSequence args, MarshallerSnippet marshallerSnippets) { CharSequence hsCallsInstance = new CodeBuilder(builder).invokeStatic(typeCache.foreignException, "getJNICalls").build(); TypeMirror retType = methodData.type.getReturnType(); return new CodeBuilder(builder).invoke(hsCallsInstance, callHotSpotName(marshallerSnippets.getEndPointMethodParameterType(retType)), @@ -861,7 +877,7 @@ private void generateNativeToHSEndMethod(CodeBuilder builder, MethodData methodD marshallerSnippets(methodData.getReturnTypeMarshaller()).write(builder, receiverMethodReturnType, resultVariable, marshalledOutputVar, null); } } else if (resultVariable != null) { - MarshallerSnippets returnTypeSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); + MarshallerSnippet returnTypeSnippets = marshallerSnippets(methodData.getReturnTypeMarshaller()); CharSequence resultOverride = returnTypeSnippets.preMarshallResult(builder, receiverMethodReturnType, resultVariable, marshalledOutputVar, null); if (resultOverride != null) { resultVariable = resultOverride; @@ -877,7 +893,7 @@ private void generateNativeToHSEndMethod(CodeBuilder builder, MethodData methodD // Generate post unmarshall statements. for (int i = nonReceiverParameterStart; i < methodParameters.size(); i++) { - MarshallerSnippets marshallerSnippets = marshallerSnippets(methodData.getParameterMarshaller(i)); + MarshallerSnippet marshallerSnippets = marshallerSnippets(methodData.getParameterMarshaller(i)); marshallerSnippets.postUnmarshallParameter(builder, methodParameterTypes.get(i), methodParameters.get(i).getSimpleName(), marshalledOutputVar, null, resultVariable); } @@ -921,34 +937,34 @@ private static final class BinaryMarshallVariables { } } - private abstract static class NativeToHotSpotMarshallerSnippets extends MarshallerSnippets { + private abstract static class NativeToHotSpotMarshallerSnippet extends MarshallerSnippet { final TypeCache cache; - NativeToHotSpotMarshallerSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { + NativeToHotSpotMarshallerSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, typeCache, binaryNameCache); this.cache = typeCache; } - static NativeToHotSpotMarshallerSnippets forData(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, + static NativeToHotSpotMarshallerSnippet forData(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache typeCache, BinaryNameCache binaryNameCache) { switch (marshallerData.kind) { case VALUE: - return new DirectSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new DirectSnippet(processor, marshallerData, types, typeCache, binaryNameCache); case REFERENCE: - return new ReferenceSnippets(processor, data, marshallerData, types, typeCache, binaryNameCache); + return new ReferenceSnippet(processor, data, marshallerData, types, typeCache, binaryNameCache); case RAW_REFERENCE: - return new RawReferenceSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new RawReferenceSnippet(processor, marshallerData, types, typeCache, binaryNameCache); case CUSTOM: - return new CustomSnippets(processor, marshallerData, types, typeCache, binaryNameCache); + return new CustomSnippet(processor, marshallerData, types, typeCache, binaryNameCache); default: throw new IllegalArgumentException(String.valueOf(marshallerData.kind)); } } - private static final class DirectSnippets extends NativeToHotSpotMarshallerSnippets { + private static final class DirectSnippet extends NativeToHotSpotMarshallerSnippet { - DirectSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + DirectSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } @@ -1112,11 +1128,11 @@ private static CharSequence arrayFactoryMethodName(TypeMirror jniArrayType) { } } - private static final class ReferenceSnippets extends NativeToHotSpotMarshallerSnippets { + private static final class ReferenceSnippet extends NativeToHotSpotMarshallerSnippet { private final DefinitionData data; - ReferenceSnippets(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + ReferenceSnippet(NativeBridgeProcessor processor, DefinitionData data, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); this.data = data; } @@ -1429,9 +1445,9 @@ void read(CodeBuilder currentBuilder, TypeMirror resultType, CharSequence result } } - private static final class RawReferenceSnippets extends NativeToHotSpotMarshallerSnippets { + private static final class RawReferenceSnippet extends NativeToHotSpotMarshallerSnippet { - RawReferenceSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + RawReferenceSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } @@ -1473,9 +1489,9 @@ void read(CodeBuilder currentBuilder, TypeMirror resultType, CharSequence result } } - private static final class CustomSnippets extends NativeToHotSpotMarshallerSnippets { + private static final class CustomSnippet extends NativeToHotSpotMarshallerSnippet { - CustomSnippets(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { + CustomSnippet(NativeBridgeProcessor processor, MarshallerData marshallerData, Types types, TypeCache cache, BinaryNameCache binaryNameCache) { super(processor, marshallerData, types, cache, binaryNameCache); } diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java similarity index 62% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java index 31994f6d1de9..35283d8880c5 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToHotSpotBridgeParser.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java similarity index 71% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java index e290b6f86c9c..355b1ffaa02c 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeGenerator.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; @@ -89,7 +105,7 @@ void generateImpl(CodeBuilder builder, CharSequence targetClassSimpleName) { } @Override - MarshallerSnippets marshallerSnippets(AbstractBridgeParser.MarshallerData marshallerData) { + MarshallerSnippet marshallerSnippets(AbstractBridgeParser.MarshallerData marshallerData) { throw new UnsupportedOperationException("Should not reach here"); } diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java similarity index 60% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java index 7c2104e29bff..07f6f089a7cb 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/NativeToNativeBridgeParser.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/SuppressFBWarnings.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/SuppressFBWarnings.java new file mode 100644 index 000000000000..3692068fa02e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/SuppressFBWarnings.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge.processor; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to suppress SpotBugs warnings. + */ +@Retention(RetentionPolicy.CLASS) +@interface SuppressFBWarnings { + /** + * @see "https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html" + */ + String[] value(); + + /** + * Reason why the warning is suppressed. Use a SpotBugs issue id where appropriate. + */ + String justification(); +} diff --git a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java similarity index 82% rename from compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java rename to sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java index 1f9cf5b60c51..ac11962bca6f 100644 --- a/compiler/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java +++ b/sdk/src/org.graalvm.nativebridge.processor/src/org/graalvm/nativebridge/processor/Utilities.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge.processor; diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReference.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReference.java new file mode 100644 index 000000000000..3fcde4ac8854 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReference.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation configuring a type as a by reference parameter in the whole annotated compilation + * unit. For classes that have many methods using {@link ByReference} parameters, using this + * annotation is more convenient. Instead of overriding these methods and specifying + * {@link ByReference} in each method, the whole class can be annotated with + * {@link AlwaysByReference}. It is always possible to override {@link AlwaysByReference} + * configuration with {@link ByReference} annotation on a particular method or parameter. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +@Repeatable(AlwaysByReferenceRepeated.class) +public @interface AlwaysByReference { + /** + * Method parameter or return type that should always be handled as a {@link ByReference} in the + * annotated compilation unit. + * + * @see ByReference + */ + Class type(); + + /** + * The class to instantiate for a foreign handle. + * + * @see ByReference#value() for the start point class requirements. + */ + Class startPointClass(); +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java new file mode 100644 index 000000000000..ec7b26092f19 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/AlwaysByReferenceRepeated.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Container for repeated {@link AlwaysByReference} annotations. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface AlwaysByReferenceRepeated { + AlwaysByReference[] value(); +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryInput.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryInput.java new file mode 100644 index 000000000000..59bdb922be98 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryInput.java @@ -0,0 +1,656 @@ +/* + * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import static org.graalvm.nativebridge.BinaryOutput.LARGE_STRING_TAG; +import static org.graalvm.nativebridge.BinaryOutput.NULL; +import static org.graalvm.nativebridge.BinaryOutput.BYTE; +import static org.graalvm.nativebridge.BinaryOutput.BOOLEAN; +import static org.graalvm.nativebridge.BinaryOutput.SHORT; +import static org.graalvm.nativebridge.BinaryOutput.CHAR; +import static org.graalvm.nativebridge.BinaryOutput.INT; +import static org.graalvm.nativebridge.BinaryOutput.LONG; +import static org.graalvm.nativebridge.BinaryOutput.FLOAT; +import static org.graalvm.nativebridge.BinaryOutput.DOUBLE; +import static org.graalvm.nativebridge.BinaryOutput.STRING; +import static org.graalvm.nativebridge.BinaryOutput.ARRAY; +import static org.graalvm.nativebridge.BinaryOutput.bufferSize; + +/** + * A buffer used by the {@link BinaryMarshaller} to unmarshal parameters and results passed by + * value. + * + * @see BinaryOutput + * @see BinaryMarshaller + * @see JNIConfig.Builder#registerMarshaller(Class, BinaryMarshaller) + */ +public abstract class BinaryInput { + + private static final int EOF = -1; + + private byte[] tempEncodingByteBuffer; + private char[] tempEncodingCharBuffer; + protected final int length; + protected int pos; + + private BinaryInput(int length) { + this.length = length; + } + + /** + * Reads a single byte and returns {@code true} if that byte is non-zero, {@code false} if that + * byte is zero. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final boolean readBoolean() throws IndexOutOfBoundsException { + int b = read(); + if (b < 0) { + throw new IndexOutOfBoundsException(); + } + return b != 0; + } + + /** + * Reads and returns a single byte. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final byte readByte() throws IndexOutOfBoundsException { + int b = read(); + if (b < 0) { + throw new IndexOutOfBoundsException(); + } + return (byte) b; + } + + /** + * Reads two bytes and returns a {@code short} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final short readShort() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + return packShort(b1, b2); + } + + /** + * Creates a Java {@code short} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b2} is the least significant {@code byte}. + */ + private static short packShort(int b1, int b2) { + return (short) ((b1 << 8) + b2); + } + + /** + * Reads two bytes and returns a {@code char} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final char readChar() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + return packChar(b1, b2); + } + + /** + * Creates a Java {@code char} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b2} is the least significant {@code byte}. + */ + private static char packChar(int b1, int b2) { + return (char) ((b1 << 8) + b2); + } + + /** + * Reads four bytes and returns an {@code int} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final int readInt() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + int b3 = read(); + int b4 = read(); + if ((b1 | b2 | b3 | b4) < 0) { + throw new IndexOutOfBoundsException(); + } + return packInt(b1, b2, b3, b4); + } + + /** + * Creates a Java {@code int} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b4} is the least significant {@code byte}. + */ + private static int packInt(int b1, int b2, int b3, int b4) { + return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; + } + + /** + * Reads eight bytes and returns a {@code long} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final long readLong() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + int b3 = read(); + int b4 = read(); + int b5 = read(); + int b6 = read(); + int b7 = read(); + int b8 = read(); + if ((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) { + throw new IndexOutOfBoundsException(); + } + return packLong(b1, b2, b3, b4, b5, b6, b7, b8); + } + + /** + * Creates a Java {@code long} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b8} is the least significant {@code byte}. + */ + private static long packLong(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) { + return ((long) b1 << 56) + ((long) b2 << 48) + ((long) b3 << 40) + ((long) b4 << 32) + + ((long) b5 << 24) + ((long) b6 << 16) + ((long) b7 << 8) + b8; + } + + /** + * Reads four bytes and returns a {@code float} value. It does this by reading an {@code int} + * value and converting the {@code int} value to a {@code float} using + * {@link Float#intBitsToFloat(int)}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final float readFloat() throws IndexOutOfBoundsException { + return Float.intBitsToFloat(readInt()); + } + + /** + * Reads eight bytes and returns a {@code double} value. It does this by reading a {@code long} + * value and converting the {@code long} value to a {@code double} using + * {@link Double#longBitsToDouble(long)}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final double readDouble() throws IndexOutOfBoundsException { + return Double.longBitsToDouble(readLong()); + } + + /** + * Reads a single byte. The byte value is returned as an {@code int} in the range {@code 0} to + * {@code 255}. If no byte is available because the end of the stream has been reached, the + * value {@code -1} is returned. + */ + public abstract int read(); + + /** + * Reads {@code len} bytes into a byte array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public abstract void read(byte[] b, int off, int len) throws IndexOutOfBoundsException; + + /** + * Reads a string using a modified UTF-8 encoding in a machine-independent manner. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + * @throws IllegalArgumentException if the bytes do not represent a valid modified UTF-8 + * encoding of a string. + */ + public final String readUTF() throws IndexOutOfBoundsException, IllegalArgumentException { + int len; + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + if ((b1 & LARGE_STRING_TAG) == LARGE_STRING_TAG) { + int b3 = read(); + int b4 = read(); + if ((b3 | b4) < 0) { + throw new IndexOutOfBoundsException(); + } + len = ((b1 & ~LARGE_STRING_TAG) << 24) + (b2 << 16) + (b3 << 8) + b4; + } else { + len = (b1 << 8) + b2; + } + ensureBufferSize(len); + if (tempEncodingCharBuffer == null || tempEncodingCharBuffer.length < len) { + tempEncodingCharBuffer = new char[Math.max(bufferSize(0, len), 80)]; + } + + int c1; + int c2; + int c3; + int byteCount = 0; + int charCount = 0; + + read(tempEncodingByteBuffer, 0, len); + + while (byteCount < len) { + c1 = tempEncodingByteBuffer[byteCount] & 0xff; + if (c1 > 127) { + break; + } + byteCount++; + tempEncodingCharBuffer[charCount++] = (char) c1; + } + + while (byteCount < len) { + c1 = tempEncodingByteBuffer[byteCount] & 0xff; + switch (c1 >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* 0xxxxxxx */ + byteCount++; + tempEncodingCharBuffer[charCount++] = (char) c1; + break; + case 12: + case 13: + /* 110x xxxx 10xx xxxx */ + byteCount += 2; + if (byteCount > len) { + throw new IllegalArgumentException("Partial character at end"); + } + c2 = tempEncodingByteBuffer[byteCount - 1]; + if ((c2 & 0xC0) != 0x80) { + throw new IllegalArgumentException("malformed input around byte " + byteCount); + } + tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F)); + break; + case 14: + /* 1110 xxxx 10xx xxxx 10xx xxxx */ + byteCount += 3; + if (byteCount > len) { + throw new IllegalArgumentException("malformed input: partial character at end"); + } + c2 = tempEncodingByteBuffer[byteCount - 2]; + c3 = tempEncodingByteBuffer[byteCount - 1]; + if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) { + throw new IllegalArgumentException("malformed input around byte " + (byteCount - 1)); + } + tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); + break; + default: + /* 10xx xxxx, 1111 xxxx */ + throw new IllegalArgumentException("malformed input around byte " + byteCount); + } + } + // The number of chars produced may be less than len + return new String(tempEncodingCharBuffer, 0, charCount); + } + + /** + * Reads a single value, using the data type encoded in the marshalled data. + * + * @return The read value, such as a boxed Java primitive, a {@link String}, a {@code null}, or + * an array of these types. + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + * @throws IllegalArgumentException when the marshaled type is not supported or if the bytes do + * not represent a valid modified UTF-8 encoding of a string. + */ + public final Object readTypedValue() throws IndexOutOfBoundsException, IllegalArgumentException { + byte tag = readByte(); + switch (tag) { + case ARRAY: + int len = readInt(); + Object[] arr = new Object[len]; + for (int i = 0; i < len; i++) { + arr[i] = readTypedValue(); + } + return arr; + case NULL: + return null; + case BOOLEAN: + return readBoolean(); + case BYTE: + return readByte(); + case SHORT: + return readShort(); + case CHAR: + return readChar(); + case INT: + return readInt(); + case LONG: + return readLong(); + case FLOAT: + return readFloat(); + case DOUBLE: + return readDouble(); + case STRING: + return readUTF(); + default: + throw new IllegalArgumentException(String.format("Unknown tag %d", tag)); + } + } + + /** + * Reads {@code len} bytes into a boolean array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(boolean[] b, int off, int len) { + ensureBufferSize(len); + read(tempEncodingByteBuffer, 0, len); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + b[i] = tempEncodingByteBuffer[j++] != 0; + } + } + + /** + * Reads {@code len} shorts into a short array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(short[] b, int off, int len) { + int size = len * Short.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packShort(b1, b2); + } + } + + /** + * Reads {@code len} chars into a char array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(char[] b, int off, int len) { + int size = len * Character.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packChar(b1, b2); + } + } + + /** + * Reads {@code len} ints into an int array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(int[] b, int off, int len) { + int size = len * Integer.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packInt(b1, b2, b3, b4); + } + } + + /** + * Reads {@code len} longs into a long array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(long[] b, int off, int len) { + int size = len * Long.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + int b5 = (tempEncodingByteBuffer[j++] & 0xff); + int b6 = (tempEncodingByteBuffer[j++] & 0xff); + int b7 = (tempEncodingByteBuffer[j++] & 0xff); + int b8 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packLong(b1, b2, b3, b4, b5, b6, b7, b8); + } + } + + /** + * Reads {@code len} floats into a float array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(float[] b, int off, int len) { + int size = len * Float.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = Float.intBitsToFloat(packInt(b1, b2, b3, b4)); + } + } + + /** + * Reads {@code len} doubles into a double array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(double[] b, int off, int len) { + int size = len * Double.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + int b5 = (tempEncodingByteBuffer[j++] & 0xff); + int b6 = (tempEncodingByteBuffer[j++] & 0xff); + int b7 = (tempEncodingByteBuffer[j++] & 0xff); + int b8 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = Double.longBitsToDouble(packLong(b1, b2, b3, b4, b5, b6, b7, b8)); + } + } + + /** + * Returns a read only {@link ByteBuffer} backed by the {@link BinaryInput} internal buffer. The + * content of the buffer will start at the {@link BinaryInput}'s current position. The buffer's + * capacity and limit will be {@code len}, its position will be zero, its mark will be + * undefined, and its byte order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}. After a + * successful call, the {@link BinaryInput}'s current position is incremented by the + * {@code len}. + * + * @throws IndexOutOfBoundsException if the BinaryInput has not enough remaining bytes. + */ + public abstract ByteBuffer asByteBuffer(int len); + + /** + * Creates a new buffer backed by a byte array. + */ + public static BinaryInput create(byte[] buffer) { + return new ByteArrayBinaryInput(buffer); + } + + /** + * Creates a new buffer backed by a byte array only up to a given length. + */ + public static BinaryInput create(byte[] buffer, int length) { + return new ByteArrayBinaryInput(buffer, length); + } + + /** + * Creates a new buffer wrapping an off-heap memory segment starting at an {@code address} + * having {@code length} bytes. + */ + public static BinaryInput create(CCharPointer address, int length) { + return new CCharPointerInput(address, length); + } + + private void ensureBufferSize(int len) { + if (tempEncodingByteBuffer == null || tempEncodingByteBuffer.length < len) { + tempEncodingByteBuffer = new byte[Math.max(bufferSize(0, len), 80)]; + } + } + + private static final class ByteArrayBinaryInput extends BinaryInput { + + private final byte[] buffer; + + ByteArrayBinaryInput(byte[] buffer) { + super(buffer.length); + this.buffer = buffer; + } + + ByteArrayBinaryInput(byte[] buffer, int length) { + super(length); + this.buffer = buffer; + } + + @Override + public int read() { + if (pos >= length) { + return EOF; + } + return (buffer[pos++] & 0xff); + } + + @Override + public void read(byte[] b, int off, int len) { + if (len < 0) { + throw new IllegalArgumentException(String.format("Len must be non negative but was %d", len)); + } + if (pos + len > length) { + throw new IndexOutOfBoundsException(); + } + System.arraycopy(buffer, pos, b, off, len); + pos += len; + } + + @Override + public ByteBuffer asByteBuffer(int len) { + ByteBuffer result = ByteBuffer.wrap(buffer, pos, len).slice().asReadOnlyBuffer(); + pos += len; + return result; + } + } + + private static final class CCharPointerInput extends BinaryInput { + + /** + * Represents the point at which the average cost of a JNI call exceeds the expense of an + * element by element copy. See {@code java.nio.Bits#JNI_COPY_TO_ARRAY_THRESHOLD}. + */ + private static final int BYTEBUFFER_COPY_TO_ARRAY_THRESHOLD = 6; + + private final CCharPointer address; + /** + * ByteBuffer view of this {@link CCharPointerInput} direct memory. The ByteBuffer is used + * for bulk data transfers, where the bulk ByteBuffer operations outperform element by + * element copying by an order of magnitude. + */ + private ByteBuffer byteBufferView; + + CCharPointerInput(CCharPointer address, int length) { + super(length); + this.address = address; + } + + @Override + public int read() { + if (pos >= length) { + return EOF; + } + return (address.read(pos++) & 0xff); + } + + @Override + public void read(byte[] b, int off, int len) { + if (len < 0) { + throw new IllegalArgumentException(String.format("Len must be non negative but was %d", len)); + } + if (pos + len > length) { + throw new IndexOutOfBoundsException(); + } + if (len > BYTEBUFFER_COPY_TO_ARRAY_THRESHOLD) { + if (byteBufferView == null) { + byteBufferView = CTypeConversion.asByteBuffer(address, length); + } + byteBufferView.position(pos); + byteBufferView.get(b, off, len); + } else { + for (int i = 0, j = pos; i < len; i++, j++) { + b[off + i] = address.read(j); + } + } + pos += len; + } + + @Override + public ByteBuffer asByteBuffer(int len) { + ByteBuffer result = CTypeConversion.asByteBuffer(address.addressOf(pos), len).order(ByteOrder.BIG_ENDIAN).asReadOnlyBuffer(); + pos += len; + return result; + } + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryMarshaller.java similarity index 72% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryMarshaller.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryMarshaller.java index 75cb8115635d..f90dbd576db1 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryMarshaller.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryMarshaller.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryOutput.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryOutput.java new file mode 100644 index 000000000000..24ce6a9e9b59 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/BinaryOutput.java @@ -0,0 +1,689 @@ +/* + * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.nativebridge.JNIConfig.Builder; +import org.graalvm.nativeimage.UnmanagedMemory; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.word.WordFactory; + +import java.io.Closeable; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Objects; + +/** + * A buffer used by the {@link BinaryMarshaller} to marshall parameters and results passed by value. + * + * @see BinaryInput + * @see BinaryMarshaller + * @see Builder#registerMarshaller(Class, BinaryMarshaller) + */ +public abstract class BinaryOutput { + + /** + * Maximum string length for string encoded by 4 bytes length followed be content. + */ + private static final int MAX_LENGTH = Integer.MAX_VALUE - Integer.BYTES; + /** + * Maximum string length for string encoded by 2 bytes length followed be content. + */ + private static final int MAX_SHORT_LENGTH = Short.MAX_VALUE; + /** + * Tag to distinguish between long and short string. The tag is set in the first string length + * byte. + */ + static final int LARGE_STRING_TAG = 1 << 7; + + // Type tags used by writeTypedValue + static final byte NULL = 0; + static final byte BOOLEAN = NULL + 1; + static final byte BYTE = BOOLEAN + 1; + static final byte SHORT = BYTE + 1; + static final byte CHAR = SHORT + 1; + static final byte INT = CHAR + 1; + static final byte LONG = INT + 1; + static final byte FLOAT = LONG + 1; + static final byte DOUBLE = FLOAT + 1; + static final byte STRING = DOUBLE + 1; + static final byte ARRAY = STRING + 1; + + private byte[] tempDecodingBuffer; + protected int pos; + + private BinaryOutput() { + } + + /** + * Writes a {@code boolean} as a single byte value. The value {@code true} is written as the + * value {@code (byte)1}, the value {@code false} is written as the value {@code (byte)0}. The + * buffer position is incremented by {@code 1}. + */ + public final void writeBoolean(boolean value) { + write(value ? 1 : 0); + } + + /** + * Writes a {@code byte} as a single byte value. The buffer position is incremented by + * {@code 1}. + */ + public final void writeByte(int value) { + write(value); + } + + /** + * Writes a {@code short} as two bytes, high byte first. The buffer position is incremented by + * {@code 2}. + */ + public final void writeShort(int value) { + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes a {@code char} as two bytes, high byte first. The buffer position is incremented by + * {@code 2}. + */ + public final void writeChar(int value) { + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes an {@code int} as four bytes, high byte first. The buffer position is incremented by + * {@code 4}. + */ + public final void writeInt(int value) { + write((value >>> 24) & 0xff); + write((value >>> 16) & 0xff); + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes a {@code long} as eight bytes, high byte first. The buffer position is incremented by + * {@code 8}. + */ + public final void writeLong(long value) { + write((int) ((value >>> 56) & 0xff)); + write((int) ((value >>> 48) & 0xff)); + write((int) ((value >>> 40) & 0xff)); + write((int) ((value >>> 32) & 0xff)); + write((int) ((value >>> 24) & 0xff)); + write((int) ((value >>> 16) & 0xff)); + write((int) ((value >>> 8) & 0xff)); + write((int) (value & 0xff)); + } + + /** + * Converts a {@code float} value to an {@code int} using the + * {@link Float#floatToIntBits(float)}, and then writes that {@code int} as four bytes, high + * byte first. The buffer position is incremented by {@code 4}. + */ + public final void writeFloat(float value) { + writeInt(Float.floatToIntBits(value)); + } + + /** + * Converts a {@code double} value to a {@code long} using the + * {@link Double#doubleToLongBits(double)}, and then writes that {@code long} as eight bytes, + * high byte first. The buffer position is incremented by {@code 8}. + */ + public final void writeDouble(double value) { + writeLong(Double.doubleToLongBits(value)); + } + + /** + * Writes the lowest byte of the argument as a single byte value. The buffer position is + * incremented by {@code 1}. + */ + public abstract void write(int b); + + /** + * Writes {@code len} bytes from the byte {@code array} starting at offset {@code off}. The + * buffer position is incremented by {@code len}. + */ + public abstract void write(byte[] array, int off, int len); + + /** + * Reserves a buffer space. The reserved space can be used for out parameters. + * + * @param numberOfBytes number of bytes to reserve. + */ + public abstract void skip(int numberOfBytes); + + /** + * Writes a string using a modified UTF-8 encoding in a machine-independent manner. + * + * @throws IllegalArgumentException if the {@code string} cannot be encoded using modified UTF-8 + * encoding. + */ + public final void writeUTF(String string) throws IllegalArgumentException { + int len = string.length(); + int utfLen = 0; + int c; + int count = 0; + + for (int i = 0; i < len; i++) { + c = string.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + utfLen++; + } else if (c > 0x07FF) { + utfLen += 3; + } else { + utfLen += 2; + } + } + + if (utfLen > MAX_LENGTH) { + throw new IllegalArgumentException("String too long to encode, " + utfLen + " bytes"); + } + int headerSize; + if (utfLen > MAX_SHORT_LENGTH) { + headerSize = Integer.BYTES; + ensureBufferSize(headerSize, utfLen); + tempDecodingBuffer[count++] = (byte) ((LARGE_STRING_TAG | (utfLen >>> 24)) & 0xff); + tempDecodingBuffer[count++] = (byte) ((utfLen >>> 16) & 0xFF); + } else { + headerSize = Short.BYTES; + ensureBufferSize(headerSize, utfLen); + } + tempDecodingBuffer[count++] = (byte) ((utfLen >>> 8) & 0xFF); + tempDecodingBuffer[count++] = (byte) (utfLen & 0xFF); + + int i = 0; + for (; i < len; i++) { + c = string.charAt(i); + if (!((c >= 0x0001) && (c <= 0x007F))) { + break; + } + tempDecodingBuffer[count++] = (byte) c; + } + + for (; i < len; i++) { + c = string.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + tempDecodingBuffer[count++] = (byte) c; + } else if (c > 0x07FF) { + tempDecodingBuffer[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); + tempDecodingBuffer[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); + tempDecodingBuffer[count++] = (byte) (0x80 | (c & 0x3F)); + } else { + tempDecodingBuffer[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); + tempDecodingBuffer[count++] = (byte) (0x80 | (c & 0x3F)); + } + } + write(tempDecodingBuffer, 0, headerSize + utfLen); + } + + /** + * Returns this buffer's position. + */ + public int getPosition() { + return pos; + } + + /** + * Returns true if a value is a typed value writable using + * {@link #writeTypedValue(Object)}, else false. + */ + public static boolean isTypedValue(Object value) { + if (value == null) { + return true; + } + return value instanceof Object[] || value == null || value instanceof Boolean || value instanceof Byte || + value instanceof Short || value instanceof Character || value instanceof Integer || + value instanceof Long || value instanceof Float || value instanceof Double || value instanceof String; + } + + /** + * Writes the value that is represented by the given object, together with information on the + * value's data type. Supported types are boxed Java primitive types, {@link String}, + * {@code null}, and arrays of these types. + * + * @throws IllegalArgumentException when the {@code value} type is not supported or the + * {@code value} is a string which cannot be encoded using modified UTF-8 encoding. + * @see #isTypedValue(Object) to find out whether a value can be serialized. + */ + public final void writeTypedValue(Object value) throws IllegalArgumentException { + if (value instanceof Object[]) { + Object[] arr = (Object[]) value; + writeByte(ARRAY); + writeInt(arr.length); + for (Object arrElement : arr) { + writeTypedValue(arrElement); + } + } else if (value == null) { + writeByte(NULL); + } else if (value instanceof Boolean) { + writeByte(BOOLEAN); + writeBoolean((boolean) value); + } else if (value instanceof Byte) { + writeByte(BYTE); + writeByte((byte) value); + } else if (value instanceof Short) { + writeByte(SHORT); + writeShort((short) value); + } else if (value instanceof Character) { + writeByte(CHAR); + writeChar((char) value); + } else if (value instanceof Integer) { + writeByte(INT); + writeInt((int) value); + } else if (value instanceof Long) { + writeByte(LONG); + writeLong((long) value); + } else if (value instanceof Float) { + writeByte(FLOAT); + writeFloat((float) value); + } else if (value instanceof Double) { + writeByte(DOUBLE); + writeDouble((double) value); + } else if (value instanceof String) { + writeByte(STRING); + writeUTF((String) value); + } else { + throw new IllegalArgumentException(String.format("Unsupported type %s", value.getClass())); + } + } + + /** + * Writes {@code len} bytes from the boolean {@code array} starting at offset {@code off}. The + * value {@code true} is written as the value {@code (byte)1}, the value {@code false} is + * written as the value {@code (byte)0}. The buffer position is incremented by {@code len}. + */ + public final void write(boolean[] array, int off, int len) { + ensureBufferSize(0, len); + for (int i = 0, j = 0; i < len; i++, j++) { + tempDecodingBuffer[j] = (byte) (array[off + i] ? 1 : 0); + } + write(tempDecodingBuffer, 0, len); + } + + /** + * Writes {@code len} shorts from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 2 * len}. + */ + public final void write(short[] array, int off, int len) { + int size = len * Short.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} chars from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 2 * len}. + */ + public final void write(char[] array, int off, int len) { + int size = len * Character.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} ints from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 4 * len}. + */ + public final void write(int[] array, int off, int len) { + int size = len * Integer.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} longs from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 8 * len}. + */ + public final void write(long[] array, int off, int len) { + int size = len * Long.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 56) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 48) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 40) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 32) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} floats from the {@code array} starting at offset {@code off}. Each + * {@code float} value is converted to an {@code int} using the + * {@link Float#floatToIntBits(float)} and written as an int. The buffer position is incremented + * by {@code 4 * len}. + */ + public final void write(float[] array, int off, int len) { + int size = len * Float.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + int bits = Float.floatToIntBits(array[off + i]); + tempDecodingBuffer[j++] = (byte) ((bits >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (bits & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} doubles from the {@code array} starting at offset {@code off}. Each + * {@code double} value is converted to an {@code lang} using the + * {@link Double#doubleToLongBits(double)} and written as a long. The buffer position is + * incremented by {@code 8 * len}. + */ + public final void write(double[] array, int off, int len) { + int size = len * Double.BYTES; + ensureBufferSize(Integer.BYTES, size); + for (int i = 0, j = 0; i < len; i++) { + long bits = Double.doubleToLongBits(array[off + i]); + tempDecodingBuffer[j++] = (byte) ((bits >>> 56) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 48) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 40) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 32) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (bits & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + private void ensureBufferSize(int headerSize, int dataSize) { + if (tempDecodingBuffer == null || tempDecodingBuffer.length < (headerSize + dataSize)) { + tempDecodingBuffer = new byte[bufferSize(headerSize, dataSize)]; + } + } + + /** + * Creates a new buffer backed by a byte array. + */ + public static ByteArrayBinaryOutput create() { + return new ByteArrayBinaryOutput(ByteArrayBinaryOutput.INITIAL_SIZE); + } + + /** + * Creates a new buffer wrapping the {@code initialBuffer}. If the {@code initialBuffer} + * capacity is not sufficient for writing the data, a new array is allocated. Always use + * {@link ByteArrayBinaryOutput#getArray()} to obtain the marshaled data. + */ + public static ByteArrayBinaryOutput create(byte[] initialBuffer) { + Objects.requireNonNull(initialBuffer, "InitialBuffer must be non null."); + return new ByteArrayBinaryOutput(initialBuffer); + } + + /** + * Creates a new buffer wrapping an off-heap memory segment starting at {@code address} having + * {@code length} bytes. If the capacity of an off-heap memory segment is not sufficient for + * writing the data, a new off-heap memory is allocated. Always use + * {@link CCharPointerBinaryOutput#getAddress()} to obtain the marshaled data. + * + * @param address the off-heap memory address + * @param length the off-heap memory size + * @param dynamicallyAllocated {@code true} if the memory was dynamically allocated and should + * be freed when the buffer is closed; {@code false} for the stack allocated memory. + */ + public static CCharPointerBinaryOutput create(CCharPointer address, int length, boolean dynamicallyAllocated) { + return new CCharPointerBinaryOutput(address, length, dynamicallyAllocated); + } + + static int bufferSize(int headerSize, int dataSize) { + return headerSize + (dataSize <= MAX_SHORT_LENGTH ? dataSize << 1 : dataSize); + } + + /** + * A {@link BinaryOutput} backed by a byte array. + */ + public static final class ByteArrayBinaryOutput extends BinaryOutput { + + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + static final int INITIAL_SIZE = 32; + + private byte[] buffer; + + private ByteArrayBinaryOutput(int size) { + buffer = new byte[size]; + } + + private ByteArrayBinaryOutput(byte[] initialBuffer) { + buffer = initialBuffer; + } + + @Override + public void write(int b) { + ensureCapacity(pos + 1); + buffer[pos] = (byte) b; + pos += 1; + } + + @Override + public void write(byte[] b, int off, int len) { + ensureCapacity(pos + len); + System.arraycopy(b, off, buffer, pos, len); + pos += len; + } + + @Override + public void skip(int numberOfBytes) { + ensureCapacity(pos + numberOfBytes); + pos += numberOfBytes; + } + + /** + * Returns the byte array containing the marshalled data. + */ + public byte[] getArray() { + return buffer; + } + + private void ensureCapacity(int neededCapacity) { + if (neededCapacity - buffer.length > 0) { + int newCapacity = buffer.length << 1; + if (newCapacity - neededCapacity < 0) { + newCapacity = neededCapacity; + } + if (newCapacity - MAX_ARRAY_SIZE > 0) { + throw new OutOfMemoryError(); + } + buffer = Arrays.copyOf(buffer, newCapacity); + } + } + + /** + * Creates a new buffer backed by a byte array. The buffer initial size is + * {@code initialSize}. + */ + public static ByteArrayBinaryOutput create(int initialSize) { + return new ByteArrayBinaryOutput(initialSize); + } + } + + /** + * A {@link BinaryOutput} backed by an off-heap memory. + */ + public static final class CCharPointerBinaryOutput extends BinaryOutput implements Closeable { + + /** + * Represents the point at which the average cost of a JNI call exceeds the expense of an + * element by element copy. See {@code java.nio.Bits#JNI_COPY_FROM_ARRAY_THRESHOLD}. + */ + private static final int BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD = 6; + + private CCharPointer address; + private int length; + private boolean unmanaged; + /** + * ByteBuffer view of this {@link CCharPointerBinaryOutput} direct memory. The ByteBuffer is + * used for bulk data transfers, where the bulk ByteBuffer operations outperform element by + * element copying by an order of magnitude. + */ + private ByteBuffer byteBufferView; + + private CCharPointerBinaryOutput(CCharPointer address, int length, boolean unmanaged) { + this.address = address; + this.length = length; + this.unmanaged = unmanaged; + } + + @Override + public int getPosition() { + checkClosed(); + return super.getPosition(); + } + + /** + * Returns an address of an off-heap memory segment containing the marshalled data. + */ + public CCharPointer getAddress() { + checkClosed(); + return address; + } + + @Override + public void write(int b) { + checkClosed(); + ensureCapacity(pos + 1); + address.write(pos++, (byte) b); + } + + @Override + public void write(byte[] b, int off, int len) { + checkClosed(); + if ((off | len | b.length) < 0 || b.length - off < len) { + throw new IndexOutOfBoundsException("offset: " + off + ", length: " + len + ", array length: " + b.length); + } + ensureCapacity(pos + len); + if (len > BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD) { + if (byteBufferView == null) { + byteBufferView = CTypeConversion.asByteBuffer(address, length); + } + byteBufferView.position(pos); + byteBufferView.put(b, off, len); + } else { + for (int i = 0; i < len; i++) { + address.write(pos + i, b[off + i]); + } + } + pos += len; + } + + @Override + public void skip(int numberOfBytes) { + ensureCapacity(pos + numberOfBytes); + pos += numberOfBytes; + } + + /** + * Closes the buffer and frees off-heap allocated resources. + */ + @Override + public void close() { + if (unmanaged) { + UnmanagedMemory.free(address); + byteBufferView = null; + address = WordFactory.nullPointer(); + length = 0; + unmanaged = false; + pos = Integer.MIN_VALUE; + } + } + + private void checkClosed() { + if (pos == Integer.MIN_VALUE) { + throw new IllegalStateException("Already closed"); + } + } + + private void ensureCapacity(int neededCapacity) { + if (neededCapacity - length > 0) { + byteBufferView = null; + int newCapacity = length << 1; + if (newCapacity - neededCapacity < 0) { + newCapacity = neededCapacity; + } + if (newCapacity - Integer.MAX_VALUE > 0) { + throw new OutOfMemoryError(); + } + if (unmanaged) { + address = UnmanagedMemory.realloc(address, WordFactory.unsigned(newCapacity)); + } else { + CCharPointer newAddress = UnmanagedMemory.malloc(newCapacity); + memcpy(newAddress, address, pos); + address = newAddress; + } + length = newCapacity; + unmanaged = true; + } + } + + private static void memcpy(CCharPointer dst, CCharPointer src, int len) { + for (int i = 0; i < len; i++) { + dst.write(i, src.read(i)); + } + } + + /** + * Creates a new buffer backed by an off-heap memory segment. The buffer initial size is + * {@code initialSize}. + */ + public static CCharPointerBinaryOutput create(int initialSize) { + return new CCharPointerBinaryOutput(UnmanagedMemory.malloc(initialSize), initialSize, true); + } + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ByReference.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ByReference.java similarity index 50% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ByReference.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ByReference.java index 95344252e0b0..5a5c1b5fa249 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ByReference.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ByReference.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchAccessor.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchAccessor.java new file mode 100644 index 000000000000..fc90b041010b --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchAccessor.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a method as a custom dispatch accessor. In the class with a custom dispatch, the method is + * used to translate the API object to the dispatch class handling the operation. The method + * annotated by {@link CustomDispatchAccessor} must be a non-private static method with a single + * parameter returning the bridged type. + * + * @see CustomReceiverAccessor + * @see CustomDispatchFactory + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.METHOD) +public @interface CustomDispatchAccessor { +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchFactory.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchFactory.java new file mode 100644 index 000000000000..4089d5befb3e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomDispatchFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a method as a factory for custom dispatch API objects. In the class with a custom dispatch, + * the method is used to create a custom dispatch API object from a receiver transferred by a + * reference. The method annotated by {@link CustomDispatchFactory} must be a non-private static + * method taking a receiver parameter and returning the custom dispatch API object. + * + * @see CustomDispatchAccessor + * @see CustomReceiverAccessor + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.METHOD) +public @interface CustomDispatchFactory { +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomReceiverAccessor.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomReceiverAccessor.java new file mode 100644 index 000000000000..8f1a1722627d --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/CustomReceiverAccessor.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a method as a custom receiver accessor. In the class with a custom dispatch, the method is + * used to translate the API object to the receiver. The method annotated by + * {@link CustomReceiverAccessor} must be a non-private static method with a single parameter + * returning the receiver. + * + * @see CustomDispatchAccessor + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.METHOD) +public @interface CustomReceiverAccessor { +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java new file mode 100644 index 000000000000..58b773d0784c --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultStackTraceMarshaller.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +final class DefaultStackTraceMarshaller implements BinaryMarshaller { + + static final DefaultStackTraceMarshaller INSTANCE = new DefaultStackTraceMarshaller(); + + private DefaultStackTraceMarshaller() { + } + + @Override + public StackTraceElement[] read(BinaryInput in) { + int len = in.readInt(); + StackTraceElement[] res = new StackTraceElement[len]; + for (int i = 0; i < len; i++) { + res[i] = StackTraceElementMarshaller.INSTANCE.read(in); + } + return res; + } + + @Override + public void write(BinaryOutput out, StackTraceElement[] stack) { + out.writeInt(stack.length); + for (StackTraceElement stackTraceElement : stack) { + StackTraceElementMarshaller.INSTANCE.write(out, stackTraceElement); + } + } + + @Override + public int inferSize(StackTraceElement[] object) { + return object.length == 0 ? 0 : object.length * StackTraceElementMarshaller.INSTANCE.inferSize(object[0]); + } +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java new file mode 100644 index 000000000000..640186f76f3d --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/DefaultThrowableMarshaller.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +final class DefaultThrowableMarshaller implements BinaryMarshaller { + + private static final int THROWABLE_SIZE_ESTIMATE = 1024; + private final DefaultStackTraceMarshaller stackTraceMarshaller = DefaultStackTraceMarshaller.INSTANCE; + + @Override + public Throwable read(BinaryInput in) { + String foreignExceptionClassName = in.readUTF(); + String foreignExceptionMessage = (String) in.readTypedValue(); + StackTraceElement[] foreignExceptionStack = stackTraceMarshaller.read(in); + return new MarshalledException(foreignExceptionClassName, foreignExceptionMessage, ForeignException.mergeStackTrace(foreignExceptionStack)); + } + + @Override + public void write(BinaryOutput out, Throwable object) { + out.writeUTF(object instanceof MarshalledException ? ((MarshalledException) object).getForeignExceptionClassName() : object.getClass().getName()); + out.writeTypedValue(object.getMessage()); + stackTraceMarshaller.write(out, object.getStackTrace()); + } + + @Override + public int inferSize(Throwable object) { + // We don't use Throwable#getStackTrace as it allocates. + return THROWABLE_SIZE_ESTIMATE; + } +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/EndPointHandle.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/EndPointHandle.java new file mode 100644 index 000000000000..424c680c8237 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/EndPointHandle.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.jniutils.HSObject; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a bridge class field as a foreign reference handle. + * + * When the bridged type is a class, the handle to a foreign object has to be stored in a + * non-private field annotated by the {@link EndPointHandle}. Annotation processor uses this field + * to obtain the foreign object reference. For HotSpot to native calls, the field type must be + * assignable to {@link NativeObject}. For native to HotSpot calls, the field type must be + * assignable to {@link HSObject}. + * + * Example: + * + *
+ * @GenerateHotSpotToNativeBridge(jniConfig = ExampleJNIConfig.class)
+ * abstract class NativeCalculator extends Calculator {
+ *
+ *     @EndPointHandle final NativeObject delegate;
+ *
+ *     NativeCalculator(NativeObject delegate) {
+ *         this.delegate = delegate;
+ *     }
+ * }
+ * 
+ */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.FIELD) +public @interface EndPointHandle { +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignException.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignException.java similarity index 85% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignException.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignException.java index 82f811456e94..f0095819ac00 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/ForeignException.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignException.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java new file mode 100644 index 000000000000..d78fc3ebaee7 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ForeignExceptionEndPoints.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.jniutils.JNIEntryPoint; + +final class ForeignExceptionEndPoints { + + private ForeignExceptionEndPoints() { + } + + /** + * Called by JNI to create a {@link ForeignException} used to throw native exception into Java + * code. + * + * @param rawValue marshalled original exception + * @return a {@link ForeignException} instance + */ + @JNIEntryPoint + static Throwable createForeignException(byte[] rawValue) { + return ForeignException.create(rawValue, ForeignException.HOST_TO_GUEST); + } + + /** + * Called by JNI to return a marshalled exception transferred by the {@code exception}. + */ + @JNIEntryPoint + static byte[] toByteArray(ForeignException exception) { + return exception.toByteArray(); + } +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java new file mode 100644 index 000000000000..10b50f1cd359 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateHotSpotToNativeBridge.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.nativeimage.c.function.CEntryPoint.AlwaysIncluded; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.function.BooleanSupplier; + +/** + * Generates a HotSpot to native bridge. For the annotated class, the processor generates a bridge + * delegating calls to the object in a native image heap. Further information can be found in the + * native bridge + * tutorial. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface GenerateHotSpotToNativeBridge { + + /** + * If the supplier returns {@code true}, the bridge entry points are added automatically when + * building a shared library. This means the bridge entry points are root methods for + * compilation, and everything reachable from them is compiled too. The provided class must have + * a nullary constructor, which is used to instantiate the class. The + * {@link BooleanSupplier#getAsBoolean()}} function is called on the newly instantiated + * instance. + */ + Class include() default AlwaysIncluded.class; + + /** + * The native bridge configuration. The returned class must have an accessible static + * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned + * {@link JNIConfig} instance is used for marshallers' lookup. + */ + Class jniConfig(); +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java new file mode 100644 index 000000000000..b60c00424216 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToHotSpotBridge.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Generate a native to HotSpot bridge for an annotated class. For the annotated class, the + * processor generates a bridge delegating calls to the object in a HotSpot heap. Further + * information can be found in the native bridge + * tutorial. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface GenerateNativeToHotSpotBridge { + + /** + * The native bridge configuration. The returned class must have an accessible static + * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned + * {@link JNIConfig} instance is used for marshallers' lookup. + */ + Class jniConfig(); + +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java new file mode 100644 index 000000000000..e257dcddcf63 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/GenerateNativeToNativeBridge.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import org.graalvm.nativeimage.c.function.CEntryPoint; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.function.BooleanSupplier; + +/** + * Generates a native to native bridge. For the annotated class, the processor generates a bridge + * delegating calls to the object in a native image heap. Further information can be found in the + * native bridge + * tutorial. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface GenerateNativeToNativeBridge { + /** + * If the supplier returns {@code true}, the bridge entry points are added automatically when + * building a shared library. This means the bridge entry points are root methods for + * compilation, and everything reachable from them is compiled too. The provided class must have + * a nullary constructor, which is used to instantiate the class. The + * {@link BooleanSupplier#getAsBoolean()}} function is called on the newly instantiated + * instance. + */ + Class include() default CEntryPoint.AlwaysIncluded.class; + + /** + * The native bridge configuration. The returned class must have an accessible static + * {@code getInstance()} method returning a {@link JNIConfig} instance. The returned + * {@link JNIConfig} instance is used for marshallers' lookup. + */ + Class jniConfig(); +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Idempotent.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Idempotent.java new file mode 100644 index 000000000000..05d73607cbbf --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Idempotent.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Enables the return value caching. The annotated method is called only once, the returned value is + * cached and the successive calls return the cached value. The annotated method must have a + * non-void return type. + */ +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface Idempotent { +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/In.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/In.java new file mode 100644 index 000000000000..e99e4e6359c5 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/In.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configures an array parameter as an in-parameter. For an in-parameter, the array value is copied + * over the boundary into a called method. The {@link In} is the default behavior. It's needed only + * in combination with {@link Out} for in-out parameters. + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.PARAMETER) +public @interface In { + + /** + * Copy only a part of the array starting at the offset given by the + * {@code arrayOffsetParameter} method parameter. By default, the whole array is copied. The + * {@code arrayOffsetParameter} can be used to improve the performance and copy only a part of + * the array over the boundary. + */ + String arrayOffsetParameter() default ""; + + /** + * Limits copying only to many of the elements given by the {@code arrayLengthParameter} + * parameter. By default, the whole array is copied. The {@code arrayLengthParameter} can be + * used to improve the performance and copy only a part of the array over the boundary. + */ + String arrayLengthParameter() default ""; +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIClassCache.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIClassCache.java similarity index 60% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIClassCache.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIClassCache.java index 36f1ac494be8..ce87ee5426b7 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIClassCache.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIClassCache.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIConfig.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIConfig.java similarity index 83% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIConfig.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIConfig.java index 7da2cf18ae50..60bd1a31e359 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/JNIConfig.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/JNIConfig.java @@ -1,31 +1,45 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; -import org.graalvm.collections.Pair; -import org.graalvm.polyglot.TypeLiteral; import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.GenericArrayType; @@ -37,8 +51,13 @@ import java.util.ListIterator; import java.util.Map; import java.util.Objects; +import java.util.function.Function; import java.util.function.LongBinaryOperator; import java.util.function.LongUnaryOperator; +import java.util.function.Supplier; + +import org.graalvm.collections.Pair; +import org.graalvm.polyglot.TypeLiteral; /** * A configuration used by the {@link NativeIsolate} and classes generated by the native bridge @@ -55,17 +74,20 @@ public final class JNIConfig { private final LongUnaryOperator detachThreadAction; private final LongBinaryOperator shutDownIsolateAction; private final LongBinaryOperator releaseNativeObjectAction; + private final Function, ThreadLocal> threadLocalFactory; JNIConfig(Map> binaryMarshallers, Map, List, BinaryMarshaller>>> annotationBinaryMarshallers, LongUnaryOperator attachThreadAction, LongUnaryOperator detachThreadAction, - LongBinaryOperator shutDownIsolateAction, LongBinaryOperator releaseNativeObjectAction) { + LongBinaryOperator shutDownIsolateAction, LongBinaryOperator releaseNativeObjectAction, + Function, ThreadLocal> threadLocalFactory) { this.binaryMarshallers = binaryMarshallers; this.annotationBinaryMarshallers = annotationBinaryMarshallers; this.attachThreadAction = attachThreadAction; this.detachThreadAction = detachThreadAction; this.shutDownIsolateAction = shutDownIsolateAction; this.releaseNativeObjectAction = releaseNativeObjectAction; + this.threadLocalFactory = threadLocalFactory; } /** @@ -115,6 +137,10 @@ public final BinaryMarshaller lookupMarshaller(TypeLiteral parameteriz } } + Function, ThreadLocal> getThreadLocalFactory() { + return threadLocalFactory; + } + long attachThread(long isolate) { return attachThreadAction.applyAsLong(isolate); } @@ -211,6 +237,7 @@ public static final class Builder { private LongUnaryOperator detachThreadAction = DETACH_UNSUPPORTED; private LongBinaryOperator shutDownIsolateAction = SHUTDOWN_UNSUPPORTED; private LongBinaryOperator releaseNativeObjectAction = RELEASE_UNSUPPORTED; + private Function, ThreadLocal> threadLocalFactory = ThreadLocal::withInitial; Builder() { this.binaryMarshallers = new HashMap<>(); @@ -356,13 +383,26 @@ public Builder setReleaseNativeObjectAction(LongBinaryOperator action) { return this; } + /** + * Registers a thread local factory whenever the default thread local handling should be + * overriden. This can be useful to install a terminating thread local using JVMCI services + * when needed. + * + * @see NativeObject + */ + public Builder setNativeThreadLocalFactory(Function, ThreadLocal> factory) { + Objects.requireNonNull(factory, "Action must be non null."); + this.threadLocalFactory = factory; + return this; + } + /** * Builds the {@link JNIConfig}. */ public JNIConfig build() { return new JNIConfig(binaryMarshallers, annotationBinaryMarshallers, attachThreadAction, detachThreadAction, shutDownIsolateAction, - releaseNativeObjectAction); + releaseNativeObjectAction, threadLocalFactory); } /** @@ -372,4 +412,5 @@ public static BinaryMarshaller defaultStackTraceMarshaller( return DefaultStackTraceMarshaller.INSTANCE; } } + } diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshalledException.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshalledException.java new file mode 100644 index 000000000000..79775d57fd64 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshalledException.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +/** + * An exception representing an exception thrown over the isolate boundary. + */ +@SuppressWarnings("serial") +public final class MarshalledException extends RuntimeException { + + private final String foreignExceptionClassName; + + /** + * Creates a {@link MarshalledException} for foreign exception of the + * {@code foreignExceptionClassName} type with the {@code foreignExceptionMessage} message. + * + * @param foreignExceptionClassName the foreign exception class name + * @param foreignExceptionMessage the foreign exception message + * @param stackTrace the merged stack trace. + */ + public MarshalledException(String foreignExceptionClassName, String foreignExceptionMessage, StackTraceElement[] stackTrace) { + super(foreignExceptionMessage); + this.foreignExceptionClassName = foreignExceptionClassName; + setStackTrace(stackTrace); + } + + /** + * Returns the foreign exception class name. + */ + public String getForeignExceptionClassName() { + return foreignExceptionClassName; + } + + @Override + @SuppressWarnings("sync-override") + public Throwable fillInStackTrace() { + return this; + } + + @Override + public String toString() { + String message = getLocalizedMessage(); + return (message != null) ? (foreignExceptionClassName + ": " + message) : foreignExceptionClassName; + } +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshallerAnnotation.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshallerAnnotation.java new file mode 100644 index 000000000000..a85515b8071e --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/MarshallerAnnotation.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta-annotation that marks an annotation to be used for marshaller lookup. An annotation intended + * for {@link JNIConfig#lookupMarshaller(Class, Class[]) marshaller lookup} must be annotated by + * this annotation. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface MarshallerAnnotation { +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolate.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolate.java similarity index 81% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolate.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolate.java index 5ada2c8208ce..f978a6c4ef18 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolate.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolate.java @@ -1,31 +1,45 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -33,10 +47,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import jdk.vm.ci.services.Services; /** * Represents a single native image isolate. All {@link NativeObject}s have a {@link NativeIsolate} @@ -48,7 +58,6 @@ public final class NativeIsolate { private static final long NULL = 0L; private static final Map isolates = new ConcurrentHashMap<>(); private static final AtomicInteger UUIDS = new AtomicInteger(0); - private static final Method createTerminatingThreadLocal = methodOrNull(Services.class, "createTerminatingThreadLocal", Supplier.class, Consumer.class); private final long uuid; private final long isolateId; @@ -67,8 +76,7 @@ private NativeIsolate(long isolateId, JNIConfig config) { this.config = config; this.cleaners = Collections.newSetFromMap(new ConcurrentHashMap<>()); this.threads = new ArrayList<>(); - this.attachedIsolateThread = createTerminatingThreadLocal != null ? NativeIsolate.invoke(createTerminatingThreadLocal, null, - (Supplier) () -> null, (Consumer) this::detachThread) : new ThreadLocal<>(); + this.attachedIsolateThread = config.getThreadLocalFactory().apply(() -> null); this.state = State.ACTIVE; } @@ -283,26 +291,19 @@ private NativeIsolateThread getOrCreateNativeIsolateThread() { return nativeIsolateThread; } - private synchronized void detachThread(NativeIsolateThread nativeIsolateThread) { - if (state.isValid() && nativeIsolateThread != null && !nativeIsolateThread.isNativeThread()) { - config.detachThread(nativeIsolateThread.isolateThread); - } - } - - private static Method methodOrNull(Class enclosingClass, String methodName, Class... parameterTypes) { - try { - return enclosingClass.getDeclaredMethod(methodName, parameterTypes); - } catch (NoSuchMethodException e) { - return null; + public void detachCurrentThread() { + synchronized (this) { + NativeIsolateThread isolateThread = attachedIsolateThread.get(); + if (isolateThread != null) { + detachThread(isolateThread); + attachedIsolateThread.set(null); + } } } - @SuppressWarnings("unchecked") - private static T invoke(Method method, Object receiver, Object... args) { - try { - return (T) method.invoke(receiver, args); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new InternalError(e); + private synchronized void detachThread(NativeIsolateThread nativeIsolateThread) { + if (state.isValid() && nativeIsolateThread != null && !nativeIsolateThread.isNativeThread()) { + config.detachThread(nativeIsolateThread.isolateThread); } } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolateThread.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolateThread.java similarity index 67% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolateThread.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolateThread.java index b2dd4301c7fa..c7ccbe69b951 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeIsolateThread.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeIsolateThread.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; @@ -66,6 +82,13 @@ public long getIsolateThreadId() { return isolateThread; } + /** + * Returns the isolate for this thread. + */ + public NativeIsolate getIsolate() { + return isolate; + } + /** * Leaves the {@link NativeIsolate} on the current thread. */ diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObject.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObject.java similarity index 57% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObject.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObject.java index 7ba9a5a616ae..5db42950cac3 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObject.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObject.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectCleaner.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectCleaner.java similarity index 65% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectCleaner.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectCleaner.java index 61e188bba34a..f7c03a36accf 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectCleaner.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectCleaner.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectHandles.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectHandles.java similarity index 50% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectHandles.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectHandles.java index f2893ae3e843..cf80228d494f 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NativeObjectHandles.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NativeObjectHandles.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java similarity index 52% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java rename to sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java index 87cf9a0f5b0b..237511907299 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/NullableBinaryMarshaller.java @@ -1,26 +1,42 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.nativebridge; diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Out.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Out.java new file mode 100644 index 000000000000..b337a0a0b2ab --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/Out.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configures an array parameter as an out-parameter. For an out-parameter, the array value is + * copied over the boundary from a called method. It may be combined with {@link In} for in-out + * parameters. Example showing the configuration for + * {@link java.io.OutputStream#write(byte[], int, int)}. + * + *
+ * @Override
+ * public abstract int read(@Out(arrayOffsetParameter = "off", arrayLengthParameter = "len", trimToResult = true) byte[] b, int off, int len);
+ * 
+ */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.PARAMETER) +public @interface Out { + + /** + * Copy only a part of the array starting at offset given by the {@code arrayOffsetParameter} + * method parameter. By default, the whole array is copied. The {@code arrayOffsetParameter} can + * be used to improve the performance and copy only a part of the array over the boundary. + */ + String arrayOffsetParameter() default ""; + + /** + * Limits copying only to many of the elements given by the {@code arrayLengthParameter} + * parameter. By default, the whole array is copied. The {@code arrayLengthParameter} can be + * used to improve the performance and copy only a part of the array over the boundary. + */ + String arrayLengthParameter() default ""; + + /** + * Limits copying only to method result number of elements. It can be used to further limit the + * number of copied elements in addition to {@link #arrayLengthParameter}. When used, it's still + * good to specify {@link #arrayLengthParameter} as an upper bound to limit allocated array + * size. + */ + boolean trimToResult() default false; +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/RawReference.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/RawReference.java new file mode 100644 index 000000000000..055b78d6f7e9 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/RawReference.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Instruments the native bridge processor to marshall annotated method return type or method + * parameter as a pointer value stored as Java {@code long} type. The annotated parameter must have + * {@link Object} type. + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.METHOD}) +public @interface RawReference { +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ReceiverMethod.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ReceiverMethod.java new file mode 100644 index 000000000000..815d047839f3 --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/ReceiverMethod.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The {@link ReceiverMethod} allows you to provide a custom method implementation in the generated + * type but still generate the over the boundary call. It's useful when pre-code or post-code is + * needed before or after over the boundary call. The annotated method must have the same parameter + * types as the receiver method. + * + * Example showing a method {@code execute} with custom pre-code and post-code. + * + *
+ * @Override
+ * public final boolean execute() {
+ *     preCode();
+ *     boolean result = executeImpl();
+ *     postCode();
+ *     return result;
+ * }
+ *
+ * @ReceiverMethod("execute")
+ * abstract boolean executeImpl();
+ * 
+ * + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.METHOD) +public @interface ReceiverMethod { + String value(); +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java new file mode 100644 index 000000000000..40585dc0cebc --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StackTraceElementMarshaller.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +final class StackTraceElementMarshaller implements BinaryMarshaller { + + static final StackTraceElementMarshaller INSTANCE = new StackTraceElementMarshaller(); + + private StackTraceElementMarshaller() { + } + + private static final int STACK_TRACE_ELEMENT_SIZE_ESTIMATE = 100; + + @Override + public StackTraceElement read(BinaryInput in) { + String className = in.readUTF(); + String methodName = in.readUTF(); + String fileName = in.readUTF(); + fileName = fileName.isEmpty() ? null : fileName; + int lineNumber = in.readInt(); + return new StackTraceElement(className, methodName, fileName, lineNumber); + } + + @Override + public void write(BinaryOutput out, StackTraceElement stackTraceElement) { + out.writeUTF(stackTraceElement.getClassName()); + out.writeUTF(stackTraceElement.getMethodName()); + String fileName = stackTraceElement.getFileName(); + out.writeUTF(fileName == null ? "" : fileName); + out.writeInt(stackTraceElement.getLineNumber()); + } + + @Override + public int inferSize(StackTraceElement object) { + return STACK_TRACE_ELEMENT_SIZE_ESTIMATE; + } +} diff --git a/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StringMarshaller.java b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StringMarshaller.java new file mode 100644 index 000000000000..5aa4c6de30ab --- /dev/null +++ b/sdk/src/org.graalvm.nativebridge/src/org/graalvm/nativebridge/StringMarshaller.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativebridge; + +/** + * BinaryMarshaller used to marshall string array components. + */ +final class StringMarshaller implements BinaryMarshaller { + + private static final int STRING_SIZE_ESTIMATE = 32; + + @Override + public String read(BinaryInput in) { + return in.readUTF(); + } + + @Override + public void write(BinaryOutput out, String str) { + out.writeUTF(str); + } + + @Override + public int inferSize(String object) { + return STRING_SIZE_ESTIMATE; + } +} diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index b664b6e34e0d..710ed2a0a74c 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -938,7 +938,7 @@ def native_image_context_run(func, func_args=None, config=None, build_if_missing installable_id='native-image', license_files=[], third_party_license_files=[], - dependencies=['GraalVM compiler', 'Truffle Macro', 'SubstrateVM Static Libraries'], + dependencies=['GraalVM compiler', 'Truffle API', 'Truffle Macro', 'SubstrateVM Static Libraries'], jar_distributions=['substratevm:LIBRARY_SUPPORT'], builder_jar_distributions=[ 'substratevm:SVM', @@ -1172,20 +1172,19 @@ def _native_image_launcher_extra_jvm_args(): )) libgraal_jar_distributions = [ - 'substratevm:GRAAL_HOTSPOT_LIBRARY', - 'compiler:GRAAL_TRUFFLE_COMPILER_LIBGRAAL'] + 'sdk:NATIVEBRIDGE', + 'substratevm:GRAAL_HOTSPOT_LIBRARY'] libgraal_build_args = [ ## Pass via JVM args opening up of packages needed for image builder early on '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.hotspot=ALL-UNNAMED', '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.options=ALL-UNNAMED', - '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.common.hotspot=ALL-UNNAMED', - '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.common=ALL-UNNAMED', '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.compiler=ALL-UNNAMED', '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.compiler.hotspot=ALL-UNNAMED', - '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.jniutils=ALL-UNNAMED', - '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.libgraal.jni.annotation=ALL-UNNAMED', - '-J--add-exports=jdk.internal.vm.compiler/org.graalvm.libgraal.jni=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', '-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.annotate=ALL-UNNAMED', '-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.option=ALL-UNNAMED', ## Packages used after option-processing can be opened by the builder (`-J`-prefix not needed) @@ -1193,6 +1192,8 @@ def _native_image_launcher_extra_jvm_args(): '--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.feature=ALL-UNNAMED', # Make ModuleSupport accessible to do the remaining opening-up in LibGraalFeature constructor '--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED', + # TruffleLibGraalJVMCIServiceLocator needs access to JVMCIServiceLocator + '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=ALL-UNNAMED', '--initialize-at-build-time=org.graalvm.compiler,org.graalvm.libgraal,com.oracle.truffle', '-H:-UseServiceLoaderFeature', @@ -1234,20 +1235,19 @@ def _native_image_launcher_extra_jvm_args(): destination="", jvm_library=True, jar_distributions=libgraal_jar_distributions, - build_args=libgraal_build_args + ['--features=com.oracle.svm.graal.hotspot.libgraal.LibGraalFeature,org.graalvm.compiler.truffle.compiler.hotspot.libgraal.TruffleLibGraalFeature'], + build_args=libgraal_build_args + ['--features=com.oracle.svm.graal.hotspot.libgraal.LibGraalFeature,com.oracle.svm.graal.hotspot.libgraal.truffle.TruffleLibGraalFeature'], add_to_module='java.base', headers=False, ), ], - # GR-46611 Temporary solution. When the optimized runtime is moved to the TRUFFLE_API distribution, truffleattach should be moved as well. - support_libraries_distributions=['compiler:TRUFFLE_LIBGRAAL_TRUFFLEATTACH_GRAALVM_SUPPORT'], + support_libraries_distributions=[], stability="supported", jlink=False, ) mx_sdk_vm.register_graalvm_component(libgraal) def _native_image_configure_extra_jvm_args(): - packages = ['jdk.internal.vm.compiler/org.graalvm.compiler.phases.common', 'jdk.internal.vm.ci/jdk.vm.ci.meta', 'jdk.internal.vm.compiler/org.graalvm.compiler.core.common.util'] + packages = ['jdk.internal.vm.compiler/org.graalvm.compiler.phases.common', 'jdk.internal.vm.ci/jdk.vm.ci.meta', 'jdk.internal.vm.ci/jdk.vm.ci.services', 'jdk.internal.vm.compiler/org.graalvm.compiler.core.common.util'] args = ['--add-exports=' + packageName + '=ALL-UNNAMED' for packageName in packages] if not mx_sdk_vm.jdk_enables_jvmci_by_default(get_jdk()): args.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI']) diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 813f14b37b8a..6f520d4651b4 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1002,6 +1002,7 @@ "dependencies": [ "com.oracle.svm.graal", "truffle:TRUFFLE_API", + "truffle:TRUFFLE_RUNTIME", ], "requiresConcealed" : { "java.base" : [ @@ -1123,7 +1124,9 @@ "sourceDirs": ["src"], "dependencies": [ "com.oracle.svm.graal", - "compiler:GRAAL" + "compiler:GRAAL", + "sdk:JNIUTILS", + "sdk:NATIVEBRIDGE", ], "requires" : [ "jdk.management" @@ -1141,6 +1144,7 @@ "checkstyle" : "com.oracle.svm.hosted", "javaCompliance" : "17+", "annotationProcessors": [ + "truffle:TRUFFLE_LIBGRAAL_PROCESSOR", "compiler:GRAAL_PROCESSOR", "SVM_PROCESSOR", ], @@ -1248,6 +1252,7 @@ "sourceDirs": ["src"], "dependencies": [ "com.oracle.svm.hosted", + "truffle:TRUFFLE_RUNTIME", ], "requiresConcealed": { "jdk.internal.vm.ci": [ @@ -1304,6 +1309,7 @@ "compiler:GRAAL", "NATIVE_IMAGE_BASE", "truffle:TRUFFLE_API", + "truffle:TRUFFLE_RUNTIME", ], "moduleInfo" : { "name" : "org.graalvm.nativeimage.builder", @@ -1494,6 +1500,8 @@ ], "distDependencies": [ "SVM", + "sdk:JNIUTILS", + "sdk:NATIVEBRIDGE", ], "defaultBuild": False, "maven": False, @@ -1899,7 +1907,7 @@ "subDir" : "src", "description" : "Truffle TCK", "dependencies" : ["com.oracle.svm.truffle.tck"], - "distDependencies" : ["SVM"], + "distDependencies" : ["SVM", "truffle:TRUFFLE_RUNTIME"], "maven" : True, }, }, diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index b4909c3fd0c4..fa4209c7fb86 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -544,7 +544,7 @@ public List getBuilderModulePath() { if (libJvmciDir != null) { result.addAll(getJars(libJvmciDir, "graal-sdk", "enterprise-graal")); } - result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api")); + result.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api", "truffle-compiler", "truffle-runtime", "truffle-enterprise")); if (modulePathBuild) { result.addAll(getJars(rootDir.resolve(Paths.get("lib", "svm", "builder")))); } diff --git a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraal.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraal.java new file mode 100644 index 000000000000..638689abebde --- /dev/null +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraal.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2019, 2023, 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.graal.hotspot.libgraal; + +import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; + +import java.lang.reflect.Method; +import java.util.Arrays; + +import org.graalvm.word.PointerBase; +import org.graalvm.word.WordFactory; + +import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; +import jdk.vm.ci.hotspot.HotSpotObjectConstant; +import jdk.vm.ci.hotspot.HotSpotResolvedJavaType; +import jdk.vm.ci.services.Services; + +/** + * Access to libgraal, a shared library containing an AOT compiled version of Graal produced by + * GraalVM Native Image. The libgraal library is only available if: + *
    + *
  • the {@linkplain #inLibGraal() current runtime} is libgraal, or
  • + *
  • the HotSpot {@code UseJVMCINativeLibrary} flag is true and the current runtime includes the + * relevant JVMCI API additions for accessing libgraal.
  • + *
+ * + * The {@link #isAvailable()} method is provided to test these conditions. It must be used to guard + * usage of all other methods in this class. In addition, only the following methods can be called + * from within libgraal: + *
    + *
  • {@link #isAvailable()}
  • + *
  • {@link #inLibGraal()}
  • + *
  • {@link #translate(Object)}
  • + *
  • {@link #unhand(Class, long)}
  • + *
+ */ +public final class LibGraal { + + static final long initialIsolate = Services.IS_BUILDING_NATIVE_IMAGE ? 0L : initializeLibgraal(); + static final boolean available = initialIsolate != 0L; + + // NOTE: The use of reflection to access JVMCI API is to support + // compiling on JDKs with varying versions of JVMCI. + + static { + // Initialize JVMCI to ensure JVMCI opens its packages to Graal. + Services.initializeJVMCI(); + } + + private static final Method unhand = methodOrNull(HotSpotJVMCIRuntime.class, "unhand", sig(Class.class, Long.TYPE)); + private static final Method attachCurrentThread = methodIf(unhand, HotSpotJVMCIRuntime.class, "attachCurrentThread", sig(Boolean.TYPE, long[].class), sig(Boolean.TYPE)); + private static final Method detachCurrentThread = methodIf(unhand, HotSpotJVMCIRuntime.class, "detachCurrentThread", sig(Boolean.TYPE), sig()); + private static final Method asResolvedJavaType = methodOrNull(HotSpotJVMCIRuntime.class, "asResolvedJavaType", sig(Long.TYPE)); + private static final Method getJObjectValue = methodIf(asResolvedJavaType, HotSpotJVMCIRuntime.class, "getJObjectValue", sig(HotSpotObjectConstant.class)); + + /** + * Determines if libgraal is available for use. + */ + public static boolean isAvailable() { + return inLibGraal() || available; + } + + /** + * Determines if the current runtime is libgraal. + */ + public static boolean inLibGraal() { + return Services.IS_IN_NATIVE_IMAGE; + } + + /** + * Creates or retrieves an object in the peer runtime that mirrors {@code obj}. + * + * This mechanism can be used to pass and return values between the HotSpot and libgraal + * runtimes. In the receiving runtime, the value can be converted back to an object with + * {@link #unhand}. + * + * @param obj an object for which an equivalent instance in the peer runtime is requested + * @return a JNI global reference to the mirror of {@code obj} in the peer runtime + * @throws IllegalArgumentException if {@code obj} is not of a translatable type + */ + public static long translate(Object obj) { + return HotSpotJVMCIRuntime.runtime().translate(obj); + } + + /** + * Dereferences and returns the object referred to by the JNI global reference {@code handle}. + * The global reference is deleted prior to returning. Any further use of {@code handle} is + * invalid. + * + * @param handle a JNI global reference to an object in the current runtime + * @return the object referred to by {@code handle} + * @throws ClassCastException if the returned object cannot be cast to {@code type} + */ + @SuppressWarnings("unchecked") + public static T unhand(Class type, long handle) { + return HotSpotJVMCIRuntime.runtime().unhand(type, handle); + } + + /** + * @see HotSpotJVMCIRuntime#getJObjectValue(HotSpotObjectConstant) + */ + public static T getJObjectValue(HotSpotObjectConstant constant) { + if (getJObjectValue == null) { + return WordFactory.nullPointer(); + } + try { + return WordFactory.pointer((long) getJObjectValue.invoke(runtime(), constant)); + } catch (Throwable throwable) { + throw new InternalError(throwable); + } + } + + /** + * @see HotSpotJVMCIRuntime#asResolvedJavaType(long) + */ + public static HotSpotResolvedJavaType asResolvedJavaType(PointerBase pointer) { + if (asResolvedJavaType == null) { + return null; + } + try { + return (HotSpotResolvedJavaType) asResolvedJavaType.invoke(runtime(), pointer.rawValue()); + } catch (Throwable throwable) { + throw new InternalError(throwable); + } + } + + private static long initializeLibgraal() { + return HotSpotJVMCIRuntime.runtime().registerNativeMethods(LibGraal.class)[1]; + } + + /** + * Ensures the current thread is attached to the peer runtime. + * + * @param isDaemon if the thread is not yet attached, should it be attached as a daemon + * @param isolate if non-null, the isolate for the current thread is returned in element 0 + * @return {@code true} if this call attached the current thread, {@code false} if the current + * thread was already attached + */ + public static boolean attachCurrentThread(boolean isDaemon, long[] isolate) { + try { + if (attachCurrentThread.getParameterCount() == 2) { + long[] javaVMInfo = isolate != null ? new long[4] : null; + boolean res = (boolean) attachCurrentThread.invoke(runtime(), isDaemon, javaVMInfo); + if (isolate != null) { + isolate[0] = javaVMInfo[1]; + } + return res; + } else { + if (isolate != null) { + isolate[0] = initialIsolate; + } + return (boolean) attachCurrentThread.invoke(runtime(), isDaemon); + } + } catch (Throwable throwable) { + throw new InternalError(throwable); + } + } + + /** + * Detaches the current thread from the peer runtime. + * + * @param release if {@code true} and the VM supports releasing the {@code JavaVM} associated + * with libgraal runtimes and this is the last thread attached to a libgraal runtime, + * then this call destroys the associated {@code JavaVM} instance, releasing its + * resources + * @return {@code true} if the {@code JavaVM} associated with the libgraal runtime was destroyed + * as a result of this call + */ + public static boolean detachCurrentThread(boolean release) { + try { + if (detachCurrentThread.getParameterCount() == 1) { + return (Boolean) detachCurrentThread.invoke(runtime(), release); + } else { + detachCurrentThread.invoke(runtime()); + return false; + } + } catch (Throwable throwable) { + throw new InternalError(throwable); + } + } + + /** + * Convenience function for wrapping varargs into an array for use in calls to + * {@link #method(Class, String, Class[][])}. + */ + private static Class[] sig(Class... types) { + return types; + } + + /** + * Gets the method in {@code declaringClass} with the unique name {@code name}. + * + * @param sigs the signatures the method may have + */ + private static Method method(Class declaringClass, String name, Class[]... sigs) { + if (sigs.length == 1 || sigs.length == 0) { + try { + Class[] sig = sigs.length == 1 ? sigs[0] : new Class[0]; + return declaringClass.getDeclaredMethod(name, sig); + } catch (NoSuchMethodException | SecurityException e) { + throw (NoSuchMethodError) new NoSuchMethodError(name).initCause(e); + } + } + Method match = null; + for (Method m : declaringClass.getDeclaredMethods()) { + if (m.getName().equals(name)) { + if (match != null) { + throw new InternalError(String.format("Expected single method named %s, found %s and %s", + name, match, m)); + } + match = m; + } + } + if (match == null) { + throw new NoSuchMethodError("Cannot find method " + name + " in " + declaringClass.getName()); + } + Class[] parameterTypes = match.getParameterTypes(); + for (Class[] sig : sigs) { + if (Arrays.equals(parameterTypes, sig)) { + return match; + } + } + throw new NoSuchMethodError(String.format("Unexpected signature for %s: %s", name, Arrays.toString(parameterTypes))); + } + + /** + * Gets the method in {@code declaringClass} with the unique name {@code name} or {@code null} + * if not found. + * + * @param sigs the signatures the method may have + */ + private static Method methodOrNull(Class declaringClass, String name, Class[]... sigs) { + try { + return method(declaringClass, name, sigs); + } catch (NoSuchMethodError e) { + return null; + } + } + + /** + * Gets the method in {@code declaringClass} with the unique name {@code name} or {@code null} + * if {@code guard == null}. + * + * @param sigs the signatures the method may have + */ + private static Method methodIf(Object guard, Class declaringClass, String name, Class[]... sigs) { + if (guard == null) { + return null; + } + return method(declaringClass, name, sigs); + } + +} 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 69df667f3e9b..500152717611 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 @@ -50,18 +50,10 @@ import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.options.OptionsParser; -import org.graalvm.compiler.serviceprovider.IsolateUtil; import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNIMethodScope; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.LibGraalScope; -import org.graalvm.nativeimage.Isolate; -import org.graalvm.nativeimage.IsolateThread; -import org.graalvm.nativeimage.ObjectHandles; import org.graalvm.nativeimage.UnmanagedMemory; import org.graalvm.nativeimage.c.function.CEntryPoint; -import org.graalvm.nativeimage.c.function.CEntryPoint.Builtin; -import org.graalvm.nativeimage.c.function.CEntryPoint.IsolateContext; import org.graalvm.nativeimage.c.struct.RawField; import org.graalvm.nativeimage.c.struct.RawFieldAddress; import org.graalvm.nativeimage.c.struct.RawStructure; @@ -94,7 +86,7 @@ import jdk.vm.ci.runtime.JVMCICompiler; /** - * Entry points in libgraal corresponding to native methods in {@link LibGraalScope} and + * Entry points in libgraal corresponding to native methods in the scope and * {@code CompileTheWorld}. */ public final class LibGraalEntryPoints { @@ -210,15 +202,6 @@ static CodeInfo newCodeInfo(RuntimeStubInfo rsi, Backend backend) { } } - @CEntryPoint(builtin = Builtin.GET_CURRENT_THREAD, name = "Java_org_graalvm_libgraal_LibGraalScope_getIsolateThreadIn") - private static native IsolateThread getIsolateThreadIn(PointerBase env, PointerBase hsClazz, @IsolateContext Isolate isolate); - - @CEntryPoint(name = "Java_org_graalvm_libgraal_LibGraalScope_attachThreadTo", builtin = CEntryPoint.Builtin.ATTACH_THREAD) - static native long attachThreadTo(PointerBase env, PointerBase hsClazz, @CEntryPoint.IsolateContext long isolate); - - @CEntryPoint(name = "Java_org_graalvm_libgraal_LibGraalScope_detachThreadFrom", builtin = CEntryPoint.Builtin.DETACH_THREAD) - static native void detachThreadFrom(PointerBase env, PointerBase hsClazz, @CEntryPoint.IsolateThreadContext long isolateThread); - static class CachedOptions { final OptionValues options; final long hash; @@ -231,16 +214,6 @@ static class CachedOptions { private static final ThreadLocal cachedOptions = new ThreadLocal<>(); - public static boolean hasLibGraalIsolatePeer() { - return hasLibGraalIsolatePeer; - } - - /** - * Indicates whether this runtime has an associated peer runtime that it must be unregistered - * from during shutdown. - */ - private static boolean hasLibGraalIsolatePeer; - private static OptionValues decodeOptions(long address, int size, int hash) { CachedOptions options = cachedOptions.get(); if (options == null || options.hash != hash) { @@ -265,33 +238,6 @@ private static OptionValues decodeOptions(long address, int size, int hash) { return options.options; } - @SuppressWarnings({"unused"}) - @CEntryPoint(name = "Java_org_graalvm_libgraal_LibGraalObject_releaseHandle") - public static boolean releaseHandle(PointerBase jniEnv, - PointerBase jclass, - @CEntryPoint.IsolateThreadContext long isolateThreadId, - long handle) { - try { - ObjectHandles.getGlobal().destroy(WordFactory.pointer(handle)); - return true; - } catch (Throwable t) { - return false; - } - } - - @SuppressWarnings({"unused"}) - @CEntryPoint(name = "Java_org_graalvm_libgraal_LibGraalScope_getIsolateId") - public static long getIsolateId(PointerBase jniEnv, - PointerBase jclass, - @CEntryPoint.IsolateThreadContext long isolateThreadId) { - try { - hasLibGraalIsolatePeer = true; - return IsolateUtil.getIsolateID(); - } catch (Throwable t) { - return 0L; - } - } - @SuppressWarnings({"unused", "try"}) @CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_test_LibGraalCompilerTest_hashConstantOopFields", include = LibGraalFeature.IsEnabled.class) private static long hashConstantOopFields(JNIEnv jniEnv, diff --git a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java index b58a570d182d..9dd609f551fe 100644 --- a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java @@ -59,7 +59,6 @@ import org.graalvm.compiler.core.target.Backend; import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; -import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.hotspot.EncodedSnippets; @@ -87,7 +86,6 @@ import org.graalvm.compiler.options.OptionsParser; import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.serviceprovider.GraalServices; -import org.graalvm.compiler.serviceprovider.IsolateUtil; import org.graalvm.compiler.serviceprovider.SpeculationReasonGroup; import org.graalvm.compiler.truffle.compiler.PartialEvaluatorConfiguration; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; @@ -99,10 +97,6 @@ import org.graalvm.jniutils.JNIExceptionWrapper; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.jniutils.NativeBridgeSupport; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.jni.LibGraalNativeBridgeSupport; -import org.graalvm.libgraal.jni.LibGraalUtil; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.LogHandler; import org.graalvm.nativeimage.StackValue; @@ -194,9 +188,6 @@ public void afterImageWrite(AfterImageWriteAccess access) { @Override public boolean isInConfiguration(IsInConfigurationAccess access) { - if (!LibGraal.isSupported()) { - throw new InternalError("LibGraalFeature is not supported by the current JDK"); - } return true; } @@ -212,11 +203,6 @@ public boolean getAsBoolean() { } } - @Override - public void afterRegistration(AfterRegistrationAccess access) { - ImageSingletons.add(NativeBridgeSupport.class, new LibGraalNativeBridgeSupport()); - } - @Override public void duringSetup(DuringSetupAccess access) { ImageClassLoader imageClassLoader = ((DuringSetupAccessImpl) access).getImageClassLoader(); @@ -605,7 +591,7 @@ private static void verifyReachableTruffleClasses(AfterAnalysisAccess access) { private static boolean isAllowedType(String className) { if (className.startsWith("com.oracle.truffle.")) { - return className.startsWith("com.oracle.truffle.api.nodes.") || className.startsWith("com.oracle.truffle.compiler.enterprise."); + return className.startsWith("com.oracle.truffle.compiler."); } return true; } @@ -714,39 +700,27 @@ private static void startupLibGraal(HotSpotGraalRuntime runtime) { VMRuntime.initialize(); } + @SuppressWarnings("unused") @Substitute private static void shutdownLibGraal(HotSpotGraalRuntime runtime) { try { - // Unregister this isolate if it was created as a peer - if (LibGraalEntryPoints.hasLibGraalIsolatePeer()) { + String callback = LibGraalOptions.OnShutdownCallback.getValue(); + if (callback != null) { long offset = runtime.getVMConfig().jniEnvironmentOffset; long javaThreadAddr = HotSpotJVMCIRuntime.runtime().getCurrentJavaThread(); JNI.JNIEnv env = (JNI.JNIEnv) WordFactory.unsigned(javaThreadAddr).add(WordFactory.unsigned(offset)); - JNI.JClass libGraalIsolateClass = JNIUtil.findClass(env, JNIUtil.getJVMCIClassLoader(env), - JNIUtil.getBinaryName("org.graalvm.libgraal.LibGraalIsolate"), true); - JNI.JMethodID unregisterMethod = JNIUtil.findMethod(env, libGraalIsolateClass, true, "unregister", "(J)V"); - JNI.JValue args = StackValue.get(JNI.JValue.class); - args.setLong(IsolateUtil.getIsolateID()); - env.getFunctions().getCallStaticVoidMethodA().call(env, libGraalIsolateClass, unregisterMethod, args); - JNIExceptionWrapper.wrapAndThrowPendingJNIException(env); - - String callback = LibGraalOptions.OnShutdownCallback.getValue(); - if (callback != null) { - int lastDot = callback.lastIndexOf('.'); - if (lastDot < 1 || lastDot == callback.length() - 1) { - throw new IllegalArgumentException(LibGraalOptions.OnShutdownCallback.getName() + " value does not have . format: " + callback); - } - String cbClassName = callback.substring(0, lastDot); - String cbMethodName = callback.substring(lastDot + 1); - JNI.JClass cbClass = JNIUtil.findClass(env, JNIUtil.getSystemClassLoader(env), - JNIUtil.getBinaryName(cbClassName), true); - JNI.JMethodID cbMethod = JNIUtil.findMethod(env, cbClass, true, cbMethodName, "()V"); - env.getFunctions().getCallStaticVoidMethodA().call(env, cbClass, cbMethod, StackValue.get(0)); - JNIExceptionWrapper.wrapAndThrowPendingJNIException(env); + int lastDot = callback.lastIndexOf('.'); + if (lastDot < 1 || lastDot == callback.length() - 1) { + throw new IllegalArgumentException(LibGraalOptions.OnShutdownCallback.getName() + " value does not have . format: " + callback); } + String cbClassName = callback.substring(0, lastDot); + String cbMethodName = callback.substring(lastDot + 1); + JNI.JClass cbClass = JNIUtil.findClass(env, JNIUtil.getSystemClassLoader(env), + JNIUtil.getBinaryName(cbClassName), true); + JNI.JMethodID cbMethod = JNIUtil.findMethod(env, cbClass, true, cbMethodName, "()V"); + env.getFunctions().getCallStaticVoidMethodA().call(env, cbClass, cbMethod, StackValue.get(0)); + JNIExceptionWrapper.wrapAndThrowPendingJNIException(env); } - } catch (Throwable t) { - t.printStackTrace(TTY.out); } finally { VMRuntime.shutdown(); } @@ -857,15 +831,6 @@ private static void notifyCrash(String crashMessage) { final class Target_org_graalvm_compiler_hotspot_SymbolicSnippetEncoder { } -@TargetClass(className = "org.graalvm.compiler.truffle.compiler.hotspot.libgraal.TruffleToLibGraalEntryPoints", onlyWith = LibGraalFeature.IsEnabled.class) -final class Target_org_graalvm_compiler_truffle_compiler_hotspot_libgraal_TruffleToLibGraalEntryPoints { - @SuppressWarnings("unused") - @Substitute - private static void doReferenceHandling() { - Heap.getHeap().doReferenceHandling(); - } -} - @TargetClass(value = HotSpotForeignCallLinkageImpl.class, onlyWith = LibGraalFeature.IsEnabled.class) final class Target_org_graalvm_compiler_hotspot_HotSpotForeignCallLinkageImpl { /** diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalJNIMethodScope.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalJNIMethodScope.java similarity index 96% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalJNIMethodScope.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalJNIMethodScope.java index 9eed10cd53bb..8c58d658af68 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalJNIMethodScope.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalJNIMethodScope.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.libgraal.jni; +package com.oracle.svm.graal.hotspot.libgraal; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; diff --git a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalUtil.java similarity index 63% rename from compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalUtil.java index e82a25e2b4b2..56e6ef03a0b5 100644 --- a/compiler/src/org.graalvm.nativebridge.processor.test/src/org/graalvm/nativebridge/processor/test/references/LanguageAPI.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -22,29 +22,25 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.nativebridge.processor.test.references; +package com.oracle.svm.graal.hotspot.libgraal; import java.util.Objects; -final class LanguageAPI { +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNIMethodScope; - final CustomLanguageDispatch dispatch; - final Object receiver; +public final class LibGraalUtil { - LanguageAPI(CustomLanguageDispatch dispatch, Object receiver) { - this.dispatch = Objects.requireNonNull(dispatch); - this.receiver = Objects.requireNonNull(receiver); + private LibGraalUtil() { } - String getId() { - return dispatch.getId(receiver); + public static JNIMethodScope openScope(Class entryPointClass, Enum id, JNIEnv env) { + Objects.requireNonNull(id, "Id must be non null."); + return LibGraalJNIMethodScope.open(com.oracle.svm.util.ClassUtil.getUnqualifiedName(entryPointClass) + "::" + id, env); } - String getName() { - return dispatch.getName(receiver); + public static JNIMethodScope openScope(String scopeName, JNIEnv env) { + return LibGraalJNIMethodScope.open(scopeName, env); } - String getVersion() { - return dispatch.getVersion(receiver); - } } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/FromLibGraalCalls.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/FromLibGraalCalls.java similarity index 62% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/FromLibGraalCalls.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/FromLibGraalCalls.java index 4169edf42e57..e4fa8c45226d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/FromLibGraalCalls.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/FromLibGraalCalls.java @@ -22,52 +22,40 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.libgraal.jni; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import static org.graalvm.jniutils.JNIExceptionWrapper.wrapAndThrowPendingJNIException; - -import org.graalvm.jniutils.JNICalls; -import org.graalvm.libgraal.jni.annotation.FromLibGraalId; import static org.graalvm.jniutils.JNIUtil.GetStaticMethodID; -import static org.graalvm.jniutils.JNIUtil.NewGlobalRef; -import static org.graalvm.jniutils.JNIUtil.getBinaryName; import static org.graalvm.nativeimage.c.type.CTypeConversion.toCString; import java.util.EnumMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -import org.graalvm.jniutils.JNI; import org.graalvm.jniutils.JNI.JClass; import org.graalvm.jniutils.JNI.JMethodID; import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNI.JObject; import org.graalvm.jniutils.JNI.JValue; -import org.graalvm.jniutils.JNIUtil; +import org.graalvm.jniutils.JNICalls; import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; +import com.oracle.truffle.compiler.hotspot.libgraal.FromLibGraalId; + /** * Helpers for calling methods in HotSpot heap via JNI. */ public abstract class FromLibGraalCalls & FromLibGraalId> { - private static final Map classes = new ConcurrentHashMap<>(); - private final EnumMap> methods; private final JNICalls hotSpotCalls; - private volatile JClass peer; + private final JClass peer; - protected FromLibGraalCalls(Class idType) { - methods = new EnumMap<>(idType); - hotSpotCalls = JNICalls.getDefault(); + protected FromLibGraalCalls(Class idType, JClass peer) { + this.methods = new EnumMap<>(idType); + this.hotSpotCalls = JNICalls.getDefault(); + this.peer = peer; } - /** - * Returns a {@link JClass} for the entry points from LibGraal. - */ - protected abstract JClass resolvePeer(JNIEnv env); - /** * Describes a class and holds a reference to its {@linkplain #jclass JNI value}. */ @@ -82,7 +70,7 @@ static final class JNIClass { } /** - * Describes a method in {@link #peer(JNI.JNIEnv) HotSpot peer class}. + * Describes a method in HotSpot peer class}. */ static final class JNIMethodImpl & FromLibGraalId> implements JNICalls.JNIMethod { final T hcId; @@ -111,62 +99,28 @@ public String toString() { public final void callVoid(JNIEnv env, T id, JValue args) { JNIMethodImpl method = getJNIMethod(env, id, void.class); - hotSpotCalls.callStaticVoid(env, peer(env), method, args); + hotSpotCalls.callStaticVoid(env, peer, method, args); } public final boolean callBoolean(JNIEnv env, T id, JValue args) { JNIMethodImpl method = getJNIMethod(env, id, boolean.class); - return hotSpotCalls.callStaticBoolean(env, peer(env), method, args); + return hotSpotCalls.callStaticBoolean(env, peer, method, args); } public final long callLong(JNIEnv env, T id, JValue args) { JNIMethodImpl method = getJNIMethod(env, id, long.class); - return hotSpotCalls.callStaticLong(env, peer(env), method, args); + return hotSpotCalls.callStaticLong(env, peer, method, args); } public final int callInt(JNIEnv env, T id, JValue args) { JNIMethodImpl method = getJNIMethod(env, id, int.class); - return hotSpotCalls.callStaticInt(env, peer(env), method, args); + return hotSpotCalls.callStaticInt(env, peer, method, args); } @SuppressWarnings("unchecked") public final R callJObject(JNIEnv env, T id, JValue args) { JNIMethodImpl method = getJNIMethod(env, id, Object.class); - return hotSpotCalls.callStaticJObject(env, peer(env), method, args); - } - - public static JClass getJNIClass(JNIEnv env, Class clazz) { - if (clazz.isArray()) { - throw new UnsupportedOperationException("Array classes are not supported"); - } - return getJNIClassImpl(env, clazz.getName()).jclass; - } - - public static JClass getJNIClass(JNIEnv env, String className) { - return getJNIClassImpl(env, className).jclass; - } - - private static JNIClass getJNIClassImpl(JNIEnv env, String className) { - try { - return classes.computeIfAbsent(className, new Function() { - @Override - public JNIClass apply(String name) { - JNI.JObject classLoader = JNIUtil.getJVMCIClassLoader(env); - // If the JVMCI classloader does not exist, then JVMCI must have been loaded on - // the boot classpath. This is the case, for example, in unit tests, when the - // -XX:-UseJVMCIClassLoader flag is specified. - JClass clazz = classLoader.isNull() ? JNIUtil.findClass(env, getBinaryName(name)) : JNIUtil.findClass(env, classLoader, getBinaryName(name)); - if (clazz.isNull()) { - JNIUtil.ExceptionClear(env); - throw new InternalError("Cannot load class: " + name); - } - return new JNIClass(name, NewGlobalRef(env, clazz, "Class<" + name + ">")); - } - }); - } catch (InternalError ie) { - wrapAndThrowPendingJNIException(env); - throw ie; - } + return hotSpotCalls.callStaticJObject(env, peer, method, args); } private JNIMethodImpl getJNIMethod(JNIEnv env, T hcId, Class expectedReturnType) { @@ -175,7 +129,7 @@ private JNIMethodImpl getJNIMethod(JNIEnv env, T hcId, Class expectedRetur return methods.computeIfAbsent(hcId, new Function>() { @Override public JNIMethodImpl apply(T id) { - JClass c = peer(env); + JClass c = peer; String methodName = id.getMethodName(); try (CCharPointerHolder name = toCString(methodName); CCharPointerHolder sig = toCString(id.getSignature())) { JMethodID jniId = GetStaticMethodID(env, c, name.get(), sig.get()); @@ -192,10 +146,4 @@ public JNIMethodImpl apply(T id) { } } - private JClass peer(JNIEnv env) { - if (peer.isNull()) { - peer = resolvePeer(env); - } - return peer; - } } diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilable.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilable.java similarity index 59% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilable.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilable.java index 54b3660cd8dc..185e29384448 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilable.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilable.java @@ -22,34 +22,34 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; - -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AsJavaConstant; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CancelCompilation; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableCallCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetFailedSpeculationsAddress; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetKnownCallSiteCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNonTrivialNodeCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsSameOrSplit; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsTrivial; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationFailed; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callAsJavaConstant; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callCancelCompilation; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callCompilableToString; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callCountDirectCallNodes; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callCreateStringSupplier; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callGetCompilableCallCount; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callGetCompilableName; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callGetFailedSpeculationsAddress; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callGetKnownCallSiteCount; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callGetNonTrivialNodeCount; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callIsSameOrSplit; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callIsTrivial; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callOnCompilationFailed; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilableGen.callPrepareForCompilation; +package com.oracle.svm.graal.hotspot.libgraal.truffle; + +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callAsJavaConstant; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callCancelCompilation; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callCompilableToString; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callCountDirectCallNodes; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callCreateStringSupplier; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callGetCompilableCallCount; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callGetCompilableName; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callGetFailedSpeculationsAddress; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callGetKnownCallSiteCount; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callGetNonTrivialNodeCount; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callIsSameOrSplit; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callIsTrivial; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callOnCompilationFailed; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilableGen.callPrepareForCompilation; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AsJavaConstant; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CancelCompilation; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableCallCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetFailedSpeculationsAddress; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetKnownCallSiteCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNonTrivialNodeCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsSameOrSplit; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsTrivial; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationFailed; import static org.graalvm.jniutils.JNIMethodScope.env; import static org.graalvm.jniutils.JNIUtil.createString; @@ -59,9 +59,6 @@ import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.hotspot.HotSpotGraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id; import org.graalvm.jniutils.HSObject; import org.graalvm.jniutils.JNI; import org.graalvm.jniutils.JNI.JNIEnv; @@ -69,9 +66,13 @@ import org.graalvm.jniutils.JNI.JString; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.libgraal.LibGraal; import org.graalvm.nativebridge.BinaryInput; +import com.oracle.svm.graal.hotspot.libgraal.LibGraal; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id; + import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.SpeculationLog; @@ -80,6 +81,7 @@ */ final class HSTruffleCompilable extends HSObject implements TruffleCompilable { + private final TruffleFromLibGraalCalls calls; private volatile String cachedName; /** @@ -94,8 +96,9 @@ final class HSTruffleCompilable extends HSObject implements TruffleCompilable { * @param scope the owning scope * @param handle the JNI object reference */ - HSTruffleCompilable(JNIMethodScope scope, JObject handle) { + HSTruffleCompilable(JNIMethodScope scope, JObject handle, HSTruffleCompilerRuntime runtime) { super(scope, handle); + this.calls = runtime.calls; } @TruffleFromLibGraal(GetFailedSpeculationsAddress) @@ -103,7 +106,7 @@ final class HSTruffleCompilable extends HSObject implements TruffleCompilable { public SpeculationLog getCompilationSpeculationLog() { Long res = cachedFailedSpeculationsAddress; if (res == null) { - res = callGetFailedSpeculationsAddress(env(), getHandle()); + res = callGetFailedSpeculationsAddress(calls, env(), getHandle()); cachedFailedSpeculationsAddress = res; } return HotSpotGraalServices.newHotSpotSpeculationLog(cachedFailedSpeculationsAddress); @@ -113,7 +116,7 @@ public SpeculationLog getCompilationSpeculationLog() { @TruffleFromLibGraal(Id.GetCompilerOptions) public Map getCompilerOptions() { JNIEnv env = env(); - JNI.JByteArray res = HSTruffleCompilableGen.callGetCompilerOptions(env, getHandle()); + JNI.JByteArray res = HSTruffleCompilableGen.callGetCompilerOptions(calls, env, getHandle()); byte[] realArray = JNIUtil.createArray(env, res); return readDebugMap(BinaryInput.create(realArray)); } @@ -131,25 +134,25 @@ private static Map readDebugMap(BinaryInput in) { @Override @TruffleFromLibGraal(Id.EngineId) public long engineId() { - return HSTruffleCompilableGen.callEngineId(env(), getHandle()); + return HSTruffleCompilableGen.callEngineId(calls, env(), getHandle()); } @Override @TruffleFromLibGraal(Id.PrepareForCompilation) public void prepareForCompilation() { - callPrepareForCompilation(env(), getHandle()); + callPrepareForCompilation(calls, env(), getHandle()); } @TruffleFromLibGraal(IsTrivial) @Override public boolean isTrivial() { - return callIsTrivial(env(), getHandle()); + return callIsTrivial(calls, env(), getHandle()); } @TruffleFromLibGraal(AsJavaConstant) @Override public JavaConstant asJavaConstant() { - return LibGraal.unhand(JavaConstant.class, callAsJavaConstant(env(), getHandle())); + return LibGraal.unhand(JavaConstant.class, callAsJavaConstant(calls, env(), getHandle())); } @TruffleFromLibGraal(CreateStringSupplier) @@ -160,8 +163,8 @@ public void onCompilationFailed(Supplier serializedException, boolean si boolean success = false; JNIEnv env = env(); try { - JObject instance = callCreateStringSupplier(env, serializedExceptionHandle); - callOnCompilationFailed(env, getHandle(), instance, silent, bailout, permanentBailout, graphTooBig); + JObject instance = callCreateStringSupplier(calls, env, serializedExceptionHandle); + callOnCompilationFailed(calls, env, getHandle(), instance, silent, bailout, permanentBailout, graphTooBig); success = true; } finally { if (!success) { @@ -176,7 +179,7 @@ public String getName() { String res = cachedName; if (res == null) { JNIEnv env = JNIMethodScope.env(); - JString name = callGetCompilableName(env, getHandle()); + JString name = callGetCompilableName(calls, env, getHandle()); res = createString(env, name); cachedName = res; } @@ -186,19 +189,19 @@ public String getName() { @TruffleFromLibGraal(GetNonTrivialNodeCount) @Override public int getNonTrivialNodeCount() { - return callGetNonTrivialNodeCount(env(), getHandle()); + return callGetNonTrivialNodeCount(calls, env(), getHandle()); } @TruffleFromLibGraal(Id.CountDirectCallNodes) @Override public int countDirectCallNodes() { - return callCountDirectCallNodes(env(), getHandle()); + return callCountDirectCallNodes(calls, env(), getHandle()); } @TruffleFromLibGraal(GetCompilableCallCount) @Override public int getCallCount() { - return callGetCompilableCallCount(env(), getHandle()); + return callGetCompilableCallCount(calls, env(), getHandle()); } private volatile String cachedString; @@ -209,7 +212,7 @@ public String toString() { String res = cachedString; if (res == null) { JNIEnv env = JNIMethodScope.env(); - JString value = callCompilableToString(env, getHandle()); + JString value = callCompilableToString(calls, env, getHandle()); res = createString(env, value); cachedString = res; } @@ -221,20 +224,20 @@ public String toString() { public boolean cancelCompilation(CharSequence reason) { JNIEnv env = env(); JString jniReason = JNIUtil.createHSString(env, reason.toString()); - return callCancelCompilation(env, getHandle(), jniReason); + return callCancelCompilation(calls, env, getHandle(), jniReason); } @TruffleFromLibGraal(IsSameOrSplit) @Override public boolean isSameOrSplit(TruffleCompilable ast) { JObject astHandle = ((HSTruffleCompilable) ast).getHandle(); - return callIsSameOrSplit(env(), getHandle(), astHandle); + return callIsSameOrSplit(calls, env(), getHandle(), astHandle); } @TruffleFromLibGraal(GetKnownCallSiteCount) @Override public int getKnownCallSiteCount() { - return callGetKnownCallSiteCount(env(), getHandle()); + return callGetKnownCallSiteCount(calls, env(), getHandle()); } @Override diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilationTask.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilationTask.java similarity index 51% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilationTask.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilationTask.java index 10ea33424635..8e3893584c6d 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilationTask.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilationTask.java @@ -22,39 +22,39 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; - -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AddInlinedTarget; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AddTargetToDequeue; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetDescription; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetLanguage; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetLineNumber; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeClassName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeId; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetEnd; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetStart; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetPosition; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetURI; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.HasNextTier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsCancelled; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsLastTier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.SetCallCounts; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callAddInlinedTarget; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callAddTargetToDequeue; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetDebugProperties; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetDescription; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetLanguage; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetLineNumber; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetNodeClassName; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetNodeId; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetOffsetEnd; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetOffsetStart; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetPosition; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callGetURI; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callHasNextTier; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callIsCancelled; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callIsLastTier; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilationTaskGen.callSetCallCounts; +package com.oracle.svm.graal.hotspot.libgraal.truffle; + +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callAddInlinedTarget; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callAddTargetToDequeue; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetDebugProperties; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetDescription; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetLanguage; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetLineNumber; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetNodeClassName; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetNodeId; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetOffsetEnd; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetOffsetStart; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetPosition; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callGetURI; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callHasNextTier; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callIsCancelled; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callIsLastTier; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilationTaskGen.callSetCallCounts; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AddInlinedTarget; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AddTargetToDequeue; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetDescription; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetLanguage; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetLineNumber; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeClassName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeId; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetEnd; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetStart; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetPosition; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetURI; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.HasNextTier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsCancelled; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsLastTier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.SetCallCounts; import static org.graalvm.jniutils.JNIMethodScope.env; import static org.graalvm.jniutils.JNIUtil.createString; @@ -62,11 +62,6 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id; import org.graalvm.jniutils.HSObject; import org.graalvm.jniutils.JNI; import org.graalvm.jniutils.JNI.JNIEnv; @@ -74,9 +69,15 @@ import org.graalvm.jniutils.JNI.JString; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.libgraal.LibGraal; import org.graalvm.nativebridge.BinaryInput; +import com.oracle.svm.graal.hotspot.libgraal.LibGraal; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id; + import jdk.vm.ci.meta.JavaConstant; /** @@ -84,57 +85,60 @@ */ final class HSTruffleCompilationTask extends HSObject implements TruffleCompilationTask { - HSTruffleCompilationTask(JNIMethodScope scope, JObject handle) { + private final TruffleFromLibGraalCalls calls; + + HSTruffleCompilationTask(JNIMethodScope scope, JObject handle, HSTruffleCompilerRuntime runtime) { super(scope, handle); + this.calls = runtime.calls; } @TruffleFromLibGraal(IsCancelled) @Override public boolean isCancelled() { - return callIsCancelled(env(), getHandle()); + return callIsCancelled(calls, env(), getHandle()); } @TruffleFromLibGraal(HasNextTier) @Override public boolean hasNextTier() { - return callHasNextTier(env(), getHandle()); + return callHasNextTier(calls, env(), getHandle()); } @TruffleFromLibGraal(IsLastTier) @Override public boolean isLastTier() { - return callIsLastTier(env(), getHandle()); + return callIsLastTier(calls, env(), getHandle()); } @TruffleFromLibGraal(GetPosition) @Override public TruffleSourceLanguagePosition getPosition(JavaConstant node) { long nodeHandle = LibGraal.translate(node); - JObject res = callGetPosition(env(), getHandle(), nodeHandle); + JObject res = callGetPosition(calls, env(), getHandle(), nodeHandle); if (res.isNull()) { return null; } - return new HSTruffleSourceLanguagePosition(JNIMethodScope.scope(), res); + return new HSTruffleSourceLanguagePosition(JNIMethodScope.scope(), res, calls); } @TruffleFromLibGraal(AddTargetToDequeue) @Override public void addTargetToDequeue(TruffleCompilable target) { JObject hsCompilable = ((HSTruffleCompilable) target).getHandle(); - callAddTargetToDequeue(env(), getHandle(), hsCompilable); + callAddTargetToDequeue(calls, env(), getHandle(), hsCompilable); } @TruffleFromLibGraal(SetCallCounts) @Override public void setCallCounts(int total, int inlined) { - callSetCallCounts(env(), getHandle(), total, inlined); + callSetCallCounts(calls, env(), getHandle(), total, inlined); } @TruffleFromLibGraal(AddInlinedTarget) @Override public void addInlinedTarget(TruffleCompilable target) { JObject hsCompilable = ((HSTruffleCompilable) target).getHandle(); - callAddInlinedTarget(env(), getHandle(), hsCompilable); + callAddInlinedTarget(calls, env(), getHandle(), hsCompilable); } @TruffleFromLibGraal(Id.GetDebugProperties) @@ -142,7 +146,7 @@ public void addInlinedTarget(TruffleCompilable target) { public Map getDebugProperties(JavaConstant node) { long nodeHandle = LibGraal.translate(node); JNIEnv env = env(); - JNI.JByteArray res = callGetDebugProperties(env, getHandle(), nodeHandle); + JNI.JByteArray res = callGetDebugProperties(calls, env, getHandle(), nodeHandle); byte[] realArray = JNIUtil.createArray(env, res); return readDebugMap(BinaryInput.create(realArray)); } @@ -163,46 +167,49 @@ private static Map readDebugMap(BinaryInput in) { */ private static final class HSTruffleSourceLanguagePosition extends HSObject implements TruffleSourceLanguagePosition { - HSTruffleSourceLanguagePosition(JNIMethodScope scope, JObject handle) { + private final TruffleFromLibGraalCalls calls; + + HSTruffleSourceLanguagePosition(JNIMethodScope scope, JObject handle, TruffleFromLibGraalCalls calls) { super(scope, handle); + this.calls = calls; } @TruffleFromLibGraal(GetOffsetStart) @Override public int getOffsetStart() { - return callGetOffsetStart(JNIMethodScope.env(), getHandle()); + return callGetOffsetStart(calls, JNIMethodScope.env(), getHandle()); } @TruffleFromLibGraal(GetOffsetEnd) @Override public int getOffsetEnd() { - return callGetOffsetEnd(JNIMethodScope.env(), getHandle()); + return callGetOffsetEnd(calls, JNIMethodScope.env(), getHandle()); } @TruffleFromLibGraal(GetLineNumber) @Override public int getLineNumber() { - return callGetLineNumber(JNIMethodScope.env(), getHandle()); + return callGetLineNumber(calls, JNIMethodScope.env(), getHandle()); } @TruffleFromLibGraal(GetLanguage) @Override public String getLanguage() { - JString res = callGetLanguage(JNIMethodScope.env(), getHandle()); + JString res = callGetLanguage(calls, JNIMethodScope.env(), getHandle()); return createString(JNIMethodScope.env(), res); } @TruffleFromLibGraal(GetDescription) @Override public String getDescription() { - JString res = callGetDescription(JNIMethodScope.env(), getHandle()); + JString res = callGetDescription(calls, JNIMethodScope.env(), getHandle()); return createString(JNIMethodScope.env(), res); } @TruffleFromLibGraal(GetURI) @Override public URI getURI() { - JString res = callGetURI(JNIMethodScope.env(), getHandle()); + JString res = callGetURI(calls, JNIMethodScope.env(), getHandle()); String stringifiedURI = createString(JNIMethodScope.env(), res); return stringifiedURI == null ? null : URI.create(stringifiedURI); } @@ -210,14 +217,14 @@ public URI getURI() { @TruffleFromLibGraal(GetNodeClassName) @Override public String getNodeClassName() { - JString res = callGetNodeClassName(JNIMethodScope.env(), getHandle()); + JString res = callGetNodeClassName(calls, JNIMethodScope.env(), getHandle()); return createString(JNIMethodScope.env(), res); } @TruffleFromLibGraal(GetNodeId) @Override public int getNodeId() { - return callGetNodeId(JNIMethodScope.env(), getHandle()); + return callGetNodeId(calls, JNIMethodScope.env(), getHandle()); } } } diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerListener.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerListener.java similarity index 70% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerListener.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerListener.java index 9a3fc96d0d08..3498168d4fbc 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerListener.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerListener.java @@ -22,30 +22,32 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; - -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationRetry; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnFailure; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnGraalTierFinished; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnSuccess; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnTruffleTierFinished; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerListenerGen.callOnCompilationRetry; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerListenerGen.callOnFailure; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerListenerGen.callOnGraalTierFinished; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerListenerGen.callOnSuccess; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerListenerGen.callOnTruffleTierFinished; +package com.oracle.svm.graal.hotspot.libgraal.truffle; + +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationRetry; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnFailure; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnGraalTierFinished; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnSuccess; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnTruffleTierFinished; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerListenerGen.callOnCompilationRetry; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerListenerGen.callOnFailure; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerListenerGen.callOnGraalTierFinished; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerListenerGen.callOnSuccess; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerListenerGen.callOnTruffleTierFinished; import static org.graalvm.jniutils.JNIUtil.createHSString; import java.io.Closeable; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal; import org.graalvm.jniutils.HSObject; import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNI.JObject; import org.graalvm.jniutils.JNI.JString; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; + import org.graalvm.jniutils.JNIMethodScope; /** @@ -53,8 +55,11 @@ */ final class HSTruffleCompilerListener extends HSObject implements TruffleCompilerListener { - HSTruffleCompilerListener(JNIMethodScope scope, JObject handle) { + private final TruffleFromLibGraalCalls calls; + + HSTruffleCompilerListener(JNIMethodScope scope, JObject handle, HSTruffleCompilerRuntime runtime) { super(scope, handle); + this.calls = runtime.calls; } @TruffleFromLibGraal(OnSuccess) @@ -65,7 +70,7 @@ public void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task, JNIEnv env = JNIMethodScope.env(); try (LibGraalObjectHandleScope graphInfoScope = LibGraalObjectHandleScope.forObject(graphInfo); LibGraalObjectHandleScope compilationResultInfoScope = LibGraalObjectHandleScope.forObject(compilationResultInfo)) { - callOnSuccess(env, getHandle(), hsCompilable, hsTask, graphInfoScope.getHandle(), compilationResultInfoScope.getHandle(), tier); + callOnSuccess(calls, env, getHandle(), hsCompilable, hsTask, graphInfoScope.getHandle(), compilationResultInfoScope.getHandle(), tier); } } @@ -76,7 +81,7 @@ public void onTruffleTierFinished(TruffleCompilable compilable, TruffleCompilati JObject hasTask = ((HSTruffleCompilationTask) task).getHandle(); JNIEnv env = JNIMethodScope.env(); try (LibGraalObjectHandleScope graphInfoScope = LibGraalObjectHandleScope.forObject(graph)) { - callOnTruffleTierFinished(env, getHandle(), hsCompilable, hasTask, graphInfoScope.getHandle()); + callOnTruffleTierFinished(calls, env, getHandle(), hsCompilable, hasTask, graphInfoScope.getHandle()); } } @@ -87,7 +92,7 @@ public void onGraalTierFinished(TruffleCompilable compilable, GraphInfo graph) { JObject hsCompilable = ((HSTruffleCompilable) compilable).getHandle(); JNIEnv env = JNIMethodScope.env(); try (LibGraalObjectHandleScope graphInfoScope = LibGraalObjectHandleScope.forObject(graph)) { - callOnGraalTierFinished(env, getHandle(), hsCompilable, graphInfoScope.getHandle()); + callOnGraalTierFinished(calls, env, getHandle(), hsCompilable, graphInfoScope.getHandle()); } } @@ -97,7 +102,7 @@ public void onFailure(TruffleCompilable compilable, String serializedException, JObject hsCompilable = ((HSTruffleCompilable) compilable).getHandle(); JNIEnv env = JNIMethodScope.env(); JString hsReason = createHSString(env, serializedException); - callOnFailure(env, getHandle(), hsCompilable, hsReason, bailout, permanentBailout, tier); + callOnFailure(calls, env, getHandle(), hsCompilable, hsReason, bailout, permanentBailout, tier); } @TruffleFromLibGraal(OnCompilationRetry) @@ -106,7 +111,7 @@ public void onCompilationRetry(TruffleCompilable compilable, TruffleCompilationT JObject hsCompilable = ((HSTruffleCompilable) compilable).getHandle(); JObject hsTask = ((HSTruffleCompilationTask) task).getHandle(); JNIEnv env = JNIMethodScope.env(); - callOnCompilationRetry(env, getHandle(), hsCompilable, hsTask); + callOnCompilationRetry(calls, env, getHandle(), hsCompilable, hsTask); } private static final class LibGraalObjectHandleScope implements Closeable { diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerRuntime.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerRuntime.java similarity index 71% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerRuntime.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerRuntime.java index 132ff72204e0..004f82d13de8 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/HSTruffleCompilerRuntime.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerRuntime.java @@ -22,26 +22,26 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callConsumeOptimizedAssumptionDependency; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callCreateStringSupplier; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callGetConstantFieldInfo; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callIsSuppressedFailure; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callIsValueType; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callLog; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callOnCodeInstallation; +import static com.oracle.svm.graal.hotspot.libgraal.truffle.HSTruffleCompilerRuntimeGen.callRegisterOptimizedAssumptionDependency; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.ConsumeOptimizedAssumptionDependency; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetConstantFieldInfo; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetPartialEvaluationMethodInfo; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsSuppressedFailure; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsValueType; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.Log; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCodeInstallation; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.RegisterOptimizedAssumptionDependency; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.ConsumeOptimizedAssumptionDependency; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetConstantFieldInfo; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetPartialEvaluationMethodInfo; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsSuppressedFailure; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsValueType; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.Log; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCodeInstallation; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.RegisterOptimizedAssumptionDependency; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callConsumeOptimizedAssumptionDependency; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callCreateStringSupplier; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callGetConstantFieldInfo; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callIsSuppressedFailure; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callIsValueType; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callLog; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callOnCodeInstallation; -import static org.graalvm.compiler.truffle.compiler.hotspot.libgraal.HSTruffleCompilerRuntimeGen.callRegisterOptimizedAssumptionDependency; import static org.graalvm.jniutils.JNIMethodScope.env; import static org.graalvm.jniutils.JNIMethodScope.scope; import static org.graalvm.jniutils.JNIUtil.getInternalName; @@ -50,29 +50,31 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilerAssumptionDependency; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id; import org.graalvm.jniutils.HSObject; import org.graalvm.jniutils.JNI.JByteArray; +import org.graalvm.jniutils.JNI.JClass; import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNI.JObject; import org.graalvm.jniutils.JNI.JString; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.jni.annotation.FromLibGraalEntryPointsResolver; import org.graalvm.nativebridge.BinaryInput; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.word.WordFactory; +import com.oracle.svm.graal.hotspot.libgraal.LibGraal; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.hotspot.libgraal.FromLibGraalEntryPointsResolver; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id; + import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.hotspot.HotSpotObjectConstant; import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; @@ -87,24 +89,26 @@ /** * Proxy for a {@link TruffleCompilerRuntime} object in the HotSpot heap. */ -@FromLibGraalEntryPointsResolver(value = TruffleFromLibGraal.Id.class, entryPointsClassName = "org.graalvm.compiler.truffle.runtime.hotspot.libgraal.TruffleFromLibGraalEntryPoints") +@FromLibGraalEntryPointsResolver(value = TruffleFromLibGraal.Id.class, entryPointsClassName = "com.oracle.truffle.runtime.hotspot.libgraal.TruffleFromLibGraalEntryPoints") final class HSTruffleCompilerRuntime extends HSObject implements TruffleCompilerRuntime { private final ResolvedJavaType classLoaderDelegate; + final TruffleFromLibGraalCalls calls; - HSTruffleCompilerRuntime(JNIEnv env, JObject handle, ResolvedJavaType classLoaderDelegate) { + HSTruffleCompilerRuntime(JNIEnv env, JObject handle, ResolvedJavaType classLoaderDelegate, JClass peer) { /* * Note global duplicates may happen if the compiler is initialized by a host compilation. */ super(env, handle, true, false); this.classLoaderDelegate = classLoaderDelegate; + this.calls = new TruffleFromLibGraalCalls(env, peer); } @TruffleFromLibGraal(GetPartialEvaluationMethodInfo) @Override public PartialEvaluationMethodInfo getPartialEvaluationMethodInfo(ResolvedJavaMethod method) { long methodHandle = LibGraal.translate(method); - JByteArray hsByteArray = HSTruffleCompilerRuntimeGen.callGetPartialEvaluationMethodInfo(env(), getHandle(), methodHandle); + JByteArray hsByteArray = HSTruffleCompilerRuntimeGen.callGetPartialEvaluationMethodInfo(calls, env(), getHandle(), methodHandle); CCharPointer buffer = StackValue.get(5); JNIUtil.GetByteArrayRegion(env(), hsByteArray, 0, 5, buffer); BinaryInput in = BinaryInput.create(buffer, 5); @@ -120,7 +124,7 @@ public PartialEvaluationMethodInfo getPartialEvaluationMethodInfo(ResolvedJavaMe @Override public HostMethodInfo getHostMethodInfo(ResolvedJavaMethod method) { long methodHandle = LibGraal.translate(method); - JByteArray hsByteArray = HSTruffleCompilerRuntimeGen.callGetHostMethodInfo(env(), getHandle(), methodHandle); + JByteArray hsByteArray = HSTruffleCompilerRuntimeGen.callGetHostMethodInfo(calls, env(), getHandle(), methodHandle); CCharPointer buffer = StackValue.get(4); JNIUtil.GetByteArrayRegion(env(), hsByteArray, 0, 4, buffer); BinaryInput in = BinaryInput.create(buffer, 4); @@ -141,7 +145,7 @@ public TruffleCompilable asCompilableTruffleAST(JavaConstant constant) { return null; } JObject hsCompilable = JNIUtil.NewLocalRef(scope.getEnv(), LibGraal.getJObjectValue((HotSpotObjectConstant) constant)); - return new HSTruffleCompilable(scope, hsCompilable); + return new HSTruffleCompilable(scope, hsCompilable, this); } @TruffleFromLibGraal(OnCodeInstallation) @@ -149,7 +153,7 @@ public TruffleCompilable asCompilableTruffleAST(JavaConstant constant) { public void onCodeInstallation(TruffleCompilable compilable, InstalledCode installedCode) { long installedCodeHandle = LibGraal.translate(installedCode); JNIEnv env = env(); - callOnCodeInstallation(env, getHandle(), ((HSTruffleCompilable) compilable).getHandle(), installedCodeHandle); + callOnCodeInstallation(calls, env, getHandle(), ((HSTruffleCompilable) compilable).getHandle(), installedCodeHandle); } @TruffleFromLibGraal(RegisterOptimizedAssumptionDependency) @@ -157,14 +161,14 @@ public void onCodeInstallation(TruffleCompilable compilable, InstalledCode insta public Consumer registerOptimizedAssumptionDependency(JavaConstant optimizedAssumption) { long optimizedAssumptionHandle = LibGraal.translate(optimizedAssumption); JNIEnv env = env(); - JObject assumptionConsumer = callRegisterOptimizedAssumptionDependency(env, getHandle(), optimizedAssumptionHandle); - return assumptionConsumer.isNull() ? null : new HSConsumer(scope(), assumptionConsumer); + JObject assumptionConsumer = callRegisterOptimizedAssumptionDependency(calls, env, getHandle(), optimizedAssumptionHandle); + return assumptionConsumer.isNull() ? null : new HSConsumer(scope(), assumptionConsumer, calls); } @TruffleFromLibGraal(IsValueType) @Override public boolean isValueType(ResolvedJavaType type) { - return callIsValueType(env(), getHandle(), LibGraal.translate(type)); + return callIsValueType(calls, env(), getHandle(), LibGraal.translate(type)); } @TruffleFromLibGraal(GetConstantFieldInfo) @@ -189,7 +193,7 @@ public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) { Arrays.toString(declaredFields))); } long typeHandle = LibGraal.translate(enclosingType); - int rawValue = callGetConstantFieldInfo(env(), getHandle(), typeHandle, isStatic, fieldIndex); + int rawValue = callGetConstantFieldInfo(calls, env(), getHandle(), typeHandle, isStatic, fieldIndex); if (rawValue == Integer.MIN_VALUE) { return null; } @@ -229,7 +233,7 @@ public void log(String loggerId, TruffleCompilable compilable, String message) { JNIEnv env = env(); JString jniLoggerId = JNIUtil.createHSString(env, loggerId); JString jniMessage = JNIUtil.createHSString(env, message); - callLog(env, getHandle(), jniLoggerId, ((HSTruffleCompilable) compilable).getHandle(), jniMessage); + callLog(calls, env, getHandle(), jniLoggerId, ((HSTruffleCompilable) compilable).getHandle(), jniMessage); } @TruffleFromLibGraal(CreateStringSupplier) @@ -240,8 +244,8 @@ public boolean isSuppressedFailure(TruffleCompilable compilable, Supplier { + private final TruffleFromLibGraalCalls calls; - HSConsumer(JNIMethodScope scope, JObject handle) { + HSConsumer(JNIMethodScope scope, JObject handle, TruffleFromLibGraalCalls calls) { super(scope, handle); + this.calls = calls; } @TruffleFromLibGraal(ConsumeOptimizedAssumptionDependency) @@ -279,7 +285,7 @@ public void accept(OptimizedAssumptionDependency optimizedDependency) { } installedCode = LibGraal.translate(dependency.getInstalledCode()); } - callConsumeOptimizedAssumptionDependency(env(), getHandle(), compilable, installedCode); + callConsumeOptimizedAssumptionDependency(calls, env(), getHandle(), compilable, installedCode); } } } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalUtil.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalChecker.java similarity index 91% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalUtil.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalChecker.java index 60126df5fcf2..1271ee40f08e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalUtil.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -22,35 +22,23 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.libgraal.jni; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.EnumSet; -import java.util.Objects; import java.util.Set; import org.graalvm.jniutils.JNI; -import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.function.CEntryPoint; -public final class LibGraalUtil { +final class LibGraalChecker { - private LibGraalUtil() { - } - - public static JNIMethodScope openScope(Class entryPointClass, Enum id, JNIEnv env) { - Objects.requireNonNull(id, "Id must be non null."); - return LibGraalJNIMethodScope.open(entryPointClass.getSimpleName() + "::" + id, env); - } - - public static JNIMethodScope openScope(String scopeName, JNIEnv env) { - return LibGraalJNIMethodScope.open(scopeName, env); + private LibGraalChecker() { } /*----------------- CHECKING ------------------*/ diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalNativeBridgeSupport.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalNativeBridgeSupport.java similarity index 82% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalNativeBridgeSupport.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalNativeBridgeSupport.java index ea9c383df087..7a36aca2c4d7 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/jni/LibGraalNativeBridgeSupport.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalNativeBridgeSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -22,13 +22,16 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.libgraal.jni; +package com.oracle.svm.graal.hotspot.libgraal.truffle; + +import java.util.concurrent.atomic.AtomicInteger; -import jdk.vm.ci.services.Services; import org.graalvm.compiler.debug.TTY; +import org.graalvm.compiler.serviceprovider.IsolateUtil; +import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.NativeBridgeSupport; -import java.util.concurrent.atomic.AtomicInteger; +import jdk.vm.ci.services.Services; public final class LibGraalNativeBridgeSupport implements NativeBridgeSupport { @@ -60,7 +63,14 @@ public void trace(String message) { if (!inTrace.get()) { inTrace.set(true); try { - TTY.println(message); + StringBuilder sb = new StringBuilder(); + sb.append('[').append(IsolateUtil.getIsolateID()).append(':').append(Thread.currentThread().getName()).append(']'); + JNIMethodScope scope = JNIMethodScope.scopeOrNull(); + if (scope != null) { + sb.append(" ".repeat(2 + (scope.depth() * 2))); + } + sb.append(message); + TTY.println(sb.toString()); } finally { inTrace.remove(); } @@ -85,4 +95,5 @@ private int traceLevel() { } return res; } + } diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalObjectHandles.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalObjectHandles.java similarity index 93% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalObjectHandles.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalObjectHandles.java index 15ea6afe8fb9..8d5b4ed54947 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalObjectHandles.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalObjectHandles.java @@ -22,15 +22,14 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import org.graalvm.nativeimage.ObjectHandles; import org.graalvm.word.WordFactory; /** * Manages handles to libgraal objects whose lifetime is controlled by - * {@code org.graalvm.compiler.truffle.runtime.hotspot.libgraal.LibGraalObject} instances in the - * HotSpot heap. + * {@code com.oracle.truffle.runtime.hotspot.libgraal.LibGraalObject} instances in the HotSpot heap. */ final class LibGraalObjectHandles { diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironment.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironment.java similarity index 89% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironment.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironment.java index 3d1d859fbc20..c462c2ae8991 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironment.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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 @@ -22,17 +22,18 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import org.graalvm.compiler.core.common.util.MethodKey; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.compiler.truffle.compiler.TruffleElementCache; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; import org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironmentLookup.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironmentLookup.java similarity index 84% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironmentLookup.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironmentLookup.java index f4d990ee893f..86177c3e6463 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/LibGraalTruffleHostEnvironmentLookup.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/LibGraalTruffleHostEnvironmentLookup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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 @@ -22,21 +22,22 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.serviceprovider.GlobalAtomicLong; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; +import org.graalvm.jniutils.JNI.JClass; import org.graalvm.jniutils.JNI.JNIEnv; import org.graalvm.jniutils.JNI.JObject; import org.graalvm.jniutils.JNI.JWeak; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.libgraal.LibGraal; import org.graalvm.word.WordFactory; import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; +import com.oracle.svm.graal.hotspot.libgraal.LibGraal; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.meta.ResolvedJavaType; @@ -82,7 +83,8 @@ public TruffleHostEnvironment lookup(ResolvedJavaType forType) { return environment; } } - ResolvedJavaType runtimeType = LibGraal.asResolvedJavaType(JNIUtil.GetObjectClass(env, runtimeLocalRef)); + JClass runtimeClass = JNIUtil.GetObjectClass(env, runtimeLocalRef); + ResolvedJavaType runtimeType = LibGraal.asResolvedJavaType(runtimeClass); if (runtimeType == null) { throw GraalError.shouldNotReachHere("The object class needs to be available for a Truffle runtime object."); } @@ -90,7 +92,7 @@ public TruffleHostEnvironment lookup(ResolvedJavaType forType) { * We do not currently validate the forType. But in the future we want to lookup the runtime * per type. So in theory multiple truffle runtimes can be loaded. */ - HSTruffleCompilerRuntime runtime = new HSTruffleCompilerRuntime(env, runtimeLocalRef, runtimeType); + HSTruffleCompilerRuntime runtime = new HSTruffleCompilerRuntime(env, runtimeLocalRef, runtimeType, runtimeClass); this.previousRuntime = environment = new LibGraalTruffleHostEnvironment(runtime, HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getMetaAccess()); assert JNIUtil.IsSameObject(env, hsRuntime(environment).getHandle(), runtimeLocalRef); return environment; @@ -100,6 +102,20 @@ private static HSTruffleCompilerRuntime hsRuntime(TruffleHostEnvironment environ return (HSTruffleCompilerRuntime) environment.runtime(); } + static JClass lookupPeer(JNIEnv env) { + long globalReference = WEAK_TRUFFLE_RUNTIME_INSTANCE.get(); + if (globalReference == NO_TRUFFLE_REGISTERED) { + // fast path if Truffle was not initialized + return WordFactory.nullPointer(); + } + JObject runtimeLocalRef = JNIUtil.NewLocalRef(env, WordFactory.pointer(globalReference)); + if (runtimeLocalRef.isNull()) { + // The Truffle runtime was collected by the GC + return WordFactory.nullPointer(); + } + return JNIUtil.GetObjectClass(env, runtimeLocalRef); + } + public static boolean registerRuntime(JNIEnv env, JObject truffleRuntime) { // TODO GR-44222 support multiple runtimes. JWeak globalRuntimeRef = JNIUtil.NewWeakGlobalRef(env, truffleRuntime, ""); diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalCalls.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleFromLibGraalCalls.java similarity index 56% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalCalls.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleFromLibGraalCalls.java index 693e74ae5a3c..509d0eec4f92 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalCalls.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleFromLibGraalCalls.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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 @@ -22,23 +22,31 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; -import org.graalvm.libgraal.jni.FromLibGraalCalls; import org.graalvm.jniutils.JNI.JClass; import org.graalvm.jniutils.JNI.JNIEnv; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id; +import org.graalvm.jniutils.JNI.JObject; + +import static org.graalvm.jniutils.JNIUtil.NewGlobalRef; + +import org.graalvm.jniutils.JNIUtil; + +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id; final class TruffleFromLibGraalCalls extends FromLibGraalCalls { - static final TruffleFromLibGraalCalls INSTANCE = new TruffleFromLibGraalCalls(); + private static final String ENTRY_POINT_CLASS_NAME = "com.oracle.truffle.runtime.hotspot.libgraal.TruffleFromLibGraalEntryPoints"; + private static final String CLASS_ENTRY_POINT_CLASS_NAME = "Class<" + ENTRY_POINT_CLASS_NAME + ">"; - private TruffleFromLibGraalCalls() { - super(Id.class); + TruffleFromLibGraalCalls(JNIEnv env, JClass runtimeClass) { + super(Id.class, resolvePeer(env, runtimeClass)); } - @Override - protected JClass resolvePeer(JNIEnv env) { - return getJNIClass(env, "org.graalvm.compiler.truffle.runtime.hotspot.libgraal.TruffleFromLibGraalEntryPoints"); + private static JClass resolvePeer(JNIEnv env, JClass runtimeClass) { + JObject classLoader = JNIUtil.getClassLoader(env, runtimeClass); + JClass clazz = JNIUtil.findClass(env, classLoader, ENTRY_POINT_CLASS_NAME); + return NewGlobalRef(env, clazz, CLASS_ENTRY_POINT_CLASS_NAME); } + } diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleLibGraalFeature.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalFeature.java similarity index 78% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleLibGraalFeature.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalFeature.java index a67981463b12..1eae250612a4 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleLibGraalFeature.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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 @@ -22,9 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; +package com.oracle.svm.graal.hotspot.libgraal.truffle; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; +import org.graalvm.jniutils.NativeBridgeSupport; +import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; public class TruffleLibGraalFeature implements Feature { @@ -34,4 +36,9 @@ public class TruffleLibGraalFeature implements Feature { public void beforeAnalysis(BeforeAnalysisAccess access) { TruffleHostEnvironment.overrideLookup(new LibGraalTruffleHostEnvironmentLookup()); } + + @Override + public void afterRegistration(AfterRegistrationAccess access) { + ImageSingletons.add(NativeBridgeSupport.class, new LibGraalNativeBridgeSupport()); + } } diff --git a/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalShutdownHook.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalShutdownHook.java new file mode 100644 index 000000000000..7b3dbdc797bc --- /dev/null +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleLibGraalShutdownHook.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023, 2023, 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.graal.hotspot.libgraal.truffle; + +import org.graalvm.compiler.serviceprovider.IsolateUtil; +import org.graalvm.compiler.serviceprovider.ServiceProvider; +import org.graalvm.jniutils.JNI.JClass; +import org.graalvm.jniutils.JNI.JNIEnv; +import org.graalvm.jniutils.JNI.JavaVM; +import org.graalvm.jniutils.JNIUtil; + +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; + +import jdk.vm.ci.hotspot.HotSpotVMEventListener; +import jdk.vm.ci.services.JVMCIServiceLocator; + +@ServiceProvider(JVMCIServiceLocator.class) +public class TruffleLibGraalShutdownHook extends JVMCIServiceLocator { + + private static volatile ShutdownHook registeredHook; + + @Override + protected S getProvider(Class service) { + ShutdownHook hook = registeredHook; + if (hook != null && service == HotSpotVMEventListener.class) { + return service.cast(hook); + } + return null; + } + + static void registerShutdownHook(JNIEnv env, JClass runtimeClass) { + JavaVM vm = JNIUtil.GetJavaVM(env); + ShutdownHook hook = registeredHook; + assert hook == null || hook.javaVm.isNull() || hook.javaVm.equal(vm); + registeredHook = new ShutdownHook(vm, new TruffleFromLibGraalCalls(env, runtimeClass)); + } + + static class ShutdownHook implements HotSpotVMEventListener { + + private final JavaVM javaVm; + private final TruffleFromLibGraalCalls calls; + + ShutdownHook(JavaVM javaVm, TruffleFromLibGraalCalls calls) { + this.javaVm = javaVm; + this.calls = calls; + } + + @Override + @TruffleFromLibGraal(TruffleFromLibGraal.Id.OnIsolateShutdown) + public void notifyShutdown() { + JNIEnv env = JNIUtil.GetEnv(javaVm); + assert env.isNonNull(); + TruffleLibGraalShutdownHookGen.callOnIsolateShutdown(calls, env, IsolateUtil.getIsolateID()); + } + + } + +} diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleToLibGraalEntryPoints.java b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleToLibGraalEntryPoints.java similarity index 68% rename from compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleToLibGraalEntryPoints.java rename to substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleToLibGraalEntryPoints.java index 0fedb969f978..7081626be8f5 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleToLibGraalEntryPoints.java +++ b/substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/TruffleToLibGraalEntryPoints.java @@ -22,28 +22,28 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.truffle.compiler.hotspot.libgraal; - -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.DoCompile; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetCompilerConfigurationFactoryName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetDataPatchesCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetExceptionHandlersCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopoints; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopointsCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetMarksCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeTypes; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetTargetCodeSize; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetTotalFrameSize; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InitializeCompiler; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InitializeRuntime; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleCallBoundaryMethod; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.NewCompiler; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.PendingTransferToInterpreterOffset; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.PurgePartialEvaluationCaches; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.RegisterRuntime; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.Shutdown; +package com.oracle.svm.graal.hotspot.libgraal.truffle; + +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.DoCompile; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetCompilerConfigurationFactoryName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetDataPatchesCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetExceptionHandlersCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopoints; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopointsCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetMarksCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeTypes; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetTargetCodeSize; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetTotalFrameSize; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InitializeCompiler; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InitializeRuntime; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleCallBoundaryMethod; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.NewCompiler; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.PendingTransferToInterpreterOffset; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.PurgePartialEvaluationCaches; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.RegisterRuntime; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.Shutdown; import static org.graalvm.jniutils.JNIUtil.NewObjectArray; import static org.graalvm.jniutils.JNIUtil.SetObjectArrayElement; import static org.graalvm.jniutils.JNIUtil.createHSString; @@ -52,14 +52,7 @@ import org.graalvm.compiler.hotspot.CompilationContext; import org.graalvm.compiler.hotspot.HotSpotGraalServices; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id; +import org.graalvm.compiler.serviceprovider.IsolateUtil; import org.graalvm.compiler.truffle.compiler.TruffleCompilerOptions; import org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilationSupport; import org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl; @@ -72,14 +65,29 @@ import org.graalvm.jniutils.JNIExceptionWrapper; import org.graalvm.jniutils.JNIMethodScope; import org.graalvm.jniutils.JNIUtil; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.jni.FromLibGraalCalls; -import org.graalvm.libgraal.jni.LibGraalUtil; import org.graalvm.nativebridge.BinaryOutput; import org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput; +import org.graalvm.nativeimage.Isolate; +import org.graalvm.nativeimage.IsolateThread; +import org.graalvm.nativeimage.ObjectHandles; import org.graalvm.nativeimage.c.function.CEntryPoint; +import org.graalvm.nativeimage.c.function.CEntryPoint.Builtin; +import org.graalvm.nativeimage.c.function.CEntryPoint.IsolateContext; +import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; +import com.oracle.svm.core.heap.Heap; +import com.oracle.svm.graal.hotspot.libgraal.LibGraal; +import com.oracle.svm.graal.hotspot.libgraal.LibGraalUtil; +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 com.oracle.truffle.compiler.TruffleCompilerOptionDescriptor; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id; + import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -92,9 +100,55 @@ */ final class TruffleToLibGraalEntryPoints { + @CEntryPoint(builtin = Builtin.GET_CURRENT_THREAD, name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_getIsolateThreadIn") + private static native IsolateThread getIsolateThreadIn(PointerBase env, PointerBase hsClazz, @IsolateContext Isolate isolate); + + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_attachThreadTo", builtin = CEntryPoint.Builtin.ATTACH_THREAD) + static native long attachThreadTo(PointerBase env, PointerBase hsClazz, @CEntryPoint.IsolateContext long isolate); + + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_detachThreadFrom", builtin = CEntryPoint.Builtin.DETACH_THREAD) + static native void detachThreadFrom(PointerBase env, PointerBase hsClazz, @CEntryPoint.IsolateThreadContext long isolateThread); + + @SuppressWarnings({"unused"}) + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalObject_releaseHandle") + public static boolean releaseHandle(PointerBase jniEnv, + PointerBase jclass, + @CEntryPoint.IsolateThreadContext long isolateThreadId, + long handle) { + try { + ObjectHandles.getGlobal().destroy(WordFactory.pointer(handle)); + return true; + } catch (Throwable t) { + return false; + } + } + + @SuppressWarnings({"unused"}) + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_LibGraalScope_getIsolateId") + public static long getIsolateId(PointerBase jniEnv, + PointerBase jclass, + @CEntryPoint.IsolateThreadContext long isolateThreadId) { + try { + return IsolateUtil.getIsolateID(); + } catch (Throwable t) { + return 0L; + } + } + + @TruffleToLibGraal(Id.InitializeIsolate) + @SuppressWarnings({"unused", "try"}) + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeIsolate") + public static void initializeIsolate(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JClass runtimeClass) { + try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Id.InitializeIsolate, env)) { + TruffleLibGraalShutdownHook.registerShutdownHook(env, runtimeClass); + } catch (Throwable t) { + JNIExceptionWrapper.throwInHotSpot(env, t); + } + } + @TruffleToLibGraal(RegisterRuntime) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_registerRuntime") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_registerRuntime") public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JObject truffleRuntime) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, RegisterRuntime, env)) { return LibGraalTruffleHostEnvironmentLookup.registerRuntime(env, truffleRuntime); @@ -106,12 +160,12 @@ public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @CEntryPoint.I @TruffleToLibGraal(InitializeRuntime) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeRuntime") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeRuntime") public static long initializeRuntime(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JObject truffleRuntime, JClass hsClassLoaderDelegate) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, InitializeRuntime, env)) { ResolvedJavaType classLoaderDelegate = LibGraal.asResolvedJavaType(hsClassLoaderDelegate); - HSTruffleCompilerRuntime hsTruffleRuntime = new HSTruffleCompilerRuntime(env, truffleRuntime, classLoaderDelegate); + HSTruffleCompilerRuntime hsTruffleRuntime = new HSTruffleCompilerRuntime(env, truffleRuntime, classLoaderDelegate, hsClassLoaderDelegate); long truffleRuntimeHandle = LibGraalObjectHandles.create(hsTruffleRuntime); return truffleRuntimeHandle; } catch (Throwable t) { @@ -122,7 +176,7 @@ public static long initializeRuntime(JNIEnv env, JClass hsClazz, @CEntryPoint.Is @TruffleToLibGraal(NewCompiler) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_newCompiler") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_newCompiler") public static long newCompiler(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, NewCompiler, env)) { HSTruffleCompilerRuntime hsTruffleRuntime = LibGraalObjectHandles.resolve(truffleRuntimeHandle, HSTruffleCompilerRuntime.class); @@ -134,14 +188,19 @@ public static long newCompiler(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateT } } + private static JClass getStringClass(JNIEnv env) { + return JNIUtil.NewGlobalRef(env, JNIUtil.findClass(env, "java/lang/String"), "Class"); + } + @TruffleToLibGraal(InitializeCompiler) @SuppressWarnings("unused") - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeCompiler") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_initializeCompiler") public static void initializeCompiler(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, JObject hsCompilable, boolean firstInitialization) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, InitializeCompiler, env)) { HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class); - TruffleCompilable compilable = new HSTruffleCompilable(s, hsCompilable); + HSTruffleCompilerRuntime runtime = (HSTruffleCompilerRuntime) compiler.getConfig().runtime(); + TruffleCompilable compilable = new HSTruffleCompilable(s, hsCompilable, runtime); compiler.initialize(compilable, firstInitialization); } catch (Throwable t) { JNIExceptionWrapper.throwInHotSpot(env, t); @@ -150,7 +209,7 @@ public static void initializeCompiler(JNIEnv env, JClass hsClazz, @CEntryPoint.I @TruffleToLibGraal(GetCompilerConfigurationFactoryName) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerConfigurationFactoryName") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getCompilerConfigurationFactoryName") public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long truffleRuntimeHandle) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetCompilerConfigurationFactoryName, env); try (JNIMethodScope s = scope) { @@ -165,7 +224,7 @@ public static JString getCompilerConfigurationFactoryName(JNIEnv env, JClass hsC @TruffleToLibGraal(DoCompile) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_doCompile") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_doCompile") public static void doCompile(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, @@ -174,31 +233,24 @@ public static void doCompile(JNIEnv env, JObject hsCompilable, JObject hsListener) { try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, DoCompile, env)) { - HSTruffleCompilable compilable = new HSTruffleCompilable(scope, hsCompilable); - TruffleCompilationTask task = hsTask.isNull() ? null : new HSTruffleCompilationTask(scope, hsTask); + HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class); + HSTruffleCompilerRuntime runtime = (HSTruffleCompilerRuntime) compiler.getConfig().runtime(); + HSTruffleCompilable compilable = new HSTruffleCompilable(scope, hsCompilable, runtime); + TruffleCompilationTask task = hsTask.isNull() ? null : new HSTruffleCompilationTask(scope, hsTask, runtime); try (CompilationContext hotSpotObjectConstantScope = HotSpotGraalServices.openLocalCompilationContext(compilable)) { - HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class); - TruffleCompilerListener listener = hsListener.isNull() ? null : new HSTruffleCompilerListener(scope, hsListener); + TruffleCompilerListener listener = hsListener.isNull() ? null : new HSTruffleCompilerListener(scope, hsListener, runtime); compiler.doCompile(task, compilable, listener); } finally { - doReferenceHandling(); + Heap.getHeap().doReferenceHandling(); } } catch (Throwable t) { JNIExceptionWrapper.throwInHotSpot(env, t); } } - /* - * To avoid reference handling threads in the compiler isolate we explicitly call into reference - * handling after each compilation. - */ - private static void doReferenceHandling() { - // Substituted in LibGraalFeature. - } - @TruffleToLibGraal(Shutdown) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_shutdown") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_shutdown") public static void shutdown(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Shutdown, env)) { HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class); @@ -210,7 +262,7 @@ public static void shutdown(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThre @TruffleToLibGraal(InstallTruffleCallBoundaryMethod) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleCallBoundaryMethod") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleCallBoundaryMethod") public static void installTruffleCallBoundaryMethod(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, long methodHandle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, InstallTruffleCallBoundaryMethod, env)) { HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class); @@ -222,7 +274,7 @@ public static void installTruffleCallBoundaryMethod(JNIEnv env, JClass hsClazz, @TruffleToLibGraal(Id.InstallTruffleReservedOopMethod) @SuppressWarnings({"unused", "try"}) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleReservedOopMethod") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_installTruffleReservedOopMethod") public static void installTruffleReservedOopMethod(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, long methodHandle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Id.InstallTruffleReservedOopMethod, env)) { HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class); @@ -234,11 +286,12 @@ public static void installTruffleReservedOopMethod(JNIEnv env, JClass hsClazz, @ @TruffleToLibGraal(PendingTransferToInterpreterOffset) @SuppressWarnings("unused") - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_pendingTransferToInterpreterOffset") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_pendingTransferToInterpreterOffset") public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JObject hsCompilable) { try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, PendingTransferToInterpreterOffset, env)) { HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(handle, HotSpotTruffleCompilerImpl.class); - TruffleCompilable compilable = new HSTruffleCompilable(scope, hsCompilable); + HSTruffleCompilerRuntime runtime = (HSTruffleCompilerRuntime) compiler.getConfig().runtime(); + TruffleCompilable compilable = new HSTruffleCompilable(scope, hsCompilable, runtime); return compiler.pendingTransferToInterpreterOffset(compilable); } catch (Throwable t) { JNIExceptionWrapper.throwInHotSpot(env, t); @@ -247,7 +300,7 @@ public static int pendingTransferToInterpreterOffset(JNIEnv env, JClass hsClazz, } @TruffleToLibGraal(GetSuppliedString) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getSuppliedString") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getSuppliedString") @SuppressWarnings({"unused", "unchecked", "try"}) public static JString getString(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetSuppliedString, env); @@ -267,7 +320,7 @@ public static JString getString(JNIEnv env, JClass hsClazz, @CEntryPoint.Isolate } @TruffleToLibGraal(GetNodeCount) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeCount") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeCount") @SuppressWarnings({"unused", "try"}) public static int getNodeCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetNodeCount, env)) { @@ -280,14 +333,14 @@ public static int getNodeCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateT } @TruffleToLibGraal(GetNodeTypes) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeTypes") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getNodeTypes") @SuppressWarnings({"unused", "try"}) public static JObjectArray getNodeTypes(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, boolean simpleNames) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetNodeTypes, env); try (JNIMethodScope s = scope) { GraphInfo orig = LibGraalObjectHandles.resolve(handle, GraphInfo.class); String[] nodeTypes = orig.getNodeTypes(simpleNames); - JClass componentType = FromLibGraalCalls.getJNIClass(env, String.class); + JClass componentType = getStringClass(env); JObjectArray res = NewObjectArray(env, nodeTypes.length, componentType, WordFactory.nullPointer()); for (int i = 0; i < nodeTypes.length; i++) { SetObjectArrayElement(env, res, i, JNIUtil.createHSString(env, nodeTypes[i])); @@ -301,7 +354,7 @@ public static JObjectArray getNodeTypes(JNIEnv env, JClass hsClazz, @CEntryPoint } @TruffleToLibGraal(GetTargetCodeSize) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTargetCodeSize") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTargetCodeSize") @SuppressWarnings({"unused", "try"}) public static int getTargetCodeSize(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetTargetCodeSize, env)) { @@ -313,7 +366,7 @@ public static int getTargetCodeSize(JNIEnv env, JClass hsClazz, @CEntryPoint.Iso } @TruffleToLibGraal(GetTotalFrameSize) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTotalFrameSize") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getTotalFrameSize") @SuppressWarnings({"unused", "try"}) public static int getTotalFrameSize(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetTotalFrameSize, env)) { @@ -325,7 +378,7 @@ public static int getTotalFrameSize(JNIEnv env, JClass hsClazz, @CEntryPoint.Iso } @TruffleToLibGraal(GetExceptionHandlersCount) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getExceptionHandlersCount") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getExceptionHandlersCount") @SuppressWarnings({"unused", "try"}) public static int getExceptionHandlersCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetExceptionHandlersCount, env)) { @@ -337,7 +390,7 @@ public static int getExceptionHandlersCount(JNIEnv env, JClass hsClazz, @CEntryP } @TruffleToLibGraal(GetInfopointsCount) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopointsCount") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopointsCount") @SuppressWarnings({"unused", "try"}) public static int getInfopointsCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetInfopointsCount, env)) { @@ -349,13 +402,13 @@ public static int getInfopointsCount(JNIEnv env, JClass hsClazz, @CEntryPoint.Is } @TruffleToLibGraal(GetInfopoints) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopoints") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getInfopoints") @SuppressWarnings({"unused", "try"}) public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetInfopoints, env); try (JNIMethodScope s = scope) { String[] infoPoints = LibGraalObjectHandles.resolve(handle, CompilationResultInfo.class).getInfopoints(); - JClass componentType = FromLibGraalCalls.getJNIClass(env, String.class); + JClass componentType = getStringClass(env); JObjectArray res = NewObjectArray(env, infoPoints.length, componentType, WordFactory.nullPointer()); for (int i = 0; i < infoPoints.length; i++) { SetObjectArrayElement(env, res, i, createHSString(env, infoPoints[i])); @@ -369,7 +422,7 @@ public static JObjectArray getInfopoints(JNIEnv env, JClass hsClazz, @CEntryPoin } @TruffleToLibGraal(Id.ListCompilerOptions) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_listCompilerOptions") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_listCompilerOptions") @SuppressWarnings({"unused", "try"}) public static JByteArray listCompilerOptions(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Id.ListCompilerOptions, env); @@ -398,7 +451,7 @@ public static JByteArray listCompilerOptions(JNIEnv env, JClass hsClazz, @CEntry } @TruffleToLibGraal(Id.CompilerOptionExists) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_compilerOptionExists") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_compilerOptionExists") @SuppressWarnings({"unused", "try"}) public static boolean existsCompilerOption(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JString optionName) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Id.CompilerOptionExists, env); @@ -411,7 +464,7 @@ public static boolean existsCompilerOption(JNIEnv env, JClass hsClazz, @CEntryPo } @TruffleToLibGraal(Id.ValidateCompilerOption) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_validateCompilerOption") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_validateCompilerOption") @SuppressWarnings({"unused", "try"}) public static JString validateCompilerOption(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, JString optionName, JString optionValue) { JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, Id.ValidateCompilerOption, env); @@ -424,7 +477,7 @@ public static JString validateCompilerOption(JNIEnv env, JClass hsClazz, @CEntry } @TruffleToLibGraal(GetMarksCount) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getMarksCount") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getMarksCount") @SuppressWarnings({"unused", "try"}) public static int getMarksCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetMarksCount, env)) { @@ -436,7 +489,7 @@ public static int getMarksCount(JNIEnv env, JClass hsClazz, @CEntryPoint.Isolate } @TruffleToLibGraal(GetDataPatchesCount) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getDataPatchesCount") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_getDataPatchesCount") @SuppressWarnings({"unused", "try"}) public static int getDataPatchesCount(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, GetDataPatchesCount, env)) { @@ -448,7 +501,7 @@ public static int getDataPatchesCount(JNIEnv env, JClass hsClazz, @CEntryPoint.I } @TruffleToLibGraal(PurgePartialEvaluationCaches) - @CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_purgePartialEvaluationCaches") + @CEntryPoint(name = "Java_com_oracle_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_purgePartialEvaluationCaches") @SuppressWarnings({"unused", "try"}) public static void purgePartialEvaluationCaches(JNIEnv env, JClass hsClass, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle) { try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, PurgePartialEvaluationCaches, env)) { @@ -463,8 +516,8 @@ public static void purgePartialEvaluationCaches(JNIEnv env, JClass hsClass, @CEn static { try { - Class callsClass = Class.forName("org.graalvm.compiler.truffle.runtime.hotspot.libgraal.TruffleToLibGraalCalls"); - LibGraalUtil.checkToLibGraalCalls(TruffleToLibGraalEntryPoints.class, callsClass, TruffleToLibGraal.class); + Class callsClass = Class.forName("com.oracle.truffle.runtime.hotspot.libgraal.TruffleToLibGraalCalls"); + LibGraalChecker.checkToLibGraalCalls(TruffleToLibGraalEntryPoints.class, callsClass, TruffleToLibGraal.class); } catch (ClassNotFoundException e) { throw new InternalError(e); } diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java index ca8e5afef144..5bea3b0063b1 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCodeInstallBridge.java @@ -24,11 +24,10 @@ */ package com.oracle.svm.graal.isolated; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; - import com.oracle.svm.core.deopt.SubstrateInstalledCode; import com.oracle.svm.core.util.VMError; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilable; import jdk.vm.ci.code.InstalledCode; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java index ebbd649fd5fa..375eb9f5d58d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java @@ -636,7 +636,9 @@ private void run() { List requiresInit = Arrays.asList( "jdk.internal.vm.ci", "jdk.internal.vm.compiler", "com.oracle.graal.graal_enterprise", - "org.graalvm.sdk", "org.graalvm.truffle"); + "org.graalvm.sdk", "org.graalvm.truffle", "org.graalvm.truffle.runtime", + "org.graalvm.truffle.compiler", "com.oracle.truffle.enterprise", "org.graalvm.jniutils", + "org.graalvm.nativebridge"); for (ModuleReference moduleReference : upgradeAndSystemModuleFinder.findAll()) { if (requiresInit.contains(moduleReference.descriptor().name())) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java index e80ff0afbb99..544e042f3009 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java @@ -224,6 +224,8 @@ private static void transitiveRequires(boolean verbose, Module requiringModule, potentialNeedModule.getName().startsWith("org.graalvm.") || /* enterprise graal */ potentialNeedModule.getName().startsWith("com.oracle.graal.") || + /* exclude all truffle modules */ + potentialNeedModule.getName().startsWith("com.oracle.truffle.") || /* llvm-backend optional dependencies */ potentialNeedModule.getName().startsWith("com.oracle.svm.shadowed.")) { continue; @@ -733,6 +735,9 @@ public static void setModuleAccesses() { ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base", "sun.reflect.annotation"); ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base", "sun.security.jca"); ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "jdk.jdeps", "com.sun.tools.classfile"); + ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "org.graalvm.truffle.runtime"); + ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "org.graalvm.truffle.compiler"); + ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, true, "com.oracle.truffle.enterprise"); } } } diff --git a/substratevm/src/com.oracle.svm.truffle.tck/src/META-INF/native-image/native-image.properties b/substratevm/src/com.oracle.svm.truffle.tck/src/META-INF/native-image/native-image.properties index 48b81adde379..c43b228f5498 100644 --- a/substratevm/src/com.oracle.svm.truffle.tck/src/META-INF/native-image/native-image.properties +++ b/substratevm/src/com.oracle.svm.truffle.tck/src/META-INF/native-image/native-image.properties @@ -11,7 +11,7 @@ JavaArgs = --add-exports org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UN --add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes=ALL-UNNAMED \ --add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java=ALL-UNNAMED \ --add-exports jdk.internal.vm.compiler/org.graalvm.compiler.options=ALL-UNNAMED \ - --add-exports jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime=ALL-UNNAMED \ + --add-exports org.graalvm.truffle.runtime/com.oracle.truffle.runtime=ALL-UNNAMED \ --add-exports jdk.internal.vm.compiler/org.graalvm.util.json=ALL-UNNAMED \ --add-exports jdk.internal.vm.ci/jdk.vm.ci.common=ALL-UNNAMED \ --add-exports jdk.internal.vm.ci/jdk.vm.ci.meta=ALL-UNNAMED diff --git a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java index c75e6603ee4b..feadbaa5e7d8 100644 --- a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java +++ b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java @@ -60,7 +60,6 @@ import org.graalvm.compiler.nodes.java.NewInstanceNode; import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionType; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.polyglot.io.FileSystem; @@ -83,6 +82,7 @@ import com.oracle.svm.hosted.config.ConfigurationParserUtils; import com.oracle.svm.util.ClassUtil; import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.ModifiersProvider; 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 fb002e314526..c4ba776fd3e7 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 @@ -25,11 +25,11 @@ package com.oracle.svm.truffle; import org.graalvm.compiler.debug.GraalError; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier; import com.oracle.svm.core.graal.code.SubstrateCompilationIdentifier; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; public final class SubstrateTruffleCompilationIdentifier extends SubstrateCompilationIdentifier implements TruffleCompilationIdentifier { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleHostEnvironment.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleHostEnvironment.java index fb0de6bf26c3..e5828e4441df 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleHostEnvironment.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/SubstrateTruffleHostEnvironment.java @@ -24,15 +24,16 @@ */ package com.oracle.svm.truffle; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.compiler.truffle.compiler.TruffleElementCache; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; + import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java index 55fb6f3798e5..d29e423942bd 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java @@ -125,7 +125,6 @@ import org.graalvm.compiler.truffle.compiler.host.HostInliningPhase; import org.graalvm.compiler.truffle.compiler.host.TruffleHostEnvironment; import org.graalvm.compiler.truffle.compiler.nodes.asserts.NeverPartOfCompilationNode; -import org.graalvm.compiler.truffle.runtime.TruffleCallBoundary; import org.graalvm.nativeimage.AnnotationAccess; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -175,6 +174,7 @@ import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.nodes.BytecodeOSRNode; import com.oracle.truffle.api.nodes.ExplodeLoop; +import com.oracle.truffle.runtime.TruffleCallBoundary; import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ResolvedJavaField; @@ -436,7 +436,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { DuringAnalysisAccessImpl impl = (DuringAnalysisAccessImpl) acc; /* Pass known reachable classes to the initializer: it will decide there what to do. */ Boolean modified = TruffleBaseFeature.invokeStaticMethod( - "org.graalvm.compiler.truffle.runtime.BytecodeOSRRootNode", + "com.oracle.truffle.runtime.BytecodeOSRRootNode", "initializeClassUsingDeprecatedFrameTransfer", Collections.singleton(Class.class), klass); @@ -1024,8 +1024,8 @@ public void registerGraalPhases(Providers providers, SnippetReflectionProvider s } } -@TargetClass(className = "org.graalvm.compiler.truffle.runtime.OptimizedCallTarget", onlyWith = TruffleFeature.IsEnabled.class) -final class Target_org_graalvm_compiler_truffle_runtime_OptimizedCallTarget { +@TargetClass(className = "com.oracle.truffle.runtime.OptimizedCallTarget", onlyWith = TruffleFeature.IsEnabled.class) +final class Target_com_oracle_truffle_runtime_OptimizedCallTarget { /* * Retry compilation when they failed during image generation. diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java index 2b9d186f67ec..c686f5bd8a48 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleJFRFeature.java @@ -27,15 +27,15 @@ import java.util.Iterator; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; -import org.graalvm.compiler.truffle.jfr.EventFactory; -import org.graalvm.compiler.truffle.jfr.EventFactory.Provider; -import org.graalvm.compiler.truffle.runtime.serviceprovider.TruffleRuntimeServices; import org.graalvm.nativeimage.ImageSingletons; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jfr.JfrFeature; import com.oracle.svm.core.util.UserError; +import com.oracle.truffle.runtime.jfr.EventFactory; +import com.oracle.truffle.runtime.jfr.EventFactory.Provider; +import com.oracle.truffle.runtime.serviceprovider.TruffleRuntimeServices; @AutomaticallyRegisteredFeature public class TruffleJFRFeature implements InternalFeature { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleSupport.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleSupport.java index ec67adc2fddc..8f2aea9a7ffd 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleSupport.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleSupport.java @@ -31,19 +31,12 @@ import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import org.graalvm.compiler.phases.util.Providers; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; import org.graalvm.compiler.truffle.compiler.EconomyPartialEvaluatorConfiguration; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PartialEvaluatorConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.compiler.truffle.compiler.TruffleTierConfiguration; -import org.graalvm.compiler.truffle.runtime.BackgroundCompileQueue; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.OptimizedAssumption; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -65,6 +58,13 @@ import com.oracle.svm.util.ReflectionUtil; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.utilities.TriState; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.runtime.BackgroundCompileQueue; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedAssumption; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; import jdk.vm.ci.meta.JavaConstant; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateCompilableTruffleAST.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateCompilableTruffleAST.java index 3b6c28d7db75..6b17e9dd0d91 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateCompilableTruffleAST.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateCompilableTruffleAST.java @@ -24,10 +24,9 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.TruffleCompilable; - import com.oracle.svm.core.deopt.SubstrateInstalledCode; import com.oracle.svm.graal.meta.SubstrateCodeCacheProvider; +import com.oracle.truffle.compiler.TruffleCompilable; import jdk.vm.ci.code.InstalledCode; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateFastThreadLocal.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateFastThreadLocal.java index a39dcd4e284b..bce05f40b04c 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateFastThreadLocal.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateFastThreadLocal.java @@ -24,7 +24,6 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.runtime.GraalFastThreadLocal; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -32,8 +31,9 @@ import com.oracle.svm.core.threadlocal.FastThreadLocal; import com.oracle.svm.core.threadlocal.FastThreadLocalFactory; import com.oracle.svm.core.threadlocal.FastThreadLocalObject; +import com.oracle.truffle.runtime.OptimizedFastThreadLocal; -final class SubstrateFastThreadLocal extends GraalFastThreadLocal { +final class SubstrateFastThreadLocal extends OptimizedFastThreadLocal { static final SubstrateFastThreadLocal SINGLETON = new SubstrateFastThreadLocal(); private static final FastThreadLocalObject CONTEXT = FastThreadLocalFactory.createObject(Object[].class, "SubstrateFastThreadLocal.CONTEXT") diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateKnownTruffleTypes.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateKnownTruffleTypes.java index 33d969ff7fbc..941f8702b1cc 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateKnownTruffleTypes.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateKnownTruffleTypes.java @@ -24,10 +24,10 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.KnownTruffleTypes; import com.oracle.graal.pointsto.meta.AnalysisType; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.MetaAccessProvider; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTarget.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTarget.java index 8d8afca98e4b..5a9948f633d8 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTarget.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTarget.java @@ -24,8 +24,6 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; import org.graalvm.nativeimage.c.function.CFunctionPointer; import com.oracle.svm.core.Uninterruptible; @@ -34,6 +32,8 @@ import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.truffle.TruffleSupport; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedCallTarget; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.meta.SpeculationLog; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTargetInstalledCode.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTargetInstalledCode.java index 56d0d81a1956..9bf3bf161c67 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTargetInstalledCode.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateOptimizedCallTargetInstalledCode.java @@ -27,8 +27,6 @@ import java.lang.ref.WeakReference; import org.graalvm.compiler.core.common.CompilationIdentifier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; import org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl; import org.graalvm.word.WordFactory; @@ -43,6 +41,8 @@ import com.oracle.svm.core.deopt.SubstrateSpeculationLog; import com.oracle.svm.core.thread.VMOperation; import com.oracle.svm.core.util.VMError; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilable; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java index 3dac3f287863..88f80291f188 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java @@ -40,8 +40,6 @@ import org.graalvm.compiler.phases.util.Providers; import org.graalvm.compiler.replacements.PEGraphDecoder; import org.graalvm.compiler.replacements.PEGraphDecoder.SpecialCallTargetCacheKey; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.PartialEvaluatorConfiguration; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; @@ -49,6 +47,9 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; + import jdk.vm.ci.meta.ResolvedJavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilationSupport.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilationSupport.java index 61a0117d34fc..b765a9e3e827 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilationSupport.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilationSupport.java @@ -24,8 +24,6 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.compiler.truffle.compiler.AbstractTruffleCompilationSupport; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -33,6 +31,8 @@ import com.oracle.svm.core.graal.GraalConfiguration; import com.oracle.svm.truffle.TruffleSupport; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; /** * Represents a truffle compilation bundling compilable and task into a single object. Also installs diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompiler.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompiler.java index f9c398e10f72..ecc281aabfd6 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompiler.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompiler.java @@ -24,12 +24,13 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.TruffleCompiler; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.phases.TruffleTier; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.truffle.compiler.TruffleCompiler; + public interface SubstrateTruffleCompiler extends TruffleCompiler { @Platforms(Platform.HOSTED_ONLY.class) diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilerImpl.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilerImpl.java index 30f437d48876..c4b098b32e23 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilerImpl.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleCompilerImpl.java @@ -36,8 +36,6 @@ import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.tiers.HighTierContext; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier; import org.graalvm.compiler.truffle.compiler.TruffleCompilerConfiguration; @@ -55,6 +53,8 @@ import com.oracle.svm.graal.SubstrateGraalUtils; import com.oracle.svm.truffle.SubstrateTruffleCompilationIdentifier; import com.oracle.svm.truffle.TruffleSupport; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; import jdk.vm.ci.code.InstalledCode; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleField.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleField.java index 5111f3b66b07..1535679ebf17 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleField.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleField.java @@ -24,13 +24,13 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import com.oracle.graal.pointsto.meta.AnalysisField; import com.oracle.svm.core.util.HostedStringDeduplication; import com.oracle.svm.graal.meta.SubstrateField; +import com.oracle.truffle.compiler.ConstantFieldInfo; public class SubstrateTruffleField extends SubstrateField implements TruffleField { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleMethod.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleMethod.java index a982aa520664..aa185b22b116 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleMethod.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleMethod.java @@ -24,13 +24,13 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import com.oracle.graal.pointsto.meta.AnalysisMethod; import com.oracle.svm.core.util.HostedStringDeduplication; import com.oracle.svm.graal.meta.SubstrateMethod; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; public class SubstrateTruffleMethod extends SubstrateMethod implements TruffleMethod { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java index d06e6e778ec1..2144ce1905eb 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java @@ -34,19 +34,6 @@ import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.options.Option; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.BackgroundCompileQueue; -import org.graalvm.compiler.truffle.runtime.CompilationTask; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platform.HOSTED_ONLY; @@ -73,6 +60,19 @@ import com.oracle.truffle.api.impl.ThreadLocalHandshake; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.utilities.TriState; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.BackgroundCompileQueue; +import com.oracle.truffle.runtime.CompilationTask; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.stack.StackIntrospection; @@ -103,7 +103,7 @@ static boolean isMultiThreaded() { } } -public final class SubstrateTruffleRuntime extends GraalTruffleRuntime { +public final class SubstrateTruffleRuntime extends OptimizedTruffleRuntime { private static final int DEBUG_TEAR_DOWN_TIMEOUT = 2_000; private static final int PRODUCTION_TEAR_DOWN_TIMEOUT = 10_000; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleUniverseFactory.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleUniverseFactory.java index 99f52dd4d19c..35d30e6452a3 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleUniverseFactory.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleUniverseFactory.java @@ -27,9 +27,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -40,6 +37,9 @@ import com.oracle.svm.graal.meta.SubstrateField; import com.oracle.svm.graal.meta.SubstrateMethod; import com.oracle.svm.graal.meta.SubstrateUniverseFactory; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleBoundaryPhase.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleBoundaryPhase.java index 8cd87af6e700..83fb3b6c75a6 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleBoundaryPhase.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleBoundaryPhase.java @@ -32,11 +32,11 @@ import org.graalvm.compiler.nodes.java.ExceptionObjectNode; import org.graalvm.compiler.nodes.util.GraphUtil; import org.graalvm.compiler.phases.Phase; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime.InlineKind; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import com.oracle.svm.hosted.phases.SubstrateGraphBuilderPhase.SubstrateBytecodeParser; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.compiler.TruffleCompilerRuntime.InlineKind; import jdk.vm.ci.meta.DeoptimizationAction; import jdk.vm.ci.meta.DeoptimizationReason; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleField.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleField.java index 2f3d34d7f1ab..58e63c394244 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleField.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleField.java @@ -24,7 +24,7 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; +import com.oracle.truffle.compiler.ConstantFieldInfo; public interface TruffleField { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleMethod.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleMethod.java index f4579b91cf13..063c15e2a31e 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleMethod.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/TruffleMethod.java @@ -24,7 +24,7 @@ */ package com.oracle.svm.truffle.api; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; public interface TruffleMethod { diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryInput.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryInput.java similarity index 94% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryInput.java rename to substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryInput.java index 57fff7551577..f5ca95856086 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryInput.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryInput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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 @@ -22,37 +22,32 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.nativebridge; - -import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.c.type.CTypeConversion; +package com.oracle.svm.truffle.isolated; + +import static com.oracle.svm.truffle.isolated.BinaryOutput.ARRAY; +import static com.oracle.svm.truffle.isolated.BinaryOutput.BOOLEAN; +import static com.oracle.svm.truffle.isolated.BinaryOutput.BYTE; +import static com.oracle.svm.truffle.isolated.BinaryOutput.CHAR; +import static com.oracle.svm.truffle.isolated.BinaryOutput.DOUBLE; +import static com.oracle.svm.truffle.isolated.BinaryOutput.FLOAT; +import static com.oracle.svm.truffle.isolated.BinaryOutput.INT; +import static com.oracle.svm.truffle.isolated.BinaryOutput.LARGE_STRING_TAG; +import static com.oracle.svm.truffle.isolated.BinaryOutput.LONG; +import static com.oracle.svm.truffle.isolated.BinaryOutput.NULL; +import static com.oracle.svm.truffle.isolated.BinaryOutput.SHORT; +import static com.oracle.svm.truffle.isolated.BinaryOutput.STRING; +import static com.oracle.svm.truffle.isolated.BinaryOutput.bufferSize; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import static org.graalvm.nativebridge.BinaryOutput.LARGE_STRING_TAG; -import static org.graalvm.nativebridge.BinaryOutput.NULL; -import static org.graalvm.nativebridge.BinaryOutput.BYTE; -import static org.graalvm.nativebridge.BinaryOutput.BOOLEAN; -import static org.graalvm.nativebridge.BinaryOutput.SHORT; -import static org.graalvm.nativebridge.BinaryOutput.CHAR; -import static org.graalvm.nativebridge.BinaryOutput.INT; -import static org.graalvm.nativebridge.BinaryOutput.LONG; -import static org.graalvm.nativebridge.BinaryOutput.FLOAT; -import static org.graalvm.nativebridge.BinaryOutput.DOUBLE; -import static org.graalvm.nativebridge.BinaryOutput.STRING; -import static org.graalvm.nativebridge.BinaryOutput.ARRAY; -import static org.graalvm.nativebridge.BinaryOutput.bufferSize; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; /** - * A buffer used by the {@link BinaryMarshaller} to unmarshal parameters and results passed by - * value. - * - * @see BinaryOutput - * @see BinaryMarshaller - * @see JNIConfig.Builder#registerMarshaller(Class, BinaryMarshaller) + * Copy from native-bridge to avoid depenency from now. Keep in sync with native-bridge. */ -public abstract class BinaryInput { +abstract class BinaryInput { private static final int EOF = -1; @@ -295,7 +290,7 @@ public final String readUTF() throws IndexOutOfBoundsException, IllegalArgumentE } c2 = tempEncodingByteBuffer[byteCount - 1]; if ((c2 & 0xC0) != 0x80) { - throw new IllegalArgumentException("malformed input around byte " + byteCount); + throw new IllegalArgumentException("Malformed input around byte " + byteCount); } tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F)); break; @@ -303,18 +298,18 @@ public final String readUTF() throws IndexOutOfBoundsException, IllegalArgumentE /* 1110 xxxx 10xx xxxx 10xx xxxx */ byteCount += 3; if (byteCount > len) { - throw new IllegalArgumentException("malformed input: partial character at end"); + throw new IllegalArgumentException("Malformed input: partial character at end"); } c2 = tempEncodingByteBuffer[byteCount - 2]; c3 = tempEncodingByteBuffer[byteCount - 1]; if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) { - throw new IllegalArgumentException("malformed input around byte " + (byteCount - 1)); + throw new IllegalArgumentException("Malformed input around byte " + (byteCount - 1)); } tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); break; default: /* 10xx xxxx, 1111 xxxx */ - throw new IllegalArgumentException("malformed input around byte " + byteCount); + throw new IllegalArgumentException("Malformed input around byte " + byteCount); } } // The number of chars produced may be less than len diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryOutput.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryOutput.java similarity index 97% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryOutput.java rename to substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryOutput.java index 898224bdfc2f..8c251b193196 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/nativebridge/BinaryOutput.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/BinaryOutput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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 @@ -22,27 +22,22 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.nativebridge; - -import org.graalvm.nativebridge.JNIConfig.Builder; -import org.graalvm.nativeimage.UnmanagedMemory; -import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.word.WordFactory; +package com.oracle.svm.truffle.isolated; import java.io.Closeable; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Objects; +import org.graalvm.nativeimage.UnmanagedMemory; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.word.WordFactory; + /** - * A buffer used by the {@link BinaryMarshaller} to marshall parameters and results passed by value. - * - * @see BinaryInput - * @see BinaryMarshaller - * @see Builder#registerMarshaller(Class, BinaryMarshaller) + * Copy from native-bridge to avoid depenency from now. Keep in sync with native-bridge. */ -public abstract class BinaryOutput { +abstract class BinaryOutput { /** * Maximum string length for string encoded by 4 bytes length followed be content. @@ -53,7 +48,6 @@ public abstract class BinaryOutput { */ private static final int MAX_SHORT_LENGTH = Short.MAX_VALUE; /** - * Tag to distinguish between long and short string. The tag is set in the first string length * byte. */ static final int LARGE_STRING_TAG = 1 << 7; @@ -590,7 +584,7 @@ public void write(int b) { public void write(byte[] b, int off, int len) { checkClosed(); if ((off | len | b.length) < 0 || b.length - off < len) { - throw new IndexOutOfBoundsException("offset: " + off + ", length: " + len + ", array length: " + b.length); + throw new IndexOutOfBoundsException("Offset: " + off + ", length: " + len + ", array length: " + b.length); } ensureCapacity(pos + len); if (len > BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD) { 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 4e9ad0fc520b..e90b6a0904f3 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 @@ -31,9 +31,6 @@ import org.graalvm.compiler.core.common.CompilationIdentifier; import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.nodes.PauseNode; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; import org.graalvm.compiler.truffle.compiler.PartialEvaluator; import org.graalvm.compiler.truffle.compiler.TruffleCompilation; import org.graalvm.compiler.truffle.compiler.phases.TruffleTier; @@ -65,6 +62,9 @@ import com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST; import com.oracle.svm.truffle.api.SubstrateTruffleCompiler; import com.oracle.svm.truffle.api.SubstrateTruffleCompilerImpl; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerListener; public class IsolateAwareTruffleCompiler implements SubstrateTruffleCompiler { private static final Word ISOLATE_INITIALIZING = WordFactory.signed(-1); diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java index a566384e7640..91bece15a676 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java @@ -29,10 +29,6 @@ import java.util.function.Supplier; import org.graalvm.compiler.debug.GraalError; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.nativebridge.BinaryInput; -import org.graalvm.nativebridge.BinaryOutput; -import org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; @@ -50,6 +46,8 @@ import com.oracle.svm.graal.isolated.IsolatedObjectProxy; import com.oracle.svm.graal.isolated.IsolatedSpeculationLog; import com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST; +import com.oracle.svm.truffle.isolated.BinaryOutput.ByteArrayBinaryOutput; +import com.oracle.truffle.compiler.TruffleCompilable; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.meta.JavaConstant; 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 f3ce1054cd96..b2619834fa50 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 @@ -25,8 +25,6 @@ package com.oracle.svm.truffle.isolated; import org.graalvm.compiler.core.common.CompilationIdentifier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; import org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier; import org.graalvm.nativeimage.c.function.CEntryPoint; @@ -36,6 +34,8 @@ import com.oracle.svm.graal.isolated.IsolatedCompileClient; import com.oracle.svm.graal.isolated.IsolatedCompileContext; import com.oracle.svm.graal.isolated.IsolatedObjectProxy; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; final class IsolatedTruffleCompilationIdentifier extends IsolatedObjectProxy implements TruffleCompilationIdentifier { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationTask.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationTask.java index 2fb79f6c106f..bedccd6bdd4b 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationTask.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleCompilationTask.java @@ -28,12 +28,6 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; -import org.graalvm.nativebridge.BinaryInput; -import org.graalvm.nativebridge.BinaryOutput; -import org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.type.CCharPointer; import org.graalvm.nativeimage.c.type.CTypeConversion; @@ -49,6 +43,10 @@ import com.oracle.svm.graal.isolated.IsolatedObjectConstant; import com.oracle.svm.graal.isolated.IsolatedObjectProxy; import com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST; +import com.oracle.svm.truffle.isolated.BinaryOutput.ByteArrayBinaryOutput; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; import jdk.vm.ci.meta.JavaConstant; 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 9feef18a948a..db16ae8ae9a3 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,11 +24,6 @@ */ package com.oracle.svm.truffle.isolated; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; import org.graalvm.nativeimage.StackValue; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.struct.RawField; @@ -44,6 +39,11 @@ import com.oracle.svm.graal.isolated.CompilerIsolateThread; import com.oracle.svm.graal.isolated.IsolatedCompileClient; import com.oracle.svm.graal.isolated.IsolatedCompileContext; +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; final class IsolatedTruffleCompilerEventForwarder implements TruffleCompilerListener { private final ClientHandle contextHandle; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleRuntimeSupport.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleRuntimeSupport.java index 64b59f8eb2bc..a0146fe72d13 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleRuntimeSupport.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleRuntimeSupport.java @@ -27,11 +27,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.runtime.OptimizedAssumption; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; import org.graalvm.nativeimage.c.function.CEntryPoint; import com.oracle.svm.core.deopt.SubstrateInstalledCode; @@ -50,6 +45,11 @@ import com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST; import com.oracle.svm.truffle.api.SubstrateTruffleRuntime; import com.oracle.truffle.api.utilities.TriState; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.runtime.OptimizedAssumption; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; import jdk.vm.ci.meta.JavaConstant; diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleSourceLanguagePosition.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleSourceLanguagePosition.java index 62c949625e72..110198881393 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleSourceLanguagePosition.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedTruffleSourceLanguagePosition.java @@ -27,7 +27,6 @@ import java.net.URI; import java.net.URISyntaxException; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; import org.graalvm.nativeimage.c.function.CEntryPoint; import com.oracle.svm.core.util.VMError; @@ -38,6 +37,7 @@ import com.oracle.svm.graal.isolated.IsolatedCompileContext; import com.oracle.svm.graal.isolated.IsolatedHandles; import com.oracle.svm.graal.isolated.IsolatedObjectProxy; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; final class IsolatedTruffleSourceLanguagePosition extends IsolatedObjectProxy implements TruffleSourceLanguagePosition { private final int lineNumber; diff --git a/tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/EnginesGCedTest.java b/tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/EnginesGCedTest.java index e5db7c524d8b..2eff548caba0 100644 --- a/tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/EnginesGCedTest.java +++ b/tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/EnginesGCedTest.java @@ -81,7 +81,7 @@ void checkCollected() { for (Thread t : threads) { if (t != null) { if (!threadIDs.contains(getThreadId(t))) { - if (t.getClass().getPackage().getName().startsWith("org.graalvm.compiler")) { + if (t.getClass().getPackage().getName().startsWith("com.oracle.truffle.runtime")) { // A compiler thread continue; } diff --git a/truffle/docs/HostCompilation.md b/truffle/docs/HostCompilation.md index 1719bae5058f..02bd63d0b0f5 100644 --- a/truffle/docs/HostCompilation.md +++ b/truffle/docs/HostCompilation.md @@ -178,7 +178,7 @@ This prints: CUTOFF org.graalvm.compiler.truffle.test.HostInliningBytecodeInterpreterExampleTest$BytecodeNode.protectedByInIntepreter() [inlined -1, monomorphic false, deopt false, inInterpreter true, propDeopt false, subTreeInvokes 1, subTreeCost 0, incomplete false, reason protected by inInterpreter()] INLINE com.oracle.truffle.api.CompilerDirectives.transferToInterpreterAndInvalidate() [inlined 3, monomorphic false, deopt true, inInterpreter false, propDeopt false, subTreeInvokes 0, subTreeCost 32, incomplete false, reason null] INLINE com.oracle.truffle.api.CompilerDirectives.inInterpreter() [inlined 3, monomorphic false, deopt true, inInterpreter false, propDeopt false, subTreeInvokes 0, subTreeCost 6, incomplete false, reason null] - CUTOFF org.graalvm.compiler.truffle.runtime.hotspot.AbstractHotSpotTruffleRuntime.traceTransferToInterpreter() [inlined -1, monomorphic false, deopt true, inInterpreter true, propDeopt false, subTreeInvokes 0, subTreeCost 0, incomplete false, reason dominated by transferToInterpreter()] + CUTOFF com.oracle.truffle.runtime.hotspot.AbstractHotSpotTruffleRuntime.traceTransferToInterpreter() [inlined -1, monomorphic false, deopt true, inInterpreter true, propDeopt false, subTreeInvokes 0, subTreeCost 0, incomplete false, reason dominated by transferToInterpreter()] CUTOFF org.graalvm.compiler.truffle.test.HostInliningBytecodeInterpreterExampleTest$BytecodeNode.dominatedByTransferToInterpreter() [inlined -1, monomorphic false, deopt true, inInterpreter false, propDeopt false, subTreeInvokes 0, subTreeCost 0, incomplete false, reason dominated by transferToInterpreter()] INLINE org.graalvm.compiler.truffle.test.HostInliningBytecodeInterpreterExampleTest$BytecodeNode.recursive(int) [inlined 4, monomorphic false, deopt false, inInterpreter false, propDeopt false, subTreeInvokes 1, subTreeCost 20, incomplete false, reason null] CUTOFF org.graalvm.compiler.truffle.test.HostInliningBytecodeInterpreterExampleTest$BytecodeNode.recursive(int) [inlined -1, monomorphic false, deopt false, inInterpreter false, propDeopt false, subTreeInvokes 1, subTreeCost 0, incomplete false, reason recursive] diff --git a/truffle/docs/Optimizing.md b/truffle/docs/Optimizing.md index de3170fdb5b8..ffd232b9f174 100644 --- a/truffle/docs/Optimizing.md +++ b/truffle/docs/Optimizing.md @@ -149,8 +149,8 @@ The `store` enables warnings when the store location argument is not a partial e at com.oracle.truffle.js.nodes.function.FunctionBodyNode.execute(FunctionBodyNode.java:73) at com.oracle.truffle.js.nodes.function.FunctionRootNode.executeInRealm(FunctionRootNode.java:147) at com.oracle.truffle.js.runtime.JavaScriptRealmBoundaryRootNode.execute(JavaScriptRealmBoundaryRootNode.java:93) - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:503) - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:480) + at com.oracle.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:503) + at com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:480) ``` The `--engine.CompilationStatistics` command prints statistics on compilations at the end of the process: @@ -571,8 +571,8 @@ This is often the most efficient way to find where a deoptimization comes from t at org.truffleruby.core.string.StringNodes$GetIndexNode.getIndex(StringNodes.java:650) at org.truffleruby.core.string.StringNodesFactory$GetIndexNodeFactory$GetIndexNodeGen.execute(StringNodesFactory.java:1435) at org.truffleruby.language.RubyCoreMethodRootNode.execute(RubyCoreMethodRootNode.java:53) - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:632) - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:603) + at com.oracle.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:632) + at com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:603) [Deoptimization of frame name: String#[] sp: 0x7ffd7b992710 ip: 0x7f26a8d8079f @@ -582,8 +582,8 @@ This is often the most efficient way to find where a deoptimization comes from t at org.truffleruby.core.string.StringNodes$GetIndexNode.getIndex(StringNodes.java:650) bci 25 duringCall return address 0x415f197 at org.truffleruby.core.string.StringNodesFactory$GetIndexNodeFactory$GetIndexNodeGen.execute(StringNodesFactory.java:1435) bci 109 duringCall return address 0x4182391 at org.truffleruby.language.RubyCoreMethodRootNode.execute(RubyCoreMethodRootNode.java:53) bci 14 duringCall return address 0x4239a29 - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:632) bci 9 duringCall return address 0x3f1c4c9 - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:603) bci 37 duringCall return address 0x3f1d965 + at com.oracle.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:632) bci 9 duringCall return address 0x3f1c4c9 + at com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:603) bci 37 duringCall return address 0x3f1d965 ] ] ``` @@ -616,7 +616,7 @@ The `TraceDeoptimization` option might require using a `fastdebug` JDK. ```shell Uncommon trap bci=9 pc=0x00000001097f2235, relative_pc=501, method=com.oracle.truffle.js.nodes.access.PropertyNode.executeInt(Ljava/lang/Object;Ljava/lang/Object;)I, debug_id=0 -Uncommon trap occurred in org.graalvm.compiler.truffle.runtime.OptimizedCallTarget::profiledPERoot compiler=JVMCI compile_id=2686 (JVMCI: installed code name=BinaryConstraint.output#2) (@0x00000001097f2235) thread=5891 reason=transfer_to_interpreter action=reinterpret unloaded_class_index=-1 debug_id=0 +Uncommon trap occurred in com.oracle.truffle.runtime.OptimizedCallTarget::profiledPERoot compiler=JVMCI compile_id=2686 (JVMCI: installed code name=BinaryConstraint.output#2) (@0x00000001097f2235) thread=5891 reason=transfer_to_interpreter action=reinterpret unloaded_class_index=-1 debug_id=0 ``` Finally, on native images, `--vm.XX:+TraceDeoptimizationDetails` prints additional information: @@ -631,8 +631,8 @@ Finally, on native images, `--vm.XX:+TraceDeoptimizationDetails` prints addition name: BinaryConstraint.output sp: 0x7ffee7324d90 ip: 0x1126c51a8 stack trace where execution continues: - at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:475) bci 0 return address 0x10aab9e5e - org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:475) + at com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:475) bci 0 return address 0x10aab9e5e + com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:475) bci: 0 deoptMethodOffset: 35524160 deoptMethod: 0x10aab9e40 return address: 0x10aab9e5e offset: 0 slot 0 kind: Object value: com.oracle.svm.truffle.api.SubstrateOptimizedCallTarget@0x112cbbaa0 offset: 64 slot 1 kind: Object value: [Ljava.lang.Object;@0x1144a7db0 offset: 56 diff --git a/truffle/docs/TraversingCompilationQueue.md b/truffle/docs/TraversingCompilationQueue.md index cf21a618561f..f009e984b778 100644 --- a/truffle/docs/TraversingCompilationQueue.md +++ b/truffle/docs/TraversingCompilationQueue.md @@ -13,7 +13,7 @@ This document gives motivation and an overview of this approach. During execution of guest code each Truffle call target counts how many times it was executed as well as how many loop iterations happened during those executions (i.e. the target's "call and loop count"). Once this counter reaches a certain threshold the call target is deemed "hot" and scheduled for compilation. -In order to minimize the impact this has on the execution of the guest code the notion that the target should be compiled is made concrete as a [compilation task](https://github.com/oracle/graal/blob/master/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/CompilationTask.java) and placed into a [compilation queue](https://github.com/oracle/graal/blob/master/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BackgroundCompileQueue.java) to await compilation. +In order to minimize the impact this has on the execution of the guest code the notion that the target should be compiled is made concrete as a [compilation task](https://github.com/oracle/graal/blob/master/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationTask.java) and placed into a [compilation queue](https://github.com/oracle/graal/blob/master/compiler/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BackgroundCompileQueue.java) to await compilation. The Truffle runtime spawns several compiler threads (`--engine.CompilerThreads`) that take tasks from the queue and compile the specified call targets. The initial implementation of the compilation queue in Truffle was a straightforward FIFO queue. @@ -48,10 +48,10 @@ Using a FIFO queue, we would compile the `lowUsage` function first, even though ## Traversing Compilation Queue -The new compilation queue in Truffle, colloquially called ["Traversing Compilation Queue"](https://github.com/oracle/graal/blob/master/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TraversingBlockingQueue.java), takes a more dynamic approach to selecting the order in which targets are compiled. +The new compilation queue in Truffle, colloquially called ["Traversing Compilation Queue"](https://github.com/oracle/graal/blob/master/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TraversingBlockingQueue.java), takes a more dynamic approach to selecting the order in which targets are compiled. Every time a compiler thread requests the next compilation task the queue will traverse all the entries in the queue and pick the one with the highest priority. -A task's priority is [determined based on several factors](https://github.com/oracle/graal/blob/master/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/hotspot/CompilationTask.java#L209). +A task's priority is [determined based on several factors](https://github.com/oracle/graal/blob/master/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationTask.java#L209). For starters, targets scheduled for [first-tier compilation](https://medium.com/graalvm/multi-tier-compilation-in-graalvm-5fbc65f92402) (i.e. first-tier tasks) always have higher priority than second-tier tasks. The rational behind this is that performance difference between executing code in the interpreter and executing it in first-tier compiled code is much greater then the difference between tier-one and tier-two compiled code, meaning that we get more benefit from compiling these targets sooner. @@ -78,7 +78,7 @@ One problem of the traversing compilation queue is that it needs to traverse all This does not have a significant performance impact as long as the size of the queue remains reasonable. This means that in order to always choose the highest priority task in a reasonable about of time we need to ensure that the queue does not grow indefinitely. -This is achieved by an approach we call ["dynamic compilation thresholds"](https://github.com/oracle/graal/blob/master/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DynamicThresholdsQueue.java). +This is achieved by an approach we call ["dynamic compilation thresholds"](https://github.com/oracle/graal/blob/master/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DynamicThresholdsQueue.java). Simply put, dynamic compilation thresholds means that the compilation threshold (the one each call target's call and loop count is compared against when determining whether to compile it) may change over time depending on the state of the queue. If the queue is overloaded we aim to increase the compilation thresholds to reduce the number of incoming compilation tasks, i.e. targets need to be "more hot" to get scheduled for compilation. On the other hand, if the queue is close to empty, we can reduce the compilation thresholds to allow more targets to get scheduled for compilation, i.e. the compilation threads are in danger of idling so let's give them even "less hot" targets to compile. diff --git a/truffle/docs/splitting/Splitting.md b/truffle/docs/splitting/Splitting.md index 35e626ca1a86..8067b91739b3 100644 --- a/truffle/docs/splitting/Splitting.md +++ b/truffle/docs/splitting/Splitting.md @@ -28,7 +28,7 @@ re-profiled specifically for this call site, since it is the only call site call Following recursive algorithm (expressed as pseudo code) is a simplified version of the approach used to decide which call targets need to be marked "needs split". This algorithm is applied to every call target once one of its nodes reports a polymorphic specialization. -The full implementation can be found in `org.graalvm.compiler.truffle.runtime.OptimizedCallTarget#maybeSetNeedsSplit`. +The full implementation can be found in `com.oracle.truffle.runtime.OptimizedCallTarget#maybeSetNeedsSplit`. ```java setNeedsSplit(callTarget) diff --git a/truffle/mx.truffle/macro-truffle.properties b/truffle/mx.truffle/macro-truffle.properties index 0bad94cf3f5d..d33125463435 100644 --- a/truffle/mx.truffle/macro-truffle.properties +++ b/truffle/mx.truffle/macro-truffle.properties @@ -3,6 +3,8 @@ Args = -H:Features=com.oracle.svm.truffle.TruffleFeature,com.oracle.svm.truffle. -H:MaxRuntimeCompileMethods=2500 \ --initialize-at-build-time=com.oracle.truffle \ --initialize-at-build-time=org.graalvm.shadowed.org.jcodings \ + --initialize-at-build-time=org.graalvm.jniutils \ + --initialize-at-build-time=org.graalvm.nativebridge \ --initialize-at-build-time=com.oracle.truffle.tools.utils.json \ --initialize-at-build-time=org.graalvm.shadowed.org.jline,org.graalvm.shadowed.org.fusesource.jansi \ --initialize-at-run-time=sun.rmi \ @@ -11,6 +13,10 @@ Args = -H:Features=com.oracle.svm.truffle.TruffleFeature,com.oracle.svm.truffle. # The `--add-exports` are a temporary solution for languages on classpath, will be fixed by languages modularization, GR-44217. JavaArgs = -Dtruffle.TruffleRuntime=com.oracle.svm.truffle.api.SubstrateTruffleRuntime \ -Dgraalvm.ForcePolyglotInvalid=false \ + --add-exports com.oracle.truffle.enterprise/com.oracle.truffle.polyglot.enterprise=ALL-UNNAMED \ + --add-exports com.oracle.truffle.enterprise/com.oracle.truffle.runtime.enterprise=ALL-UNNAMED \ + --add-exports org.graalvm.truffle.runtime/com.oracle.truffle.runtime=ALL-UNNAMED \ + --add-exports org.graalvm.truffle.compiler/com.oracle.truffle.compiler=ALL-UNNAMED \ --add-exports org.graalvm.truffle/com.oracle.truffle.api=ALL-UNNAMED \ --add-exports org.graalvm.truffle/com.oracle.truffle.api.debug=ALL-UNNAMED \ --add-exports org.graalvm.truffle/com.oracle.truffle.api.debug.impl=ALL-UNNAMED \ @@ -46,4 +52,4 @@ JavaArgs = -Dtruffle.TruffleRuntime=com.oracle.svm.truffle.api.SubstrateTruffleR --add-exports org.graalvm.truffle/org.graalvm.shadowed.org.jcodings.transcode=ALL-UNNAMED \ --add-exports org.graalvm.truffle/org.graalvm.shadowed.org.jcodings.transcode.specific=ALL-UNNAMED \ --add-exports org.graalvm.truffle/org.graalvm.shadowed.org.jcodings.unicode=ALL-UNNAMED \ - --add-exports org.graalvm.truffle/org.graalvm.shadowed.org.jcodings.util=ALL-UNNAMED + --add-exports org.graalvm.truffle/org.graalvm.shadowed.org.jcodings.util=ALL-UNNAMED diff --git a/truffle/mx.truffle/mx_truffle.py b/truffle/mx.truffle/mx_truffle.py index c9ba9daa3de4..e2f47c458ded 100644 --- a/truffle/mx.truffle/mx_truffle.py +++ b/truffle/mx.truffle/mx_truffle.py @@ -1144,7 +1144,10 @@ def glob_match(path, pattern): jar_distributions=[], jvmci_parent_jars=[ 'truffle:TRUFFLE_API', + 'truffle:TRUFFLE_COMPILER', + 'truffle:TRUFFLE_RUNTIME', ], + support_libraries_distributions=['truffle:TRUFFLE_RUNTIME_ATTACH_SUPPORT'], stability="supported", )) diff --git a/truffle/mx.truffle/suite.py b/truffle/mx.truffle/suite.py index 7977f1fbb6bc..952ba54f9656 100644 --- a/truffle/mx.truffle/suite.py +++ b/truffle/mx.truffle/suite.py @@ -245,6 +245,58 @@ "workingSets" : "API,Truffle", }, + "com.oracle.truffle.runtime" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + "sdk:GRAAL_SDK", + "TRUFFLE_API", + "TRUFFLE_COMPILER", + ], + "requires" : [ + "java.logging", + "jdk.management", + "jdk.jfr", + "jdk.unsupported", # sun.misc.Unsafe + ], + "requiresConcealed" : { + "jdk.internal.vm.ci" : [ + "jdk.vm.ci.meta", + "jdk.vm.ci.services", + "jdk.vm.ci.code", + "jdk.vm.ci.code.stack", + ], + "java.base" : [ + "jdk.internal.module", + ], + }, + "annotationProcessors" : ["TRUFFLE_DSL_PROCESSOR", "TRUFFLE_LIBGRAAL_PROCESSOR"], + "checkstyle" : "com.oracle.truffle.api", + "javaCompliance" : "17+", + "workingSets" : "API,Truffle", + }, + + "com.oracle.truffle.compiler" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + ], + "requires" : [ + "java.logging", + "jdk.management", + "jdk.unsupported", # sun.misc.Unsafe + ], + "requiresConcealed" : { + "jdk.internal.vm.ci" : [ + "jdk.vm.ci.meta", + "jdk.vm.ci.code", + ], + }, + "checkstyle" : "com.oracle.truffle.api", + "javaCompliance" : "17+", + "workingSets" : "API,Truffle", + }, + "com.oracle.truffle.host" : { "subDir" : "src", "sourceDirs" : ["src"], @@ -1037,6 +1089,48 @@ "javac.lint.overrides" : 'none', "jacoco" : "exclude", }, + + "com.oracle.truffle.runtime.attach" : { + "subDir" : "src", + "native" : "shared_lib", + "deliverable" : "truffleattach", + "use_jdk_headers" : True, + "buildDependencies" : [ + ], + "os_arch" : { + "windows" : { + "" : { + "cflags" : ["--std=c++11"] + } + }, + "linux" : { + "" : { + "cflags" : ["--std=c++11", "-g", "-Wall", "-Werror", "-D_GNU_SOURCE"], + "ldlibs" : ["-ldl"], + }, + }, + "" : { + "" : { + "cflags" : ["--std=c++11", "-g", "-Wall", "-Werror"], + "ldlibs" : ["-ldl"], + }, + }, + }, + }, + + "com.oracle.truffle.libgraal.processor" : { + "subDir" : "src", + "sourceDirs" : ["src"], + "dependencies" : [ + "truffle:ANTLR4" + ], + "requires" : [ + "java.compiler", + "jdk.management" + ], + "checkstyle" : "com.oracle.truffle.api", + "javaCompliance" : "17+", + }, }, "licenses" : { @@ -1058,6 +1152,89 @@ } }, + "TRUFFLE_COMPILER" : { + # This distribution defines a module. + "moduleInfo" : { + "name" : "org.graalvm.truffle.compiler", + "requires" : [ + "jdk.unsupported", # sun.misc.Unsafe + "java.logging", + "java.management", + ], + "exports" : [ + # Qualified exports + "com.oracle.truffle.compiler to org.graalvm.truffle.runtime, jdk.internal.vm.compiler, com.oracle.truffle.enterprise, com.oracle.graal.graal_enterprise, org.graalvm.nativeimage.builder", + "com.oracle.truffle.compiler.hotspot to org.graalvm.truffle.runtime, jdk.internal.vm.compiler", + "com.oracle.truffle.compiler.hotspot.libgraal to org.graalvm.truffle.runtime, jdk.internal.vm.compiler" + ], + "uses" : [ + ], + "requiresConcealed" : { + "jdk.internal.vm.ci" : [ + "jdk.vm.ci.meta", + "jdk.vm.ci.code", + ], + }, + }, + + "subDir" : "src", + "javaCompliance" : "17+", + "dependencies" : [ + "com.oracle.truffle.compiler", + ], + "distDependencies" : [ + ], + "description" : "Truffle compiler API.", + "maven": True, + }, + + "TRUFFLE_RUNTIME" : { + # This distribution defines a module. + "moduleInfo" : { + "name" : "org.graalvm.truffle.runtime", + "requires" : [ + "jdk.unsupported", # sun.misc.Unsafe + "java.logging", + "java.management", + ], + "exports" : [ + # Qualified exports + "* to org.graalvm.truffle, jdk.internal.vm.compiler, com.oracle.truffle.enterprise, com.oracle.svm.svm_enterprise, org.graalvm.nativeimage.builder", + ], + "uses" : [ + "com.oracle.truffle.api.impl.TruffleLocator", + "com.oracle.truffle.api.object.LayoutFactory", + "com.oracle.truffle.runtime.LoopNodeFactory", + "com.oracle.truffle.runtime.TruffleTypes", + "com.oracle.truffle.runtime.EngineCacheSupport", + "com.oracle.truffle.runtime.jfr.EventFactory.Provider", + "com.oracle.truffle.runtime.FloodControlHandler", + "org.graalvm.home.HomeFinder", + ], + }, + "requiresConcealed" : { + "jdk.internal.vm.ci" : [ + "jdk.vm.ci.meta", + "jdk.vm.ci.code", + "jdk.vm.ci.code.stack", + "jdk.vm.ci.services", + ], + }, + "subDir" : "src", + "javaCompliance" : "17+", + "dependencies" : [ + "com.oracle.truffle.runtime", + ], + "distDependencies" : [ + "sdk:GRAAL_SDK", + "sdk:JNIUTILS", + "TRUFFLE_API", + "TRUFFLE_COMPILER", + ], + "description" : "Truffle runtime distribution.", + "maven": True, + }, + "TRUFFLE_API" : { # This distribution defines a module. "moduleInfo" : { @@ -1093,8 +1270,8 @@ "com.oracle.truffle.api.library.provider", # Qualified exports - "com.oracle.truffle.api.impl to jdk.internal.vm.compiler, org.graalvm.locator", - "com.oracle.truffle.object to jdk.internal.vm.compiler, com.oracle.graal.graal_enterprise", + "com.oracle.truffle.api.impl to jdk.internal.vm.compiler, org.graalvm.locator, org.graalvm.truffle.runtime, org.graalvm.nativeimage.builder", + "com.oracle.truffle.object to jdk.internal.vm.compiler, com.oracle.truffle.enterprise, org.graalvm.truffle.runtime, org.graalvm.nativeimage.builder", ], "uses" : [ "com.oracle.truffle.api.TruffleRuntimeAccess", @@ -1119,10 +1296,10 @@ "com.oracle.truffle.api.instrumentation.provider", "com.oracle.truffle.api.library.provider", # Qualified exports - "com.oracle.truffle.api* to jdk.internal.vm.compiler, jdk.internal.vm.compiler.truffle.jfr, com.oracle.graal.graal_enterprise, com.oracle.svm.svm_enterprise, org.graalvm.nativeimage.builder", - "com.oracle.truffle.api.impl to org.graalvm.locator", - "com.oracle.truffle.api to org.graalvm.locator, org.graalvm.nativeimage.builder", - "com.oracle.truffle.object to jdk.internal.vm.compiler, com.oracle.graal.graal_enterprise", + "com.oracle.truffle.api* to jdk.internal.vm.compiler, jdk.internal.vm.compiler.truffle.jfr, com.oracle.truffle.enterprise, com.oracle.svm.svm_enterprise, org.graalvm.nativeimage.builder, org.graalvm.truffle.runtime", + "com.oracle.truffle.api.impl to jdk.internal.vm.compiler,org.graalvm.locator, org.graalvm.truffle.runtime, org.graalvm.nativeimage.builder", + "com.oracle.truffle.api to org.graalvm.locator, org.graalvm.nativeimage.builder, org.graalvm.truffle.runtime, org.graalvm.nativeimage.builder", + "com.oracle.truffle.object to jdk.internal.vm.compiler, com.oracle.truffle.enterprise, org.graalvm.truffle.runtime, org.graalvm.nativeimage.builder", ], }, "subDir" : "src", @@ -1152,6 +1329,33 @@ } }, + "TRUFFLE_RUNTIME_ATTACH" : { + "native" : True, + "platformDependent" : True, + "platforms" : [ + "linux-amd64", + "linux-aarch64", + "darwin-amd64", + "darwin-aarch64", + "windows-amd64", + ], + "layout" : { + "bin/" : "dependency:com.oracle.truffle.runtime.attach", + }, + "description" : "Contains a library to provide access for the Truffle runtime to JVMCI.", + "maven": True, + }, + + "TRUFFLE_RUNTIME_ATTACH_SUPPORT" : { + "native" : True, + "platformDependent" : True, + "layout" : { + "./" : ["dependency:com.oracle.truffle.runtime.attach"], + }, + "description" : "Contains a library to provide access for the Truffle runtime to JVMCI.", + "maven" : False, + }, + "TRUFFLE_NFI" : { # This distribution defines a module. "moduleInfo" : { @@ -1299,6 +1503,14 @@ "allowsJavadocWarnings": True, }, + "TRUFFLE_LIBGRAAL_PROCESSOR" : { + "subDir" : "src", + "dependencies" : ["com.oracle.truffle.libgraal.processor"], + "distDependencies" : [], + "description" : "The Truffle libgraal processor is shared across Truffle and the compiler to generate code for the compiler bridge.", + "allowsJavadocWarnings": True, + }, + "TRUFFLE_SL" : { "subDir" : "src", "moduleInfo" : { @@ -1423,6 +1635,7 @@ ], "distDependencies" : [ "TRUFFLE_API", + "TRUFFLE_RUNTIME", "TRUFFLE_SL", "TRUFFLE_TCK_COMMON", "TRUFFLE_TCK_TESTS", diff --git a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LoggingTest.java b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LoggingTest.java index 9c8e429974e1..80137b38e940 100644 --- a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LoggingTest.java +++ b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/LoggingTest.java @@ -1283,7 +1283,7 @@ public void testInterpreterOnlyWarning() { private static boolean hasInterpreterOnlyWarning(Iterable> log) { for (Map.Entry record : log) { String message = record.getValue(); - if (message.startsWith("The polyglot context is using an implementation that does not support runtime compilation.")) { + if (message.startsWith("The polyglot context uses a fallback Truffle implementation that does not support runtime optimization.")) { return true; } } diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java index 0058b3b011d1..258e70f88931 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/Truffle.java @@ -104,41 +104,66 @@ private static TruffleRuntimeAccess selectTruffleRuntimeAccess(List runtimeClass = Class.forName(runtimeClassName, false, cl); + /* + * This path is taken if a truffle runtime class is directly specified. In such case + * we try to export JVMCI to the module of that class. + */ + maybeExportJVMCITo(runtimeClass); + return (TruffleRuntime) runtimeClass.getDeclaredConstructor().newInstance(); + } catch (Throwable e) { + // Fail fast for other errors + throw new InternalError(e); + } + } + + Class lookupClass = Truffle.class; + ModuleLayer moduleLayer = lookupClass.getModule().getLayer(); + TruffleRuntimeAccess access; + if (moduleLayer != null) { + access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(moduleLayer, TruffleRuntimeAccess.class))); + } else { + access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(TruffleRuntimeAccess.class, lookupClass.getClassLoader()))); + } + if (access == null) { + access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(TruffleRuntimeAccess.class))); + } + + if (access != null) { + exportTo(access.getClass()); + TruffleRuntime runtime = access.getRuntime(); + if (runtime != null) { + return runtime; + } + } + return new DefaultTruffleRuntime("No optimizing Truffle runtime found on the module-path."); + } + + private static void maybeExportJVMCITo(Class runtimeClass) throws ReflectiveOperationException { + Class modulesSupport; + try { + modulesSupport = Class.forName("com.oracle.truffle.runtime.ModulesSupport"); + } catch (ClassNotFoundException e) { + // we ignore if modules support is not available. + // this typically means that the runtime not on the module-path + return; + } + modulesSupport.getMethod("exportJVMCI", Class.class).invoke(null, runtimeClass); + } + + @SuppressWarnings("deprecation") private static TruffleRuntime initRuntime() { return AccessController.doPrivileged(new PrivilegedAction() { public TruffleRuntime run() { - String runtimeClassName = System.getProperty("truffle.TruffleRuntime"); - if (runtimeClassName != null && !runtimeClassName.isEmpty()) { - if (runtimeClassName.equals(DefaultTruffleRuntime.class.getName())) { - return new DefaultTruffleRuntime(); - } - try { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Class runtimeClass = Class.forName(runtimeClassName, false, cl); - return (TruffleRuntime) runtimeClass.getDeclaredConstructor().newInstance(); - } catch (Throwable e) { - // Fail fast for other errors - throw new InternalError(e); - } - } - - Class lookupClass = Truffle.class; - ModuleLayer moduleLayer = lookupClass.getModule().getLayer(); - TruffleRuntimeAccess access; - if (moduleLayer != null) { - access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(moduleLayer, TruffleRuntimeAccess.class))); - } else { - access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(TruffleRuntimeAccess.class, lookupClass.getClassLoader()))); - } - if (access == null) { - access = selectTruffleRuntimeAccess(List.of(ServiceLoader.load(TruffleRuntimeAccess.class))); - } - - if (access != null) { - exportTo(access.getClass()); - return access.getRuntime(); - } - return new DefaultTruffleRuntime(); + return createRuntime(); } }); } diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java index 0b60ff96ddb9..571801885ebc 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java @@ -1224,6 +1224,9 @@ public AbstractFastThreadLocal getContextThreadLocal() { } public abstract boolean isLegacyCompilerOption(String key); + + public abstract ThreadLocal createTerminatingThreadLocal(Supplier initialValue, Consumer onThreadTermination); + } public abstract static class LanguageProviderSupport extends Support { @@ -1351,7 +1354,7 @@ protected Accessor() { "com.oracle.truffle.api.test.TestAPIAccessor".equals(thisClassName) || "com.oracle.truffle.api.impl.TVMCIAccessor".equals(thisClassName) || "com.oracle.truffle.api.impl.DefaultRuntimeAccessor".equals(thisClassName) || - "org.graalvm.compiler.truffle.runtime.GraalRuntimeAccessor".equals(thisClassName) || + "com.oracle.truffle.runtime.OptimizedRuntimeAccessor".equals(thisClassName) || "com.oracle.truffle.api.dsl.DSLAccessor".equals(thisClassName) || "com.oracle.truffle.api.impl.ImplAccessor".equals(thisClassName) || "com.oracle.truffle.api.memory.MemoryFenceAccessor".equals(thisClassName) || diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultRuntimeAccessor.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultRuntimeAccessor.java index 816953de8940..af29c1b73105 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultRuntimeAccessor.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultRuntimeAccessor.java @@ -40,7 +40,9 @@ */ package com.oracle.truffle.api.impl; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; import org.graalvm.options.OptionDescriptors; import org.graalvm.options.OptionValues; @@ -271,6 +273,11 @@ public AbstractFastThreadLocal getContextThreadLocal() { return DefaultContextThreadLocal.SINGLETON; } + @Override + public ThreadLocal createTerminatingThreadLocal(Supplier initialValue, Consumer onThreadTermination) { + return ThreadLocal.withInitial(initialValue); + } + } } diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java index 8a421251b5d0..1e26c703d914 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java @@ -41,8 +41,6 @@ package com.oracle.truffle.api.impl; import java.io.Closeable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Iterator; import java.util.Objects; import java.util.ServiceConfigurationError; @@ -77,6 +75,10 @@ public final class DefaultTruffleRuntime implements TruffleRuntime { private final ThreadLocal stackTraces = new ThreadLocal<>(); private final DefaultTVMCI tvmci = new DefaultTVMCI(); + /** + * Contains a reason why the default fallback engine was selected. + */ + private final String fallbackReason; private final TVMCI.Test testTvmci = new TVMCI.Test<>() { @@ -97,6 +99,15 @@ public void finishWarmup(Closeable testContext, CallTarget callTarget) { }; public DefaultTruffleRuntime() { + this.fallbackReason = null; + } + + public DefaultTruffleRuntime(String fallbackReason) { + this.fallbackReason = fallbackReason; + } + + public String getFallbackReason() { + return fallbackReason; } /** @@ -220,61 +231,23 @@ public T getCapability(Class capability) { } private static final class Loader { - private static final Method LOAD_METHOD; - static { - Method loadMethod = null; - try { - Class servicesClass = Class.forName("jdk.vm.ci.services.Services"); - loadMethod = servicesClass.getMethod("load", Class.class); - } catch (ClassNotFoundException | NoSuchMethodException e) { - // Services.load is not available - } - if (loadMethod != null) { - try { - try { - loadMethod.invoke(null, (Object) null); - } catch (InvocationTargetException e) { - throw e.getTargetException(); - } - } catch (NullPointerException npe) { - // Services.load is accessible - } catch (IllegalAccessException iae) { - // Services.load is not accessible. This happens on JDK 9+ when EnableJVMCI is - // true (either explicitly or by default) which causes the jdk.internal.vm.ci - // module to be resolved. - loadMethod = null; - } catch (Throwable e) { - throw new InternalError(e); - } - } - LOAD_METHOD = loadMethod; - } - @SuppressWarnings("unchecked") static Iterable load(Class service) { Module truffleModule = DefaultTruffleRuntime.class.getModule(); if (!truffleModule.canUse(service)) { truffleModule.addUses(service); } - if (LOAD_METHOD != null) { - try { - return (Iterable) LOAD_METHOD.invoke(null, service); - } catch (Exception e) { - throw new InternalError(e); - } + ModuleLayer moduleLayer = truffleModule.getLayer(); + Iterable services; + if (moduleLayer != null) { + services = ServiceLoader.load(moduleLayer, service); } else { - ModuleLayer moduleLayer = truffleModule.getLayer(); - Iterable services; - if (moduleLayer != null) { - services = ServiceLoader.load(moduleLayer, service); - } else { - services = ServiceLoader.load(service, DefaultTruffleRuntime.class.getClassLoader()); - } - if (!services.iterator().hasNext()) { - services = ServiceLoader.load(service); - } - return services; + services = ServiceLoader.load(service, DefaultTruffleRuntime.class.getClassLoader()); + } + if (!services.iterator().hasNext()) { + services = ServiceLoader.load(service); } + return services; } } diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/TVMCI.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/TVMCI.java index 88bb3f0b3af4..4d6ac1fdc41a 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/TVMCI.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/TVMCI.java @@ -110,7 +110,7 @@ protected TVMCI() { private boolean checkCaller() { final String packageName = getClass().getPackage().getName(); - assert packageName.equals("org.graalvm.compiler.truffle.runtime") || + assert packageName.equals("com.oracle.truffle.runtime") || packageName.equals("org.graalvm.graal.truffle") || packageName.equals("com.oracle.graal.truffle") || packageName.equals("com.oracle.truffle.api.impl") : // diff --git a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/BlockNode.java b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/BlockNode.java index 7a79c576a4bb..3ed1aa7880aa 100644 --- a/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/BlockNode.java +++ b/truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/BlockNode.java @@ -100,7 +100,7 @@ public abstract class BlockNode extends Node { protected BlockNode(T[] elements) { this.elements = elements; assert getClass().getName().equals("com.oracle.truffle.api.impl.DefaultBlockNode") || - getClass().getName().equals("org.graalvm.compiler.truffle.runtime.OptimizedBlockNode") : "Custom block implementations are not allowed."; + getClass().getName().equals("com.oracle.truffle.runtime.OptimizedBlockNode") : "Custom block implementations are not allowed."; } /** diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/ConstantFieldInfo.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/ConstantFieldInfo.java similarity index 60% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/ConstantFieldInfo.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/ConstantFieldInfo.java index 9479c7948333..aa70872915b7 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/ConstantFieldInfo.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/ConstantFieldInfo.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; import jdk.vm.ci.meta.ResolvedJavaField; diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/HostMethodInfo.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/HostMethodInfo.java new file mode 100644 index 000000000000..1aa24b2f3949 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/HostMethodInfo.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023, 2023, 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.compiler; + +/** + * TODO GR-44222 as soon as the annotation API is available in libgraal this can be moved to the + * compiler implementation side. + * + * @param isTruffleBoundary specifies if the method is annotated by {@code TruffleBoundary} + * @param isBytecodeInterpreterSwitch specifies if the method is annotated by + * {@code BytecodeInterpreterSwitch}. + * @param isBytecodeInterpreterSwitchBoundary specifies if the method is annotated by + * {@code BytecodeInterpreterSwitchBoundary} + * @param isInliningCutoff specifies if the method is annotated by {@code InliningCutoff} + */ +public record HostMethodInfo( + boolean isTruffleBoundary, + boolean isBytecodeInterpreterSwitch, + boolean isBytecodeInterpreterSwitchBoundary, + boolean isInliningCutoff) { + +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/OptimizedAssumptionDependency.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/OptimizedAssumptionDependency.java new file mode 100644 index 000000000000..b3e04852a797 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/OptimizedAssumptionDependency.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler; + +/** + * Represents some machine code whose validity depends on an assumption. Valid machine code can + * still be executed. + */ +public interface OptimizedAssumptionDependency { + + /** + * Called when a depended-on assumption is invalidated, with the intention to invalidate the + * machine code referenced by this object. + */ + void onAssumptionInvalidated(Object source, CharSequence reason); + + /** + * Determines if the machine code referenced by this object is valid. + */ + boolean isAlive(); + + /** + * Gets the Truffle AST whose machine code is represented by this object. May be {@code null}. + */ + default TruffleCompilable getCompilable() { + return null; + } + +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/PartialEvaluationMethodInfo.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/PartialEvaluationMethodInfo.java new file mode 100644 index 000000000000..cbc2390db20b --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/PartialEvaluationMethodInfo.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023, 2023, 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.compiler; + +import com.oracle.truffle.compiler.TruffleCompilerRuntime.InlineKind; +import com.oracle.truffle.compiler.TruffleCompilerRuntime.LoopExplosionKind; + +/** + * TODO GR-44222 as soon as the annotation API is available in libgraal this can be moved to the + * compiler implementation side. + * + * @param loopExplosion Queries how loops in {@code method} with constant number of invocations + * should be unrolled. + * @param inlineForPartialEvaluation Gets an object describing whether and how a method can be + * inlined based on Truffle directives during partial evaluation + * @param inlineForTruffleBoundary Gets an object describing whether and how a method can be inlined + * based on Truffle directives after partial evaluation e.g. during later inlining + * phases. + * @param isInlineable Determines if {@code method} can be inlined by the runtime (independently + * from Truffle). + * @param isSpecializationMethod Determines if {@code method} is annotated by + * {@code Specialization}. + */ +public record PartialEvaluationMethodInfo( + LoopExplosionKind loopExplosion, + InlineKind inlineForPartialEvaluation, + InlineKind inlineForTruffleBoundary, + boolean isInlineable, + boolean isSpecializationMethod) { + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilable.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilable.java similarity index 73% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilable.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilable.java index 33677e308656..43f1a0d36d6e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilable.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilable.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationSupport.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationSupport.java new file mode 100644 index 000000000000..1d70e948fe79 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationSupport.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023, 2023, 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.compiler; + +/** + * Represents entry points for Truffle runtime implementations to Truffle compilation. + */ +public interface TruffleCompilationSupport { + + /** + * Registers a runtime instance after it was fully initialized. + */ + void registerRuntime(TruffleCompilerRuntime runtime); + + /** + * Creates a new compiler handle for compilation. A runtime must be + * {@link #registerRuntime(TruffleCompilerRuntime) registered} prior to calling this method. + * Only one compiler instance should be created per Truffle runtime instance. + */ + TruffleCompiler createCompiler(TruffleCompilerRuntime runtime); + + /** + * Lists all compiler options available, including deprecated options. + */ + TruffleCompilerOptionDescriptor[] listCompilerOptions(); + + /** + * Returns true if a compilation key exists, else false. + */ + boolean compilerOptionExists(String key); + + /** + * Validates a compiler option and returns null if the option is null. An error + * message otherwise. + */ + String validateCompilerOption(String key, String value); + + /** + * Returns a compiler configuration name that will be used. + */ + String getCompilerConfigurationName(TruffleCompilerRuntime runtime); + + /** + * Opens a compiler thread scope for compilation threads. Use with try-with-resourcce. + */ + default AutoCloseable openCompilerThreadScope() { + return null; + } + + default boolean isSuppressedCompilationFailure(@SuppressWarnings("unused") Throwable throwable) { + return false; + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationTask.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationTask.java similarity index 53% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationTask.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationTask.java index cd98cd5aa739..202c21b0c42c 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilationTask.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilationTask.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; import java.util.Collections; import java.util.Map; diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompiler.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompiler.java new file mode 100644 index 000000000000..faa1c9ce36f9 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompiler.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler; + +/** + * A compiler that partially evaluates and compiles a {@link TruffleCompilable} to machine code. + */ +public interface TruffleCompiler { + + String FIRST_TIER_COMPILATION_SUFFIX = "#1"; + String SECOND_TIER_COMPILATION_SUFFIX = "#2"; + + /** + * Initializes the compiler before the first compilation. + * + * @param compilable the Truffle AST that triggered the initialization + * @param firstInitialization first initialization. For a multi-isolate compiler the + * {@code firstInitialization} must be {@code true} for an initialization in the + * first isolate and {@code false} for an initialization in the following isolates. + * + * @since 20.0.0 + */ + void initialize(TruffleCompilable compilable, boolean firstInitialization); + + /** + * Compiles {@code compilable} to machine code. + * + * @param listener a listener receiving events about compilation success or failure + */ + void doCompile(TruffleCompilationTask task, TruffleCompilable compilable, TruffleCompilerListener listener); + + /** + * Notifies this object that it will no longer being used and should thus perform all relevant + * finalization tasks. This is typically performed when the process exits. + */ + void shutdown(); + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerAssumptionDependency.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerAssumptionDependency.java similarity index 51% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerAssumptionDependency.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerAssumptionDependency.java index b718b170e607..10883dc35999 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerAssumptionDependency.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerAssumptionDependency.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; import java.lang.ref.WeakReference; import java.util.Objects; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerListener.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java similarity index 74% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerListener.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java index 4bb31aaaf138..0620d69f639b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerListener.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerListener.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; /** * A listener for events related to the compilation of a {@link TruffleCompilable}. The events are diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerOptionDescriptor.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerOptionDescriptor.java new file mode 100644 index 000000000000..dd84972d0cf3 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerOptionDescriptor.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler; + +/** + * Represents the description of a Truffle compiler options. + */ +public record TruffleCompilerOptionDescriptor(String name, Type type, boolean deprecated, String help, String deprecationMessage) { + + public enum Type { + /** + * An option common for users to apply. + */ + USER, + + /** + * An option only relevant in corner cases and for fine-tuning. + */ + EXPERT, + + /** + * An option only relevant when debugging the compiler. + */ + DEBUG + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerRuntime.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerRuntime.java similarity index 87% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerRuntime.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerRuntime.java index 8f70d9dc954d..ca31c7121442 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/TruffleCompilerRuntime.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleCompilerRuntime.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common; +package com.oracle.truffle.compiler; import java.util.Map; import java.util.function.Consumer; diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleSourceLanguagePosition.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleSourceLanguagePosition.java new file mode 100644 index 000000000000..83b51d82e8d0 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/TruffleSourceLanguagePosition.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler; + +import java.net.URI; + +public interface TruffleSourceLanguagePosition { + + String getDescription(); + + int getOffsetEnd(); + + int getOffsetStart(); + + int getLineNumber(); + + URI getURI(); + + String getLanguage(); + + int getNodeId(); + + String getNodeClassName(); +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/HotSpotTruffleCompiler.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/HotSpotTruffleCompiler.java new file mode 100644 index 000000000000..44e3924819e2 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/HotSpotTruffleCompiler.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 2023, 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.compiler.hotspot; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompiler; + +import jdk.vm.ci.meta.ResolvedJavaMethod; + +public interface HotSpotTruffleCompiler extends TruffleCompiler { + + /** + * Compiles and installs special code for truffle call boundary methods. The passed method must + * have compilation and inlining disabled in HotSpot. + */ + void installTruffleCallBoundaryMethod(ResolvedJavaMethod method, TruffleCompilable compilable); + + /** + * Compiles and installs special code fast thread local object access. The passed method must + * have compilation and inlining disabled in HotSpot. + */ + void installTruffleReservedOopMethod(ResolvedJavaMethod method, TruffleCompilable compilable); + + int pendingTransferToInterpreterOffset(TruffleCompilable compilable); + + /** + * Releases caches used for PE/compilation. + */ + void purgePartialEvaluationCaches(); + +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalEntryPointsResolver.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalEntryPointsResolver.java new file mode 100644 index 000000000000..a0d07605f37c --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalEntryPointsResolver.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler.hotspot.libgraal; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PACKAGE; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to generate the {@code FromLibGraalCalls} for given id type. The annotation can be + * applied to packages, types and methods. When applied to method the generated + * {@code FromLibGraalCalls} subclass delegates to the annotated method. The annotated method must + * be static and its return type must be {@code JClass}. When applied to package or type the + * {@link #entryPointsClassName} is used to resolve the {@code JClass}. + */ +@Retention(RetentionPolicy.SOURCE) +@Target({PACKAGE, TYPE, METHOD}) +public @interface FromLibGraalEntryPointsResolver { + /** + * The id class. It has to implement the {@link FromLibGraalId}. + */ + Class> value(); + + /** + * The fully qualified name of the entry points class on the HotSpot side. The + * {@code entryPointsClassName} is mandatory when the annotation is present on package or type + * element. + */ + String entryPointsClassName() default ""; +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalId.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalId.java new file mode 100644 index 000000000000..e024f312b7fa --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/FromLibGraalId.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020, 2023, 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.compiler.hotspot.libgraal; + +public interface FromLibGraalId { + + String getName(); + + String getSignature(); + + String getMethodName(); + + Class[] getParameterTypes(); + + Class getReturnType(); + + /** + * Creates a JVM method signature as specified in the Sections 4.3.3 of the JVM Specification. + */ + static String encodeMethodSignature(Class returnType, Class... parameterTypes) { + StringBuilder builder = new StringBuilder("("); + for (Class type : parameterTypes) { + Utilities.encodeType(type, builder); + } + builder.append(")"); + Utilities.encodeType(returnType, builder); + return builder.toString(); + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraal.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraal.java similarity index 77% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraal.java rename to truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraal.java index 978b84b0f215..449ab7070966 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/common/hotspot/libgraal/TruffleFromLibGraal.java +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraal.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.common.hotspot.libgraal; +package com.oracle.truffle.compiler.hotspot.libgraal; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; @@ -33,8 +49,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import org.graalvm.libgraal.jni.annotation.FromLibGraalId; - /** * Annotates methods associated with both ends of a libgraal to HotSpot call. This annotation * simplifies navigating between these methods in an IDE. @@ -164,7 +178,9 @@ enum Id implements FromLibGraalId { @Signature({Consumer.class, Object.class, long.class}) RegisterOptimizedAssumptionDependency, @Signature({void.class, Object.class, int.class, int.class}) - SetCallCounts; + SetCallCounts, + @Signature({void.class, long.class}) + OnIsolateShutdown; // @formatter:on private final String signature; diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalRepeated.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalRepeated.java new file mode 100644 index 000000000000..5871021ee70c --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleFromLibGraalRepeated.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler.hotspot.libgraal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Container for repeated {@link TruffleFromLibGraal} annotations. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface TruffleFromLibGraalRepeated { + TruffleFromLibGraal[] value(); +} 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 new file mode 100644 index 000000000000..66abe85106c2 --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/TruffleToLibGraal.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler.hotspot.libgraal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotates methods associated with both ends of a HotSpot to libgraal call. This annotation + * simplifies navigating between these methods in an IDE. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface TruffleToLibGraal { + /** + * Gets the token identifying a call from HotSpot to libgraal. + */ + Id value(); + + /** + * Identifier for a call from HotSpot to libgraal. + */ + // Please keep sorted + enum Id { + DoCompile, + GetCompilerConfigurationFactoryName, + GetDataPatchesCount, + GetExceptionHandlersCount, + GetInfopoints, + GetInfopointsCount, + GetMarksCount, + GetNodeCount, + GetNodeTypes, + GetSuppliedString, + GetTargetCodeSize, + GetTotalFrameSize, + InitializeIsolate, + InitializeCompiler, + RegisterRuntime, + ListCompilerOptions, + CompilerOptionExists, + ValidateCompilerOption, + InitializeRuntime, + InstallTruffleCallBoundaryMethod, + InstallTruffleReservedOopMethod, + NewCompiler, + PendingTransferToInterpreterOffset, + PurgePartialEvaluationCaches, + Shutdown; + } +} diff --git a/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/Utilities.java b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/Utilities.java new file mode 100644 index 000000000000..6120991c23ef --- /dev/null +++ b/truffle/src/com.oracle.truffle.compiler/src/com/oracle/truffle/compiler/hotspot/libgraal/Utilities.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018, 2023, 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.compiler.hotspot.libgraal; + +final class Utilities { + + private Utilities() { + } + + static void encodeType(Class type, StringBuilder buf) { + String desc; + if (type == boolean.class) { + desc = "Z"; + } else if (type == byte.class) { + desc = "B"; + } else if (type == char.class) { + desc = "C"; + } else if (type == short.class) { + desc = "S"; + } else if (type == int.class) { + desc = "I"; + } else if (type == long.class) { + desc = "J"; + } else if (type == float.class) { + desc = "F"; + } else if (type == double.class) { + desc = "D"; + } else if (type == void.class) { + desc = "V"; + } else if (type.isArray()) { + buf.append('['); + encodeType(type.getComponentType(), buf); + return; + } else { + desc = "L" + type.getName().replace('.', '/') + ";"; + } + buf.append(desc); + } +} diff --git a/truffle/src/com.oracle.truffle.libgraal.processor/src/META-INF/services/javax.annotation.processing.Processor b/truffle/src/com.oracle.truffle.libgraal.processor/src/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000000..e1769605c8e4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.libgraal.processor/src/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.oracle.truffle.libgraal.processor.TruffleFromLibGraalProcessor diff --git a/truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/BaseProcessor.java b/truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/BaseProcessor.java new file mode 100644 index 000000000000..6a340f012a3a --- /dev/null +++ b/truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/BaseProcessor.java @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2018, 2023, 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.libgraal.processor; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.processing.Filer; +import javax.annotation.processing.FilerException; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.tools.Diagnostic.Kind; +import javax.tools.FileObject; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; + +/** + * {@link javax.annotation.processing.AbstractProcessor} subclass that provides extra functionality. + */ +public abstract class BaseProcessor extends javax.annotation.processing.AbstractProcessor { + + /** + * Gets the processing environment available to this processor. + */ + public ProcessingEnvironment env() { + return processingEnv; + } + + @Override + public final SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return doProcess(annotations, roundEnv); + } + + protected abstract boolean doProcess(Set annotations, RoundEnvironment roundEnv); + + private final Map types = new HashMap<>(); + + /** + * Gets the {@link TypeMirror} for a given class name. + * + * @throws NoClassDefFoundError if the class cannot be resolved + */ + public TypeMirror getType(String className) { + return getTypeElement(className).asType(); + } + + public TypeMirror getType(Class element) { + if (element.isArray()) { + return processingEnv.getTypeUtils().getArrayType(getType(element.getComponentType())); + } + if (element.isPrimitive()) { + if (element == void.class) { + return processingEnv.getTypeUtils().getNoType(TypeKind.VOID); + } + TypeKind typeKind; + if (element == boolean.class) { + typeKind = TypeKind.BOOLEAN; + } else if (element == byte.class) { + typeKind = TypeKind.BYTE; + } else if (element == short.class) { + typeKind = TypeKind.SHORT; + } else if (element == char.class) { + typeKind = TypeKind.CHAR; + } else if (element == int.class) { + typeKind = TypeKind.INT; + } else if (element == long.class) { + typeKind = TypeKind.LONG; + } else if (element == float.class) { + typeKind = TypeKind.FLOAT; + } else if (element == double.class) { + typeKind = TypeKind.DOUBLE; + } else { + assert false; + return null; + } + return processingEnv.getTypeUtils().getPrimitiveType(typeKind); + } else { + TypeElement typeElement = getTypeElement(element.getCanonicalName()); + if (typeElement == null) { + return null; + } + return processingEnv.getTypeUtils().erasure(typeElement.asType()); + } + } + + /** + * Gets the {@link TypeMirror} for a given class name. + * + * @return {@code null} if the class cannot be resolved + */ + public TypeMirror getTypeOrNull(String className) { + TypeElement element = getTypeElementOrNull(className); + if (element == null) { + return null; + } + return element.asType(); + } + + /** + * Gets the {@link TypeElement} for a given class name. + * + * @throws NoClassDefFoundError if the class cannot be resolved + */ + public TypeElement getTypeElement(String className) { + TypeElement type = getTypeElementOrNull(className); + if (type == null) { + throw new NoClassDefFoundError(className); + } + return type; + } + + /** + * Gets the {@link TypeElement} for a given class name. + * + * @returns {@code null} if the class cannot be resolved + */ + public TypeElement getTypeElementOrNull(String className) { + TypeElement type = types.get(className); + if (type == null) { + type = processingEnv.getElementUtils().getTypeElement(className); + if (type == null) { + return null; + } + types.put(className, type); + } + return type; + } + + /** + * Converts a given {@link TypeMirror} to a {@link TypeElement}. + * + * @throws ClassCastException if type cannot be converted to a {@link TypeElement} + */ + public TypeElement asTypeElement(TypeMirror type) { + Element element = processingEnv.getTypeUtils().asElement(type); + if (element == null) { + throw new ClassCastException(type + " cannot be converted to a " + TypeElement.class.getName()); + } + return (TypeElement) element; + } + + /** + * Regular expression for a qualified class name that assumes package names start with lowercase + * and non-package components start with uppercase. + */ + private static final Pattern QUALIFIED_CLASS_NAME_RE = Pattern.compile("(?:[a-z]\\w*\\.)+([A-Z].*)"); + + /** + * Gets the non-package component of a qualified class name. + * + * @throws IllegalArgumentException if {@code className} does not match + * {@link #QUALIFIED_CLASS_NAME_RE} + */ + public static String getSimpleName(String className) { + Matcher m = QUALIFIED_CLASS_NAME_RE.matcher(className); + if (m.matches()) { + return m.group(1); + } + throw new IllegalArgumentException("Class name \"" + className + "\" does not match pattern " + QUALIFIED_CLASS_NAME_RE); + } + + /** + * Gets the package component of a qualified class name. + * + * @throws IllegalArgumentException if {@code className} does not match + * {@link #QUALIFIED_CLASS_NAME_RE} + */ + public static String getPackageName(String className) { + String simpleName = getSimpleName(className); + return className.substring(0, className.length() - simpleName.length() - 1); + } + + /** + * Gets the annotation of type {@code annotationType} directly present on {@code element}. + * + * @return {@code null} if an annotation of type {@code annotationType} is not on + * {@code element} + */ + public AnnotationMirror getAnnotation(Element element, TypeMirror annotationType) { + List mirrors = getAnnotations(element, annotationType); + return mirrors.isEmpty() ? null : mirrors.get(0); + } + + /** + * Gets all annotations directly present on {@code element}. + */ + public List getAnnotations(Element element, TypeMirror typeMirror) { + List result = new ArrayList<>(); + for (AnnotationMirror mirror : element.getAnnotationMirrors()) { + if (processingEnv.getTypeUtils().isSameType(mirror.getAnnotationType(), typeMirror)) { + result.add(mirror); + } + } + return result; + } + + /** + * Gets the value of the {@code name} element of {@code annotation} and converts it to a value + * of type {@code type}. + * + * @param type the expected type of the element value. This must be a subclass of one of the + * types described by {@link AnnotationValue}. + * @throws NoSuchElementException if {@code annotation} has no element named {@code name} + * @throws ClassCastException if the value of the specified element cannot be converted to + * {@code type} + */ + public static T getAnnotationValue(AnnotationMirror annotation, String name, Class type) { + ExecutableElement valueMethod = null; + for (ExecutableElement method : ElementFilter.methodsIn(annotation.getAnnotationType().asElement().getEnclosedElements())) { + if (method.getSimpleName().toString().equals(name)) { + valueMethod = method; + break; + } + } + + if (valueMethod == null) { + return null; + } + + AnnotationValue value = annotation.getElementValues().get(valueMethod); + if (value == null) { + value = valueMethod.getDefaultValue(); + } + + return type.cast(value.getValue()); + } + + /** + * Gets the value of the {@code name} array-typed element of {@code annotation} and converts it + * to list of values of type {@code type}. + * + * @param componentType the expected component type of the element value. This must be a + * subclass of one of the types described by {@link AnnotationValue}. + * @throws NoSuchElementException if {@code annotation} has no element named {@code name} + * @throws ClassCastException if the value of the specified element is not an array whose + * components cannot be converted to {@code componentType} + */ + @SuppressWarnings("unchecked") + public static List getAnnotationValueList(AnnotationMirror annotation, String name, Class componentType) { + List values = getAnnotationValue(annotation, name, List.class); + List result = new ArrayList<>(); + + if (values != null) { + for (AnnotationValue value : values) { + result.add(componentType.cast(value.getValue())); + } + } + return result; + } + + public static PackageElement getPackage(Element element) { + Element e = element.getEnclosingElement(); + while (e != null && e.getKind() != ElementKind.PACKAGE) { + e = e.getEnclosingElement(); + } + return (PackageElement) e; + } + + public static PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { + try { + /* Ensure Unix line endings to comply with code style guide checked by Checkstyle. */ + String className = pkg + "." + relativeName; + JavaFileObject sourceFile = filer.createSourceFile(className, originatingElements); + return new PrintWriter(sourceFile.openWriter()) { + @Override + public void println() { + print("\n"); + } + }; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Creates a {@code META-INF/providers/} file whose contents are a single + * line containing {@code serviceClassName}. + */ + public void createProviderFile(String providerClassName, String serviceClassName, Element... originatingElements) { + assert originatingElements.length > 0; + String filename = "META-INF/providers/" + providerClassName; + try { + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + writer.println(serviceClassName); + writer.close(); + } catch (IOException e) { + processingEnv.getMessager().printMessage(isBug367599(e) ? Kind.NOTE : Kind.ERROR, e.getMessage(), originatingElements[0]); + } + } + + /** + * Determines if a given exception is (most likely) caused by + * Bug 367599. + */ + private static boolean isBug367599(Throwable t) { + if (t instanceof FilerException) { + for (StackTraceElement ste : t.getStackTrace()) { + if (ste.toString().contains("org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.create")) { + // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=367599 + return true; + } + } + } + return t.getCause() != null && isBug367599(t.getCause()); + } +} diff --git a/compiler/src/jdk.internal.vm.compiler.processor/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/processor/TruffleFromLibGraalProcessor.java b/truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/TruffleFromLibGraalProcessor.java similarity index 78% rename from compiler/src/jdk.internal.vm.compiler.processor/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/processor/TruffleFromLibGraalProcessor.java rename to truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/TruffleFromLibGraalProcessor.java index 98bf3cd16ff9..953e0c0b925e 100644 --- a/compiler/src/jdk.internal.vm.compiler.processor/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/processor/TruffleFromLibGraalProcessor.java +++ b/truffle/src/com.oracle.truffle.libgraal.processor/src/com/oracle/truffle/libgraal/processor/TruffleFromLibGraalProcessor.java @@ -1,28 +1,53 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.compiler.hotspot.libgraal.processor; +package com.oracle.truffle.libgraal.processor; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.annotation.processing.Filer; import javax.annotation.processing.RoundEnvironment; @@ -41,17 +66,6 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import org.graalvm.compiler.processor.AbstractProcessor; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - /** * Processor for the * {@code org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal} annotation that @@ -61,9 +75,9 @@ * {@code org.graalvm.nativeimage.StackValue}, it's very hard to use runtime assertion checking. */ @SupportedAnnotationTypes({ - "org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal", - "org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraalRepeated"}) -public class TruffleFromLibGraalProcessor extends AbstractProcessor { + "com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal", + "com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraalRepeated"}) +public class TruffleFromLibGraalProcessor extends BaseProcessor { /** * Captures the info defined by a @@ -153,7 +167,7 @@ private void processElement(ExecutableElement hsCall, DeclaredType annotationTyp annotations = Collections.singletonList(annotation); } - TypeMirror signatureAnnotationType = getType("org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Signature"); + TypeMirror signatureAnnotationType = getType("com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Signature"); for (AnnotationMirror a : annotations) { VariableElement annotationValue = getAnnotationValue(a, "value", VariableElement.class); String idName = annotationValue.getSimpleName().toString(); @@ -211,7 +225,7 @@ private void createGenSource(CallsInfo info, String pkg, Name topDeclaringClass, out.println(""); boolean usesJObject = false; for (Id id : info.ids) { - out.printf("import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.%s;%n", id.name); + out.printf("import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.%s;%n", id.name); TypeMirror returnType = id.returnType; if (!isPrimitiveOrVoid(returnType)) { usesJObject = true; @@ -238,9 +252,9 @@ private void createGenSource(CallsInfo info, String pkg, Name topDeclaringClass, out.println(""); if (!isPrimitiveOrVoid(rt)) { out.println(" @SuppressWarnings(\"unchecked\")"); - out.printf(" static T call%s(JNIEnv env", idName); + out.printf(" static T call%s(TruffleFromLibGraalCalls calls, JNIEnv env", idName); } else { - out.printf(" static %s call%s(JNIEnv env", toJNIType(rt, false), idName); + out.printf(" static %s call%s(TruffleFromLibGraalCalls calls, JNIEnv env", toJNIType(rt, false), idName); } List parameterTypes = id.parameterTypes; for (TypeMirror t : parameterTypes) { @@ -262,7 +276,7 @@ private void createGenSource(CallsInfo info, String pkg, Name topDeclaringClass, } else { returnPrefix = "return "; } - out.printf(" %sTruffleFromLibGraalCalls.INSTANCE.call%s(env, %s, args);%n", returnPrefix, toJNIType(rt, true), idName); + out.printf(" %scalls.call%s(env, %s, args);%n", returnPrefix, toJNIType(rt, true), idName); out.println(" }"); } out.println("}"); diff --git a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java index c512b2c1e52d..17e46662805c 100644 --- a/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java +++ b/truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/PolyglotEngineImpl.java @@ -1859,7 +1859,7 @@ public PolyglotContextImpl createContext(SandboxPolicy contextSandboxPolicy, Out } } } - checkTruffleRuntime(); + logTruffleRuntimeWarning(); return context; } @@ -1963,14 +1963,19 @@ private static boolean arePreInitializedLanguagesCompatible(PolyglotContextImpl return preInitializedLanguages.isEmpty(); } - private void checkTruffleRuntime() { + private void logTruffleRuntimeWarning() { if (getEngineOptionValues().get(PolyglotEngineOptions.WarnInterpreterOnly) && Truffle.getRuntime().getClass() == DefaultTruffleRuntime.class) { - getEngineLogger().log(Level.WARNING, "" + - "The polyglot context is using an implementation that does not support runtime compilation.\n" + - "The guest application code will therefore be executed in interpreted mode only.\n" + - "Execution only in interpreted mode will strongly impact the guest application performance.\n" + - "For more information on using GraalVM see https://www.graalvm.org/java/quickstart/.\n" + - "To disable this warning the '--engine.WarnInterpreterOnly=false' option or use the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property."); + DefaultTruffleRuntime runtime = (DefaultTruffleRuntime) Truffle.getRuntime(); + String reason = runtime.getFallbackReason(); + if (reason == null) { + reason = "No optimizing Truffle runtime found."; + } + getEngineLogger().log(Level.WARNING, String.format(""" + The polyglot context uses a fallback Truffle implementation that does not support runtime optimization. + Execution without runtime optimization will strongly impact the guest application performance. + The following reason was found: %s + For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/. + To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.""", reason)); } } diff --git a/compiler/src/org.graalvm.compiler.truffle.libgraal.truffleattach/src/truffle_attach.cc b/truffle/src/com.oracle.truffle.runtime.attach/src/truffle_attach.cc similarity index 70% rename from compiler/src/org.graalvm.compiler.truffle.libgraal.truffleattach/src/truffle_attach.cc rename to truffle/src/com.oracle.truffle.runtime.attach/src/truffle_attach.cc index 994198d5c297..d714c6708ce9 100644 --- a/compiler/src/org.graalvm.compiler.truffle.libgraal.truffleattach/src/truffle_attach.cc +++ b/truffle/src/com.oracle.truffle.runtime.attach/src/truffle_attach.cc @@ -29,15 +29,16 @@ return; \ } - -static void openJVMCITo(JNIEnv* jniEnv, jobject callerModule) { - jclass servicesClz = jniEnv->FindClass("jdk/vm/ci/services/Services"); +static void addExports(JNIEnv* jniEnv, jobject m1, jobject pn, jobject m2) { + jclass modulesClass = jniEnv->FindClass("jdk/internal/module/Modules"); EXCEPTION_CHECK_VOID(jniEnv) - jmethodID openJVMCIMethod = jniEnv->GetStaticMethodID(servicesClz, "openJVMCITo", "(Ljava/lang/Module;)V"); + jmethodID addExports = jniEnv->GetStaticMethodID(modulesClass, "addExports", "(Ljava/lang/Module;Ljava/lang/String;Ljava/lang/Module;)V"); EXCEPTION_CHECK_VOID(jniEnv) - jvalue args[2] {}; - args[0].l = callerModule; - jniEnv->CallStaticVoidMethodA(servicesClz, openJVMCIMethod, args); + jvalue args[4] {}; + args[0].l = m1; + args[1].l = pn; + args[2].l = m2; + jniEnv->CallStaticVoidMethodA(modulesClass, addExports, args); } // Library entry points @@ -46,10 +47,11 @@ static void openJVMCITo(JNIEnv* jniEnv, jobject callerModule) { extern "C" { #endif -JNIEXPORT void JNICALL Java_org_graalvm_compiler_truffle_runtime_hotspot_JVMCIOpenSupport_openJVMCITo0(JNIEnv *env, jclass clz, jobject callerModule) { - openJVMCITo(env, callerModule); +JNIEXPORT void JNICALL Java_com_oracle_truffle_runtime_ModulesSupport_addExports0(JNIEnv *env, jclass clz, jobject m1, jobject pn, jobject m2) { + addExports(env, m1, pn, m2); } + #ifdef __cplusplus } #endif diff --git a/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess new file mode 100644 index 000000000000..e23812cfb47e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.api.TruffleRuntimeAccess @@ -0,0 +1 @@ +com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntimeAccess diff --git a/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.LoopNodeFactory b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.LoopNodeFactory new file mode 100644 index 000000000000..7b030b8cb8b4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.LoopNodeFactory @@ -0,0 +1 @@ +com.oracle.truffle.runtime.DefaultLoopNodeFactory diff --git a/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.jfr.EventFactory$Provider b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.jfr.EventFactory$Provider new file mode 100644 index 000000000000..f2facffe6e9c --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/META-INF/services/com.oracle.truffle.runtime.jfr.EventFactory$Provider @@ -0,0 +1 @@ +com.oracle.truffle.runtime.jfr.impl.ProviderImpl diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractCompilationTask.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractCompilationTask.java similarity index 80% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractCompilationTask.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractCompilationTask.java index 5534b2d7a5a9..c2dbb89505c2 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/AbstractCompilationTask.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractCompilationTask.java @@ -1,30 +1,46 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; -import static org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.runtime; +import static com.oracle.truffle.runtime.OptimizedCallTarget.runtime; import java.net.URI; import java.util.ArrayList; @@ -35,9 +51,6 @@ import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; import com.oracle.truffle.api.dsl.Introspection; import com.oracle.truffle.api.nodes.DirectCallNode; @@ -45,6 +58,9 @@ import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeUtil; import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; import jdk.vm.ci.meta.JavaConstant; diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractGraalTruffleRuntimeListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractGraalTruffleRuntimeListener.java new file mode 100644 index 000000000000..5b40c2952804 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractGraalTruffleRuntimeListener.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018, 2023, 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; + +public abstract class AbstractGraalTruffleRuntimeListener implements OptimizedTruffleRuntimeListener { + + protected final OptimizedTruffleRuntime runtime; + + protected AbstractGraalTruffleRuntimeListener(OptimizedTruffleRuntime runtime) { + this.runtime = runtime; + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractOptimizedLoopNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractOptimizedLoopNode.java new file mode 100644 index 000000000000..0d77f7d59ab4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/AbstractOptimizedLoopNode.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021, 2023, 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; + +import java.util.Objects; + +import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.nodes.LoopNode; +import com.oracle.truffle.api.nodes.RepeatingNode; + +abstract class AbstractOptimizedLoopNode extends LoopNode { + + @Child protected RepeatingNode repeatingNode; + + @CompilationFinal private long trueCount; // long for long running loops. + @CompilationFinal private int falseCount; + + protected AbstractOptimizedLoopNode(RepeatingNode repeatingNode) { + this.repeatingNode = Objects.requireNonNull(repeatingNode); + } + + @Override + public final RepeatingNode getRepeatingNode() { + return repeatingNode; + } + + protected final void profileCounted(long iterations) { + if (CompilerDirectives.inInterpreter()) { + long trueCountLocal = trueCount + iterations; + if (trueCountLocal >= 0) { // don't write overflow values + trueCount = trueCountLocal; + int falseCountLocal = falseCount; + if (falseCountLocal < Integer.MAX_VALUE) { + falseCount = falseCountLocal + 1; + } + } + } + } + + protected final boolean inject(boolean condition) { + if (CompilerDirectives.inCompiledCode()) { + return CompilerDirectives.injectBranchProbability(calculateProbability(trueCount, falseCount), condition); + } else { + return condition; + } + } + + private static double calculateProbability(long trueCountLocal, int falseCountLocal) { + if (falseCountLocal == 0 && trueCountLocal == 0) { + // Avoid division by zero and assume default probability for AOT. + return 0.5; + } else { + return (double) trueCountLocal / (double) (trueCountLocal + falseCountLocal); + } + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BackgroundCompileQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BackgroundCompileQueue.java similarity index 86% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BackgroundCompileQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BackgroundCompileQueue.java index 98adc24a97a2..bd4009f37cfa 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BackgroundCompileQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BackgroundCompileQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -54,14 +70,14 @@ */ public class BackgroundCompileQueue { - protected final GraalTruffleRuntime runtime; + protected final OptimizedTruffleRuntime runtime; private final AtomicLong idCounter; private volatile ThreadPoolExecutor compilationExecutorService; private volatile BlockingQueue compilationQueue; private boolean shutdown = false; private long delayMillis; - public BackgroundCompileQueue(GraalTruffleRuntime runtime) { + public BackgroundCompileQueue(OptimizedTruffleRuntime runtime) { this.runtime = runtime; this.idCounter = new AtomicLong(); } @@ -267,9 +283,9 @@ public enum Tier { private final class TruffleCompilerThreadFactory implements ThreadFactory { private final String namePrefix; - private final GraalTruffleRuntime runtime; + private final OptimizedTruffleRuntime runtime; - TruffleCompilerThreadFactory(final String namePrefix, GraalTruffleRuntime runtime) { + TruffleCompilerThreadFactory(final String namePrefix, OptimizedTruffleRuntime runtime) { this.namePrefix = namePrefix; this.runtime = runtime; } @@ -283,7 +299,7 @@ public Thread newThread(Runnable r) { public void run() { setContextClassLoader(getClass().getClassLoader()); try (AutoCloseable compilerThreadScope = runtime.openCompilerThreadScope(); - AutoCloseable polyglotThreadScope = GraalRuntimeAccessor.ENGINE.createPolyglotThreadScope()) { + AutoCloseable polyglotThreadScope = OptimizedRuntimeAccessor.ENGINE.createPolyglotThreadScope()) { super.run(); if (compilationExecutorService.allowsCoreThreadTimeOut()) { // If core threads are always kept alive (no timeout), the diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BaseOSRRootNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BaseOSRRootNode.java new file mode 100644 index 000000000000..8a68b47561b3 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BaseOSRRootNode.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, 2023, 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; + +import java.lang.ref.Reference; + +import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.api.frame.FrameDescriptor; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.NodeInterface; +import com.oracle.truffle.api.nodes.RootNode; + +/** + * Base class for on-stack replaced (OSR) root nodes. + */ +public abstract class BaseOSRRootNode extends RootNode { + + /** + * Not adopted by the OSRRootNode; belongs to another RootNode. OptimizedCallTarget treats + * OSRRootNodes specially, skipping adoption of child nodes. + * + * This loop node instance is also used by the compiler to find the real root node e.g. for the + * truffle guest safepoint location. See TruffleSafepointInsertionPhase#skipOSRRoot. + */ + @Child protected NodeInterface loopNode; + + protected BaseOSRRootNode(TruffleLanguage language, FrameDescriptor frameDescriptor, NodeInterface loopNode) { + super(language, frameDescriptor); + this.loopNode = loopNode; + } + + @Override + public final Object execute(VirtualFrame frame) { + try { + return executeOSR(frame); + } finally { + // reachability fence is needed to keep the values from being cleared as non-live locals + Reference.reachabilityFence(frame); + Reference.reachabilityFence(this); + } + } + + /** + * Entrypoint for OSR root nodes. + */ + protected abstract Object executeOSR(VirtualFrame frame); +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRMetadata.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRMetadata.java similarity index 91% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRMetadata.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRMetadata.java index 625a2af57897..317d5cd1633a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRMetadata.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRMetadata.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.HashSet; import java.util.Map; @@ -50,10 +66,10 @@ *

* Performance note: We do not require the metadata field to be {@code volatile}. As long as the * field is initialized under double-checked locking (as is done in - * {@link GraalRuntimeSupport#pollBytecodeOSRBackEdge}, all threads will observe the same metadata - * instance. The JMM guarantees that the instance's final fields will be safely initialized before - * it is published; the non-final + non-volatile fields (e.g., the back edge counter) may not be, - * but we tolerate this inaccuracy in order to avoid volatile accesses in the hot path. + * {@link OptimizedRuntimeSupport#pollBytecodeOSRBackEdge}, all threads will observe the same + * metadata instance. The JMM guarantees that the instance's final fields will be safely initialized + * before it is published; the non-final + non-volatile fields (e.g., the back edge counter) may not + * be, but we tolerate this inaccuracy in order to avoid volatile accesses in the hot path. */ public final class BytecodeOSRMetadata { // Marker object to indicate that OSR is disabled. @@ -319,7 +335,7 @@ private void resetCounter() { * AST lock should be held when this is invoked. */ private OptimizedCallTarget createOSRTarget(int target, Object interpreterState, FrameDescriptor frameDescriptor, Object frameEntryState) { - TruffleLanguage language = GraalRuntimeAccessor.NODES.getLanguage(((Node) osrNode).getRootNode()); + TruffleLanguage language = OptimizedRuntimeAccessor.NODES.getLanguage(((Node) osrNode).getRootNode()); return (OptimizedCallTarget) new BytecodeOSRRootNode(language, frameDescriptor, osrNode, target, interpreterState, frameEntryState).getCallTarget(); } @@ -396,7 +412,7 @@ public void transferFrame(FrameWithoutBoxing source, FrameWithoutBoxing target, OsrEntryDescription description = (OsrEntryDescription) targetMetadata; CompilerAsserts.partialEvaluationConstant(description); - GraalRuntimeAccessor.ACCESSOR.startOSRFrameTransfer(target); + OptimizedRuntimeAccessor.ACCESSOR.startOSRFrameTransfer(target); // Transfer indexed frame slots transferLoop(description.indexedFrameTags.length, source, target, description.indexedFrameTags); // transfer auxiliary slots @@ -537,7 +553,7 @@ private static void transferIndexedFrameSlot(FrameWithoutBoxing source, FrameWit target.setObject(slot, source.getObject(slot)); break; case FrameWithoutBoxing.STATIC_TAG: - GraalRuntimeAccessor.ACCESSOR.transferOSRFrameStaticSlot(source, target, slot); + OptimizedRuntimeAccessor.ACCESSOR.transferOSRFrameStaticSlot(source, target, slot); break; case FrameWithoutBoxing.ILLEGAL_TAG: target.clear(slot); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRRootNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRRootNode.java similarity index 71% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRRootNode.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRRootNode.java index 7d3b6722e744..dd86ba17c94a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/BytecodeOSRRootNode.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/BytecodeOSRRootNode.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.lang.reflect.Method; import java.util.Map; @@ -57,7 +73,7 @@ final class BytecodeOSRRootNode extends BaseOSRRootNode { } private static boolean materializeCalled(FrameDescriptor frameDescriptor) { - return ((GraalTruffleRuntime) Truffle.getRuntime()).getFrameMaterializeCalled(frameDescriptor); + return ((OptimizedTruffleRuntime) Truffle.getRuntime()).getFrameMaterializeCalled(frameDescriptor); } Object getEntryTagsCache() { diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationState.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationState.java new file mode 100644 index 000000000000..a148421d64a6 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationState.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021, 2023, 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; + +import com.oracle.truffle.api.CompilerDirectives; + +public enum CompilationState { + + INTERPRETED, + + FIRST_TIER_ROOT, + LAST_TIER_ROOT, + + FIRST_TIER_INLINED, + LAST_TIER_INLINED; + + boolean isCompilationRoot() { + return this == FIRST_TIER_ROOT || this == LAST_TIER_ROOT; + } + + boolean isCompiled() { + return this != INTERPRETED; + } + + int getTier() { + switch (this) { + case INTERPRETED: + return 0; + case FIRST_TIER_INLINED: + case FIRST_TIER_ROOT: + return 1; + case LAST_TIER_INLINED: + case LAST_TIER_ROOT: + return 2; + default: + throw CompilerDirectives.shouldNotReachHere("invalid state"); + } + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationTask.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationTask.java similarity index 84% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationTask.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationTask.java index 85b166f9bc17..c75e69efcda0 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/CompilationTask.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/CompilationTask.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.lang.ref.WeakReference; import java.util.concurrent.Callable; @@ -44,7 +60,7 @@ public void accept(CompilationTask task) { OptimizedCallTarget callTarget = task.targetRef.get(); if (callTarget != null && task.start()) { try { - ((GraalTruffleRuntime) Truffle.getRuntime()).doCompile(callTarget, task); + ((OptimizedTruffleRuntime) Truffle.getRuntime()).doCompile(callTarget, task); } finally { callTarget.compiledTier(task.tier()); task.finished(); diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DefaultLoopNodeFactory.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DefaultLoopNodeFactory.java new file mode 100644 index 000000000000..898207df4a9b --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DefaultLoopNodeFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 2023, 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; + +import com.oracle.truffle.api.nodes.LoopNode; +import com.oracle.truffle.api.nodes.RepeatingNode; + +public class DefaultLoopNodeFactory implements LoopNodeFactory { + + @Override + public LoopNode create(RepeatingNode repeatingNode) { + return OptimizedOSRLoopNode.create(repeatingNode); + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DynamicThresholdsQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DynamicThresholdsQueue.java similarity index 53% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DynamicThresholdsQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DynamicThresholdsQueue.java index 9b5ead3b7cbb..991351ed5ae8 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/DynamicThresholdsQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/DynamicThresholdsQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; @@ -82,7 +98,7 @@ public Runnable poll() { } private void scaleThresholds() { - GraalTruffleRuntime.getRuntime().setCompilationThresholdScale(FixedPointMath.toFixedPoint(scale())); + OptimizedTruffleRuntime.getRuntime().setCompilationThresholdScale(FixedPointMath.toFixedPoint(scale())); } /** diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineCacheSupport.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineCacheSupport.java new file mode 100644 index 000000000000..0e51145fb2e1 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineCacheSupport.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020, 2023, 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; + +import java.util.function.Function; + +import org.graalvm.options.OptionDescriptors; +import org.graalvm.options.OptionValues; + +import com.oracle.truffle.api.TruffleLogger; + +public interface EngineCacheSupport extends OptimizedRuntimeServiceProvider { + + void onEngineCreated(EngineData e); + + void onEnginePatch(EngineData e); + + boolean onEngineClosing(EngineData e); + + void onEngineClosed(EngineData e); + + boolean isStoreEnabled(OptionValues options); + + Object tryLoadingCachedEngine(OptionValues options, Function loggerFactory); + + final class Disabled implements EngineCacheSupport { + + @Override + public void onEngineCreated(EngineData e) { + } + + @Override + public void onEnginePatch(EngineData e) { + } + + @Override + public Object tryLoadingCachedEngine(OptionValues options, Function loggerFactory) { + return null; + } + + @Override + public boolean onEngineClosing(EngineData e) { + return false; + } + + @Override + public boolean isStoreEnabled(OptionValues options) { + return false; + } + + @Override + public void onEngineClosed(EngineData e) { + } + + @Override + public int getPriority() { + // only last resort + return Integer.MIN_VALUE; + } + + @Override + public OptionDescriptors getEngineOptions() { + return OptionDescriptors.EMPTY; + } + + } + + static EngineCacheSupport get() { + return OptimizedTruffleRuntime.getRuntime().getEngineCacheSupport(); + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineData.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineData.java similarity index 71% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineData.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineData.java index 62a845fcd4fe..71bc2f81bc4a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/EngineData.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/EngineData.java @@ -1,67 +1,83 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; - -import static org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime.getRuntime; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ArgumentTypeSpeculation; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.BackgroundCompilation; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.Compilation; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompilationFailureAction; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompilationStatisticDetails; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompilationStatistics; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompileAOTOnCreate; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompileImmediately; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompileOnly; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.FirstTierCompilationThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.FirstTierMinInvokeThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.LastTierCompilationThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.MinInvokeThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.Mode; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.MultiTier; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.PriorityQueue; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.Profiling; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.PropagateLoopCountToLexicalSingleCaller; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.PropagateLoopCountToLexicalSingleCallerMaxDepth; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ReturnTypeSpeculation; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.Splitting; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingAllowForcedSplits; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingDumpDecisions; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingGrowthLimit; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingMaxCalleeSize; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingMaxPropagationDepth; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.SplittingTraceEvents; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceCompilation; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceCompilationDetails; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceDeoptimizeFrame; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceSplitting; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceSplittingSummary; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraceTransferToInterpreter; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueFirstTierBonus; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueFirstTierPriority; -import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueWeightingBothTiers; +package com.oracle.truffle.runtime; + +import static com.oracle.truffle.runtime.OptimizedTruffleRuntime.getRuntime; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.ArgumentTypeSpeculation; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.BackgroundCompilation; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.Compilation; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompilationFailureAction; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompilationStatisticDetails; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompilationStatistics; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompileAOTOnCreate; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompileImmediately; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompileOnly; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.FirstTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.FirstTierMinInvokeThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.LastTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.MinInvokeThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.Mode; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.MultiTier; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.PriorityQueue; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.Profiling; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.PropagateLoopCountToLexicalSingleCaller; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.PropagateLoopCountToLexicalSingleCallerMaxDepth; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.ReturnTypeSpeculation; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SingleTierCompilationThreshold; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.Splitting; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingAllowForcedSplits; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingDumpDecisions; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingGrowthLimit; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingMaxCalleeSize; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingMaxPropagationDepth; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.SplittingTraceEvents; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceCompilation; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceCompilationDetails; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceDeoptimizeFrame; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceSplitting; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceSplittingSummary; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraceTransferToInterpreter; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueFirstTierBonus; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueFirstTierPriority; +import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.TraversingQueueWeightingBothTiers; import java.util.ArrayList; import java.util.Collection; @@ -74,9 +90,6 @@ import java.util.logging.Level; import org.graalvm.collections.Pair; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.EngineModeEnum; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; -import org.graalvm.compiler.truffle.runtime.debug.StatisticsListener; import org.graalvm.options.OptionValues; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; @@ -85,6 +98,9 @@ import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.source.Source; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions.EngineModeEnum; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; +import com.oracle.truffle.runtime.debug.StatisticsListener; /** * Class used to store data used by the compiler in the Engine. Enables "global" compiler state per @@ -173,15 +189,15 @@ public final class EngineData { } public void preinitializeContext() { - GraalRuntimeAccessor.ENGINE.preinitializeContext(this.polyglotEngine); + OptimizedRuntimeAccessor.ENGINE.preinitializeContext(this.polyglotEngine); } public void finalizeStore() { - GraalRuntimeAccessor.ENGINE.finalizeStore(this.polyglotEngine); + OptimizedRuntimeAccessor.ENGINE.finalizeStore(this.polyglotEngine); } public Object getEngineLock() { - return GraalRuntimeAccessor.ENGINE.getEngineLock(this.polyglotEngine); + return OptimizedRuntimeAccessor.ENGINE.getEngineLock(this.polyglotEngine); } @SuppressWarnings("unchecked") @@ -288,7 +304,7 @@ private void loadOptions(OptionValues options) { this.callAndLoopThresholdInFirstTier = computeCallAndLoopThresholdInFirstTier(options); this.callTargetStatisticDetails = options.get(CompilationStatisticDetails); this.callTargetStatistics = options.get(CompilationStatistics) || this.callTargetStatisticDetails; - this.statisticsListener = this.callTargetStatistics ? StatisticsListener.createEngineListener(GraalTruffleRuntime.getRuntime()) : null; + this.statisticsListener = this.callTargetStatistics ? StatisticsListener.createEngineListener(OptimizedTruffleRuntime.getRuntime()) : null; this.profilingEnabled = options.get(Profiling); this.traceTransferToInterpreter = options.get(TraceTransferToInterpreter); this.traceDeoptimizeFrame = options.get(TraceDeoptimizeFrame); @@ -296,7 +312,7 @@ private void loadOptions(OptionValues options) { validateOptions(); parsedCompileOnly = null; - Map compilerOptionValues = GraalTruffleRuntime.CompilerOptionsDescriptors.extractOptions(engineOptions); + Map compilerOptionValues = OptimizedTruffleRuntime.CompilerOptionsDescriptors.extractOptions(engineOptions); updateCompilerOptions(compilerOptionValues); this.compilerOptions = compilerOptionValues; } @@ -396,7 +412,7 @@ public Collection getCallTargets() { if (polyglotEngine == null) { throw new IllegalStateException("The polyglot engine is closed."); } - return (Collection) GraalRuntimeAccessor.ENGINE.findCallTargets(polyglotEngine); + return (Collection) OptimizedRuntimeAccessor.ENGINE.findCallTargets(polyglotEngine); } private void validateOptions() { @@ -451,23 +467,23 @@ public TruffleLogger getLogger(String loggerId) { @SuppressWarnings("static-method") public void mergeLoadedSources(Source[] sources) { - GraalRuntimeAccessor.SOURCE.mergeLoadedSources(sources); + OptimizedRuntimeAccessor.SOURCE.mergeLoadedSources(sources); } @SuppressWarnings("static-method") public Object enterLanguage(TruffleLanguage language) { - return GraalRuntimeAccessor.ENGINE.enterLanguageFromRuntime(language); + return OptimizedRuntimeAccessor.ENGINE.enterLanguageFromRuntime(language); } @SuppressWarnings("static-method") public void leaveLanguage(TruffleLanguage language, Object prev) { - GraalRuntimeAccessor.ENGINE.leaveLanguageFromRuntime(language, prev); + OptimizedRuntimeAccessor.ENGINE.leaveLanguageFromRuntime(language, prev); } @SuppressWarnings("static-method") public TruffleLanguage getLanguage(OptimizedCallTarget target) { RootNode root = target.getRootNode(); - return GraalRuntimeAccessor.NODES.getLanguage(root); + return OptimizedRuntimeAccessor.NODES.getLanguage(root); } } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FixedPointMath.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FixedPointMath.java new file mode 100644 index 000000000000..be7e26bda1dd --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FixedPointMath.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2023, 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; + +public final class FixedPointMath { + private static final int SCALE = 4; + + /** + * should not be instantiated. + */ + private FixedPointMath() { + throw new IllegalStateException("Should not instantiate " + this.getClass().getName()); + } + + public static int toFixedPoint(double x) { + return (int) (x * (1 << SCALE)); + } + + public static int multiply(int fixedPointValue, int anInteger) { + return (fixedPointValue * anInteger) >> SCALE; + } + + public static double toDouble(int fixedPointValue) { + return ((double) fixedPointValue) / (1 << SCALE); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FloodControlHandler.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FloodControlHandler.java new file mode 100644 index 000000000000..1a15d37a2c3c --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/FloodControlHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020, 2023, 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; + +import java.util.function.Supplier; + +import com.oracle.truffle.compiler.TruffleCompilable; + +/** + * Support for an embedder to impose control over logging and dumping during Truffle compilation + * failure handling. + */ +public interface FloodControlHandler extends OptimizedRuntimeServiceProvider { + + /** + * Return {@code true} to suppress logging and dumping of a given exception. + */ + boolean isSuppressedFailure(TruffleCompilable compilable, Supplier serializedException); +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/InlineDecision.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/InlineDecision.java similarity index 52% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/InlineDecision.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/InlineDecision.java index 3c05af24b840..f93d0512170d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/InlineDecision.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/InlineDecision.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; /** * Since SVM overrides {@link OptimizedCallTarget#doInvoke(Object[])} to specialize behaviour on diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/LoopNodeFactory.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/LoopNodeFactory.java new file mode 100644 index 000000000000..be6163dc6ceb --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/LoopNodeFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, 2023, 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; + +import com.oracle.truffle.api.nodes.LoopNode; +import com.oracle.truffle.api.nodes.RepeatingNode; + +public interface LoopNodeFactory extends OptimizedRuntimeServiceProvider { + + LoopNode create(RepeatingNode repeatingNode); + +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModuleUtil.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModuleUtil.java new file mode 100644 index 000000000000..7a6c6161756e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModuleUtil.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022, 2023, 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; + +import java.util.Set; + +public final class ModuleUtil { + + public static void exportTo(Class client) { + Module truffleModule = ModuleUtil.class.getModule(); + exportFromTo(truffleModule, client.getModule()); + } + + private static void exportFromTo(Module truffleModule, Module clientModule) { + if (truffleModule != clientModule) { + Set packages = truffleModule.getPackages(); + for (String pkg : packages) { + boolean exported = truffleModule.isExported(pkg, clientModule); + if (!exported) { + truffleModule.addExports(pkg, clientModule); + } + } + } + } + +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModulesSupport.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModulesSupport.java new file mode 100644 index 000000000000..bd1ecbe2cb95 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/ModulesSupport.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2023, 2023, 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; + +import java.lang.module.ModuleDescriptor.Requires; + +import com.oracle.truffle.api.Truffle; + +import jdk.internal.module.Modules; + +public final class ModulesSupport { + + private static final boolean ATTACH_AVAILABLE; + + static { + ATTACH_AVAILABLE = loadModulesSupportLibrary(); + + if (ATTACH_AVAILABLE) { + // this is the only access we really need to request natively using JNI. + // after that we can access through the Modules class + addExports0(ModulesSupport.class.getModule().getLayer().findModule("java.base").orElseThrow(), "jdk.internal.module", ModulesSupport.class.getModule()); + } + } + + private ModulesSupport() { + } + + /** + * This is invoked reflectively from {@link Truffle}. + */ + public static String exportJVMCI(Class toClass) { + ModuleLayer layer = toClass.getModule().getLayer(); + if (layer == null) { + /* + * Truffle is running in an unnamed module, so we cannot export jvmci to it. + */ + if (ModulesSupport.class.getModule().getLayer() != null) { + /* + * Even if the runtime is in the unnamed mode, make sure truffle runtime classes are + * in a module layer and ensure they have access to JVMCI. + */ + exportJVMCI(ModulesSupport.class); + } + return "Truffle was loaded from the class-path. Use Truffle from the module-path instead."; + } + + Module jvmciModule = layer.findModule("jdk.internal.vm.ci").orElse(null); + if (jvmciModule == null) { + // jvmci not found -> fallback to default runtime + return "JVMCI is not enabled for this JVM. Enable JVMCI using -XX:+EnableJVMCI."; + } + + if (!ATTACH_AVAILABLE) { + return "The Truffle attach library is not available."; + } + + addExportsRecursive(jvmciModule, toClass.getModule()); + return null; + } + + private static void addExportsRecursive(Module jvmciModule, Module runtimeModule) { + for (String pn : jvmciModule.getPackages()) { + ModulesSupport.addExports(jvmciModule, pn, runtimeModule); + } + for (Requires requires : runtimeModule.getDescriptor().requires()) { + Module requiredModule = ModulesSupport.class.getModule().getLayer().findModule(requires.name()).orElse(null); + if (requiredModule != null) { + if (requiredModule.getName().equals("java.base")) { + continue; + } + addExportsRecursive(jvmciModule, requiredModule); + } + } + } + + public static void addExports(Module m1, String pn, Module m2) { + // we check available to avoid illegal access errors for the Modules class + if (ATTACH_AVAILABLE) { + Modules.addExports(m1, pn, m2); + } else { + throw new UnsupportedOperationException(); + } + } + + private static boolean loadModulesSupportLibrary() { + String attachLib = System.getProperty("truffle.attach.library"); + try { + if (attachLib == null) { + try { + System.loadLibrary("truffleattach"); + } catch (UnsatisfiedLinkError invalidLibrary) { + return false; + } + } else { + System.load(attachLib); + } + return true; + } catch (Throwable throwable) { + throw new InternalError(throwable); + } + } + + private static native void addExports0(Module m1, String pn, Module m2); + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedAssumption.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedAssumption.java similarity index 83% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedAssumption.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedAssumption.java index 899889055f7f..c6f10e6e8989 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedAssumption.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedAssumption.java @@ -1,33 +1,48 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.function.Consumer; import java.util.logging.Level; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; import org.graalvm.options.OptionValues; import com.oracle.truffle.api.Assumption; @@ -36,6 +51,7 @@ import com.oracle.truffle.api.TruffleLogger; import com.oracle.truffle.api.impl.AbstractAssumption; import com.oracle.truffle.api.nodes.InvalidAssumptionException; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; import jdk.vm.ci.meta.JavaKind.FormatWithToString; @@ -191,7 +207,7 @@ private synchronized void invalidateImpl(String message) { engineOptions = callTarget.getOptionValues(); logger = callTarget.engine.getEngineLogger(); } else { - EngineData engineData = GraalTVMCI.getEngineData(null); + EngineData engineData = OptimizedTVMCI.getEngineData(null); engineOptions = engineData.engineOptions; logger = engineData.getEngineLogger(); } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedBlockNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedBlockNode.java similarity index 92% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedBlockNode.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedBlockNode.java index 6d55dc242999..41fa6c312fe3 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedBlockNode.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedBlockNode.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.ArrayList; import java.util.Arrays; @@ -631,7 +647,7 @@ public static final class PartialBlocks { RootNode rootNode = rootCompilation.getRootNode(); assert rootNode == block.getRootNode(); - GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime(); + OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime(); Class materializedFrameClass = runtime.createMaterializedFrame(new Object[0]).getClass(); FrameDescriptor descriptor = rootNode.getFrameDescriptor(); runtime.markFrameMaterializeCalled(descriptor); @@ -646,7 +662,7 @@ public static final class PartialBlocks { } PartialBlockRootNode partialRootNode = new PartialBlockRootNode<>(new FrameDescriptor(), block, startIndex, endIndex, blockIndex); - GraalRuntimeAccessor.NODES.applySharingLayer(rootNode, partialRootNode); + OptimizedRuntimeAccessor.NODES.applySharingLayer(rootNode, partialRootNode); targets[i] = (OptimizedCallTarget) partialRootNode.getCallTarget(); targets[i].setNonTrivialNodeCount(blockSizes[i]); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedCallTarget.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedCallTarget.java similarity index 94% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedCallTarget.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedCallTarget.java index 2f89398e8de9..70b325e5f004 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedCallTarget.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedCallTarget.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.lang.ref.Reference; import java.lang.ref.WeakReference; @@ -36,8 +52,6 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.function.Supplier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; import org.graalvm.options.OptionKey; import org.graalvm.options.OptionValues; @@ -63,6 +77,8 @@ import com.oracle.truffle.api.nodes.NodeUtil; import com.oracle.truffle.api.nodes.NodeVisitor; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.SpeculationLog; @@ -80,7 +96,7 @@ * depending on the type of call. * *

- *              GraalRuntimeSupport#callProfiled                    GraalRuntimeSupport#callInlined
+ *              OptimizedRuntimeSupport#callProfiled                    OptimizedRuntimeSupport#callInlined
  *                                |                                               |
  *                                |                                               V
  *  PUBLIC   call -> callIndirect | callOSR   callDirect <================> callInlined
@@ -347,7 +363,7 @@ protected OptimizedCallTarget(OptimizedCallTarget sourceCallTarget, RootNode roo
         this.sourceCallTarget = sourceCallTarget;
         this.speculationLog = sourceCallTarget != null ? sourceCallTarget.getSpeculationLog() : null;
         this.rootNode = rootNode;
-        this.engine = GraalTVMCI.getEngineData(rootNode);
+        this.engine = OptimizedTVMCI.getEngineData(rootNode);
         this.resetCompilationProfile();
         // Do not adopt children of OSRRootNodes; we want to preserve the parent of the child
         // node(s).
@@ -371,8 +387,8 @@ private int uninitializedNodeCount(RootNode rootNode) {
         if (isOSR()) {
             return -1;
         }
-        int childrenCount = GraalRuntimeAccessor.NODES.adoptChildrenAndCount(rootNode);
-        int size = GraalRuntimeAccessor.NODES.computeSize(rootNode);
+        int childrenCount = OptimizedRuntimeAccessor.NODES.adoptChildrenAndCount(rootNode);
+        int size = OptimizedRuntimeAccessor.NODES.computeSize(rootNode);
         return size > 0 ? size : childrenCount;
     }
 
@@ -407,11 +423,11 @@ final Assumption getValidRootAssumption() {
 
     @Override
     public boolean isTrivial() {
-        return GraalRuntimeAccessor.NODES.isTrivial(rootNode);
+        return OptimizedRuntimeAccessor.NODES.isTrivial(rootNode);
     }
 
     private FrameDescriptor getParentFrameDescriptor() {
-        return GraalRuntimeAccessor.NODES.getParentFrameDescriptor(rootNode);
+        return OptimizedRuntimeAccessor.NODES.getParentFrameDescriptor(rootNode);
     }
 
     /**
@@ -483,7 +499,7 @@ public final Object call(Object... args) {
         try {
             return callIndirect(prev, args);
         } catch (Throwable t) {
-            GraalRuntimeAccessor.LANGUAGE.addStackFrameInfo(prev, null, t, null);
+            OptimizedRuntimeAccessor.LANGUAGE.addStackFrameInfo(prev, null, t, null);
             throw rethrow(t);
         } finally {
             encapsulating.set(prev);
@@ -745,7 +761,7 @@ private Object executeRootNode(VirtualFrame frame, CompilationState tier) {
 
     private RuntimeException handleException(VirtualFrame frame, Throwable t) {
         Throwable profiledT = profileExceptionType(t);
-        GraalRuntimeAccessor.LANGUAGE.addStackFrameInfo(null, this, profiledT, frame);
+        OptimizedRuntimeAccessor.LANGUAGE.addStackFrameInfo(null, this, profiledT, frame);
         throw rethrow(profiledT);
     }
 
@@ -753,8 +769,8 @@ private void notifyDeoptimized(VirtualFrame frame) {
         runtime().getListener().onCompilationDeoptimized(this, frame);
     }
 
-    protected static GraalTruffleRuntime runtime() {
-        return (GraalTruffleRuntime) Truffle.getRuntime();
+    protected static OptimizedTruffleRuntime runtime() {
+        return (OptimizedTruffleRuntime) Truffle.getRuntime();
     }
 
     // This should be private but can't be due to SVM bug.
@@ -771,14 +787,14 @@ public final boolean isInitialized() {
 
     private synchronized void initialize(boolean validate) {
         if (!initialized) {
-            if (isSourceCallTarget() && rootNode.isCloningAllowed() && !GraalRuntimeAccessor.NODES.isCloneUninitializedSupported(rootNode)) {
+            if (isSourceCallTarget() && rootNode.isCloningAllowed() && !OptimizedRuntimeAccessor.NODES.isCloneUninitializedSupported(rootNode)) {
                 // We are the source CallTarget, so make a copy.
                 this.uninitializedRootNode = NodeUtil.cloneNode(rootNode);
             }
 
-            assert !validate || GraalRuntimeAccessor.NODES.getCallTargetWithoutInitialization(rootNode) == this : "Call target out of sync.";
+            assert !validate || OptimizedRuntimeAccessor.NODES.getCallTargetWithoutInitialization(rootNode) == this : "Call target out of sync.";
 
-            GraalRuntimeAccessor.INSTRUMENT.onFirstExecution(getRootNode(), validate);
+            OptimizedRuntimeAccessor.INSTRUMENT.onFirstExecution(getRootNode(), validate);
             if (engine.callTargetStatistics) {
                 this.initializedTimestamp = System.nanoTime();
             } else {
@@ -925,7 +941,7 @@ public final boolean invalidate(CharSequence reason) {
     final OptimizedCallTarget cloneUninitialized() {
         assert !isSplit() : "Cannot clone a clone.";
         ensureInitialized();
-        RootNode clonedRoot = GraalRuntimeAccessor.NODES.cloneUninitialized(this, rootNode, uninitializedRootNode);
+        RootNode clonedRoot = OptimizedRuntimeAccessor.NODES.cloneUninitialized(this, rootNode, uninitializedRootNode);
         return (OptimizedCallTarget) clonedRoot.getCallTarget();
     }
 
@@ -936,7 +952,7 @@ final OptimizedCallTarget cloneUninitialized() {
      */
     public SpeculationLog getSpeculationLog() {
         if (speculationLog == null) {
-            SPECULATION_LOG_UPDATER.compareAndSet(this, null, ((GraalTruffleRuntime) Truffle.getRuntime()).createSpeculationLog());
+            SPECULATION_LOG_UPDATER.compareAndSet(this, null, ((OptimizedTruffleRuntime) Truffle.getRuntime()).createSpeculationLog());
         }
         return speculationLog;
     }
@@ -947,7 +963,7 @@ final void setSpeculationLog(SpeculationLog speculationLog) {
 
     @Override
     public final JavaConstant asJavaConstant() {
-        return GraalTruffleRuntime.getRuntime().forObject(this);
+        return OptimizedTruffleRuntime.getRuntime().forObject(this);
     }
 
     @SuppressWarnings({"unchecked"})
@@ -1010,7 +1026,7 @@ public final boolean computeBlockCompilations() {
     public final boolean onInvalidate(Object source, CharSequence reason, boolean wasActive) {
         cachedNonTrivialNodeCount = -1;
         if (wasActive) {
-            GraalTruffleRuntime.getRuntime().getListener().onCompilationInvalidated(this, source, reason);
+            OptimizedTruffleRuntime.getRuntime().getListener().onCompilationInvalidated(this, source, reason);
         }
         return cancelCompilation(reason) || wasActive;
     }
@@ -1043,7 +1059,7 @@ public final void onCompilationFailed(Supplier serializedException, bool
             throw new OptimizationFailedException(error, this);
         }
         if (action.ordinal() >= ExceptionAction.Print.ordinal()) {
-            GraalTruffleRuntime rt = runtime();
+            OptimizedTruffleRuntime rt = runtime();
             Map properties = new LinkedHashMap<>();
             properties.put("AST", getNonTrivialNodeCount());
             rt.logEvent(this, 0, "opt fail", toString(), properties, serializedException.get());
@@ -1168,7 +1184,7 @@ public static int calculateNonTrivialNodes(Node node) {
 
     public final Map getDebugProperties() {
         Map properties = new LinkedHashMap<>();
-        GraalTruffleRuntimeListener.addASTSizeProperty(this, properties);
+        OptimizedTruffleRuntimeListener.addASTSizeProperty(this, properties);
         String callsThresholdInInterpreter = String.format("%7d/%5d", getCallCount(), engine.callThresholdInInterpreter);
         String loopsThresholdInInterpreter = String.format("%7d/%5d", getCallAndLoopCount(), engine.callAndLoopThresholdInInterpreter);
         if (engine.multiTier) {
@@ -1768,7 +1784,7 @@ private boolean prepareForAOTImpl() {
             return false;
         }
 
-        ExecutionSignature profile = GraalRuntimeAccessor.NODES.prepareForAOT(rootNode);
+        ExecutionSignature profile = OptimizedRuntimeAccessor.NODES.prepareForAOT(rootNode);
         if (profile == null) {
             return false;
         }
diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedDirectCallNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedDirectCallNode.java
similarity index 75%
rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedDirectCallNode.java
rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedDirectCallNode.java
index 176bb462f00e..2e4f03f66371 100644
--- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedDirectCallNode.java
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedDirectCallNode.java
@@ -1,28 +1,44 @@
 /*
- * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023, 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.
+ * The Universal Permissive License (UPL), Version 1.0
  *
- * 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).
+ * 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
  *
- * 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.
+ * (a) the Software, and
  *
- * 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.
+ * (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 org.graalvm.compiler.truffle.runtime;
+package com.oracle.truffle.runtime;
 
 import com.oracle.truffle.api.CallTarget;
 import com.oracle.truffle.api.CompilerAsserts;
@@ -83,7 +99,7 @@ public Object call(Object... arguments) {
 
     private RuntimeException handleException(Throwable t) {
         Throwable profiledT = profileExceptionType(t);
-        GraalRuntimeAccessor.LANGUAGE.addStackFrameInfo(this, null, profiledT, null);
+        OptimizedRuntimeAccessor.LANGUAGE.addStackFrameInfo(this, null, profiledT, null);
         throw OptimizedCallTarget.rethrow(profiledT);
     }
 
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFastThreadLocal.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFastThreadLocal.java
new file mode 100644
index 000000000000..fd444eeff48b
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFastThreadLocal.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2021, 2023, 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;
+
+import static com.oracle.truffle.api.CompilerAsserts.partialEvaluationConstant;
+import static com.oracle.truffle.api.CompilerDirectives.inCompiledCode;
+import static com.oracle.truffle.runtime.OptimizedCallTarget.castArrayFixedLength;
+import static com.oracle.truffle.runtime.OptimizedCallTarget.unsafeCast;
+
+import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.impl.AbstractFastThreadLocal;
+
+public abstract class OptimizedFastThreadLocal extends AbstractFastThreadLocal {
+
+    protected OptimizedFastThreadLocal() {
+    }
+
+    @Override
+    public abstract void set(Object[] data);
+
+    @Override
+    public abstract Object[] get();
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public final  C fastGet(int index, Class castType, boolean invalidateOnNull) {
+        Object[] data;
+        if (inCompiledCode()) {
+            partialEvaluationConstant(index);
+            partialEvaluationConstant(castType);
+            Object[] array = get();
+            if (array == null) {
+                if (invalidateOnNull) {
+                    CompilerDirectives.transferToInterpreterAndInvalidate();
+                }
+                return null;
+            }
+            Object v = castArrayFixedLength(array, index + 1)[index];
+            C result = unsafeCast(v, castType, true, false, true);
+            return result;
+        } else {
+            data = get();
+            if (data == null) {
+                return null;
+            }
+            C result = (C) data[index];
+            assert castType == null || result == null || result.getClass() == castType : "Invalid exact type returned";
+            return result;
+        }
+    }
+
+}
diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFrameInstance.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFrameInstance.java
similarity index 59%
rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFrameInstance.java
rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFrameInstance.java
index 0cd277794331..9714731e368d 100644
--- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalFrameInstance.java
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedFrameInstance.java
@@ -1,28 +1,44 @@
 /*
- * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2023, 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.
+ * The Universal Permissive License (UPL), Version 1.0
  *
- * 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).
+ * 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
  *
- * 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.
+ * (a) the Software, and
  *
- * 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.
+ * (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 org.graalvm.compiler.truffle.runtime;
+package com.oracle.truffle.runtime;
 
 import java.lang.reflect.Method;
 
@@ -35,7 +51,7 @@
 
 import jdk.vm.ci.code.stack.InspectedFrame;
 
-public class GraalFrameInstance implements FrameInstance {
+public class OptimizedFrameInstance implements FrameInstance {
     static final int CALL_TARGET_INDEX = 0;
     static final int FRAME_INDEX = 1;
     static final int OPTIMIZATION_TIER_FRAME_INDEX = 2;
@@ -52,7 +68,7 @@ public class GraalFrameInstance implements FrameInstance {
         try {
             CALL_DIRECT = OptimizedCallTarget.class.getDeclaredMethod("callDirect", Node.class, Object[].class);
             CALL_INLINED = OptimizedCallTarget.class.getDeclaredMethod("callInlined", Node.class, Object[].class);
-            CALL_INLINED_CALL = GraalRuntimeSupport.class.getDeclaredMethod(GraalRuntimeSupport.CALL_INLINED_METHOD_NAME, Node.class, CallTarget.class, Object[].class);
+            CALL_INLINED_CALL = OptimizedRuntimeSupport.class.getDeclaredMethod(OptimizedRuntimeSupport.CALL_INLINED_METHOD_NAME, Node.class, CallTarget.class, Object[].class);
             CALL_INDIRECT = OptimizedCallTarget.class.getDeclaredMethod("callIndirect", Node.class, Object[].class);
             CALL_TARGET_METHOD = OptimizedCallTarget.class.getDeclaredMethod("executeRootNode", VirtualFrame.class, CompilationState.class);
         } catch (NoSuchMethodException | SecurityException e) {
@@ -63,7 +79,7 @@ public class GraalFrameInstance implements FrameInstance {
     private final InspectedFrame callTargetFrame;
     private final InspectedFrame callNodeFrame;
 
-    GraalFrameInstance(InspectedFrame callTargetFrame, InspectedFrame callNodeFrame) {
+    OptimizedFrameInstance(InspectedFrame callTargetFrame, InspectedFrame callNodeFrame) {
         this.callTargetFrame = callTargetFrame;
         this.callNodeFrame = callNodeFrame;
     }
@@ -74,7 +90,7 @@ protected Frame getFrameFrom(InspectedFrame inspectedFrame, FrameAccess access)
             if (inspectedFrame.isVirtual(FRAME_INDEX)) {
                 final OptimizedCallTarget callTarget = (OptimizedCallTarget) getCallTarget();
                 if (callTarget.engine.traceDeoptimizeFrame) {
-                    GraalTruffleRuntime.StackTraceHelper.logHostAndGuestStacktrace("FrameInstance#getFrame(MATERIALIZE)", callTarget);
+                    OptimizedTruffleRuntime.StackTraceHelper.logHostAndGuestStacktrace("FrameInstance#getFrame(MATERIALIZE)", callTarget);
                 }
                 inspectedFrame.materializeVirtualObjects(false);
             }
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedIndirectCallNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedIndirectCallNode.java
new file mode 100644
index 000000000000..1fd0e2d2a75e
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedIndirectCallNode.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2023, 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;
+
+import com.oracle.truffle.api.CallTarget;
+import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
+import com.oracle.truffle.api.nodes.IndirectCallNode;
+import com.oracle.truffle.api.nodes.NodeInfo;
+
+/**
+ * A call node with a dynamic {@link CallTarget} that can be optimized by Graal.
+ */
+@NodeInfo
+public final class OptimizedIndirectCallNode extends IndirectCallNode {
+
+    @CompilationFinal private Class exceptionProfile;
+
+    /*
+     * Should be instantiated with the runtime.
+     */
+    OptimizedIndirectCallNode() {
+    }
+
+    @Override
+    public Object call(CallTarget target, Object... arguments) {
+        try {
+            OptimizedCallTarget optimizedTarget = ((OptimizedCallTarget) target);
+            return optimizedTarget.callIndirect(this, arguments);
+        } catch (Throwable t) {
+            throw handleException(t);
+        }
+    }
+
+    private RuntimeException handleException(Throwable t) {
+        Throwable profiledT = profileExceptionType(t);
+        OptimizedRuntimeAccessor.LANGUAGE.addStackFrameInfo(this, null, profiledT, null);
+        throw OptimizedCallTarget.rethrow(profiledT);
+    }
+
+    @SuppressWarnings("unchecked")
+    private  T profileExceptionType(T value) {
+        Class clazz = exceptionProfile;
+        if (clazz != Throwable.class) {
+            if (clazz != null && value.getClass() == clazz) {
+                if (CompilerDirectives.inInterpreter()) {
+                    return value;
+                } else {
+                    return (T) CompilerDirectives.castExact(value, clazz);
+                }
+            } else {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
+                if (clazz == null) {
+                    exceptionProfile = value.getClass();
+                } else {
+                    exceptionProfile = Throwable.class;
+                }
+            }
+        }
+        return value;
+    }
+}
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedLoopNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedLoopNode.java
new file mode 100644
index 000000000000..21426459cae4
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedLoopNode.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2014, 2023, 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;
+
+import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.TruffleSafepoint;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.nodes.LoopNode;
+import com.oracle.truffle.api.nodes.RepeatingNode;
+
+public final class OptimizedLoopNode extends AbstractOptimizedLoopNode {
+
+    OptimizedLoopNode(RepeatingNode repeatingNode) {
+        super(repeatingNode);
+    }
+
+    @Override
+    public Object execute(VirtualFrame frame) {
+        Object status;
+        long loopCount = 0;
+        try {
+            while (inject(repeatingNode.shouldContinue(status = repeatingNode.executeRepeatingWithValue(frame)))) {
+                if (CompilerDirectives.hasNextTier()) {
+                    loopCount++;
+                }
+                TruffleSafepoint.poll(this);
+            }
+            return status;
+        } finally {
+            profileCounted(loopCount);
+            reportLoopCount(this, OptimizedOSRLoopNode.toIntOrMaxInt(loopCount));
+        }
+    }
+
+    static LoopNode create(RepeatingNode repeatingNode) {
+        return new OptimizedLoopNode(repeatingNode);
+    }
+
+}
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRFrameInstance.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRFrameInstance.java
new file mode 100644
index 000000000000..618b47bfaeb7
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRFrameInstance.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2021, 2023, 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;
+
+import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.frame.Frame;
+import com.oracle.truffle.api.nodes.RootNode;
+
+import jdk.vm.ci.code.stack.InspectedFrame;
+
+/**
+ * Represents a Truffle {@link com.oracle.truffle.api.frame.FrameInstance} where OSR occurred.
+ *
+ * Contains a separate field for the {@link InspectedFrame} containing the most up-to-date Frame.
+ */
+final class OptimizedOSRFrameInstance extends OptimizedFrameInstance {
+    private final InspectedFrame osrFrame;
+
+    OptimizedOSRFrameInstance(InspectedFrame callTargetFrame, InspectedFrame callNodeFrame, InspectedFrame osrFrame) {
+        super(callTargetFrame, callNodeFrame);
+        this.osrFrame = osrFrame;
+    }
+
+    @TruffleBoundary
+    @Override
+    public Frame getFrame(FrameAccess access) {
+        Frame materializedOSRFrame = getFrameFrom(osrFrame, access);
+        if (getOSRRootNode() instanceof OptimizedOSRLoopNode.LoopOSRRootNode) {
+            return (Frame) materializedOSRFrame.getArguments()[0];
+        }
+        return materializedOSRFrame;
+    }
+
+    private RootNode getOSRRootNode() {
+        return ((OptimizedCallTarget) osrFrame.getLocal(OptimizedFrameInstance.CALL_TARGET_INDEX)).getRootNode();
+    }
+
+    @TruffleBoundary
+    @Override
+    public boolean isVirtualFrame() {
+        return osrFrame.isVirtual(FRAME_INDEX);
+    }
+
+    @TruffleBoundary
+    @Override
+    public int getCompilationTier() {
+        return ((CompilationState) osrFrame.getLocal(OPTIMIZATION_TIER_FRAME_INDEX)).getTier();
+    }
+
+    @TruffleBoundary
+    @Override
+    public boolean isCompilationRoot() {
+        return ((CompilationState) osrFrame.getLocal(OPTIMIZATION_TIER_FRAME_INDEX)).isCompilationRoot();
+    }
+}
diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedOSRLoopNode.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRLoopNode.java
similarity index 86%
rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedOSRLoopNode.java
rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRLoopNode.java
index c44ac6e5c9ef..1497be1e77c8 100644
--- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/OptimizedOSRLoopNode.java
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedOSRLoopNode.java
@@ -1,28 +1,44 @@
 /*
- * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023, 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.
+ * The Universal Permissive License (UPL), Version 1.0
  *
- * 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).
+ * 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
  *
- * 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.
+ * (a) the Software, and
  *
- * 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.
+ * (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 org.graalvm.compiler.truffle.runtime;
+package com.oracle.truffle.runtime;
 
 import org.graalvm.options.OptionValues;
 
@@ -258,7 +274,7 @@ private AbstractLoopOSRRootNode createRootNodeImpl(RootNode root, Class T unsafeCast(Object value, Class type, boolean condition, boolean
     @Override
     public void flushCompileQueue(Object runtimeData) {
         EngineData engine = (EngineData) runtimeData;
-        BackgroundCompileQueue queue = GraalTruffleRuntime.getRuntime().getCompileQueue();
+        BackgroundCompileQueue queue = OptimizedTruffleRuntime.getRuntime().getCompileQueue();
         // compile queue might be null if no call target was yet created
         if (queue != null) {
             for (OptimizedCallTarget target : queue.getQueuedTargets(engine)) {
@@ -273,7 +291,7 @@ public void flushCompileQueue(Object runtimeData) {
 
     @Override
     public Object tryLoadCachedEngine(OptionValues options, Function loggerFactory) {
-        return GraalTruffleRuntime.getRuntime().getEngineCacheSupport().tryLoadingCachedEngine(options, loggerFactory);
+        return OptimizedTruffleRuntime.getRuntime().getEngineCacheSupport().tryLoadingCachedEngine(options, loggerFactory);
     }
 
     @Override
@@ -313,22 +331,22 @@ public boolean isOSRRootNode(RootNode rootNode) {
 
     @Override
     public int getObjectAlignment() {
-        return GraalTruffleRuntime.getRuntime().getObjectAlignment();
+        return OptimizedTruffleRuntime.getRuntime().getObjectAlignment();
     }
 
     @Override
     public int getArrayBaseOffset(Class componentType) {
-        return GraalTruffleRuntime.getRuntime().getArrayBaseOffset(componentType);
+        return OptimizedTruffleRuntime.getRuntime().getArrayBaseOffset(componentType);
     }
 
     @Override
     public int getArrayIndexScale(Class componentType) {
-        return GraalTruffleRuntime.getRuntime().getArrayIndexScale(componentType);
+        return OptimizedTruffleRuntime.getRuntime().getArrayIndexScale(componentType);
     }
 
     @Override
     public int getBaseInstanceSize(Class type) {
-        return GraalTruffleRuntime.getRuntime().getBaseInstanceSize(type);
+        return OptimizedTruffleRuntime.getRuntime().getBaseInstanceSize(type);
     }
 
     @Override
@@ -338,16 +356,22 @@ public boolean isLegacyCompilerOption(String key) {
 
     @Override
     public int[] getFieldOffsets(Class type, boolean includePrimitive, boolean includeSuperclasses) {
-        return GraalTruffleRuntime.getRuntime().getFieldOffsets(type, includePrimitive, includeSuperclasses);
+        return OptimizedTruffleRuntime.getRuntime().getFieldOffsets(type, includePrimitive, includeSuperclasses);
     }
 
     @Override
     public AbstractFastThreadLocal getContextThreadLocal() {
-        AbstractFastThreadLocal local = GraalTruffleRuntime.getRuntime().getFastThreadLocalImpl();
+        AbstractFastThreadLocal local = OptimizedTruffleRuntime.getRuntime().getFastThreadLocalImpl();
         if (local == null) {
             return super.getContextThreadLocal();
         }
         return local;
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public  ThreadLocal createTerminatingThreadLocal(Supplier initialValue, Consumer onThreadTermination) {
+        return OptimizedTruffleRuntime.createTerminatingThreadLocal(initialValue, onThreadTermination);
+    }
+
 }
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTVMCI.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTVMCI.java
new file mode 100644
index 000000000000..13975b20bdfc
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTVMCI.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2014, 2023, 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;
+
+import com.oracle.truffle.api.impl.Accessor.EngineSupport;
+import com.oracle.truffle.api.impl.Accessor.RuntimeSupport;
+import com.oracle.truffle.api.impl.TVMCI;
+import com.oracle.truffle.api.nodes.RootNode;
+
+public final class OptimizedTVMCI extends TVMCI {
+
+    @Override
+    protected RuntimeSupport createRuntimeSupport(Object permission) {
+        return new OptimizedRuntimeSupport(permission);
+    }
+
+    static EngineData getEngineData(RootNode rootNode) {
+        final EngineSupport engineAccess = OptimizedRuntimeAccessor.ENGINE;
+        final Object layer;
+        if (rootNode == null) {
+            layer = engineAccess.getCurrentSharingLayer();
+        } else {
+            layer = OptimizedRuntimeAccessor.NODES.getSharingLayer(rootNode);
+        }
+        return engineAccess.getOrCreateRuntimeData(layer);
+    }
+
+}
diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTestTVMCI.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTestTVMCI.java
new file mode 100644
index 000000000000..a20b5717e3f6
--- /dev/null
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTestTVMCI.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017, 2023, 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;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import com.oracle.truffle.api.impl.TVMCI;
+import com.oracle.truffle.api.nodes.RootNode;
+import com.oracle.truffle.runtime.OptimizedTestTVMCI.GraalTestContext;
+
+final class OptimizedTestTVMCI extends TVMCI.Test {
+
+    static final class GraalTestContext implements Closeable {
+
+        @Override
+        public synchronized void close() throws IOException {
+        }
+    }
+
+    @Override
+    protected GraalTestContext createTestContext(String testName) {
+        return new GraalTestContext();
+    }
+
+    @Override
+    public OptimizedCallTarget createTestCallTarget(GraalTestContext testContext, RootNode testNode) {
+        return (OptimizedCallTarget) testNode.getCallTarget();
+    }
+
+    @SuppressWarnings("try")
+    @Override
+    public void finishWarmup(GraalTestContext testContext, OptimizedCallTarget callTarget) {
+        callTarget.compile(true);
+        callTarget.waitForCompilation();
+    }
+}
diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntime.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntime.java
similarity index 87%
rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntime.java
rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntime.java
index 4dd3fa8c52cf..58ed800d7430 100644
--- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntime.java
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntime.java
@@ -2,34 +2,51 @@
  * Copyright (c) 2013, 2023, 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.
+ * The Universal Permissive License (UPL), Version 1.0
  *
- * 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).
+ * 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
  *
- * 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.
+ * (a) the Software, and
  *
- * 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.
+ * (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 org.graalvm.compiler.truffle.runtime;
+package com.oracle.truffle.runtime;
 
-import static org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.CompilerIdleDelay;
+import static com.oracle.truffle.runtime.OptimizedRuntimeOptions.CompilerIdleDelay;
 
 import java.io.CharArrayWriter;
 import java.io.PrintWriter;
 import java.lang.annotation.Annotation;
 import java.lang.invoke.MethodHandle;
+import java.lang.reflect.Method;
 import java.nio.Buffer;
 import java.nio.file.FileSystems;
 import java.nio.file.Path;
@@ -51,27 +68,8 @@
 import java.util.logging.Level;
 import java.util.stream.Collectors;
 
-import com.oracle.truffle.api.TruffleLogger;
 import org.graalvm.collections.EconomicMap;
 import org.graalvm.collections.UnmodifiableEconomicMap;
-import org.graalvm.compiler.truffle.common.ConstantFieldInfo;
-import org.graalvm.compiler.truffle.common.HostMethodInfo;
-import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency;
-import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo;
-import org.graalvm.compiler.truffle.common.TruffleCompilable;
-import org.graalvm.compiler.truffle.common.TruffleCompilationSupport;
-import org.graalvm.compiler.truffle.common.TruffleCompiler;
-import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor;
-import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime;
-import org.graalvm.compiler.truffle.runtime.BackgroundCompileQueue.Priority;
-import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction;
-import org.graalvm.compiler.truffle.runtime.debug.JFRListener;
-import org.graalvm.compiler.truffle.runtime.debug.StatisticsListener;
-import org.graalvm.compiler.truffle.runtime.debug.TraceASTCompilationListener;
-import org.graalvm.compiler.truffle.runtime.debug.TraceCompilationListener;
-import org.graalvm.compiler.truffle.runtime.debug.TraceCompilationPolymorphismListener;
-import org.graalvm.compiler.truffle.runtime.debug.TraceSplittingListener;
-import org.graalvm.compiler.truffle.runtime.serviceprovider.TruffleRuntimeServices;
 import org.graalvm.nativeimage.ImageInfo;
 import org.graalvm.options.OptionCategory;
 import org.graalvm.options.OptionDescriptor;
@@ -95,6 +93,7 @@
 import com.oracle.truffle.api.OptimizationFailedException;
 import com.oracle.truffle.api.RootCallTarget;
 import com.oracle.truffle.api.Truffle;
+import com.oracle.truffle.api.TruffleLogger;
 import com.oracle.truffle.api.TruffleOptions;
 import com.oracle.truffle.api.TruffleRuntime;
 import com.oracle.truffle.api.TruffleSafepoint;
@@ -129,6 +128,24 @@
 import com.oracle.truffle.api.source.SourceSection;
 import com.oracle.truffle.api.strings.AbstractTruffleString;
 import com.oracle.truffle.api.strings.TruffleString;
+import com.oracle.truffle.compiler.ConstantFieldInfo;
+import com.oracle.truffle.compiler.HostMethodInfo;
+import com.oracle.truffle.compiler.OptimizedAssumptionDependency;
+import com.oracle.truffle.compiler.PartialEvaluationMethodInfo;
+import com.oracle.truffle.compiler.TruffleCompilable;
+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.runtime.BackgroundCompileQueue.Priority;
+import com.oracle.truffle.runtime.OptimizedRuntimeOptions.ExceptionAction;
+import com.oracle.truffle.runtime.debug.JFRListener;
+import com.oracle.truffle.runtime.debug.StatisticsListener;
+import com.oracle.truffle.runtime.debug.TraceASTCompilationListener;
+import com.oracle.truffle.runtime.debug.TraceCompilationListener;
+import com.oracle.truffle.runtime.debug.TraceCompilationPolymorphismListener;
+import com.oracle.truffle.runtime.debug.TraceSplittingListener;
+import com.oracle.truffle.runtime.serviceprovider.TruffleRuntimeServices;
 
 import jdk.vm.ci.code.BailoutException;
 import jdk.vm.ci.code.InstalledCode;
@@ -148,7 +165,7 @@
  * Implementation of the Truffle runtime when running on top of Graal. There is only one per VM.
  */
 
-public abstract class GraalTruffleRuntime implements TruffleRuntime, TruffleCompilerRuntime {
+public abstract class OptimizedTruffleRuntime implements TruffleRuntime, TruffleCompilerRuntime {
 
     private static final int JAVA_SPECIFICATION_VERSION = Runtime.version().feature();
 
@@ -160,21 +177,21 @@ protected void clearState() {
         knownMethods = null;
     }
 
-    private final GraalTruffleRuntimeListenerDispatcher listeners = new GraalTruffleRuntimeListenerDispatcher();
+    private final OptimizedTruffleRuntimeListenerDispatcher listeners = new OptimizedTruffleRuntimeListenerDispatcher();
 
     protected volatile TruffleCompiler truffleCompiler;
     protected volatile OptimizedCallTarget initializeCallTarget;
 
     protected KnownMethods knownMethods;
 
-    private final GraalTVMCI tvmci = new GraalTVMCI();
-    private volatile GraalTestTVMCI testTvmci;
+    private final OptimizedTVMCI tvmci = new OptimizedTVMCI();
+    private volatile OptimizedTestTVMCI testTvmci;
 
     /**
      * Utility method that casts the singleton {@link TruffleRuntime}.
      */
-    public static GraalTruffleRuntime getRuntime() {
-        return (GraalTruffleRuntime) Truffle.getRuntime();
+    public static OptimizedTruffleRuntime getRuntime() {
+        return (OptimizedTruffleRuntime) Truffle.getRuntime();
     }
 
     private final LoopNodeFactory loopNodeFactory;
@@ -186,7 +203,7 @@ public static GraalTruffleRuntime getRuntime() {
 
     protected final TruffleCompilationSupport compilationSupport;
 
-    public GraalTruffleRuntime(TruffleCompilationSupport compilationSupport, Iterable> extraLookupTypes) {
+    public OptimizedTruffleRuntime(TruffleCompilationSupport compilationSupport, Iterable> extraLookupTypes) {
         this.compilationSupport = compilationSupport;
         this.lookupTypes = initLookupTypes(extraLookupTypes);
         List options = new ArrayList<>();
@@ -248,7 +265,7 @@ public final String validateCompilerOption(String key, String value) {
         return compilationSupport.validateCompilerOption(key, value);
     }
 
-    protected GraalTVMCI getTvmci() {
+    protected OptimizedTVMCI getTvmci() {
         return tvmci;
     }
 
@@ -256,7 +273,7 @@ protected GraalTVMCI getTvmci() {
         if (testTvmci == null) {
             synchronized (this) {
                 if (testTvmci == null) {
-                    testTvmci = new GraalTestTVMCI();
+                    testTvmci = new OptimizedTestTVMCI();
                 }
             }
         }
@@ -289,13 +306,13 @@ private static  T loadServiceProvider(Class clazz, boolean failIfNotFound)
         } else {
             providers = TruffleRuntimeServices.load(clazz);
         }
-        boolean priorityService = GraalRuntimeServiceProvider.class.isAssignableFrom(clazz);
+        boolean priorityService = OptimizedRuntimeServiceProvider.class.isAssignableFrom(clazz);
         T bestFactory = null;
         int bestPriority = 0;
         for (T factory : providers) {
             int currentPriority;
             if (priorityService) {
-                currentPriority = ((GraalRuntimeServiceProvider) factory).getPriority();
+                currentPriority = ((OptimizedRuntimeServiceProvider) factory).getPriority();
             } else {
                 currentPriority = 0;
             }
@@ -310,7 +327,7 @@ private static  T loadServiceProvider(Class clazz, boolean failIfNotFound)
         return bestFactory;
     }
 
-    private static  T loadGraalRuntimeServiceProvider(Class clazz, List descriptors, boolean failIfNotFound) {
+    private static  T loadGraalRuntimeServiceProvider(Class clazz, List descriptors, boolean failIfNotFound) {
         T bestFactory = loadServiceProvider(clazz, failIfNotFound);
         if (descriptors != null && bestFactory != null) {
             OptionDescriptors serviceOptions = bestFactory.getEngineOptions();
@@ -587,12 +604,12 @@ public final void initializeKnownMethods(MetaAccessProvider metaAccess) {
 
     /** Accessor for non-public state in {@link FrameDescriptor}. */
     public void markFrameMaterializeCalled(FrameDescriptor descriptor) {
-        GraalRuntimeAccessor.FRAME.markMaterializeCalled(descriptor);
+        OptimizedRuntimeAccessor.FRAME.markMaterializeCalled(descriptor);
     }
 
     /** Accessor for non-public state in {@link FrameDescriptor}. */
     public boolean getFrameMaterializeCalled(FrameDescriptor descriptor) {
-        return GraalRuntimeAccessor.FRAME.getMaterializeCalled(descriptor);
+        return OptimizedRuntimeAccessor.FRAME.getMaterializeCalled(descriptor);
     }
 
     @Override
@@ -653,7 +670,7 @@ public final Assumption createAssumption(String name) {
         return new OptimizedAssumption(name);
     }
 
-    public final GraalTruffleRuntimeListener getListener() {
+    public final OptimizedTruffleRuntimeListener getListener() {
         return listeners;
     }
 
@@ -760,9 +777,9 @@ public T visitFrame(InspectedFrame frame) {
             } else {
                 try {
                     if (osrFrame != null) {
-                        return visitor.visitFrame(new GraalOSRFrameInstance(frame, callNodeFrame, osrFrame));
+                        return visitor.visitFrame(new OptimizedOSRFrameInstance(frame, callNodeFrame, osrFrame));
                     } else {
-                        return visitor.visitFrame(new GraalFrameInstance(frame, callNodeFrame));
+                        return visitor.visitFrame(new OptimizedFrameInstance(frame, callNodeFrame));
                     }
                 } finally {
                     osrFrame = null;
@@ -772,7 +789,7 @@ public T visitFrame(InspectedFrame frame) {
         }
 
         private static boolean isOSRFrame(InspectedFrame frame) {
-            return ((OptimizedCallTarget) frame.getLocal(GraalFrameInstance.CALL_TARGET_INDEX)).getRootNode() instanceof BaseOSRRootNode;
+            return ((OptimizedCallTarget) frame.getLocal(OptimizedFrameInstance.CALL_TARGET_INDEX)).getRootNode() instanceof BaseOSRRootNode;
         }
     }
 
@@ -811,11 +828,11 @@ public  T getCapability(Class capability) {
 
     protected abstract OptimizedCallTarget createInitializationCallTarget(EngineData engine);
 
-    public void addListener(GraalTruffleRuntimeListener listener) {
+    public void addListener(OptimizedTruffleRuntimeListener listener) {
         listeners.add(listener);
     }
 
-    public void removeListener(GraalTruffleRuntimeListener listener) {
+    public void removeListener(OptimizedTruffleRuntimeListener listener) {
         listeners.remove(listener);
     }
 
@@ -982,7 +999,7 @@ public KnownMethods getKnownMethods() {
      * Use {@link OptimizedCallTarget#engine} whenever possible as it's much faster.
      */
     protected static EngineData getEngineData(RootNode rootNode) {
-        return GraalTVMCI.getEngineData(rootNode);
+        return OptimizedTVMCI.getEngineData(rootNode);
     }
 
     @SuppressWarnings("deprecation")
@@ -991,15 +1008,24 @@ private static com.oracle.truffle.api.object.LayoutFactory loadObjectLayoutFacto
     }
 
     private static  List> loadService(Class service) {
-        ServiceLoader graalLoader = ServiceLoader.load(service, GraalTruffleRuntime.class.getClassLoader());
-        /*
-         * The Graal module (i.e., jdk.internal.vm.compiler) is loaded by the platform class loader.
-         * Its module dependencies such as Truffle are supplied via --module-path which means they
-         * are loaded by the app class loader. As such, we need to search the app class loader path
-         * as well.
-         */
-        ServiceLoader appLoader = ServiceLoader.load(service, service.getClassLoader());
-        return Arrays.asList(graalLoader, appLoader);
+        ClassLoader runtimeClassLoader = OptimizedTruffleRuntime.class.getClassLoader();
+        ClassLoader appClassLoader = service.getClassLoader();
+        ServiceLoader appLoader = ServiceLoader.load(service, appClassLoader);
+        if (runtimeClassLoader.equals(appClassLoader)) {
+            /*
+             * Primary mode of operation for Truffle consumed from the application module path.
+             */
+            return List.of(appLoader);
+        } else {
+            ServiceLoader runtimeLoader = ServiceLoader.load(service, runtimeClassLoader);
+            /*
+             * The Graal module (i.e., jdk.internal.vm.compiler) is loaded by the platform class
+             * loader. Its module dependencies such as Truffle are supplied via --module-path which
+             * means they are loaded by the app class loader. As such, we need to search the app
+             * class loader path as well.
+             */
+            return List.of(runtimeLoader, appLoader);
+        }
     }
 
     @SuppressWarnings("deprecation")
@@ -1040,11 +1066,11 @@ public final class KnownMethods {
         public final ResolvedJavaMethod[] anyFrameMethod;
 
         public KnownMethods(MetaAccessProvider metaAccess) {
-            this.callDirectMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_DIRECT);
-            this.callIndirectMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_INDIRECT);
-            this.callInlinedMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_INLINED);
-            this.callInlinedCallMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_INLINED_CALL);
-            this.callTargetMethod = metaAccess.lookupJavaMethod(GraalFrameInstance.CALL_TARGET_METHOD);
+            this.callDirectMethod = metaAccess.lookupJavaMethod(OptimizedFrameInstance.CALL_DIRECT);
+            this.callIndirectMethod = metaAccess.lookupJavaMethod(OptimizedFrameInstance.CALL_INDIRECT);
+            this.callInlinedMethod = metaAccess.lookupJavaMethod(OptimizedFrameInstance.CALL_INLINED);
+            this.callInlinedCallMethod = metaAccess.lookupJavaMethod(OptimizedFrameInstance.CALL_INLINED_CALL);
+            this.callTargetMethod = metaAccess.lookupJavaMethod(OptimizedFrameInstance.CALL_TARGET_METHOD);
             this.anyFrameMethod = new ResolvedJavaMethod[]{callDirectMethod, callIndirectMethod, callInlinedMethod, callTargetMethod, callInlinedCallMethod};
         }
     }
@@ -1069,7 +1095,7 @@ public boolean isSuppressedFailure(TruffleCompilable compilable, Supplier ThreadLocal createTerminatingThreadLocal(Supplier initialValue, Consumer onThreadTermination) {
+        try {
+            Method m = Services.class.getMethod("createTerminatingThreadLocal", Supplier.class, Consumer.class);
+            return (ThreadLocal) m.invoke(null, initialValue, onThreadTermination);
+        } catch (NoSuchMethodException e) {
+            return ThreadLocal.withInitial(initialValue);
+        } catch (ReflectiveOperationException e) {
+            throw CompilerDirectives.shouldNotReachHere(e);
+        }
+    }
+
     public static class StackTraceHelper {
         public static void logHostAndGuestStacktrace(String reason, OptimizedCallTarget callTarget) {
             final int limit = callTarget.getOptionValue(OptimizedRuntimeOptions.TraceStackTraceLimit);
-            final GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
+            final OptimizedTruffleRuntime runtime = OptimizedTruffleRuntime.getRuntime();
             final StringBuilder messageBuilder = new StringBuilder();
             messageBuilder.append(reason).append(" at\n");
             runtime.iterateFrames(new FrameInstanceVisitor() {
@@ -1291,7 +1331,7 @@ public OptionDescriptor get(String optionName) {
                 newOptionName = convertFromLegacyOptionName(optionName);
             }
 
-            if (newOptionName != null && GraalTruffleRuntime.getRuntime().existsCompilerOption(newOptionName)) {
+            if (newOptionName != null && OptimizedTruffleRuntime.getRuntime().existsCompilerOption(newOptionName)) {
                 OptionDescriptor.Builder b = OptionDescriptor.newBuilder(getOrCreateOptionKey(optionName), optionName);
                 if (isLegacyOption(optionName)) {
                     b.deprecated(true).deprecationMessage(
@@ -1310,7 +1350,7 @@ static OptionKey getOrCreateOptionKey(String name) {
                     if (isLegacyOption(optionName)) {
                         optionName = convertFromLegacyOptionName(optionName);
                     }
-                    String result = GraalTruffleRuntime.getRuntime().validateCompilerOption(optionName, v);
+                    String result = OptimizedTruffleRuntime.getRuntime().validateCompilerOption(optionName, v);
                     if (result != null) {
                         throw new IllegalArgumentException(result);
                     }
@@ -1375,7 +1415,7 @@ public Iterator iterator() {
                 /*
                  * Compiler options descriptor never change so it is save to cache them per runtime.
                  */
-                options = optionsArray = GraalTruffleRuntime.getRuntime().listCompilerOptions();
+                options = optionsArray = OptimizedTruffleRuntime.getRuntime().listCompilerOptions();
             }
             List descriptors = new ArrayList<>();
             for (TruffleCompilerOptionDescriptor descriptor : optionsArray) {
@@ -1389,26 +1429,21 @@ public Iterator iterator() {
 
         static OptionDescriptor convertDescriptorLegacy(TruffleCompilerOptionDescriptor d) {
             String name = convertToLegacyOptionName(d.name());
-            return OptionDescriptor.newBuilder(getOrCreateOptionKey(name), name) //
-                            .help(d.help()) //
-                            // we do not have stable compiler options yet.
-                            // maybe this needs to be extended in the future.
-                            .stability(OptionStability.EXPERIMENTAL) //
-                            .category(matchCategory(d)) //
-                            .deprecated(true) //
-                            .deprecationMessage(String.format("The option %s is now deprecated. Please use the new option name '%s' instead to resolve this.", name, d.name())).build();
+            return OptionDescriptor.newBuilder(getOrCreateOptionKey(name), name).help(d.help()).//
+                            stability(OptionStability.EXPERIMENTAL).//
+                            category(matchCategory(d)).//
+                            deprecated(true).//
+                            deprecationMessage(String.format("The option %s is now deprecated. Please use the new option name '%s' instead to resolve this.", name, d.name())).build();
         }
 
         static OptionDescriptor convertDescriptor(TruffleCompilerOptionDescriptor d) {
             String name = d.name();
-            return OptionDescriptor.newBuilder(getOrCreateOptionKey(name), name) //
-                            .help(d.help()) //
-                            // we do not have stable compiler options yet.
-                            // maybe this needs to be extended in the future.
-                            .stability(OptionStability.EXPERIMENTAL) //
-                            .category(matchCategory(d)) //
-                            .deprecated(d.deprecated()) //
-                            .deprecationMessage(d.deprecationMessage()).build();
+            return OptionDescriptor.newBuilder(getOrCreateOptionKey(name), name).//
+                            help(d.help()).//
+                            stability(OptionStability.EXPERIMENTAL).//
+                            category(matchCategory(d)).//
+                            deprecated(d.deprecated()).//
+                            deprecationMessage(d.deprecationMessage()).build();
         }
 
         static Map extractOptions(OptionValues values) {
diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListener.java
similarity index 80%
rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListener.java
rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListener.java
index f722bbc0ef96..c5c2609b8296 100644
--- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListener.java
+++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListener.java
@@ -1,38 +1,53 @@
 /*
- * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2023, 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.
+ * The Universal Permissive License (UPL), Version 1.0
  *
- * 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).
+ * 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
  *
- * 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.
+ * (a) the Software, and
  *
- * 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.
+ * (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 org.graalvm.compiler.truffle.runtime;
+package com.oracle.truffle.runtime;
 
 import java.util.Map;
 
-import org.graalvm.compiler.truffle.common.TruffleCompilationTask;
-import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo;
-import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo;
-
 import com.oracle.truffle.api.frame.Frame;
 import com.oracle.truffle.api.nodes.DirectCallNode;
 import com.oracle.truffle.api.nodes.Node;
+import com.oracle.truffle.compiler.TruffleCompilationTask;
+import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo;
+import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo;
 
 /**
  * A listener for events related to the execution and compilation phases of a
@@ -51,7 +66,7 @@
  * * represents the Kleene Closure.
  * 

*/ -public interface GraalTruffleRuntimeListener { +public interface OptimizedTruffleRuntimeListener { /** * Notifies this object when the target of a Truffle call node is @@ -253,13 +268,13 @@ default void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) { } /** - * Notifies this object the {@link GraalTruffleRuntime} is being shut down. + * Notifies this object the {@link OptimizedTruffleRuntime} is being shut down. */ default void onShutdown() { } /** - * Notifies this object an engine using the {@link GraalTruffleRuntime} was closed. + * Notifies this object an engine using the {@link OptimizedTruffleRuntime} was closed. * * @param runtimeData the engine's compiler configuration */ diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListenerDispatcher.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListenerDispatcher.java similarity index 62% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListenerDispatcher.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListenerDispatcher.java index c9b1367d8767..18da6c8f6ffd 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/GraalTruffleRuntimeListenerDispatcher.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/OptimizedTruffleRuntimeListenerDispatcher.java @@ -1,47 +1,62 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; - import com.oracle.truffle.api.frame.Frame; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerListener; /** - * A collection for broadcasting {@link GraalTruffleRuntimeListener} events and converting - * {@link TruffleCompilerListener} events to {@link GraalTruffleRuntimeListener} events. + * A collection for broadcasting {@link OptimizedTruffleRuntimeListener} events and converting + * {@link TruffleCompilerListener} events to {@link OptimizedTruffleRuntimeListener} events. */ @SuppressWarnings("serial") -final class GraalTruffleRuntimeListenerDispatcher extends CopyOnWriteArrayList implements GraalTruffleRuntimeListener, TruffleCompilerListener { +final class OptimizedTruffleRuntimeListenerDispatcher extends CopyOnWriteArrayList implements OptimizedTruffleRuntimeListener, TruffleCompilerListener { @Override - public boolean add(GraalTruffleRuntimeListener e) { + public boolean add(OptimizedTruffleRuntimeListener e) { if (e != this && !contains(e)) { return super.add(e); } @@ -113,9 +128,9 @@ public void onEngineClosed(EngineData runtimeData) { invokeListeners((l) -> l.onEngineClosed(runtimeData)); } - private void invokeListeners(Consumer action) { + private void invokeListeners(Consumer action) { Throwable exception = null; - for (GraalTruffleRuntimeListener l : this) { + for (OptimizedTruffleRuntimeListener l : this) { try { action.accept(l); } catch (ThreadDeath t) { @@ -138,7 +153,7 @@ private static RuntimeException sthrow(Class type, Thro throw (E) ex; } - // Conversion from TruffleCompilerListener events to GraalTruffleRuntimeListener events + // Conversion from TruffleCompilerListener events to OptimizedTruffleRuntimeListener events @Override public void onTruffleTierFinished(TruffleCompilable compilable, TruffleCompilationTask task, GraphInfo graph) { diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/SuppressFBWarnings.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/SuppressFBWarnings.java new file mode 100644 index 000000000000..2b2fc7b0f035 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/SuppressFBWarnings.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, 2023, 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; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Used to suppress SpotBugs warnings. + */ +@Retention(RetentionPolicy.CLASS) +@interface SuppressFBWarnings { + /** + * @see "https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html" + */ + String[] value(); + + /** + * Reason why the warning is suppressed. Use a SpotBugs issue id where appropriate. + */ + String justification(); +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TraversingBlockingQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TraversingBlockingQueue.java similarity index 72% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TraversingBlockingQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TraversingBlockingQueue.java index 344066650bd4..3547541fc10e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TraversingBlockingQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TraversingBlockingQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.Collection; import java.util.Iterator; diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleCallBoundary.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleCallBoundary.java new file mode 100644 index 000000000000..40c6111fc4c3 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleCallBoundary.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014, 2023, 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; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Denotes methods for which Truffle compiled code may be available. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface TruffleCallBoundary { + +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleInlining.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleInlining.java new file mode 100644 index 000000000000..0e6b37500c2c --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleInlining.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2013, 2023, 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; + +import com.oracle.truffle.compiler.TruffleCompilable; + +/** + * @deprecated this class is schedule for removal. Use {@link AbstractCompilationTask} instead. + */ +@Deprecated +public class TruffleInlining { + + private final AbstractCompilationTask task; + + public TruffleInlining(AbstractCompilationTask task) { + this.task = task; + } + + public int countCalls() { + return task.countCalls(); + } + + public int countInlinedCalls() { + return task.countInlinedCalls(); + } + + public TruffleCompilable[] inlinedTargets() { + return task.inlinedTargets(); + } + + public void addInlinedTarget(TruffleCompilable target) { + task.addInlinedTarget(target); + } + + public void setCallCounts(int total, int inlined) { + task.setCallCounts(total, inlined); + } + + public void addTargetToDequeue(TruffleCompilable target) { + task.addTargetToDequeue(target); + } + + public void dequeueTargets() { + task.dequeueTargets(); + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleSplittingStrategy.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleSplittingStrategy.java similarity index 86% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleSplittingStrategy.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleSplittingStrategy.java index 178a83e42600..61dd96b122b4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/TruffleSplittingStrategy.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleSplittingStrategy.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime; +package com.oracle.truffle.runtime; import java.util.ArrayList; import java.util.Collections; @@ -138,7 +154,7 @@ private static String recursiveSplitMessageFactory(OptimizedDirectCallNode node, private static void maybeTraceFail(EngineData engine, OptimizedDirectCallNode call, BiFunction messageFactory) { if (engine.traceSplits) { - GraalTruffleRuntime.getRuntime().getListener().onCompilationSplitFailed(call, messageFactory.apply(call, engine)); + OptimizedTruffleRuntime.getRuntime().getListener().onCompilationSplitFailed(call, messageFactory.apply(call, engine)); } } @@ -285,7 +301,7 @@ static class SplitStatisticsData { } } - private static final class SplitStatisticsReporter implements GraalTruffleRuntimeListener { + private static final class SplitStatisticsReporter implements OptimizedTruffleRuntimeListener { private static final String D_FORMAT = "%n%-82s: %10d"; private static final String D_LONG_FORMAT = "%n%-120s: %10d"; @@ -342,7 +358,7 @@ private static Map sortByIntegerValue(Map map) { } } - static void installListener(GraalTruffleRuntime runtime) { + static void installListener(OptimizedTruffleRuntime runtime) { runtime.addListener(new SplitStatisticsReporter()); } } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleTypes.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleTypes.java new file mode 100644 index 000000000000..2798085fa6e4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/TruffleTypes.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 2023, 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; + +/** + * A service for getting types that can be resolved by + * {@link OptimizedTruffleRuntime#resolveType(jdk.vm.ci.meta.MetaAccessProvider, String, boolean)}. + */ +public interface TruffleTypes { + + /** + * Gets the types supplied by this supplier. + */ + Class[] getTypes(); +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/ArrayQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/ArrayQueue.java similarity index 50% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/ArrayQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/ArrayQueue.java index 3f47886cc8c7..d96e702a13bf 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/ArrayQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/ArrayQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.collection; +package com.oracle.truffle.runtime.collection; import java.util.Arrays; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/BTreeQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/BTreeQueue.java similarity index 91% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/BTreeQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/BTreeQueue.java index 3da7c089ffbd..8c6ce5e76855 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/BTreeQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/BTreeQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.collection; +package com.oracle.truffle.runtime.collection; import java.util.ArrayList; import java.util.Arrays; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/DelegatingBlockingQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/DelegatingBlockingQueue.java similarity index 75% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/DelegatingBlockingQueue.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/DelegatingBlockingQueue.java index db570d58f362..1e595e0b93ba 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/collection/DelegatingBlockingQueue.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/DelegatingBlockingQueue.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.collection; +package com.oracle.truffle.runtime.collection; import java.util.Arrays; import java.util.Collection; diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/SerialQueue.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/SerialQueue.java new file mode 100644 index 000000000000..88c81070a94e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/collection/SerialQueue.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021, 2023, 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.collection; + +interface SerialQueue { + void add(E x); + + @SuppressWarnings("unused") + default int addIndexOf(E x) { + throw new UnsupportedOperationException(); + } + + /** + * Returns the position in the pool, or -1 if the element is not present. + */ + @SuppressWarnings("unused") + default int indexOf(E x) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + E poll(); + + @SuppressWarnings("unchecked") + E peek(); + + void clear(); + + int size(); + + Object[] toArray(); + + @SuppressWarnings("unchecked") + T[] toArray(T[] a); + + int internalCapacity(); +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/JFRListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java similarity index 81% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/JFRListener.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java index 930076a3bb4c..b099a6f59e1b 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/JFRListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/JFRListener.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.debug; +package com.oracle.truffle.runtime.debug; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; @@ -32,23 +48,23 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.jfr.CompilationEvent; -import org.graalvm.compiler.truffle.jfr.CompilationStatisticsEvent; -import org.graalvm.compiler.truffle.jfr.DeoptimizationEvent; -import org.graalvm.compiler.truffle.jfr.EventFactory; -import org.graalvm.compiler.truffle.jfr.InvalidationEvent; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.ModuleUtil; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.serviceprovider.TruffleRuntimeServices; import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.ImageSingletons; import com.oracle.truffle.api.frame.Frame; +import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.ModuleUtil; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.jfr.CompilationEvent; +import com.oracle.truffle.runtime.jfr.CompilationStatisticsEvent; +import com.oracle.truffle.runtime.jfr.DeoptimizationEvent; +import com.oracle.truffle.runtime.jfr.EventFactory; +import com.oracle.truffle.runtime.jfr.InvalidationEvent; +import com.oracle.truffle.runtime.serviceprovider.TruffleRuntimeServices; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -70,13 +86,13 @@ public final class JFRListener extends AbstractGraalTruffleRuntimeListener { private final ThreadLocal currentCompilation = new ThreadLocal<>(); private final Statistics statistics; - private JFRListener(GraalTruffleRuntime runtime) { + private JFRListener(OptimizedTruffleRuntime runtime) { super(runtime); statistics = new Statistics(); factory.addPeriodicEvent(CompilationStatisticsEvent.class, statistics); } - public static void install(GraalTruffleRuntime runtime) { + public static void install(OptimizedTruffleRuntime runtime) { if (factory != null) { runtime.addListener(new JFRListener(runtime)); } diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/StatisticsListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/StatisticsListener.java similarity index 91% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/StatisticsListener.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/StatisticsListener.java index 32107b8cf77b..37bc4e647f5d 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/StatisticsListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/StatisticsListener.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.debug; +package com.oracle.truffle.runtime.debug; import java.io.PrintWriter; import java.io.StringWriter; @@ -38,16 +54,6 @@ import java.util.function.Function; import java.util.logging.Level; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; - import com.oracle.truffle.api.TruffleLogger; import com.oracle.truffle.api.nodes.DirectCallNode; import com.oracle.truffle.api.nodes.IndirectCallNode; @@ -55,6 +61,15 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.nodes.NodeVisitor; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; public final class StatisticsListener extends AbstractGraalTruffleRuntimeListener { @@ -129,7 +144,7 @@ static final class CompilationStatistics { private final Map timeQueued = new HashMap<>(); - private StatisticsListener(GraalTruffleRuntime runtime) { + private StatisticsListener(OptimizedTruffleRuntime runtime) { super(runtime); } @@ -138,11 +153,11 @@ private StatisticsListener(GraalTruffleRuntime runtime) { */ private final ThreadLocal currentCompilationStatistics = new ThreadLocal<>(); - public static void install(GraalTruffleRuntime runtime) { + public static void install(OptimizedTruffleRuntime runtime) { runtime.addListener(new StatisticsDispatcher(runtime)); } - public static StatisticsListener createEngineListener(GraalTruffleRuntime runtime) { + public static StatisticsListener createEngineListener(OptimizedTruffleRuntime runtime) { return new StatisticsListener(runtime); } @@ -313,7 +328,7 @@ static String formatLabel(String s) { } private void printStatistics(EngineData runtimeData) { - GraalTruffleRuntime rt = runtime; + OptimizedTruffleRuntime rt = runtime; long endTime = System.nanoTime(); StringWriter logMessage = new StringWriter(); try (PrintWriter out = new PrintWriter(logMessage)) { @@ -676,7 +691,7 @@ static class CurrentCompilationStatistics { private static final class StatisticsDispatcher extends AbstractGraalTruffleRuntimeListener { - private StatisticsDispatcher(GraalTruffleRuntime runtime) { + private StatisticsDispatcher(OptimizedTruffleRuntime runtime) { super(runtime); } diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceASTCompilationListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceASTCompilationListener.java new file mode 100644 index 000000000000..3a38dc5778e1 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceASTCompilationListener.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2014, 2023, 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.debug; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.nodes.NodeUtil; +import com.oracle.truffle.api.nodes.NodeVisitor; +import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; + +/** + * Traces all polymorphic and generic nodes after each successful Truffle compilation. + */ +public final class TraceASTCompilationListener extends AbstractGraalTruffleRuntimeListener { + + private TraceASTCompilationListener(OptimizedTruffleRuntime runtime) { + super(runtime); + } + + public static void install(OptimizedTruffleRuntime runtime) { + runtime.addListener(new TraceASTCompilationListener(runtime)); + } + + @Override + public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilationTask task, GraphInfo graphInfo, CompilationResultInfo compilationResultInfo) { + if (target.getOptionValue(OptimizedRuntimeOptions.TraceCompilationAST)) { + StringWriter logMessage = new StringWriter(); + try (PrintWriter out = new PrintWriter(logMessage)) { + printCompactTree(out, target); + } + runtime.logEvent(target, 0, "opt AST", target.toString(), target.getDebugProperties(), logMessage.toString()); + } + } + + private static void printCompactTree(PrintWriter out, OptimizedCallTarget target) { + target.accept(new NodeVisitor() { + private boolean newLine = false; + + @Override + public boolean visit(Node node) { + if (node == null) { + return true; + } + Node parent = node.getParent(); + if (newLine) { + out.println(); + } else { + newLine = true; + } + if (parent == null) { + out.printf("%s", node.getClass().getSimpleName()); + } else { + String fieldName = NodeUtil.findChildFieldName(parent, node); + out.printf("%s = %s", fieldName, node.getClass().getSimpleName()); + } + return true; + } + + }); + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java similarity index 81% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationListener.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java index a00e8eebc9c2..2e36d04e8e9e 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceCompilationListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationListener.java @@ -1,44 +1,59 @@ /* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.debug; - -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.CompilationResultInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener.GraphInfo; -import org.graalvm.compiler.truffle.runtime.AbstractCompilationTask; -import org.graalvm.compiler.truffle.runtime.AbstractGraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.CompilationTask; -import org.graalvm.compiler.truffle.runtime.FixedPointMath; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; +package com.oracle.truffle.runtime.debug; import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.NodeVisitor; import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.CompilationTask; +import com.oracle.truffle.runtime.FixedPointMath; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; /** * Traces AST-level compilation events with a detailed log message sent to the Truffle log stream @@ -48,11 +63,11 @@ public final class TraceCompilationListener extends AbstractGraalTruffleRuntimeL private final ThreadLocal currentCompilation = new ThreadLocal<>(); - private TraceCompilationListener(GraalTruffleRuntime runtime) { + private TraceCompilationListener(OptimizedTruffleRuntime runtime) { super(runtime); } - public static void install(GraalTruffleRuntime runtime) { + public static void install(OptimizedTruffleRuntime runtime) { runtime.addListener(new TraceCompilationListener(runtime)); } @@ -291,8 +306,8 @@ public void onCompilationInvalidated(OptimizedCallTarget target, Object source, /** * Determines if a failure is permanent. * - * @see GraalTruffleRuntimeListener#onCompilationFailed(OptimizedCallTarget, String, boolean, - * boolean, int) + * @see OptimizedTruffleRuntimeListener#onCompilationFailed(OptimizedCallTarget, String, + * boolean, boolean, int) */ private static boolean isPermanentFailure(boolean bailout, boolean permanentBailout) { return !bailout || permanentBailout; diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationPolymorphismListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationPolymorphismListener.java new file mode 100644 index 000000000000..c7c3927fa4d2 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceCompilationPolymorphismListener.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2014, 2023, 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.debug; + +import java.util.LinkedHashMap; +import java.util.Map; + +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.nodes.NodeCost; +import com.oracle.truffle.api.nodes.NodeUtil; +import com.oracle.truffle.api.nodes.NodeVisitor; +import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; +import com.oracle.truffle.runtime.AbstractCompilationTask; +import com.oracle.truffle.runtime.AbstractGraalTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; + +public final class TraceCompilationPolymorphismListener extends AbstractGraalTruffleRuntimeListener { + + private TraceCompilationPolymorphismListener(OptimizedTruffleRuntime runtime) { + super(runtime); + } + + public static void install(OptimizedTruffleRuntime runtime) { + runtime.addListener(new TraceCompilationPolymorphismListener(runtime)); + } + + @Override + public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilationTask task, GraphInfo graph, CompilationResultInfo result) { + if (target.getOptionValue(OptimizedRuntimeOptions.TraceCompilationPolymorphism)) { + target.accept(new NodeVisitor() { + @Override + public boolean visit(Node node) { + if (node != null && (node.getCost() == NodeCost.MEGAMORPHIC || node.getCost() == NodeCost.POLYMORPHIC)) { + NodeCost cost = node.getCost(); + Map props = new LinkedHashMap<>(); + props.put("simpleName", node.getClass().getSimpleName()); + props.put("subtree", "\n" + NodeUtil.printCompactTreeToString(node)); + String msg = cost == NodeCost.MEGAMORPHIC ? "megamorphic" : "polymorphic"; + runtime.logEvent(target, 0, msg, node.toString(), props, null); + } + return true; + } + }); + } + } + +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceSplittingListener.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceSplittingListener.java similarity index 54% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceSplittingListener.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceSplittingListener.java index 65519a586cb6..6cf7c0ccfee4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/debug/TraceSplittingListener.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/debug/TraceSplittingListener.java @@ -1,47 +1,62 @@ /* - * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.debug; +package com.oracle.truffle.runtime.debug; import java.util.Map; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntimeListener; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode; -import org.graalvm.compiler.truffle.runtime.OptimizedRuntimeOptions; - import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.OptimizedTruffleRuntimeListener; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedDirectCallNode; +import com.oracle.truffle.runtime.OptimizedRuntimeOptions; -public final class TraceSplittingListener implements GraalTruffleRuntimeListener { +public final class TraceSplittingListener implements OptimizedTruffleRuntimeListener { private TraceSplittingListener() { } - public static void install(GraalTruffleRuntime runtime) { + public static void install(OptimizedTruffleRuntime runtime) { runtime.addListener(new TraceSplittingListener()); } @@ -54,7 +69,7 @@ public void onCompilationSplit(OptimizedDirectCallNode callNode) { String label = String.format("split %3s-%08x-%-4s ", splitCount++, 0xFFFF_FFFFL & callNode.getCurrentCallTarget().hashCode(), callNode.getCallCount()); final Map debugProperties = callTarget.getDebugProperties(); debugProperties.put("SourceSection", extractSourceSection(callNode)); - GraalTruffleRuntime.getRuntime().logEvent(callTarget, 0, label, debugProperties); + OptimizedTruffleRuntime.getRuntime().logEvent(callTarget, 0, label, debugProperties); } } @@ -65,7 +80,7 @@ public void onCompilationSplitFailed(OptimizedDirectCallNode callNode, CharSeque String label = String.format("split failed " + reason); final Map debugProperties = callTarget.getDebugProperties(); debugProperties.put("SourceSection", extractSourceSection(callNode)); - GraalTruffleRuntime.getRuntime().logEvent(callTarget, 0, label, debugProperties); + OptimizedTruffleRuntime.getRuntime().logEvent(callTarget, 0, label, debugProperties); } } @@ -81,9 +96,7 @@ private static String extractSourceSection(OptimizedDirectCallNode node) { } static String getShortDescription(SourceSection sourceSection) { - if (sourceSection == null || sourceSection.getSource() == null) { - // TODO the source == null branch can be removed if the deprecated - // SourceSection#createUnavailable has be removed. + if (sourceSection == null) { return ""; } StringBuilder b = new StringBuilder(); diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotFastThreadLocal.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotFastThreadLocal.java similarity index 75% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotFastThreadLocal.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotFastThreadLocal.java index 778c558adec5..89a574bc0a8a 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotFastThreadLocal.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotFastThreadLocal.java @@ -1,36 +1,53 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot; +package com.oracle.truffle.runtime.hotspot; import java.lang.invoke.MethodHandle; -import org.graalvm.compiler.truffle.runtime.GraalFastThreadLocal; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.runtime.OptimizedFastThreadLocal; + import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; -final class HotSpotFastThreadLocal extends GraalFastThreadLocal { +final class HotSpotFastThreadLocal extends OptimizedFastThreadLocal { static final HotSpotFastThreadLocal SINGLETON = new HotSpotFastThreadLocal(); @@ -54,7 +71,7 @@ protected MutableInt initialValue() { } /* - * This method is intrinsified for partial evaluation. See HotSpotTruffleGraphBuilderPlugins for + * This method is intrinsified for partial evaluation. See HotSpotGraphBuilderPlugins for * details. */ @Override @@ -63,7 +80,7 @@ public void set(Object[] data) { } /* - * This method is intrinsified for partial evaluation. See HotSpotTruffleGraphBuilderPlugins for + * This method is intrinsified for partial evaluation. See HotSpotGraphBuilderPlugins for * details. */ @Override diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java similarity index 71% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java index 52b0b01fff3a..b0b1eca6a8ee 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotOptimizedCallTarget.java @@ -1,37 +1,52 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot; +package com.oracle.truffle.runtime.hotspot; import java.lang.reflect.Method; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.TruffleCallBoundary; - import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.TruffleCallBoundary; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.hotspot.HotSpotNmethod; @@ -147,7 +162,7 @@ private void tetherSpeculationLog(HotSpotNmethod nmethod) throws Error, Internal HotSpotSpeculationLog log = (HotSpotSpeculationLog) speculationLog; if (log.managesFailedSpeculations() && log.hasSpeculations()) { try { - // org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime.createSpeculationLog() + // com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntime.createSpeculationLog() setSpeculationLog.invoke(nmethod, log); } catch (Error e) { throw e; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java similarity index 61% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java index 368897262953..3127d72e48f4 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotThreadLocalHandshake.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot; +package com.oracle.truffle.runtime.hotspot; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntime.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntime.java similarity index 90% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntime.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntime.java index 350ebdd7e26b..ff7132f32eac 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/HotSpotTruffleRuntime.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntime.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot; +package com.oracle.truffle.runtime.hotspot; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -37,24 +53,23 @@ import java.util.concurrent.ExecutionException; import java.util.function.Consumer; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationSupport; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.hotspot.HotSpotTruffleCompiler; -import org.graalvm.compiler.truffle.runtime.BackgroundCompileQueue; -import org.graalvm.compiler.truffle.runtime.CompilationTask; -import org.graalvm.compiler.truffle.runtime.EngineData; -import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode; -import org.graalvm.compiler.truffle.runtime.TruffleCallBoundary; -import org.graalvm.compiler.truffle.runtime.hotspot.libgraal.LibGraalTruffleCompilationSupport; - import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.impl.AbstractFastThreadLocal; import com.oracle.truffle.api.impl.ThreadLocalHandshake; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationSupport; +import com.oracle.truffle.compiler.TruffleCompiler; +import com.oracle.truffle.compiler.hotspot.HotSpotTruffleCompiler; +import com.oracle.truffle.runtime.BackgroundCompileQueue; +import com.oracle.truffle.runtime.CompilationTask; +import com.oracle.truffle.runtime.EngineData; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.OptimizedOSRLoopNode; +import com.oracle.truffle.runtime.OptimizedTruffleRuntime; +import com.oracle.truffle.runtime.TruffleCallBoundary; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalTruffleCompilationSupport; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.stack.StackIntrospection; @@ -83,7 +98,7 @@ * independent of where the compiler resides (i.e., co-located in the HotSpot heap or running in a * native-image shared library). */ -public final class HotSpotTruffleRuntime extends GraalTruffleRuntime { +public final class HotSpotTruffleRuntime extends OptimizedTruffleRuntime { static final int JAVA_SPEC = Runtime.version().feature(); static final sun.misc.Unsafe UNSAFE = getUnsafe(); @@ -212,6 +227,9 @@ protected StackIntrospection getStackIntrospection() { return l.stackIntrospection; } + /** + * This is called reflectively from the compiler side in HotSpotTruffleHostEnvironment. + */ @Override public TruffleCompiler getTruffleCompiler(TruffleCompilable compilable) { Objects.requireNonNull(compilable, "Compilable must be non null."); @@ -703,7 +721,7 @@ static void traceTransferToInterpreter(HotSpotTruffleRuntime runtime, HotSpotTru } public static HotSpotTruffleRuntime getRuntime() { - return (HotSpotTruffleRuntime) GraalTruffleRuntime.getRuntime(); + return (HotSpotTruffleRuntime) OptimizedTruffleRuntime.getRuntime(); } public boolean isLibGraalCompilationEnabled() { diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeAccess.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeAccess.java new file mode 100644 index 000000000000..466338c15ca5 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeAccess.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015, 2023, 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; + +import com.oracle.truffle.api.TruffleRuntime; +import com.oracle.truffle.api.TruffleRuntimeAccess; +import com.oracle.truffle.api.impl.DefaultTruffleRuntime; +import com.oracle.truffle.compiler.TruffleCompilationSupport; +import com.oracle.truffle.runtime.ModulesSupport; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraal; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalTruffleCompilationSupport; + +import jdk.internal.module.Modules; +import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; +import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; +import jdk.vm.ci.runtime.JVMCI; +import jdk.vm.ci.services.Services; + +public final class HotSpotTruffleRuntimeAccess implements TruffleRuntimeAccess { + + public HotSpotTruffleRuntimeAccess() { + } + + @Override + public TruffleRuntime getRuntime() { + return createRuntime(); + } + + @Override + public int getPriority() { + return 0; + } + + protected static TruffleRuntime createRuntime() { + String reason = ModulesSupport.exportJVMCI(HotSpotTruffleRuntimeAccess.class); + if (reason != null) { + return new DefaultTruffleRuntime(reason); + } + try { + Services.initializeJVMCI(); + } catch (Error e) { + // hack to detect the exact error that is thrown when + if (e.getClass() == Error.class && e.getMessage().startsWith("The EnableJVMCI VM option must be true")) { + return new DefaultTruffleRuntime("JVMCI is not enabled on this JVM. JVMCI may be enabled using -XX:+EnableJVMCI."); + } + throw e; + } + HotSpotJVMCIRuntime hsRuntime = (HotSpotJVMCIRuntime) JVMCI.getRuntime(); + HotSpotVMConfigAccess config = new HotSpotVMConfigAccess(hsRuntime.getConfigStore()); + boolean useCompiler = config.getFlag("UseCompiler", Boolean.class); + if (!useCompiler) { + // compilation disabled in host VM -> fallback to default runtime + return new DefaultTruffleRuntime("JVMCI compilation was disabled on this JVM. JVMCI may be enabled using -XX:+EnableJVMCI."); + } + TruffleCompilationSupport compilationSupport; + if (LibGraal.isAvailable()) { + // try LibGraal + compilationSupport = new LibGraalTruffleCompilationSupport(); + } else { + // try jar graal + try { + Module compilerModule = HotSpotTruffleRuntimeAccess.class.getModule().getLayer().findModule("jdk.internal.vm.compiler").orElse(null); + if (compilerModule == null) { + // jargraal compiler module not found -> fallback to default runtime + return new DefaultTruffleRuntime( + "Libgraal compilation is not available on this JVM. Alternatively, the compiler module jdk.internal.vm.compiler was not found on the --upgrade-module-path."); + } + Modules.addExports(compilerModule, "org.graalvm.compiler.truffle.compiler.hotspot", HotSpotTruffleRuntimeAccess.class.getModule()); + Class hotspotCompilationSupport = Class.forName("org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilationSupport"); + compilationSupport = (TruffleCompilationSupport) hotspotCompilationSupport.getConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw new InternalError(e); + } + } + HotSpotTruffleRuntime rt = new HotSpotTruffleRuntime(compilationSupport); + compilationSupport.registerRuntime(rt); + return rt; + } + +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java new file mode 100644 index 000000000000..cd8e816d50c2 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/HotSpotTruffleRuntimeServices.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2019, 2023, 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; + +import com.oracle.truffle.runtime.OptimizedCallTarget; + +import jdk.vm.ci.hotspot.HotSpotSpeculationLog; +import jdk.vm.ci.meta.SpeculationLog; + +/** + * JDK versioned functionality used by the HotSpot Truffle runtime. + * + * This version is for JDK 17+. + */ +class HotSpotTruffleRuntimeServices { + + /** + * A wrapper that holds a strong reference to another speculation log that + * {@linkplain HotSpotSpeculationLog#managesFailedSpeculations() manages} the failed + * speculations list. + */ + static class CompilationSpeculationLog extends HotSpotSpeculationLog { + private final HotSpotSpeculationLog wrappedLog; + + CompilationSpeculationLog(HotSpotSpeculationLog wrappedLog) { + super(wrappedLog.getFailedSpeculationsAddress()); + this.wrappedLog = wrappedLog; + } + + @Override + public String toString() { + return wrappedLog.toString(); + } + } + + /** + * Gets a speculation log to be used for compiling {@code callTarget}. + */ + public static SpeculationLog getCompilationSpeculationLog(OptimizedCallTarget callTarget) { + HotSpotSpeculationLog wrappedLog = (HotSpotSpeculationLog) callTarget.getSpeculationLog(); + CompilationSpeculationLog compilationSpeculationLog = new CompilationSpeculationLog(wrappedLog); + compilationSpeculationLog.collectFailedSpeculations(); + return compilationSpeculationLog; + } + +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryInput.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryInput.java new file mode 100644 index 000000000000..067ef4241656 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryInput.java @@ -0,0 +1,656 @@ +/* + * Copyright (c) 2023, 2023, 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.runtime.hotspot.libgraal.BinaryOutput.ARRAY; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.BOOLEAN; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.BYTE; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.CHAR; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.DOUBLE; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.FLOAT; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.INT; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.LARGE_STRING_TAG; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.LONG; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.NULL; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.SHORT; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.STRING; +import static com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.bufferSize; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; + +/** + * A buffer used by the {@link BinaryMarshaller} to unmarshal parameters and results passed by + * value. + * + * @see BinaryOutput + * @see BinaryMarshaller + * @see JNIConfig.Builder#registerMarshaller(Class, BinaryMarshaller) + */ +abstract class BinaryInput { + + private static final int EOF = -1; + + private byte[] tempEncodingByteBuffer; + private char[] tempEncodingCharBuffer; + protected final int length; + protected int pos; + + private BinaryInput(int length) { + this.length = length; + } + + /** + * Reads a single byte and returns {@code true} if that byte is non-zero, {@code false} if that + * byte is zero. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final boolean readBoolean() throws IndexOutOfBoundsException { + int b = read(); + if (b < 0) { + throw new IndexOutOfBoundsException(); + } + return b != 0; + } + + /** + * Reads and returns a single byte. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final byte readByte() throws IndexOutOfBoundsException { + int b = read(); + if (b < 0) { + throw new IndexOutOfBoundsException(); + } + return (byte) b; + } + + /** + * Reads two bytes and returns a {@code short} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final short readShort() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + return packShort(b1, b2); + } + + /** + * Creates a Java {@code short} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b2} is the least significant {@code byte}. + */ + private static short packShort(int b1, int b2) { + return (short) ((b1 << 8) + b2); + } + + /** + * Reads two bytes and returns a {@code char} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final char readChar() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + return packChar(b1, b2); + } + + /** + * Creates a Java {@code char} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b2} is the least significant {@code byte}. + */ + private static char packChar(int b1, int b2) { + return (char) ((b1 << 8) + b2); + } + + /** + * Reads four bytes and returns an {@code int} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final int readInt() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + int b3 = read(); + int b4 = read(); + if ((b1 | b2 | b3 | b4) < 0) { + throw new IndexOutOfBoundsException(); + } + return packInt(b1, b2, b3, b4); + } + + /** + * Creates a Java {@code int} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b4} is the least significant {@code byte}. + */ + private static int packInt(int b1, int b2, int b3, int b4) { + return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4; + } + + /** + * Reads eight bytes and returns a {@code long} value. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final long readLong() throws IndexOutOfBoundsException { + int b1 = read(); + int b2 = read(); + int b3 = read(); + int b4 = read(); + int b5 = read(); + int b6 = read(); + int b7 = read(); + int b8 = read(); + if ((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) { + throw new IndexOutOfBoundsException(); + } + return packLong(b1, b2, b3, b4, b5, b6, b7, b8); + } + + /** + * Creates a Java {@code long} from given unsigned bytes, where {@code b1} is the most + * significant byte {@code byte} and {@code b8} is the least significant {@code byte}. + */ + private static long packLong(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) { + return ((long) b1 << 56) + ((long) b2 << 48) + ((long) b3 << 40) + ((long) b4 << 32) + + ((long) b5 << 24) + ((long) b6 << 16) + ((long) b7 << 8) + b8; + } + + /** + * Reads four bytes and returns a {@code float} value. It does this by reading an {@code int} + * value and converting the {@code int} value to a {@code float} using + * {@link Float#intBitsToFloat(int)}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final float readFloat() throws IndexOutOfBoundsException { + return Float.intBitsToFloat(readInt()); + } + + /** + * Reads eight bytes and returns a {@code double} value. It does this by reading a {@code long} + * value and converting the {@code long} value to a {@code double} using + * {@link Double#longBitsToDouble(long)}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + */ + public final double readDouble() throws IndexOutOfBoundsException { + return Double.longBitsToDouble(readLong()); + } + + /** + * Reads a single byte. The byte value is returned as an {@code int} in the range {@code 0} to + * {@code 255}. If no byte is available because the end of the stream has been reached, the + * value {@code -1} is returned. + */ + public abstract int read(); + + /** + * Reads {@code len} bytes into a byte array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public abstract void read(byte[] b, int off, int len) throws IndexOutOfBoundsException; + + /** + * Reads a string using a modified UTF-8 encoding in a machine-independent manner. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + * @throws IllegalArgumentException if the bytes do not represent a valid modified UTF-8 + * encoding of a string. + */ + public final String readUTF() throws IndexOutOfBoundsException, IllegalArgumentException { + int len; + int b1 = read(); + int b2 = read(); + if ((b1 | b2) < 0) { + throw new IndexOutOfBoundsException(); + } + if ((b1 & LARGE_STRING_TAG) == LARGE_STRING_TAG) { + int b3 = read(); + int b4 = read(); + if ((b3 | b4) < 0) { + throw new IndexOutOfBoundsException(); + } + len = ((b1 & ~LARGE_STRING_TAG) << 24) + (b2 << 16) + (b3 << 8) + b4; + } else { + len = (b1 << 8) + b2; + } + ensureBufferSize(len); + if (tempEncodingCharBuffer == null || tempEncodingCharBuffer.length < len) { + tempEncodingCharBuffer = new char[Math.max(bufferSize(0, len), 80)]; + } + + int c1; + int c2; + int c3; + int byteCount = 0; + int charCount = 0; + + read(tempEncodingByteBuffer, 0, len); + + while (byteCount < len) { + c1 = tempEncodingByteBuffer[byteCount] & 0xff; + if (c1 > 127) { + break; + } + byteCount++; + tempEncodingCharBuffer[charCount++] = (char) c1; + } + + while (byteCount < len) { + c1 = tempEncodingByteBuffer[byteCount] & 0xff; + switch (c1 >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* 0xxxxxxx */ + byteCount++; + tempEncodingCharBuffer[charCount++] = (char) c1; + break; + case 12: + case 13: + /* 110x xxxx 10xx xxxx */ + byteCount += 2; + if (byteCount > len) { + throw new IllegalArgumentException("Partial character at end"); + } + c2 = tempEncodingByteBuffer[byteCount - 1]; + if ((c2 & 0xC0) != 0x80) { + throw new IllegalArgumentException("malformed input around byte " + byteCount); + } + tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F)); + break; + case 14: + /* 1110 xxxx 10xx xxxx 10xx xxxx */ + byteCount += 3; + if (byteCount > len) { + throw new IllegalArgumentException("malformed input: partial character at end"); + } + c2 = tempEncodingByteBuffer[byteCount - 2]; + c3 = tempEncodingByteBuffer[byteCount - 1]; + if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) { + throw new IllegalArgumentException("malformed input around byte " + (byteCount - 1)); + } + tempEncodingCharBuffer[charCount++] = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F)); + break; + default: + /* 10xx xxxx, 1111 xxxx */ + throw new IllegalArgumentException("malformed input around byte " + byteCount); + } + } + // The number of chars produced may be less than len + return new String(tempEncodingCharBuffer, 0, charCount); + } + + /** + * Reads a single value, using the data type encoded in the marshalled data. + * + * @return The read value, such as a boxed Java primitive, a {@link String}, a {@code null}, or + * an array of these types. + * @throws IndexOutOfBoundsException if there are not enough bytes to read. + * @throws IllegalArgumentException when the marshaled type is not supported or if the bytes do + * not represent a valid modified UTF-8 encoding of a string. + */ + public final Object readTypedValue() throws IndexOutOfBoundsException, IllegalArgumentException { + byte tag = readByte(); + switch (tag) { + case ARRAY: + int len = readInt(); + Object[] arr = new Object[len]; + for (int i = 0; i < len; i++) { + arr[i] = readTypedValue(); + } + return arr; + case NULL: + return null; + case BOOLEAN: + return readBoolean(); + case BYTE: + return readByte(); + case SHORT: + return readShort(); + case CHAR: + return readChar(); + case INT: + return readInt(); + case LONG: + return readLong(); + case FLOAT: + return readFloat(); + case DOUBLE: + return readDouble(); + case STRING: + return readUTF(); + default: + throw new IllegalArgumentException(String.format("Unknown tag %d", tag)); + } + } + + /** + * Reads {@code len} bytes into a boolean array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(boolean[] b, int off, int len) { + ensureBufferSize(len); + read(tempEncodingByteBuffer, 0, len); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + b[i] = tempEncodingByteBuffer[j++] != 0; + } + } + + /** + * Reads {@code len} shorts into a short array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(short[] b, int off, int len) { + int size = len * Short.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packShort(b1, b2); + } + } + + /** + * Reads {@code len} chars into a char array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(char[] b, int off, int len) { + int size = len * Character.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packChar(b1, b2); + } + } + + /** + * Reads {@code len} ints into an int array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(int[] b, int off, int len) { + int size = len * Integer.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packInt(b1, b2, b3, b4); + } + } + + /** + * Reads {@code len} longs into a long array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(long[] b, int off, int len) { + int size = len * Long.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + int b5 = (tempEncodingByteBuffer[j++] & 0xff); + int b6 = (tempEncodingByteBuffer[j++] & 0xff); + int b7 = (tempEncodingByteBuffer[j++] & 0xff); + int b8 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = packLong(b1, b2, b3, b4, b5, b6, b7, b8); + } + } + + /** + * Reads {@code len} floats into a float array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(float[] b, int off, int len) { + int size = len * Float.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = Float.intBitsToFloat(packInt(b1, b2, b3, b4)); + } + } + + /** + * Reads {@code len} doubles into a double array starting at offset {@code off}. + * + * @throws IndexOutOfBoundsException if there are not enough bytes to read + */ + public final void read(double[] b, int off, int len) { + int size = len * Double.BYTES; + ensureBufferSize(size); + read(tempEncodingByteBuffer, 0, size); + int limit = off + len; + for (int i = off, j = 0; i < limit; i++) { + int b1 = (tempEncodingByteBuffer[j++] & 0xff); + int b2 = (tempEncodingByteBuffer[j++] & 0xff); + int b3 = (tempEncodingByteBuffer[j++] & 0xff); + int b4 = (tempEncodingByteBuffer[j++] & 0xff); + int b5 = (tempEncodingByteBuffer[j++] & 0xff); + int b6 = (tempEncodingByteBuffer[j++] & 0xff); + int b7 = (tempEncodingByteBuffer[j++] & 0xff); + int b8 = (tempEncodingByteBuffer[j++] & 0xff); + b[i] = Double.longBitsToDouble(packLong(b1, b2, b3, b4, b5, b6, b7, b8)); + } + } + + /** + * Returns a read only {@link ByteBuffer} backed by the {@link BinaryInput} internal buffer. The + * content of the buffer will start at the {@link BinaryInput}'s current position. The buffer's + * capacity and limit will be {@code len}, its position will be zero, its mark will be + * undefined, and its byte order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}. After a + * successful call, the {@link BinaryInput}'s current position is incremented by the + * {@code len}. + * + * @throws IndexOutOfBoundsException if the BinaryInput has not enough remaining bytes. + */ + public abstract ByteBuffer asByteBuffer(int len); + + /** + * Creates a new buffer backed by a byte array. + */ + public static BinaryInput create(byte[] buffer) { + return new ByteArrayBinaryInput(buffer); + } + + /** + * Creates a new buffer backed by a byte array only up to a given length. + */ + public static BinaryInput create(byte[] buffer, int length) { + return new ByteArrayBinaryInput(buffer, length); + } + + /** + * Creates a new buffer wrapping an off-heap memory segment starting at an {@code address} + * having {@code length} bytes. + */ + public static BinaryInput create(CCharPointer address, int length) { + return new CCharPointerInput(address, length); + } + + private void ensureBufferSize(int len) { + if (tempEncodingByteBuffer == null || tempEncodingByteBuffer.length < len) { + tempEncodingByteBuffer = new byte[Math.max(bufferSize(0, len), 80)]; + } + } + + private static final class ByteArrayBinaryInput extends BinaryInput { + + private final byte[] buffer; + + ByteArrayBinaryInput(byte[] buffer) { + super(buffer.length); + this.buffer = buffer; + } + + ByteArrayBinaryInput(byte[] buffer, int length) { + super(length); + this.buffer = buffer; + } + + @Override + public int read() { + if (pos >= length) { + return EOF; + } + return (buffer[pos++] & 0xff); + } + + @Override + public void read(byte[] b, int off, int len) { + if (len < 0) { + throw new IllegalArgumentException(String.format("Len must be non negative but was %d", len)); + } + if (pos + len > length) { + throw new IndexOutOfBoundsException(); + } + System.arraycopy(buffer, pos, b, off, len); + pos += len; + } + + @Override + public ByteBuffer asByteBuffer(int len) { + ByteBuffer result = ByteBuffer.wrap(buffer, pos, len).slice().asReadOnlyBuffer(); + pos += len; + return result; + } + } + + private static final class CCharPointerInput extends BinaryInput { + + /** + * Represents the point at which the average cost of a JNI call exceeds the expense of an + * element by element copy. See {@code java.nio.Bits#JNI_COPY_TO_ARRAY_THRESHOLD}. + */ + private static final int BYTEBUFFER_COPY_TO_ARRAY_THRESHOLD = 6; + + private final CCharPointer address; + /** + * ByteBuffer view of this {@link CCharPointerInput} direct memory. The ByteBuffer is used + * for bulk data transfers, where the bulk ByteBuffer operations outperform element by + * element copying by an order of magnitude. + */ + private ByteBuffer byteBufferView; + + CCharPointerInput(CCharPointer address, int length) { + super(length); + this.address = address; + } + + @Override + public int read() { + if (pos >= length) { + return EOF; + } + return (address.read(pos++) & 0xff); + } + + @Override + public void read(byte[] b, int off, int len) { + if (len < 0) { + throw new IllegalArgumentException(String.format("Len must be non negative but was %d", len)); + } + if (pos + len > length) { + throw new IndexOutOfBoundsException(); + } + if (len > BYTEBUFFER_COPY_TO_ARRAY_THRESHOLD) { + if (byteBufferView == null) { + byteBufferView = CTypeConversion.asByteBuffer(address, length); + } + byteBufferView.position(pos); + byteBufferView.get(b, off, len); + } else { + for (int i = 0, j = pos; i < len; i++, j++) { + b[off + i] = address.read(j); + } + } + pos += len; + } + + @Override + public ByteBuffer asByteBuffer(int len) { + ByteBuffer result = CTypeConversion.asByteBuffer(address.addressOf(pos), len).order(ByteOrder.BIG_ENDIAN).asReadOnlyBuffer(); + pos += len; + return result; + } + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryOutput.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryOutput.java new file mode 100644 index 000000000000..c127987fdda9 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/BinaryOutput.java @@ -0,0 +1,688 @@ +/* + * Copyright (c) 2021, 2023, 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 org.graalvm.nativeimage.UnmanagedMemory; +import org.graalvm.nativeimage.c.type.CCharPointer; +import org.graalvm.nativeimage.c.type.CTypeConversion; +import org.graalvm.word.WordFactory; + +import java.io.Closeable; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Objects; + +/** + * A buffer used by the {@link BinaryMarshaller} to marshall parameters and results passed by value. + * + * @see BinaryInput + * @see BinaryMarshaller + * @see Builder#registerMarshaller(Class, BinaryMarshaller) + */ +abstract class BinaryOutput { + + /** + * Maximum string length for string encoded by 4 bytes length followed be content. + */ + private static final int MAX_LENGTH = Integer.MAX_VALUE - Integer.BYTES; + /** + * Maximum string length for string encoded by 2 bytes length followed be content. + */ + private static final int MAX_SHORT_LENGTH = Short.MAX_VALUE; + /** + * Tag to distinguish between long and short string. The tag is set in the first string length + * byte. + */ + static final int LARGE_STRING_TAG = 1 << 7; + + // Type tags used by writeTypedValue + static final byte NULL = 0; + static final byte BOOLEAN = NULL + 1; + static final byte BYTE = BOOLEAN + 1; + static final byte SHORT = BYTE + 1; + static final byte CHAR = SHORT + 1; + static final byte INT = CHAR + 1; + static final byte LONG = INT + 1; + static final byte FLOAT = LONG + 1; + static final byte DOUBLE = FLOAT + 1; + static final byte STRING = DOUBLE + 1; + static final byte ARRAY = STRING + 1; + + private byte[] tempDecodingBuffer; + protected int pos; + + private BinaryOutput() { + } + + /** + * Writes a {@code boolean} as a single byte value. The value {@code true} is written as the + * value {@code (byte)1}, the value {@code false} is written as the value {@code (byte)0}. The + * buffer position is incremented by {@code 1}. + */ + public final void writeBoolean(boolean value) { + write(value ? 1 : 0); + } + + /** + * Writes a {@code byte} as a single byte value. The buffer position is incremented by + * {@code 1}. + */ + public final void writeByte(int value) { + write(value); + } + + /** + * Writes a {@code short} as two bytes, high byte first. The buffer position is incremented by + * {@code 2}. + */ + public final void writeShort(int value) { + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes a {@code char} as two bytes, high byte first. The buffer position is incremented by + * {@code 2}. + */ + public final void writeChar(int value) { + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes an {@code int} as four bytes, high byte first. The buffer position is incremented by + * {@code 4}. + */ + public final void writeInt(int value) { + write((value >>> 24) & 0xff); + write((value >>> 16) & 0xff); + write((value >>> 8) & 0xff); + write(value & 0xff); + } + + /** + * Writes a {@code long} as eight bytes, high byte first. The buffer position is incremented by + * {@code 8}. + */ + public final void writeLong(long value) { + write((int) ((value >>> 56) & 0xff)); + write((int) ((value >>> 48) & 0xff)); + write((int) ((value >>> 40) & 0xff)); + write((int) ((value >>> 32) & 0xff)); + write((int) ((value >>> 24) & 0xff)); + write((int) ((value >>> 16) & 0xff)); + write((int) ((value >>> 8) & 0xff)); + write((int) (value & 0xff)); + } + + /** + * Converts a {@code float} value to an {@code int} using the + * {@link Float#floatToIntBits(float)}, and then writes that {@code int} as four bytes, high + * byte first. The buffer position is incremented by {@code 4}. + */ + public final void writeFloat(float value) { + writeInt(Float.floatToIntBits(value)); + } + + /** + * Converts a {@code double} value to a {@code long} using the + * {@link Double#doubleToLongBits(double)}, and then writes that {@code long} as eight bytes, + * high byte first. The buffer position is incremented by {@code 8}. + */ + public final void writeDouble(double value) { + writeLong(Double.doubleToLongBits(value)); + } + + /** + * Writes the lowest byte of the argument as a single byte value. The buffer position is + * incremented by {@code 1}. + */ + public abstract void write(int b); + + /** + * Writes {@code len} bytes from the byte {@code array} starting at offset {@code off}. The + * buffer position is incremented by {@code len}. + */ + public abstract void write(byte[] array, int off, int len); + + /** + * Reserves a buffer space. The reserved space can be used for out parameters. + * + * @param numberOfBytes number of bytes to reserve. + */ + public abstract void skip(int numberOfBytes); + + /** + * Writes a string using a modified UTF-8 encoding in a machine-independent manner. + * + * @throws IllegalArgumentException if the {@code string} cannot be encoded using modified UTF-8 + * encoding. + */ + public final void writeUTF(String string) throws IllegalArgumentException { + int len = string.length(); + int utfLen = 0; + int c; + int count = 0; + + for (int i = 0; i < len; i++) { + c = string.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + utfLen++; + } else if (c > 0x07FF) { + utfLen += 3; + } else { + utfLen += 2; + } + } + + if (utfLen > MAX_LENGTH) { + throw new IllegalArgumentException("String too long to encode, " + utfLen + " bytes"); + } + int headerSize; + if (utfLen > MAX_SHORT_LENGTH) { + headerSize = Integer.BYTES; + ensureBufferSize(headerSize, utfLen); + tempDecodingBuffer[count++] = (byte) ((LARGE_STRING_TAG | (utfLen >>> 24)) & 0xff); + tempDecodingBuffer[count++] = (byte) ((utfLen >>> 16) & 0xFF); + } else { + headerSize = Short.BYTES; + ensureBufferSize(headerSize, utfLen); + } + tempDecodingBuffer[count++] = (byte) ((utfLen >>> 8) & 0xFF); + tempDecodingBuffer[count++] = (byte) (utfLen & 0xFF); + + int i = 0; + for (; i < len; i++) { + c = string.charAt(i); + if (!((c >= 0x0001) && (c <= 0x007F))) { + break; + } + tempDecodingBuffer[count++] = (byte) c; + } + + for (; i < len; i++) { + c = string.charAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + tempDecodingBuffer[count++] = (byte) c; + } else if (c > 0x07FF) { + tempDecodingBuffer[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); + tempDecodingBuffer[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); + tempDecodingBuffer[count++] = (byte) (0x80 | (c & 0x3F)); + } else { + tempDecodingBuffer[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); + tempDecodingBuffer[count++] = (byte) (0x80 | (c & 0x3F)); + } + } + write(tempDecodingBuffer, 0, headerSize + utfLen); + } + + /** + * Returns this buffer's position. + */ + public int getPosition() { + return pos; + } + + /** + * Returns true if a value is a typed value writable using + * {@link #writeTypedValue(Object)}, else false. + */ + public static boolean isTypedValue(Object value) { + if (value == null) { + return true; + } + return value instanceof Object[] || value == null || value instanceof Boolean || value instanceof Byte || + value instanceof Short || value instanceof Character || value instanceof Integer || + value instanceof Long || value instanceof Float || value instanceof Double || value instanceof String; + } + + /** + * Writes the value that is represented by the given object, together with information on the + * value's data type. Supported types are boxed Java primitive types, {@link String}, + * {@code null}, and arrays of these types. + * + * @throws IllegalArgumentException when the {@code value} type is not supported or the + * {@code value} is a string which cannot be encoded using modified UTF-8 encoding. + * @see #isTypedValue(Object) to find out whether a value can be serialized. + */ + public final void writeTypedValue(Object value) throws IllegalArgumentException { + if (value instanceof Object[]) { + Object[] arr = (Object[]) value; + writeByte(ARRAY); + writeInt(arr.length); + for (Object arrElement : arr) { + writeTypedValue(arrElement); + } + } else if (value == null) { + writeByte(NULL); + } else if (value instanceof Boolean) { + writeByte(BOOLEAN); + writeBoolean((boolean) value); + } else if (value instanceof Byte) { + writeByte(BYTE); + writeByte((byte) value); + } else if (value instanceof Short) { + writeByte(SHORT); + writeShort((short) value); + } else if (value instanceof Character) { + writeByte(CHAR); + writeChar((char) value); + } else if (value instanceof Integer) { + writeByte(INT); + writeInt((int) value); + } else if (value instanceof Long) { + writeByte(LONG); + writeLong((long) value); + } else if (value instanceof Float) { + writeByte(FLOAT); + writeFloat((float) value); + } else if (value instanceof Double) { + writeByte(DOUBLE); + writeDouble((double) value); + } else if (value instanceof String) { + writeByte(STRING); + writeUTF((String) value); + } else { + throw new IllegalArgumentException(String.format("Unsupported type %s", value.getClass())); + } + } + + /** + * Writes {@code len} bytes from the boolean {@code array} starting at offset {@code off}. The + * value {@code true} is written as the value {@code (byte)1}, the value {@code false} is + * written as the value {@code (byte)0}. The buffer position is incremented by {@code len}. + */ + public final void write(boolean[] array, int off, int len) { + ensureBufferSize(0, len); + for (int i = 0, j = 0; i < len; i++, j++) { + tempDecodingBuffer[j] = (byte) (array[off + i] ? 1 : 0); + } + write(tempDecodingBuffer, 0, len); + } + + /** + * Writes {@code len} shorts from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 2 * len}. + */ + public final void write(short[] array, int off, int len) { + int size = len * Short.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} chars from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 2 * len}. + */ + public final void write(char[] array, int off, int len) { + int size = len * Character.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} ints from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 4 * len}. + */ + public final void write(int[] array, int off, int len) { + int size = len * Integer.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} longs from the {@code array} starting at offset {@code off}. The buffer + * position is incremented by {@code 8 * len}. + */ + public final void write(long[] array, int off, int len) { + int size = len * Long.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 56) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 48) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 40) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 32) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((array[off + i] >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (array[off + i] & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} floats from the {@code array} starting at offset {@code off}. Each + * {@code float} value is converted to an {@code int} using the + * {@link Float#floatToIntBits(float)} and written as an int. The buffer position is incremented + * by {@code 4 * len}. + */ + public final void write(float[] array, int off, int len) { + int size = len * Float.BYTES; + ensureBufferSize(0, size); + for (int i = 0, j = 0; i < len; i++) { + int bits = Float.floatToIntBits(array[off + i]); + tempDecodingBuffer[j++] = (byte) ((bits >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (bits & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + /** + * Writes {@code len} doubles from the {@code array} starting at offset {@code off}. Each + * {@code double} value is converted to an {@code lang} using the + * {@link Double#doubleToLongBits(double)} and written as a long. The buffer position is + * incremented by {@code 8 * len}. + */ + public final void write(double[] array, int off, int len) { + int size = len * Double.BYTES; + ensureBufferSize(Integer.BYTES, size); + for (int i = 0, j = 0; i < len; i++) { + long bits = Double.doubleToLongBits(array[off + i]); + tempDecodingBuffer[j++] = (byte) ((bits >>> 56) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 48) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 40) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 32) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 24) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 16) & 0xff); + tempDecodingBuffer[j++] = (byte) ((bits >>> 8) & 0xff); + tempDecodingBuffer[j++] = (byte) (bits & 0xff); + } + write(tempDecodingBuffer, 0, size); + } + + private void ensureBufferSize(int headerSize, int dataSize) { + if (tempDecodingBuffer == null || tempDecodingBuffer.length < (headerSize + dataSize)) { + tempDecodingBuffer = new byte[bufferSize(headerSize, dataSize)]; + } + } + + /** + * Creates a new buffer backed by a byte array. + */ + public static ByteArrayBinaryOutput create() { + return new ByteArrayBinaryOutput(ByteArrayBinaryOutput.INITIAL_SIZE); + } + + /** + * Creates a new buffer wrapping the {@code initialBuffer}. If the {@code initialBuffer} + * capacity is not sufficient for writing the data, a new array is allocated. Always use + * {@link ByteArrayBinaryOutput#getArray()} to obtain the marshaled data. + */ + public static ByteArrayBinaryOutput create(byte[] initialBuffer) { + Objects.requireNonNull(initialBuffer, "InitialBuffer must be non null."); + return new ByteArrayBinaryOutput(initialBuffer); + } + + /** + * Creates a new buffer wrapping an off-heap memory segment starting at {@code address} having + * {@code length} bytes. If the capacity of an off-heap memory segment is not sufficient for + * writing the data, a new off-heap memory is allocated. Always use + * {@link CCharPointerBinaryOutput#getAddress()} to obtain the marshaled data. + * + * @param address the off-heap memory address + * @param length the off-heap memory size + * @param dynamicallyAllocated {@code true} if the memory was dynamically allocated and should + * be freed when the buffer is closed; {@code false} for the stack allocated memory. + */ + public static CCharPointerBinaryOutput create(CCharPointer address, int length, boolean dynamicallyAllocated) { + return new CCharPointerBinaryOutput(address, length, dynamicallyAllocated); + } + + static int bufferSize(int headerSize, int dataSize) { + return headerSize + (dataSize <= MAX_SHORT_LENGTH ? dataSize << 1 : dataSize); + } + + /** + * A {@link BinaryOutput} backed by a byte array. + */ + public static final class ByteArrayBinaryOutput extends BinaryOutput { + + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + static final int INITIAL_SIZE = 32; + + private byte[] buffer; + + private ByteArrayBinaryOutput(int size) { + buffer = new byte[size]; + } + + private ByteArrayBinaryOutput(byte[] initialBuffer) { + buffer = initialBuffer; + } + + @Override + public void write(int b) { + ensureCapacity(pos + 1); + buffer[pos] = (byte) b; + pos += 1; + } + + @Override + public void write(byte[] b, int off, int len) { + ensureCapacity(pos + len); + System.arraycopy(b, off, buffer, pos, len); + pos += len; + } + + @Override + public void skip(int numberOfBytes) { + ensureCapacity(pos + numberOfBytes); + pos += numberOfBytes; + } + + /** + * Returns the byte array containing the marshalled data. + */ + public byte[] getArray() { + return buffer; + } + + private void ensureCapacity(int neededCapacity) { + if (neededCapacity - buffer.length > 0) { + int newCapacity = buffer.length << 1; + if (newCapacity - neededCapacity < 0) { + newCapacity = neededCapacity; + } + if (newCapacity - MAX_ARRAY_SIZE > 0) { + throw new OutOfMemoryError(); + } + buffer = Arrays.copyOf(buffer, newCapacity); + } + } + + /** + * Creates a new buffer backed by a byte array. The buffer initial size is + * {@code initialSize}. + */ + public static ByteArrayBinaryOutput create(int initialSize) { + return new ByteArrayBinaryOutput(initialSize); + } + } + + /** + * A {@link BinaryOutput} backed by an off-heap memory. + */ + public static final class CCharPointerBinaryOutput extends BinaryOutput implements Closeable { + + /** + * Represents the point at which the average cost of a JNI call exceeds the expense of an + * element by element copy. See {@code java.nio.Bits#JNI_COPY_FROM_ARRAY_THRESHOLD}. + */ + private static final int BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD = 6; + + private CCharPointer address; + private int length; + private boolean unmanaged; + /** + * ByteBuffer view of this {@link CCharPointerBinaryOutput} direct memory. The ByteBuffer is + * used for bulk data transfers, where the bulk ByteBuffer operations outperform element by + * element copying by an order of magnitude. + */ + private ByteBuffer byteBufferView; + + private CCharPointerBinaryOutput(CCharPointer address, int length, boolean unmanaged) { + this.address = address; + this.length = length; + this.unmanaged = unmanaged; + } + + @Override + public int getPosition() { + checkClosed(); + return super.getPosition(); + } + + /** + * Returns an address of an off-heap memory segment containing the marshalled data. + */ + public CCharPointer getAddress() { + checkClosed(); + return address; + } + + @Override + public void write(int b) { + checkClosed(); + ensureCapacity(pos + 1); + address.write(pos++, (byte) b); + } + + @Override + public void write(byte[] b, int off, int len) { + checkClosed(); + if ((off | len | b.length) < 0 || b.length - off < len) { + throw new IndexOutOfBoundsException("offset: " + off + ", length: " + len + ", array length: " + b.length); + } + ensureCapacity(pos + len); + if (len > BYTEBUFFER_COPY_FROM_ARRAY_THRESHOLD) { + if (byteBufferView == null) { + byteBufferView = CTypeConversion.asByteBuffer(address, length); + } + byteBufferView.position(pos); + byteBufferView.put(b, off, len); + } else { + for (int i = 0; i < len; i++) { + address.write(pos + i, b[off + i]); + } + } + pos += len; + } + + @Override + public void skip(int numberOfBytes) { + ensureCapacity(pos + numberOfBytes); + pos += numberOfBytes; + } + + /** + * Closes the buffer and frees off-heap allocated resources. + */ + @Override + public void close() { + if (unmanaged) { + UnmanagedMemory.free(address); + byteBufferView = null; + address = WordFactory.nullPointer(); + length = 0; + unmanaged = false; + pos = Integer.MIN_VALUE; + } + } + + private void checkClosed() { + if (pos == Integer.MIN_VALUE) { + throw new IllegalStateException("Already closed"); + } + } + + private void ensureCapacity(int neededCapacity) { + if (neededCapacity - length > 0) { + byteBufferView = null; + int newCapacity = length << 1; + if (newCapacity - neededCapacity < 0) { + newCapacity = neededCapacity; + } + if (newCapacity - Integer.MAX_VALUE > 0) { + throw new OutOfMemoryError(); + } + if (unmanaged) { + address = UnmanagedMemory.realloc(address, WordFactory.unsigned(newCapacity)); + } else { + CCharPointer newAddress = UnmanagedMemory.malloc(newCapacity); + memcpy(newAddress, address, pos); + address = newAddress; + } + length = newCapacity; + unmanaged = true; + } + } + + private static void memcpy(CCharPointer dst, CCharPointer src, int len) { + for (int i = 0; i < len; i++) { + dst.write(i, src.read(i)); + } + } + + /** + * Creates a new buffer backed by an off-heap memory segment. The buffer initial size is + * {@code initialSize}. + */ + public static CCharPointerBinaryOutput create(int initialSize) { + return new CCharPointerBinaryOutput(UnmanagedMemory.malloc(initialSize), initialSize, true); + } + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/DestroyedIsolateException.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/DestroyedIsolateException.java new file mode 100644 index 000000000000..e4b7203ad5ef --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/DestroyedIsolateException.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021, 2023, 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; + +/** + * Exception thrown when a {@link LibGraalObject} associated with a destroyed isolate context is + * used. + */ +public final class DestroyedIsolateException extends IllegalArgumentException { + + private static final long serialVersionUID = 1L; + + private final boolean vmExit; + + DestroyedIsolateException(String message, boolean vmExit) { + super(message); + this.vmExit = vmExit; + } + + /** + * Returns {@code true} if this exception was thrown during VM exit. + */ + public boolean isVmExit() { + return vmExit; + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraal.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraal.java similarity index 87% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraal.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraal.java index 2f5508412088..5c91731438eb 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraal.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraal.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; @@ -35,6 +51,8 @@ import org.graalvm.word.PointerBase; import org.graalvm.word.WordFactory; +import com.oracle.truffle.runtime.ModulesSupport; + import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotObjectConstant; import jdk.vm.ci.hotspot.HotSpotResolvedJavaType; @@ -72,6 +90,7 @@ public class LibGraal { static { // Initialize JVMCI to ensure JVMCI opens its packages to Graal. + ModulesSupport.exportJVMCI(LibGraal.class); Services.initializeJVMCI(); } @@ -191,6 +210,7 @@ private static long initializeLibgraal() { return isolate; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof UnsupportedOperationException) { + // libgraal available but not enabled return 0L; } throw new InternalError(e); 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 new file mode 100644 index 000000000000..6542b433b53f --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalCompilationResultInfo.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018, 2023, 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.runtime.hotspot.libgraal.LibGraalScope.getIsolateThread; + +import com.oracle.truffle.compiler.TruffleCompilerListener; + +/** + * Encapsulates a handle to a {@code CompilationResultInfo} object in the libgraal heap. + */ +final class LibGraalCompilationResultInfo extends LibGraalScopedHandle implements TruffleCompilerListener.CompilationResultInfo { + + LibGraalCompilationResultInfo(long handle) { + super(handle, LibGraalCompilationResultInfo.class); + } + + @Override + public int getTargetCodeSize() { + return TruffleToLibGraalCalls.getTargetCodeSize(getIsolateThread(), getHandle()); + } + + @Override + public int getTotalFrameSize() { + return TruffleToLibGraalCalls.getTotalFrameSize(getIsolateThread(), getHandle()); + } + + @Override + public int getExceptionHandlersCount() { + return TruffleToLibGraalCalls.getExceptionHandlersCount(getIsolateThread(), getHandle()); + } + + @Override + public int getInfopointsCount() { + return TruffleToLibGraalCalls.getInfopointsCount(getIsolateThread(), getHandle()); + } + + @Override + public String[] getInfopoints() { + return TruffleToLibGraalCalls.getInfopoints(getIsolateThread(), getHandle()); + } + + @Override + public int getMarksCount() { + return TruffleToLibGraalCalls.getMarksCount(getIsolateThread(), getHandle()); + } + + @Override + public int getDataPatchesCount() { + return TruffleToLibGraalCalls.getDataPatchesCount(getIsolateThread(), getHandle()); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java new file mode 100644 index 000000000000..f6f8d3dcc659 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalGraphInfo.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018, 2023, 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.runtime.hotspot.libgraal.LibGraalScope.getIsolateThread; + +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo; + +/** + * Encapsulates a handle to a {@link GraphInfo} object in the libgraal heap. + */ +final class LibGraalGraphInfo extends LibGraalScopedHandle implements TruffleCompilerListener.GraphInfo { + + LibGraalGraphInfo(long handle) { + super(handle, LibGraalGraphInfo.class); + } + + @Override + public int getNodeCount() { + return TruffleToLibGraalCalls.getNodeCount(getIsolateThread(), getHandle()); + } + + @Override + public String[] getNodeTypes(boolean simpleNames) { + return TruffleToLibGraalCalls.getNodeTypes(getIsolateThread(), getHandle(), simpleNames); + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java similarity index 68% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java index 52f2d80020cb..2e0332579100 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalHotSpotTruffleCompiler.java @@ -1,42 +1,54 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; -import static org.graalvm.libgraal.LibGraalScope.getIsolateThread; +import static com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope.getIsolateThread; import java.util.function.Supplier; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.hotspot.HotSpotTruffleCompiler; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; -import org.graalvm.libgraal.DestroyedIsolateException; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.libgraal.LibGraalObject; -import org.graalvm.libgraal.LibGraalScope; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.hotspot.HotSpotTruffleCompiler; +import com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntime; import jdk.vm.ci.meta.ResolvedJavaMethod; diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalIsolate.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalIsolate.java similarity index 69% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalIsolate.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalIsolate.java index e5a0178fe6d3..705e527cd7da 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalIsolate.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalIsolate.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; @@ -137,7 +153,7 @@ boolean clean() { * {@link DestroyedIsolateException}. Called by {@code LibGraalFeature#shutdownLibGraal} using * JNI. */ - static synchronized void unregister(long isolateId) { + public static synchronized void unregister(long isolateId) { LibGraalIsolate isolate = isolates.remove(isolateId); // The isolates.remove(isolateId) may return null when no LibGraalScope was created for the // given isolateId. diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalObject.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java similarity index 59% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalObject.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java index 556d09e22b9e..2be214f75e43 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalObject.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalObject.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; /** * Encapsulates a handle to an object in a libgraal isolate where the object's lifetime is bound to diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalScope.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScope.java similarity index 78% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalScope.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScope.java index 984f9b4b3132..b9a078d1e519 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/libgraal/LibGraalScope.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScope.java @@ -1,28 +1,44 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; import java.util.concurrent.atomic.AtomicInteger; @@ -150,18 +166,24 @@ public LibGraalScope(DetachAction detachAction) { } id = nextId.getAndIncrement(); parent = currentScope.get(); + boolean initializeIsolate; if (parent == null) { long[] isolateBox = {0}; boolean firstAttach = LibGraal.attachCurrentThread(false, isolateBox); long isolateAddress = isolateBox[0]; long isolateThread = getIsolateThreadIn(isolateAddress); long isolateId = getIsolateId(isolateThread); + initializeIsolate = firstAttach; LibGraalIsolate isolate = LibGraalIsolate.forIsolateId(isolateId, isolateAddress); shared = new Shared(firstAttach ? detachAction : null, isolate, isolateThread); } else { shared = parent.shared; + initializeIsolate = false; } currentScope.set(this); + if (initializeIsolate) { + LibGraalTruffleCompilationSupport.initializeIsolate(shared.getIsolateThread()); + } } @Override diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java new file mode 100644 index 000000000000..0a2d29ca0c56 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalScopedHandle.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019, 2023, 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; + +/** + * Encapsulates a handle to an object in the libgraal heap where the handle is only valid within the + * scope of a {@link TruffleFromLibGraalEntryPoints} method. + */ +class LibGraalScopedHandle implements AutoCloseable { + + /** + * Handle to a libgraal object. + */ + private long handle; + + private final Class handleType; + + /** + * Creates a new {@link LibGraalScopedHandle}. + * + * @param handle handle to a libgraal object + */ + LibGraalScopedHandle(long handle, Class handleType) { + this.handle = handle; + this.handleType = handleType; + } + + long getHandle() { + if (handle == 0L) { + throw new IllegalStateException("Using invalid handle to " + handleType.getName() + " object in libgraal heap"); + } + return handle; + } + + @Override + public void close() { + handle = 0L; + } + + @Override + public String toString() { + return String.format("%s@0x%x", handleType.getName(), handle); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java new file mode 100644 index 000000000000..1dbbb87d15b2 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalStringSupplier.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, 2023, 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.runtime.hotspot.libgraal.LibGraalScope.getIsolateThread; + +import java.util.function.Supplier; + +/** + * Encapsulates a handle to a {@link Supplier} object in the libgraal heap. + */ +final class LibGraalStringSupplier extends LibGraalObject implements Supplier { + + LibGraalStringSupplier(long handle) { + super(handle); + } + + @Override + public String get() { + return TruffleToLibGraalCalls.getSuppliedString(getIsolateThread(), getHandle()); + } +} diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java similarity index 62% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java index 23312542339e..95ebd17e751f 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/LibGraalTruffleCompilationSupport.java @@ -1,43 +1,55 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; +package com.oracle.truffle.runtime.hotspot.libgraal; +import static com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope.getIsolateThread; import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; -import static org.graalvm.libgraal.LibGraalScope.getIsolateThread; - -import org.graalvm.compiler.truffle.common.TruffleCompilationSupport; -import org.graalvm.compiler.truffle.common.TruffleCompiler; -import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor; -import org.graalvm.compiler.truffle.common.TruffleCompilerOptionDescriptor.Type; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.runtime.hotspot.HotSpotTruffleRuntime; -import org.graalvm.libgraal.DestroyedIsolateException; -import org.graalvm.libgraal.LibGraalObject; -import org.graalvm.libgraal.LibGraalScope; -import org.graalvm.libgraal.LibGraalScope.DetachAction; -import org.graalvm.nativebridge.BinaryInput; + +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.runtime.hotspot.HotSpotTruffleRuntime; +import com.oracle.truffle.runtime.hotspot.libgraal.LibGraalScope.DetachAction; /** * Represents a truffle compilation bundling compilable and task into a single object. Also installs @@ -47,6 +59,11 @@ public final class LibGraalTruffleCompilationSupport implements TruffleCompilati private volatile String cachedCompilerConfigurationName; + public static void initializeIsolate(long isolateThreadId) { + runtime().registerNativeMethods(TruffleToLibGraalCalls.class); + TruffleToLibGraalCalls.initializeIsolate(isolateThreadId, LibGraalTruffleCompilationSupport.class); + } + /* * When migrated to native-bridge this method should be marked @Idempotent instead. */ diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java similarity index 70% rename from compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java index c6058b37ce64..220e936fc238 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleFromLibGraalEntryPoints.java @@ -1,74 +1,91 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.runtime.hotspot.libgraal; - +package com.oracle.truffle.runtime.hotspot.libgraal; + +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AddInlinedTarget; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AddTargetToDequeue; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.AsJavaConstant; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CancelCompilation; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.ConsumeOptimizedAssumptionDependency; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableCallCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetConstantFieldInfo; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetDescription; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetFailedSpeculationsAddress; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetKnownCallSiteCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetLanguage; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetLineNumber; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeClassName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeId; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetNonTrivialNodeCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetEnd; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetStart; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetPartialEvaluationMethodInfo; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetPosition; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetSuppliedString; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.GetURI; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.HasNextTier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsCancelled; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsLastTier; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsSameOrSplit; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsSuppressedFailure; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsTrivial; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.IsValueType; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.Log; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCodeInstallation; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationFailed; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationRetry; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnFailure; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnGraalTierFinished; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnSuccess; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.OnTruffleTierFinished; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.RegisterOptimizedAssumptionDependency; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id.SetCallCounts; import static java.lang.String.format; import static java.lang.System.lineSeparator; import static java.util.stream.Collectors.joining; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AddInlinedTarget; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AddTargetToDequeue; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.AsJavaConstant; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CancelCompilation; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CompilableToString; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.ConsumeOptimizedAssumptionDependency; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.CreateStringSupplier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableCallCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetCompilableName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetConstantFieldInfo; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetDescription; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetFailedSpeculationsAddress; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetKnownCallSiteCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetLanguage; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetLineNumber; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeClassName; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNodeId; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetNonTrivialNodeCount; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetEnd; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetOffsetStart; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetPartialEvaluationMethodInfo; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetPosition; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetSuppliedString; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.GetURI; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.HasNextTier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsCancelled; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsLastTier; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsSameOrSplit; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsSuppressedFailure; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsTrivial; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.IsValueType; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.Log; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCodeInstallation; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationFailed; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnCompilationRetry; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnFailure; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnGraalTierFinished; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnSuccess; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.OnTruffleTierFinished; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.RegisterOptimizedAssumptionDependency; -import static org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id.SetCallCounts; +import java.io.PrintStream; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URI; @@ -81,22 +98,20 @@ import java.util.function.Supplier; import java.util.stream.Stream; -import org.graalvm.compiler.truffle.common.ConstantFieldInfo; -import org.graalvm.compiler.truffle.common.HostMethodInfo; -import org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency; -import org.graalvm.compiler.truffle.common.PartialEvaluationMethodInfo; -import org.graalvm.compiler.truffle.common.TruffleCompilable; -import org.graalvm.compiler.truffle.common.TruffleCompilationTask; -import org.graalvm.compiler.truffle.common.TruffleCompilerAssumptionDependency; -import org.graalvm.compiler.truffle.common.TruffleCompilerListener; -import org.graalvm.compiler.truffle.common.TruffleCompilerRuntime; -import org.graalvm.compiler.truffle.common.TruffleSourceLanguagePosition; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal; -import org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleFromLibGraal.Id; -import org.graalvm.compiler.truffle.runtime.OptimizedCallTarget; -import org.graalvm.libgraal.LibGraal; -import org.graalvm.nativebridge.BinaryOutput; -import org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput; +import com.oracle.truffle.compiler.ConstantFieldInfo; +import com.oracle.truffle.compiler.HostMethodInfo; +import com.oracle.truffle.compiler.OptimizedAssumptionDependency; +import com.oracle.truffle.compiler.PartialEvaluationMethodInfo; +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerAssumptionDependency; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.TruffleSourceLanguagePosition; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleFromLibGraal.Id; +import com.oracle.truffle.runtime.OptimizedCallTarget; +import com.oracle.truffle.runtime.hotspot.libgraal.BinaryOutput.ByteArrayBinaryOutput; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.hotspot.HotSpotSpeculationLog; @@ -114,6 +129,11 @@ final class TruffleFromLibGraalEntryPoints { assert checkHotSpotCalls(); } + @TruffleFromLibGraal(Id.OnIsolateShutdown) + static void onIsolateShutdown(long isolateId) { + LibGraalIsolate.unregister(isolateId); + } + @TruffleFromLibGraal(ConsumeOptimizedAssumptionDependency) static void consumeOptimizedAssumptionDependency(Consumer consumer, Object target, long installedCode) { OptimizedCallTarget callTarget = (OptimizedCallTarget) target; @@ -465,10 +485,11 @@ private static String missingImpl(Id id) { private static void check(Id id, boolean condition, String format, Object... args) { if (!condition) { String msg = format(format, args); + PrintStream err = System.err; if (id != null) { - System.err.printf("ERROR: %s.%s: %s%n", TruffleFromLibGraalEntryPoints.class.getName(), id, msg); + err.printf("ERROR: %s.%s: %s%n", TruffleFromLibGraalEntryPoints.class.getName(), id, msg); } else { - System.err.printf("ERROR: %s: %s%n", TruffleFromLibGraalEntryPoints.class.getName(), msg); + err.printf("ERROR: %s: %s%n", TruffleFromLibGraalEntryPoints.class.getName(), msg); } System.exit(99); } 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 new file mode 100644 index 000000000000..6642caddb409 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/hotspot/libgraal/TruffleToLibGraalCalls.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2018, 2023, 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.DoCompile; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetCompilerConfigurationFactoryName; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetDataPatchesCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetExceptionHandlersCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopoints; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetInfopointsCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetMarksCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeCount; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetNodeTypes; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetTargetCodeSize; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.GetTotalFrameSize; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InitializeCompiler; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InitializeRuntime; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleCallBoundaryMethod; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.InstallTruffleReservedOopMethod; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.NewCompiler; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.PendingTransferToInterpreterOffset; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.PurgePartialEvaluationCaches; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.RegisterRuntime; +import static com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id.Shutdown; + +import com.oracle.truffle.compiler.TruffleCompilable; +import com.oracle.truffle.compiler.TruffleCompilationTask; +import com.oracle.truffle.compiler.TruffleCompilerListener; +import com.oracle.truffle.compiler.TruffleCompilerRuntime; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal; +import com.oracle.truffle.compiler.hotspot.libgraal.TruffleToLibGraal.Id; + +/** + * Native methods linked to libgraal entry points. + */ +final class TruffleToLibGraalCalls { + + /** + * Invoked first time the isolate is attached. + */ + @TruffleToLibGraal(Id.InitializeIsolate) + static native boolean initializeIsolate(long isolateThreadId, Class runtimeClass); + + /** + * Registers a Truffle runtime. Returns true if this was the first runtime + * registered and false if there were previous calls to + * {@link #registerRuntime(long, Object)}. + */ + @TruffleToLibGraal(RegisterRuntime) + static native boolean registerRuntime(long isolateThreadId, Object truffleRuntime); + + @TruffleToLibGraal(InitializeRuntime) + static native long initializeRuntime(long isolateThreadId, TruffleCompilerRuntime truffleRuntime, Class classLoaderDelegate); + + @TruffleToLibGraal(Id.ListCompilerOptions) + static native byte[] listCompilerOptions(long isolateThreadId); + + @TruffleToLibGraal(Id.CompilerOptionExists) + static native boolean compilerOptionExists(long isolateThreadId, String optionName); + + @TruffleToLibGraal(Id.ValidateCompilerOption) + static native String validateCompilerOption(long isolateThreadId, String optionName, String optionValue); + + @TruffleToLibGraal(GetCompilerConfigurationFactoryName) + static native String getCompilerConfigurationFactoryName(long isolateThreadId, long truffleRuntimeHandle); + + @TruffleToLibGraal(NewCompiler) + static native long newCompiler(long isolateThreadId, long truffleRuntimeHandle); + + @TruffleToLibGraal(InitializeCompiler) + static native void initializeCompiler(long isolateThreadId, long compilerHandle, TruffleCompilable compilable, boolean firstInitialization); + + @TruffleToLibGraal(DoCompile) + static native void doCompile(long isolateThreadId, + long compilerHandle, + TruffleCompilationTask task, + TruffleCompilable compilable, + TruffleCompilerListener listener); + + @TruffleToLibGraal(InstallTruffleCallBoundaryMethod) + static native void installTruffleCallBoundaryMethod(long isolateThreadId, long handle, long methodHandle); + + @TruffleToLibGraal(InstallTruffleReservedOopMethod) + static native void installTruffleReservedOopMethod(long isolateThreadId, long handle, long methodHandle); + + @TruffleToLibGraal(PendingTransferToInterpreterOffset) + static native int pendingTransferToInterpreterOffset(long isolateThreadId, long handle, TruffleCompilable compilable); + + @TruffleToLibGraal(Shutdown) + static native void shutdown(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetNodeCount) + static native int getNodeCount(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetNodeTypes) + static native String[] getNodeTypes(long isolateThreadId, long handle, boolean simpleNames); + + @TruffleToLibGraal(GetSuppliedString) + static native String getSuppliedString(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetTargetCodeSize) + static native int getTargetCodeSize(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetTotalFrameSize) + static native int getTotalFrameSize(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetExceptionHandlersCount) + static native int getExceptionHandlersCount(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetInfopointsCount) + static native int getInfopointsCount(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetInfopoints) + static native String[] getInfopoints(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetMarksCount) + static native int getMarksCount(long isolateThreadId, long handle); + + @TruffleToLibGraal(GetDataPatchesCount) + static native int getDataPatchesCount(long isolateThreadId, long handle); + + @TruffleToLibGraal(PurgePartialEvaluationCaches) + static native void purgePartialEvaluationCaches(long isolateThreadId, long compilerHandle); +} 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 new file mode 100644 index 000000000000..2e85d28134ab --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationEvent.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +/** + * The JFR event describing a Truffle compilation. + */ +public interface CompilationEvent extends RootFunctionEvent { + + void compilationStarted(); + + void failed(boolean permanent, CharSequence reason); + + void succeeded(); + + void setCompiledCodeSize(int size); + + void setCompiledCodeAddress(long addr); + + void setInlinedCalls(int count); + + void setDispatchedCalls(int count); + + void setGraalNodeCount(int count); + + void setPartialEvaluationNodeCount(int count); + + void setPartialEvaluationTime(long time); +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationStatisticsEvent.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationStatisticsEvent.java new file mode 100644 index 000000000000..7e7bb5d3c48e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/CompilationStatisticsEvent.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +public interface CompilationStatisticsEvent extends Event { + + void setCompiledMethods(long compiledMethods); + + void setBailouts(long bailouts); + + void setInvalidations(long invalidations); + + void setCompiledCodeSize(long size); + + void setTotalTime(long time); + + void setPeakTime(long time); +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/DeoptimizationEvent.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/DeoptimizationEvent.java new file mode 100644 index 000000000000..ba291db11c47 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/DeoptimizationEvent.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +public interface DeoptimizationEvent extends RootFunctionEvent { +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/Event.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/Event.java new file mode 100644 index 000000000000..a301b020590e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/Event.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +public interface Event { + + boolean isEnabled(); + + void publish(); +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/EventFactory.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/EventFactory.java new file mode 100644 index 000000000000..0815f347cd2b --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/EventFactory.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +import java.lang.annotation.Annotation; + +public interface EventFactory { + + Class getRequiredAnnotation(); + + boolean isInitialized(); + + void addInitializationListener(Runnable listener); + + CompilationEvent createCompilationEvent(); + + DeoptimizationEvent createDeoptimizationEvent(); + + InvalidationEvent createInvalidationEvent(); + + CompilationStatisticsEvent createCompilationStatisticsEvent(); + + void addPeriodicEvent(Class event, Runnable producer); + + void removePeriodicEvent(Class event, Runnable producer); + + interface Provider { + EventFactory getEventFactory(); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/InvalidationEvent.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/InvalidationEvent.java new file mode 100644 index 000000000000..527af872e1d4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/InvalidationEvent.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +public interface InvalidationEvent extends RootFunctionEvent { + + void setReason(CharSequence invalidationReason); +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/RootFunctionEvent.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/RootFunctionEvent.java new file mode 100644 index 000000000000..7685e41f40ce --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/RootFunctionEvent.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr; + +import com.oracle.truffle.api.RootCallTarget; + +public interface RootFunctionEvent extends Event { + + void setRootFunction(RootCallTarget target); +} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java similarity index 57% rename from compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationEventImpl.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java index bfd079930e5c..3733cedd2974 100644 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/CompilationEventImpl.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationEventImpl.java @@ -1,28 +1,46 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.jfr.impl; +package com.oracle.truffle.runtime.jfr.impl; + +import com.oracle.truffle.runtime.jfr.CompilationEvent; import jdk.jfr.BooleanFlag; import jdk.jfr.Category; @@ -33,7 +51,6 @@ import jdk.jfr.Name; import jdk.jfr.StackTrace; import jdk.jfr.Unsigned; -import org.graalvm.compiler.truffle.jfr.CompilationEvent; @Name("org.graalvm.compiler.truffle.Compilation") @Category("Truffle Compiler") diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationFailureEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationFailureEventImpl.java new file mode 100644 index 000000000000..15e3b8902f25 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationFailureEventImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import jdk.jfr.BooleanFlag; +import jdk.jfr.Category; +import jdk.jfr.Description; +import jdk.jfr.Label; +import jdk.jfr.Name; +import jdk.jfr.StackTrace; + +@Name("org.graalvm.compiler.truffle.CompilationFailure") +@Category("Truffle Compiler") +@Label("Compilation Failure") +@Description("Truffe Compilation Failures") +@StackTrace(false) +class CompilationFailureEventImpl extends RootFunctionEventImpl { + + @Label("Permanent Failure") @Description("Permanent Failure") @BooleanFlag public boolean permanentFailure; + + @Label("Failure Reason") @Description("Failure Reason") public String failureReason; + + CompilationFailureEventImpl(String source, String language, String rootFunction, boolean permanent, CharSequence reason) { + super(source, language, rootFunction); + this.permanentFailure = permanent; + this.failureReason = reason == null ? null : reason.toString(); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationStatisticsEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationStatisticsEventImpl.java new file mode 100644 index 000000000000..db688dd92d1a --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/CompilationStatisticsEventImpl.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import com.oracle.truffle.runtime.jfr.CompilationStatisticsEvent; + +import jdk.jfr.Category; +import jdk.jfr.Description; +import jdk.jfr.DataAmount; +import jdk.jfr.Event; +import jdk.jfr.Label; +import jdk.jfr.Name; +import jdk.jfr.Period; +import jdk.jfr.StackTrace; +import jdk.jfr.Timespan; +import jdk.jfr.Unsigned; + +@Name("org.graalvm.compiler.truffle.CompilerStatistics") +@Category("Truffle Compiler") +@Label("Compiler Statistics") +@Description("Truffe Compiler Statistics") +@Period("1s") +@StackTrace(false) +class CompilationStatisticsEventImpl extends Event implements CompilationStatisticsEvent { + + @Label("Compiled Methods") @Description("Compiled Methods") @Unsigned public long compiledMethods; + + @Label("Bailouts") @Description("Bailouts") @Unsigned public long bailouts; + + @Label("Invalidated Compilations") @Description("Invalidated Compilations") @Unsigned public long invalidations; + + @Label("Compilation Resulting Size") @Description("Compilation Resulting Size") @DataAmount @Unsigned public long compiledCodeSize; + + @Label("Total Time") @Description("Total Time") @Timespan(Timespan.MILLISECONDS) public long totalTime; + + @Label("Peak Time") @Description("Peak Time") @Timespan(Timespan.MILLISECONDS) public long peakTime; + + @Override + public void setCompiledMethods(long compiledMethodsCount) { + this.compiledMethods = compiledMethodsCount; + } + + @Override + public void setBailouts(long bailoutsCount) { + this.bailouts = bailoutsCount; + } + + @Override + public void setInvalidations(long invalidationsCount) { + this.invalidations = invalidationsCount; + } + + @Override + public void setCompiledCodeSize(long codeSize) { + this.compiledCodeSize = codeSize; + } + + @Override + public void setTotalTime(long time) { + this.totalTime = time; + } + + @Override + public void setPeakTime(long time) { + this.peakTime = time; + } + + @Override + public void publish() { + commit(); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/DeoptimizationEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/DeoptimizationEventImpl.java new file mode 100644 index 000000000000..9cafa9a20427 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/DeoptimizationEventImpl.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import com.oracle.truffle.runtime.jfr.DeoptimizationEvent; + +import jdk.jfr.Category; +import jdk.jfr.Description; +import jdk.jfr.Label; +import jdk.jfr.Name; +import jdk.jfr.StackTrace; + +@Name("org.graalvm.compiler.truffle.Deoptimization") +@Category("Truffle Compiler") +@Label("Deoptimization") +@Description("Truffle Call Target Deoptimization") +@StackTrace(false) +class DeoptimizationEventImpl extends RootFunctionEventImpl implements DeoptimizationEvent { + +} diff --git a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/EventFactoryImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/EventFactoryImpl.java similarity index 55% rename from compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/EventFactoryImpl.java rename to truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/EventFactoryImpl.java index 9d751d357827..9ef657d94ba9 100644 --- a/compiler/src/jdk.internal.vm.compiler.truffle.jfr/src/org/graalvm/compiler/truffle/jfr/impl/EventFactoryImpl.java +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/EventFactoryImpl.java @@ -1,42 +1,60 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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. + * The Universal Permissive License (UPL), Version 1.0 * - * 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). + * 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 * - * 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. + * (a) the Software, and * - * 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. + * (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 org.graalvm.compiler.truffle.jfr.impl; +package com.oracle.truffle.runtime.jfr.impl; import java.lang.annotation.Annotation; import java.util.HashMap; import java.util.Map; import java.util.Objects; + +import com.oracle.truffle.runtime.jfr.CompilationEvent; +import com.oracle.truffle.runtime.jfr.CompilationStatisticsEvent; +import com.oracle.truffle.runtime.jfr.DeoptimizationEvent; +import com.oracle.truffle.runtime.jfr.Event; +import com.oracle.truffle.runtime.jfr.EventFactory; +import com.oracle.truffle.runtime.jfr.InvalidationEvent; + import jdk.jfr.FlightRecorder; import jdk.jfr.FlightRecorderListener; import jdk.jfr.Name; -import org.graalvm.compiler.truffle.jfr.Event; -import org.graalvm.compiler.truffle.jfr.EventFactory; -import org.graalvm.compiler.truffle.jfr.CompilationEvent; -import org.graalvm.compiler.truffle.jfr.CompilationStatisticsEvent; -import org.graalvm.compiler.truffle.jfr.DeoptimizationEvent; -import org.graalvm.compiler.truffle.jfr.InvalidationEvent; final class EventFactoryImpl implements EventFactory { diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/InvalidationEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/InvalidationEventImpl.java new file mode 100644 index 000000000000..bbe448fa9015 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/InvalidationEventImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import com.oracle.truffle.runtime.jfr.InvalidationEvent; + +import jdk.jfr.Category; +import jdk.jfr.Description; +import jdk.jfr.Label; +import jdk.jfr.Name; +import jdk.jfr.StackTrace; + +@Name("org.graalvm.compiler.truffle.AssumptionInvalidation") +@Category("Truffle Compiler") +@Label("Assumption Invalidation") +@Description("Truffle Assumption Invalidation") +@StackTrace(true) +class InvalidationEventImpl extends RootFunctionEventImpl implements InvalidationEvent { + + @Label("Reason") @Description("Invalidation Reason") public String reason; + + @Override + public void setReason(CharSequence invalidationReason) { + this.reason = invalidationReason == null ? null : invalidationReason.toString(); + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/ProviderImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/ProviderImpl.java new file mode 100644 index 000000000000..4a34e780bf47 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/ProviderImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import com.oracle.truffle.runtime.jfr.EventFactory; + +import jdk.jfr.FlightRecorder; + +public final class ProviderImpl implements EventFactory.Provider { + @Override + public EventFactory getEventFactory() { + return FlightRecorder.isAvailable() ? new EventFactoryImpl() : null; + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/RootFunctionEventImpl.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/RootFunctionEventImpl.java new file mode 100644 index 000000000000..8e28a05807b4 --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/jfr/impl/RootFunctionEventImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020, 2023, 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.jfr.impl; + +import com.oracle.truffle.api.nodes.LanguageInfo; +import jdk.jfr.Event; +import jdk.jfr.Label; +import jdk.jfr.Description; +import com.oracle.truffle.api.RootCallTarget; +import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.runtime.jfr.RootFunctionEvent; +import com.oracle.truffle.api.nodes.RootNode; + +abstract class RootFunctionEventImpl extends Event implements RootFunctionEvent { + + @Label("Source") @Description("Compiled Source") public String source; + @Label("Language") @Description("Guest Language") public String language; + @Label("Root Function") @Description("Root Function") public String rootFunction; + + RootFunctionEventImpl() { + } + + RootFunctionEventImpl(String source, String language, String rootFunction) { + this.source = source; + this.language = language; + this.rootFunction = rootFunction; + } + + @Override + public void setRootFunction(RootCallTarget target) { + RootNode rootNode = target.getRootNode(); + this.source = targetName(rootNode); + LanguageInfo languageInfo = rootNode.getLanguageInfo(); + this.language = languageInfo != null ? languageInfo.getId() : null; + this.rootFunction = rootNode.getName(); + if (this.rootFunction == null) { + this.rootFunction = rootNode.toString(); + } + } + + @Override + public void publish() { + commit(); + } + + private static String targetName(RootNode rootNode) { + SourceSection sourceSection = rootNode.getSourceSection(); + if (sourceSection != null && sourceSection.getSource() != null) { + return sourceSection.getSource().getName() + ":" + sourceSection.getStartLine(); + } + return null; + } +} diff --git a/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/serviceprovider/TruffleRuntimeServices.java b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/serviceprovider/TruffleRuntimeServices.java new file mode 100644 index 000000000000..a38bd1058e2e --- /dev/null +++ b/truffle/src/com.oracle.truffle.runtime/src/com/oracle/truffle/runtime/serviceprovider/TruffleRuntimeServices.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, 2023, 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.serviceprovider; + +import java.util.ServiceLoader; + +/** + * A subset of the methods defined in {@code org.graalvm.compiler.serviceprovider.GraalServices}. + */ +public final class TruffleRuntimeServices { + + /** + * Gets an {@link Iterable} of the providers available for a given service. + * + * @param service the service whose provider is being requested + */ + public static Iterable load(Class service) { + Class lookupClass = TruffleRuntimeServices.class; + ModuleLayer moduleLayer = lookupClass.getModule().getLayer(); + Iterable services; + if (moduleLayer != null) { + services = ServiceLoader.load(moduleLayer, service); + } else { + services = ServiceLoader.load(service, lookupClass.getClassLoader()); + } + if (!services.iterator().hasNext()) { + services = ServiceLoader.load(service); + } + return services; + } +} diff --git a/vm/mx.vm/mx_vm_gate.py b/vm/mx.vm/mx_vm_gate.py index 4bd8f6862beb..28eea2b2f926 100644 --- a/vm/mx.vm/mx_vm_gate.py +++ b/vm/mx.vm/mx_vm_gate.py @@ -354,7 +354,7 @@ def _test_libgraal_CompilationTimeout_Truffle(extra_vm_arguments): f'-Dpolyglot.log.file={truffle_log_file}', '-Ddebug.graal.CompilationWatchDog=true', # helps debug failure '-Dgraalvm.locatorDisabled=true', - '-Dtruffle.attach.library=' + mx_subst.path_substitutions.substitute('/bin/'), + '-Dtruffle.attach.library=' + mx_subst.path_substitutions.substitute('/bin/'), '-XX:-UseJVMCICompiler', # Stop compilation timeout being applied to JIT '-XX:+UseJVMCINativeLibrary'] # but ensure libgraal is still used by Truffle @@ -437,7 +437,7 @@ def is_truffle_fallback(arg): "-Dpolyglot.engine.BackgroundCompilation=false", "-Dpolyglot.engine.CompilationFailureAction=Throw", "-Dgraalvm.locatorDisabled=true", - '-Dtruffle.attach.library=' + mx_subst.path_substitutions.substitute('/bin/'), + '-Dtruffle.attach.library=' + mx_subst.path_substitutions.substitute('/bin/'), "truffle", "LibGraalCompilerTest"]) def gate_body(args, tasks): diff --git a/wasm/README.md b/wasm/README.md index c3421e38b84c..600168e4bb37 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -91,7 +91,7 @@ $ mx --dy /truffle,/compiler --jdk jvmci unittest \ -Dwasmtest.watToWasmExecutable=$WABT_DIR/wat2wasm \ -Dwasmtest.testFilter="^.*branch.*\$" \ WasmTestSuite -``` +`` This command results in the following output: @@ -99,7 +99,7 @@ This command results in the following output: -------------------------------------------------------------------------------- Running: BranchBlockSuite (4/16 tests - you have enabled filters) -------------------------------------------------------------------------------- -Using runtime: org.graalvm.compiler.truffle.runtime.hotspot.java.HotSpotTruffleRuntime@7b1d7fff +Using runtime: com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntime@7b1d7fff 😍😍😍😍 Finished running: BranchBlockSuite 🍀 4/4 Wasm tests passed. @@ -179,7 +179,7 @@ This will result in the following output: -------------------------------------------------------------------------------- Running: CSuite (1 tests) -------------------------------------------------------------------------------- -Using runtime: org.graalvm.compiler.truffle.runtime.hotspot.java.HotSpotTruffleRuntime@368239c8 +Using runtime: com.oracle.truffle.runtime.hotspot.HotSpotTruffleRuntime@368239c8 😍 Finished running: CSuite 🍀 1/1 Wasm tests passed.