Skip to content

Commit 2165a05

Browse files
author
Yudi Zheng
committed
8334399: [JVMCI] Implement JVMCICompiler::is_intrinsic_supported
Reviewed-by: dnsimon
1 parent 48621ae commit 2165a05

File tree

11 files changed

+100
-9
lines changed

11 files changed

+100
-9
lines changed

src/hotspot/share/jvmci/jvmciCompiler.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -200,6 +200,15 @@ void JVMCICompiler::print_timers() {
200200
_hosted_code_installs.print_on(tty, " Install Code: ");
201201
}
202202

203+
bool JVMCICompiler::is_intrinsic_supported(const methodHandle& method) {
204+
vmIntrinsics::ID id = method->intrinsic_id();
205+
assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
206+
JavaThread* thread = JavaThread::current();
207+
JVMCIEnv jvmciEnv(thread, __FILE__, __LINE__);
208+
JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread, false);
209+
return runtime->is_intrinsic_supported(&jvmciEnv, (jint) id);
210+
}
211+
203212
void JVMCICompiler::CodeInstallStats::print_on(outputStream* st, const char* prefix) const {
204213
double time = _timer.seconds();
205214
st->print_cr("%s%7.3f s (installs: %d, CodeBlob total size: %d, CodeBlob code size: %d)",

src/hotspot/share/jvmci/jvmciCompiler.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -136,6 +136,8 @@ class JVMCICompiler : public AbstractCompiler {
136136
// Print compilation timers and statistics
137137
virtual void print_timers();
138138

139+
virtual bool is_intrinsic_supported(const methodHandle& method);
140+
139141
// Gets the number of methods that have been successfully compiled by
140142
// a call to JVMCICompiler::compile_method().
141143
int methods_compiled() { return _methods_compiled; }

src/hotspot/share/jvmci/jvmciEnv.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -967,6 +967,31 @@ jboolean JVMCIEnv::call_HotSpotJVMCIRuntime_isGCSupported (JVMCIObject runtime,
967967
}
968968
}
969969

970+
jboolean JVMCIEnv::call_HotSpotJVMCIRuntime_isIntrinsicSupported (JVMCIObject runtime, jint intrinsicIdentifier) {
971+
JavaThread* THREAD = JavaThread::current(); // For exception macros.
972+
if (is_hotspot()) {
973+
JavaCallArguments jargs;
974+
jargs.push_oop(Handle(THREAD, HotSpotJVMCI::resolve(runtime)));
975+
jargs.push_int(intrinsicIdentifier);
976+
JavaValue result(T_BOOLEAN);
977+
JavaCalls::call_special(&result,
978+
HotSpotJVMCI::HotSpotJVMCIRuntime::klass(),
979+
vmSymbols::isIntrinsicSupported_name(),
980+
vmSymbols::int_bool_signature(), &jargs, CHECK_0);
981+
return result.get_jboolean();
982+
} else {
983+
JNIAccessMark jni(this, THREAD);
984+
jboolean result = jni()->CallNonvirtualBooleanMethod(runtime.as_jobject(),
985+
JNIJVMCI::HotSpotJVMCIRuntime::clazz(),
986+
JNIJVMCI::HotSpotJVMCIRuntime::isIntrinsicSupported_method(),
987+
intrinsicIdentifier);
988+
if (jni()->ExceptionCheck()) {
989+
return false;
990+
}
991+
return result;
992+
}
993+
}
994+
970995
JVMCIObject JVMCIEnv::call_HotSpotJVMCIRuntime_compileMethod (JVMCIObject runtime, JVMCIObject method, int entry_bci,
971996
jlong compile_state, int id) {
972997
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current()); // For exception macros.

src/hotspot/share/jvmci/jvmciEnv.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -359,6 +359,8 @@ class JVMCIEnv : public ResourceObj {
359359

360360
jboolean call_HotSpotJVMCIRuntime_isGCSupported(JVMCIObject runtime, jint gcIdentifier);
361361

362+
jboolean call_HotSpotJVMCIRuntime_isIntrinsicSupported(JVMCIObject runtime, jint intrinsicIdentifier);
363+
362364
void call_HotSpotJVMCIRuntime_postTranslation(JVMCIObject object, JVMCI_TRAPS);
363365

364366
// Converts the JavaKind.typeChar value in `ch` to a BasicType

src/hotspot/share/jvmci/jvmciJavaClasses.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -202,6 +202,7 @@
202202
objectarray_field(HotSpotJVMCIRuntime, excludeFromJVMCICompilation, "[Ljava/lang/Module;") \
203203
jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, compileMethod, compileMethod_signature) \
204204
jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, isGCSupported, int_bool_signature) \
205+
jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, isIntrinsicSupported, int_bool_signature) \
205206
jvmci_method(CallNonvirtualVoidMethod, GetMethodID, call_special, void, HotSpotJVMCIRuntime, bootstrapFinished, void_method_signature) \
206207
jvmci_method(CallNonvirtualVoidMethod, GetMethodID, call_special, void, HotSpotJVMCIRuntime, shutdown, void_method_signature) \
207208
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, HotSpotJVMCIRuntime, runtime, runtime_signature) \

