Skip to content

Commit ad92033

Browse files
author
Tom Rodriguez
committed
8272736: [JVMCI] Add API for reading and writing JVMCI thread locals
Reviewed-by: kvn, dnsimon
1 parent 709b591 commit ad92033

File tree

6 files changed

+137
-6
lines changed

6 files changed

+137
-6
lines changed

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,49 @@ C2V_VMENTRY(void, notifyCompilerInliningEvent, (JNIEnv* env, jobject, jint compi
26292629
}
26302630
}
26312631

2632+
C2V_VMENTRY(void, setThreadLocalObject, (JNIEnv* env, jobject, jint id, jobject value))
2633+
requireInHotSpot("setThreadLocalObject", JVMCI_CHECK);
2634+
if (id == 0) {
2635+
thread->set_jvmci_reserved_oop0(JNIHandles::resolve(value));
2636+
return;
2637+
}
2638+
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2639+
err_msg("%d is not a valid thread local id", id));
2640+
}
2641+
2642+
C2V_VMENTRY_NULL(jobject, getThreadLocalObject, (JNIEnv* env, jobject, jint id))
2643+
requireInHotSpot("getThreadLocalObject", JVMCI_CHECK_NULL);
2644+
if (id == 0) {
2645+
return JNIHandles::make_local(thread->get_jvmci_reserved_oop0());
2646+
}
2647+
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
2648+
err_msg("%d is not a valid thread local id", id));
2649+
}
2650+
2651+
C2V_VMENTRY(void, setThreadLocalLong, (JNIEnv* env, jobject, jint id, jlong value))
2652+
requireInHotSpot("setThreadLocalLong", JVMCI_CHECK);
2653+
if (id == 0) {
2654+
thread->set_jvmci_reserved0(value);
2655+
} else if (id == 1) {
2656+
thread->set_jvmci_reserved1(value);
2657+
} else {
2658+
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2659+
err_msg("%d is not a valid thread local id", id));
2660+
}
2661+
}
2662+
2663+
C2V_VMENTRY_0(jlong, getThreadLocalLong, (JNIEnv* env, jobject, jint id))
2664+
requireInHotSpot("getThreadLocalLong", JVMCI_CHECK_0);
2665+
if (id == 0) {
2666+
return thread->get_jvmci_reserved0();
2667+
} else if (id == 1) {
2668+
return thread->get_jvmci_reserved1();
2669+
} else {
2670+
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
2671+
err_msg("%d is not a valid thread local id", id));
2672+
}
2673+
}
2674+
26322675
#define CC (char*) /*cast a literal from (const char*)*/
26332676
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
26342677

