mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 17:44:40 +02:00
8272736: [JVMCI] Add API for reading and writing JVMCI thread locals
Reviewed-by: kvn, dnsimon
This commit is contained in:
parent
709b5910c3
commit
ad92033fcc
6 changed files with 137 additions and 6 deletions
|
@ -2629,6 +2629,49 @@ C2V_VMENTRY(void, notifyCompilerInliningEvent, (JNIEnv* env, jobject, jint compi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
C2V_VMENTRY(void, setThreadLocalObject, (JNIEnv* env, jobject, jint id, jobject value))
|
||||||
|
requireInHotSpot("setThreadLocalObject", JVMCI_CHECK);
|
||||||
|
if (id == 0) {
|
||||||
|
thread->set_jvmci_reserved_oop0(JNIHandles::resolve(value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||||
|
err_msg("%d is not a valid thread local id", id));
|
||||||
|
}
|
||||||
|
|
||||||
|
C2V_VMENTRY_NULL(jobject, getThreadLocalObject, (JNIEnv* env, jobject, jint id))
|
||||||
|
requireInHotSpot("getThreadLocalObject", JVMCI_CHECK_NULL);
|
||||||
|
if (id == 0) {
|
||||||
|
return JNIHandles::make_local(thread->get_jvmci_reserved_oop0());
|
||||||
|
}
|
||||||
|
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
|
||||||
|
err_msg("%d is not a valid thread local id", id));
|
||||||
|
}
|
||||||
|
|
||||||
|
C2V_VMENTRY(void, setThreadLocalLong, (JNIEnv* env, jobject, jint id, jlong value))
|
||||||
|
requireInHotSpot("setThreadLocalLong", JVMCI_CHECK);
|
||||||
|
if (id == 0) {
|
||||||
|
thread->set_jvmci_reserved0(value);
|
||||||
|
} else if (id == 1) {
|
||||||
|
thread->set_jvmci_reserved1(value);
|
||||||
|
} else {
|
||||||
|
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||||
|
err_msg("%d is not a valid thread local id", id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
C2V_VMENTRY_0(jlong, getThreadLocalLong, (JNIEnv* env, jobject, jint id))
|
||||||
|
requireInHotSpot("getThreadLocalLong", JVMCI_CHECK_0);
|
||||||
|
if (id == 0) {
|
||||||
|
return thread->get_jvmci_reserved0();
|
||||||
|
} else if (id == 1) {
|
||||||
|
return thread->get_jvmci_reserved1();
|
||||||
|
} else {
|
||||||
|
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
|
||||||
|
err_msg("%d is not a valid thread local id", id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define CC (char*) /*cast a literal from (const char*)*/
|
#define CC (char*) /*cast a literal from (const char*)*/
|
||||||
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
|
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
|
||||||
|
|
||||||
|
@ -2770,6 +2813,10 @@ JNINativeMethod CompilerToVM::methods[] = {
|
||||||
{CC "addFailedSpeculation", CC "(J[B)Z", FN_PTR(addFailedSpeculation)},
|
{CC "addFailedSpeculation", CC "(J[B)Z", FN_PTR(addFailedSpeculation)},
|
||||||
{CC "callSystemExit", CC "(I)V", FN_PTR(callSystemExit)},
|
{CC "callSystemExit", CC "(I)V", FN_PTR(callSystemExit)},
|
||||||
{CC "ticksNow", CC "()J", FN_PTR(ticksNow)},
|
{CC "ticksNow", CC "()J", FN_PTR(ticksNow)},
|
||||||
|
{CC "getThreadLocalObject", CC "(I)" OBJECT, FN_PTR(getThreadLocalObject)},
|
||||||
|
{CC "setThreadLocalObject", CC "(I" OBJECT ")V", FN_PTR(setThreadLocalObject)},
|
||||||
|
{CC "getThreadLocalLong", CC "(I)J", FN_PTR(getThreadLocalLong)},
|
||||||
|
{CC "setThreadLocalLong", CC "(IJ)V", FN_PTR(setThreadLocalLong)},
|
||||||
{CC "registerCompilerPhase", CC "(" STRING ")I", FN_PTR(registerCompilerPhase)},
|
{CC "registerCompilerPhase", CC "(" STRING ")I", FN_PTR(registerCompilerPhase)},
|
||||||
{CC "notifyCompilerPhaseEvent", CC "(JIII)V", FN_PTR(notifyCompilerPhaseEvent)},
|
{CC "notifyCompilerPhaseEvent", CC "(JIII)V", FN_PTR(notifyCompilerPhaseEvent)},
|
||||||
{CC "notifyCompilerInliningEvent", CC "(I" HS_RESOLVED_METHOD HS_RESOLVED_METHOD "ZLjava/lang/String;I)V", FN_PTR(notifyCompilerInliningEvent)},
|
{CC "notifyCompilerInliningEvent", CC "(I" HS_RESOLVED_METHOD HS_RESOLVED_METHOD "ZLjava/lang/String;I)V", FN_PTR(notifyCompilerInliningEvent)},
|
||||||
|
|
|
@ -183,8 +183,8 @@
|
||||||
nonstatic_field(JavaThread, _pending_failed_speculation, jlong) \
|
nonstatic_field(JavaThread, _pending_failed_speculation, jlong) \
|
||||||
nonstatic_field(JavaThread, _pending_transfer_to_interpreter, bool) \
|
nonstatic_field(JavaThread, _pending_transfer_to_interpreter, bool) \
|
||||||
nonstatic_field(JavaThread, _jvmci_counters, jlong*) \
|
nonstatic_field(JavaThread, _jvmci_counters, jlong*) \
|
||||||
nonstatic_field(JavaThread, _jvmci_reserved0, intptr_t*) \
|
nonstatic_field(JavaThread, _jvmci_reserved0, jlong) \
|
||||||
nonstatic_field(JavaThread, _jvmci_reserved1, intptr_t*) \
|
nonstatic_field(JavaThread, _jvmci_reserved1, jlong) \
|
||||||
nonstatic_field(JavaThread, _jvmci_reserved_oop0, oop) \
|
nonstatic_field(JavaThread, _jvmci_reserved_oop0, oop) \
|
||||||
nonstatic_field(JavaThread, _should_post_on_exceptions_flag, int) \
|
nonstatic_field(JavaThread, _should_post_on_exceptions_flag, int) \
|
||||||
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \
|
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \
|
||||||
|
|
|
@ -1015,8 +1015,8 @@ JavaThread::JavaThread() :
|
||||||
_pending_failed_speculation(0),
|
_pending_failed_speculation(0),
|
||||||
_jvmci{nullptr},
|
_jvmci{nullptr},
|
||||||
_jvmci_counters(nullptr),
|
_jvmci_counters(nullptr),
|
||||||
_jvmci_reserved0(nullptr),
|
_jvmci_reserved0(0),
|
||||||
_jvmci_reserved1(nullptr),
|
_jvmci_reserved1(0),
|
||||||
_jvmci_reserved_oop0(nullptr),
|
_jvmci_reserved_oop0(nullptr),
|
||||||
#endif // INCLUDE_JVMCI
|
#endif // INCLUDE_JVMCI
|
||||||
|
|
||||||
|
|
|
@ -958,8 +958,8 @@ class JavaThread: public Thread {
|
||||||
jlong* _jvmci_counters;
|
jlong* _jvmci_counters;
|
||||||
|
|
||||||
// Fast thread locals for use by JVMCI
|
// Fast thread locals for use by JVMCI
|
||||||
intptr_t* _jvmci_reserved0;
|
jlong _jvmci_reserved0;
|
||||||
intptr_t* _jvmci_reserved1;
|
jlong _jvmci_reserved1;
|
||||||
oop _jvmci_reserved_oop0;
|
oop _jvmci_reserved_oop0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -970,6 +970,30 @@ class JavaThread: public Thread {
|
||||||
|
|
||||||
static bool resize_all_jvmci_counters(int new_size);
|
static bool resize_all_jvmci_counters(int new_size);
|
||||||
|
|
||||||
|
void set_jvmci_reserved_oop0(oop value) {
|
||||||
|
_jvmci_reserved_oop0 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
oop get_jvmci_reserved_oop0() {
|
||||||
|
return _jvmci_reserved_oop0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_jvmci_reserved0(jlong value) {
|
||||||
|
_jvmci_reserved0 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
jlong get_jvmci_reserved0() {
|
||||||
|
return _jvmci_reserved0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_jvmci_reserved1(jlong value) {
|
||||||
|
_jvmci_reserved1 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
jlong get_jvmci_reserved1() {
|
||||||
|
return _jvmci_reserved1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#endif // INCLUDE_JVMCI
|
#endif // INCLUDE_JVMCI
|
||||||
|
|
||||||
|
|
|
@ -948,6 +948,26 @@ final class CompilerToVM {
|
||||||
*/
|
*/
|
||||||
native long ticksNow();
|
native long ticksNow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HotSpotJVMCIRuntime#setThreadLocalObject(int, Object)
|
||||||
|
*/
|
||||||
|
native void setThreadLocalObject(int id, Object value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HotSpotJVMCIRuntime#getThreadLocalObject(int)
|
||||||
|
*/
|
||||||
|
native Object getThreadLocalObject(int id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HotSpotJVMCIRuntime#setThreadLocalLong(int, long)
|
||||||
|
*/
|
||||||
|
native void setThreadLocalLong(int id, long value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HotSpotJVMCIRuntime#getThreadLocalLong(int)
|
||||||
|
*/
|
||||||
|
native long getThreadLocalLong(int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds phases in HotSpot JFR.
|
* Adds phases in HotSpot JFR.
|
||||||
*
|
*
|
||||||
|
|
|
@ -576,6 +576,46 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current thread's {@code JavaThread::_jvmci_reserved_oop<id>} field to {@code value}.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved_oop<id>} field
|
||||||
|
* does not exist
|
||||||
|
*/
|
||||||
|
public void setThreadLocalObject(int id, Object value) {
|
||||||
|
compilerToVm.setThreadLocalObject(id, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the current thread's {@code JavaThread::_jvmci_reserved_oop<id>} field.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved_oop<id>} field
|
||||||
|
* does not exist
|
||||||
|
*/
|
||||||
|
public Object getThreadLocalObject(int id) {
|
||||||
|
return compilerToVm.getThreadLocalObject(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current thread's {@code JavaThread::_jvmci_reserved<id>} field to {@code value}.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved<id>} field does
|
||||||
|
* not exist
|
||||||
|
*/
|
||||||
|
public void setThreadLocalLong(int id, long value) {
|
||||||
|
compilerToVm.setThreadLocalLong(id, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the current thread's {@code JavaThread::_jvmci_reserved<id>} field.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved<id>} field does
|
||||||
|
* not exist
|
||||||
|
*/
|
||||||
|
public long getThreadLocalLong(int id) {
|
||||||
|
return compilerToVm.getThreadLocalLong(id);
|
||||||
|
}
|
||||||
|
|
||||||
HotSpotResolvedJavaType createClass(Class<?> javaClass) {
|
HotSpotResolvedJavaType createClass(Class<?> javaClass) {
|
||||||
if (javaClass.isPrimitive()) {
|
if (javaClass.isPrimitive()) {
|
||||||
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
|
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue