8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package jdk.internal.vm.compiler.libgraal;
26
27 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
28 import jdk.vm.ci.services.Services;
29
30 /**
31 * JDK13+ version of {@code LibGraal}.
32 */
33 public class LibGraal {
34
35 public static boolean isAvailable() {
36 return inLibGraal() || isolate != 0L;
37 }
38
39 public static boolean inLibGraal() {
40 return Services.IS_IN_NATIVE_IMAGE;
41 }
42
43 public static void registerNativeMethods(HotSpotJVMCIRuntime runtime, Class<?> clazz) {
44 if (clazz.isPrimitive()) {
45 throw new IllegalArgumentException();
46 }
47 if (inLibGraal() || !isAvailable()) {
48 throw new IllegalStateException();
49 }
50 runtime.registerNativeMethods(clazz);
51 }
52
53 public static long translate(HotSpotJVMCIRuntime runtime, Object obj) {
54 if (!isAvailable()) {
55 throw new IllegalStateException();
56 }
57 if (!inLibGraal() && LibGraalScope.currentScope.get() == null) {
58 throw new IllegalStateException("Not within a " + LibGraalScope.class.getName());
74 try {
75 // Initialize JVMCI to ensure JVMCI opens its packages to
76 // Graal otherwise the call to HotSpotJVMCIRuntime.runtime()
77 // below will fail on JDK13+.
78 Services.initializeJVMCI();
79
80 HotSpotJVMCIRuntime runtime = HotSpotJVMCIRuntime.runtime();
81 long[] nativeInterface = runtime.registerNativeMethods(LibGraal.class);
82 return nativeInterface[1];
83 } catch (UnsupportedOperationException e) {
84 return 0L;
85 }
86 }
87
88 static final long isolate = Services.IS_BUILDING_NATIVE_IMAGE ? 0L : initializeLibgraal();
89
90 static boolean isCurrentThreadAttached(HotSpotJVMCIRuntime runtime) {
91 return runtime.isCurrentThreadAttached();
92 }
93
94 static boolean attachCurrentThread(HotSpotJVMCIRuntime runtime) {
95 return runtime.attachCurrentThread(false);
96 }
97
98 static void detachCurrentThread(HotSpotJVMCIRuntime runtime) {
99 runtime.detachCurrentThread();
100 }
101
102 static native long getCurrentIsolateThread(long iso);
103 }
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package jdk.internal.vm.compiler.libgraal;
26
27 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
28 import jdk.vm.ci.hotspot.HotSpotSpeculationLog;
29 import jdk.vm.ci.services.Services;
30
31 /**
32 * JDK13+ version of {@code LibGraal}.
33 */
34 public class LibGraal {
35
36 public static boolean isAvailable() {
37 return inLibGraal() || isolate != 0L;
38 }
39
40 public static boolean isSupported() {
41 return true;
42 }
43
44 public static boolean inLibGraal() {
45 return Services.IS_IN_NATIVE_IMAGE;
46 }
47
48 public static void registerNativeMethods(HotSpotJVMCIRuntime runtime, Class<?> clazz) {
49 if (clazz.isPrimitive()) {
50 throw new IllegalArgumentException();
51 }
52 if (inLibGraal() || !isAvailable()) {
53 throw new IllegalStateException();
54 }
55 runtime.registerNativeMethods(clazz);
56 }
57
58 public static long translate(HotSpotJVMCIRuntime runtime, Object obj) {
59 if (!isAvailable()) {
60 throw new IllegalStateException();
61 }
62 if (!inLibGraal() && LibGraalScope.currentScope.get() == null) {
63 throw new IllegalStateException("Not within a " + LibGraalScope.class.getName());
79 try {
80 // Initialize JVMCI to ensure JVMCI opens its packages to
81 // Graal otherwise the call to HotSpotJVMCIRuntime.runtime()
82 // below will fail on JDK13+.
83 Services.initializeJVMCI();
84
85 HotSpotJVMCIRuntime runtime = HotSpotJVMCIRuntime.runtime();
86 long[] nativeInterface = runtime.registerNativeMethods(LibGraal.class);
87 return nativeInterface[1];
88 } catch (UnsupportedOperationException e) {
89 return 0L;
90 }
91 }
92
93 static final long isolate = Services.IS_BUILDING_NATIVE_IMAGE ? 0L : initializeLibgraal();
94
95 static boolean isCurrentThreadAttached(HotSpotJVMCIRuntime runtime) {
96 return runtime.isCurrentThreadAttached();
97 }
98
99 public static boolean attachCurrentThread(HotSpotJVMCIRuntime runtime, boolean isDaemon) {
100 return runtime.attachCurrentThread(isDaemon);
101 }
102
103 public static void detachCurrentThread(HotSpotJVMCIRuntime runtime) {
104 runtime.detachCurrentThread();
105 }
106
107 static native long getCurrentIsolateThread(long iso);
108
109 public static long getFailedSpeculationsAddress(HotSpotSpeculationLog log) {
110 return log.getFailedSpeculationsAddress();
111 }
112 }
|