8272736: [JVMCI] Add API for reading and writing JVMCI thread locals
Reviewed-by: kvn, dnsimon
This commit is contained in:
parent
709b5910c3
commit
ad92033fcc
@ -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 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 "callSystemExit", CC "(I)V", FN_PTR(callSystemExit)},
|
||||
{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 "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)},
|
||||
|
@ -183,8 +183,8 @@
|
||||
nonstatic_field(JavaThread, _pending_failed_speculation, jlong) \
|
||||
nonstatic_field(JavaThread, _pending_transfer_to_interpreter, bool) \
|
||||
nonstatic_field(JavaThread, _jvmci_counters, jlong*) \
|
||||
nonstatic_field(JavaThread, _jvmci_reserved0, intptr_t*) \
|
||||
nonstatic_field(JavaThread, _jvmci_reserved1, intptr_t*) \
|
||||
nonstatic_field(JavaThread, _jvmci_reserved0, jlong) \
|
||||
nonstatic_field(JavaThread, _jvmci_reserved1, jlong) \
|
||||
nonstatic_field(JavaThread, _jvmci_reserved_oop0, oop) \
|
||||
nonstatic_field(JavaThread, _should_post_on_exceptions_flag, int) \
|
||||
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \
|
||||
|
@ -1015,8 +1015,8 @@ JavaThread::JavaThread() :
|
||||
_pending_failed_speculation(0),
|
||||
_jvmci{nullptr},
|
||||
_jvmci_counters(nullptr),
|
||||
_jvmci_reserved0(nullptr),
|
||||
_jvmci_reserved1(nullptr),
|
||||
_jvmci_reserved0(0),
|
||||
_jvmci_reserved1(0),
|
||||
_jvmci_reserved_oop0(nullptr),
|
||||
#endif // INCLUDE_JVMCI
|
||||
|
||||
|
@ -958,8 +958,8 @@ class JavaThread: public Thread {
|
||||
jlong* _jvmci_counters;
|
||||
|
||||
// Fast thread locals for use by JVMCI
|
||||
intptr_t* _jvmci_reserved0;
|
||||
intptr_t* _jvmci_reserved1;
|
||||
jlong _jvmci_reserved0;
|
||||
jlong _jvmci_reserved1;
|
||||
oop _jvmci_reserved_oop0;
|
||||
|
||||
public:
|
||||
@ -970,6 +970,30 @@ class JavaThread: public Thread {
|
||||
|
||||
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:
|
||||
#endif // INCLUDE_JVMCI
|
||||
|
||||
|
@ -948,6 +948,26 @@ final class CompilerToVM {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -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) {
|
||||
if (javaClass.isPrimitive()) {
|
||||
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
|
||||
|
Loading…
x
Reference in New Issue
Block a user