@@ -2770,6 +2813,10 @@ JNINativeMethod CompilerToVM::methods[] = {
27702813
{CC "addFailedSpeculation", CC "(J[B)Z", FN_PTR(addFailedSpeculation)},
27712814
{CC "callSystemExit", CC "(I)V", FN_PTR(callSystemExit)},
27722815
{CC "ticksNow", CC "()J", FN_PTR(ticksNow)},
2816+
{CC "getThreadLocalObject", CC "(I)" OBJECT, FN_PTR(getThreadLocalObject)},
2817+
{CC "setThreadLocalObject", CC "(I" OBJECT ")V", FN_PTR(setThreadLocalObject)},
2818+
{CC "getThreadLocalLong", CC "(I)J", FN_PTR(getThreadLocalLong)},
2819+
{CC "setThreadLocalLong", CC "(IJ)V", FN_PTR(setThreadLocalLong)},
27732820
{CC "registerCompilerPhase", CC "(" STRING ")I", FN_PTR(registerCompilerPhase)},
27742821
{CC "notifyCompilerPhaseEvent", CC "(JIII)V", FN_PTR(notifyCompilerPhaseEvent)},
27752822
{CC "notifyCompilerInliningEvent", CC "(I" HS_RESOLVED_METHOD HS_RESOLVED_METHOD "ZLjava/lang/String;I)V", FN_PTR(notifyCompilerInliningEvent)},

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@
183183
nonstatic_field(JavaThread, _pending_failed_speculation, jlong) \
184184
nonstatic_field(JavaThread, _pending_transfer_to_interpreter, bool) \
185185
nonstatic_field(JavaThread, _jvmci_counters, jlong*) \
186-
nonstatic_field(JavaThread, _jvmci_reserved0, intptr_t*) \
187-
nonstatic_field(JavaThread, _jvmci_reserved1, intptr_t*) \
186+
nonstatic_field(JavaThread, _jvmci_reserved0, jlong) \
187+
nonstatic_field(JavaThread, _jvmci_reserved1, jlong) \
188188
nonstatic_field(JavaThread, _jvmci_reserved_oop0, oop) \
189189
nonstatic_field(JavaThread, _should_post_on_exceptions_flag, int) \
190190
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \

src/hotspot/share/runtime/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,8 @@ JavaThread::JavaThread() :
10151015
_pending_failed_speculation(0),
10161016
_jvmci{nullptr},
10171017
_jvmci_counters(nullptr),
1018-
_jvmci_reserved0(nullptr),
1019-
_jvmci_reserved1(nullptr),
1018+
_jvmci_reserved0(0),
1019+
_jvmci_reserved1(0),
10201020
_jvmci_reserved_oop0(nullptr),
10211021
#endif // INCLUDE_JVMCI
10221022

src/hotspot/share/runtime/thread.hpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,8 @@ class JavaThread: public Thread {
958958
jlong* _jvmci_counters;
959959

960960
// Fast thread locals for use by JVMCI
961-
intptr_t* _jvmci_reserved0;
962-
intptr_t* _jvmci_reserved1;
961+
jlong _jvmci_reserved0;
962+
jlong _jvmci_reserved1;
963963
oop _jvmci_reserved_oop0;
964964

965965
public:
@@ -970,6 +970,30 @@ class JavaThread: public Thread {
970970

971971
static bool resize_all_jvmci_counters(int new_size);
972972

973+
void set_jvmci_reserved_oop0(oop value) {
974+
_jvmci_reserved_oop0 = value;
975+
}
976+
977+
oop get_jvmci_reserved_oop0() {
978+
return _jvmci_reserved_oop0;
979+
}
980+
981+
void set_jvmci_reserved0(jlong value) {
982+
_jvmci_reserved0 = value;
983+
}
984+
985+
jlong get_jvmci_reserved0() {
986+
return _jvmci_reserved0;
987+
}
988+
989+
void set_jvmci_reserved1(jlong value) {
990+
_jvmci_reserved1 = value;
991+
}
992+
993+
jlong get_jvmci_reserved1() {
994+
return _jvmci_reserved1;
995+
}
996+
973997
private:
974998
#endif // INCLUDE_JVMCI
975999

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,26 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean com
948948
*/
949949
native long ticksNow();
950950

951+
/**
952+
* @see HotSpotJVMCIRuntime#setThreadLocalObject(int, Object)
953+
*/
954+
native void setThreadLocalObject(int id, Object value);
955+
956+
/**
957+
* @see HotSpotJVMCIRuntime#getThreadLocalObject(int)
958+
*/
959+
native Object getThreadLocalObject(int id);
960+
961+
/**
962+
* @see HotSpotJVMCIRuntime#setThreadLocalLong(int, long)
963+
*/
964+
native void setThreadLocalLong(int id, long value);
965+
966+
/**
967+
* @see HotSpotJVMCIRuntime#getThreadLocalLong(int)
968+
*/
969+
native long getThreadLocalLong(int id);
970+
951971
/**
952972
* Adds phases in HotSpot JFR.
953973
*

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,46 @@ private HotSpotJVMCIRuntime() {
576576
}
577577
}
578578

579+
/**
580+
* Sets the current thread's {@code JavaThread::_jvmci_reserved_oop<id>} field to {@code value}.
581+
*
582+
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved_oop<id>} field
583+
* does not exist
584+
*/
585+
public void setThreadLocalObject(int id, Object value) {
586+
compilerToVm.setThreadLocalObject(id, value);
587+
}
588+
589+
/**
590+
* Get the value of the current thread's {@code JavaThread::_jvmci_reserved_oop<id>} field.
591+
*
592+
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved_oop<id>} field
593+
* does not exist
594+
*/
595+
public Object getThreadLocalObject(int id) {
596+
return compilerToVm.getThreadLocalObject(id);
597+
}
598+
599+
/**
600+
* Sets the current thread's {@code JavaThread::_jvmci_reserved<id>} field to {@code value}.
601+
*
602+
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved<id>} field does
603+
* not exist
604+
*/
605+
public void setThreadLocalLong(int id, long value) {
606+
compilerToVm.setThreadLocalLong(id, value);
607+
}
608+
609+
/**
610+
* Get the value of the current thread's {@code JavaThread::_jvmci_reserved<id>} field.
611+
*
612+
* @throws IllegalArgumentException if the {@code JavaThread::_jvmci_reserved<id>} field does
613+
* not exist
614+
*/
615+
public long getThreadLocalLong(int id) {
616+
return compilerToVm.getThreadLocalLong(id);
617+
}
618+
579619
HotSpotResolvedJavaType createClass(Class<?> javaClass) {
580620
if (javaClass.isPrimitive()) {
581621
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));

0 commit comments

Comments
 (0)