src/hotspot/share/jvmci/jvmciRuntime.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,16 @@ bool JVMCIRuntime::is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name)
20502050
return JVMCIENV->call_HotSpotJVMCIRuntime_isGCSupported(receiver, (int) name);
20512051
}
20522052

2053+
bool JVMCIRuntime::is_intrinsic_supported(JVMCIEnv* JVMCIENV, jint id) {
2054+
JVMCI_EXCEPTION_CONTEXT
2055+
2056+
JVMCIObject receiver = get_HotSpotJVMCIRuntime(JVMCIENV);
2057+
if (JVMCIENV->has_pending_exception()) {
2058+
fatal_exception(JVMCIENV, "Exception during HotSpotJVMCIRuntime initialization");
2059+
}
2060+
return JVMCIENV->call_HotSpotJVMCIRuntime_isIntrinsicSupported(receiver, id);
2061+
}
2062+
20532063
// ------------------------------------------------------------------
20542064
JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
20552065
const methodHandle& method,

src/hotspot/share/jvmci/jvmciRuntime.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
431431
// Determines if the GC identified by `name` is supported by the JVMCI compiler.
432432
bool is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name);
433433

434+
// Determines if the intrinsic identified by `id` is supported by the JVMCI compiler.
435+
bool is_intrinsic_supported(JVMCIEnv* JVMCIENV, jint id);
436+
434437
// Register the result of a compilation.
435438
JVMCI::CodeInstallResult register_method(JVMCIEnv* JVMCIENV,
436439
const methodHandle& target,

src/hotspot/share/jvmci/vmSymbols_jvmci.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -81,6 +81,7 @@
8181
template(compileMethod_name, "compileMethod") \
8282
template(compileMethod_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;IJI)Ljdk/vm/ci/hotspot/HotSpotCompilationRequestResult;") \
8383
template(isGCSupported_name, "isGCSupported") \
84+
template(isIntrinsicSupported_name, "isIntrinsicSupported") \
8485
template(fromMetaspace_name, "fromMetaspace") \
8586
template(method_fromMetaspace_signature, "(JLjdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;)Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;") \
8687
template(constantPool_fromMetaspace_signature, "(J)Ljdk/vm/ci/hotspot/HotSpotConstantPool;") \

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -987,6 +987,12 @@ private boolean isGCSupported(int gcIdentifier) {
987987
return getCompiler().isGCSupported(gcIdentifier);
988988
}
989989

990+
@SuppressWarnings("try")
991+
@VMEntryPoint
992+
private boolean isIntrinsicSupported(int intrinsicIdentifier) {
993+
return getCompiler().isIntrinsicSupported(intrinsicIdentifier);
994+
}
995+
990996
/**
991997
* Guard to ensure shut down actions are performed by at most one thread.
992998
*/

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -82,6 +82,27 @@ public List<VMIntrinsicMethod> getIntrinsics() {
8282
return Collections.unmodifiableList(vmIntrinsics);
8383
}
8484

85+
/**
86+
* Gets the VM intrinsic description by its ID.
87+
*/
88+
public VMIntrinsicMethod getIntrinsic(int intrinsicID) {
89+
if (intrinsicID >= 1 && intrinsicID <= vmIntrinsics.size()) {
90+
// valid intrinsicID starts from 1
91+
VMIntrinsicMethod intrinsic = vmIntrinsics.get(intrinsicID - 1);
92+
// We speculate that vmIntrinsics are sorted by ID
93+
if (intrinsic.id == intrinsicID) {
94+
return intrinsic;
95+
}
96+
}
97+
// Assumption failed, fall back to iteration
98+
for (VMIntrinsicMethod intrinsic : vmIntrinsics) {
99+
if (intrinsic.id == intrinsicID) {
100+
return intrinsic;
101+
}
102+
}
103+
return null;
104+
}
105+
85106
final HashMap<String, VMField> vmFields;
86107
final HashMap<String, Long> vmConstants;
87108
final HashMap<String, Long> vmAddresses;

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCICompiler.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,4 +44,15 @@ public interface JVMCICompiler {
4444
default boolean isGCSupported(int gcIdentifier) {
4545
return true;
4646
}
47+
48+
/**
49+
* Determines if this compiler supports the {@code intrinsicIdentifier} intrinsic. The default
50+
* implementation of this method returns false as that is the effective answer given by a
51+
* {@link JVMCICompiler} before this method was added.
52+
*
53+
* @param intrinsicIdentifier intrinsic identifier defined in vmIntrinsics.hpp.
54+
*/
55+
default boolean isIntrinsicSupported(int intrinsicIdentifier) {
56+
return false;
57+
}
4758
}

0 commit comments

Comments
 (0)