Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
/ jdk20 Public archive

Commit

Permalink
8272736: [JVMCI] Add API for reading and writing JVMCI thread locals
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, dnsimon
  • Loading branch information
Tom Rodriguez committed Aug 23, 2021
1 parent 709b591 commit ad92033
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 6 deletions.
47 changes: 47 additions & 0 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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)},
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 26 additions & 2 deletions src/hotspot/share/runtime/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,26 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean com
*/
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,46 @@ private HotSpotJVMCIRuntime() {
}
}

/**
* 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));
Expand Down

0 comments on commit ad92033

Please sign in to comment.