Skip to content

Commit 34221f4

Browse files
committed
ThreadID
1 parent 44205cd commit 34221f4

32 files changed

+162
-109
lines changed

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class java_lang_Thread : AllStatic {
410410
// Stack size hint
411411
static jlong stackSize(oop java_thread);
412412
// Thread ID
413-
static int64_t thread_id(oop java_thread);
413+
static ThreadID thread_id(oop java_thread);
414414
static ByteSize thread_id_offset();
415415
// Continuation
416416
static inline oop continuation(oop java_thread);

src/hotspot/share/classfile/javaClasses.inline.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "oops/oop.inline.hpp"
3535
#include "oops/oopsHierarchy.hpp"
3636
#include "oops/typeArrayOop.inline.hpp"
37+
#include "runtime/threadIdentifier.hpp"
3738

3839
void java_lang_String::set_coder(oop string, jbyte coder) {
3940
string->byte_field_put(_coder_offset, coder);
@@ -211,8 +212,8 @@ inline oop java_lang_Thread::continuation(oop java_thread) {
211212
return java_thread->obj_field(_continuation_offset);
212213
}
213214

214-
inline int64_t java_lang_Thread::thread_id(oop java_thread) {
215-
return java_thread->long_field(_tid_offset);
215+
inline ThreadID java_lang_Thread::thread_id(oop java_thread) {
216+
return static_cast<ThreadID>(java_thread->long_field(_tid_offset));
216217
}
217218

218219
inline oop java_lang_VirtualThread::vthread_scope() {

src/hotspot/share/include/jvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ JVM_FindScopedValueBindings(JNIEnv *env, jclass threadClass);
323323
JNIEXPORT jlong JNICALL
324324
JVM_GetNextThreadIdOffset(JNIEnv *env, jclass threadClass);
325325

326+
JNIEXPORT jlong JNICALL
327+
JVM_GetPrimordialThreadId(JNIEnv *env, jclass threadClass);
328+
326329
/*
327330
* jdk.internal.vm.Continuation
328331
*/

src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ traceid JfrThreadId::id(const Thread* t, oop vthread) {
9090
return os_id(t);
9191
}
9292
if (vthread != nullptr) {
93-
return java_lang_Thread::thread_id(vthread);
93+
return static_cast<traceid>(java_lang_Thread::thread_id(vthread));
9494
}
9595
const oop thread_obj = JavaThread::cast(t)->threadObj();
96-
return thread_obj != nullptr ? java_lang_Thread::thread_id(thread_obj) : 0;
96+
return thread_obj != nullptr ? static_cast<traceid>(java_lang_Thread::thread_id(thread_obj)) : 0;
9797
}
9898

9999
traceid JfrThreadId::os_id(const Thread* t) {

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
nonstatic_field(JavaThread, _vthread, OopHandle) \
226226
nonstatic_field(JavaThread, _scopedValueCache, OopHandle) \
227227
nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \
228-
nonstatic_field(JavaThread, _lock_id, int64_t) \
228+
nonstatic_field(JavaThread, _lock_id, ThreadID) \
229229
nonstatic_field(JavaThread, _vm_result, oop) \
230230
nonstatic_field(JavaThread, _stack_overflow_state._stack_overflow_limit, address) \
231231
volatile_nonstatic_field(JavaThread, _exception_oop, oop) \
@@ -330,7 +330,7 @@
330330
volatile_nonstatic_field(ObjectMonitor, _recursions, intptr_t) \
331331
volatile_nonstatic_field(ObjectMonitor, _cxq, ObjectWaiter*) \
332332
volatile_nonstatic_field(ObjectMonitor, _EntryList, ObjectWaiter*) \
333-
volatile_nonstatic_field(ObjectMonitor, _succ, int64_t) \
333+
volatile_nonstatic_field(ObjectMonitor, _succ, ThreadID) \
334334
volatile_nonstatic_field(ObjectMonitor, _stack_locker, BasicLock*) \
335335
\
336336
volatile_nonstatic_field(oopDesc, _mark, markWord) \

src/hotspot/share/prims/jvm.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3097,13 +3097,17 @@ JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
30973097
JVM_END
30983098

30993099
JVM_ENTRY_NO_ENV(void, JVM_SetCurrentLockId(JNIEnv* env, jclass threadClass, jlong tid))
3100-
thread->set_lock_id(tid);
3100+
thread->set_lock_id(static_cast<ThreadID>(tid));
31013101
JVM_END
31023102

31033103
JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
31043104
return static_cast<jlong>(ThreadIdentifier::unsafe_offset());
31053105
JVM_END
31063106

3107+
JVM_ENTRY(jlong, JVM_GetPrimordialThreadId(JNIEnv* env, jclass threadClass))
3108+
return static_cast<jlong>(ThreadID::PRIMORDIAL_TID);
3109+
JVM_END
3110+
31073111
JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
31083112
ThreadsListHandle tlh(thread);
31093113
JavaThread* receiver = nullptr;

src/hotspot/share/prims/jvmtiTagMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ class StackRefCollector {
22712271
bool StackRefCollector::set_thread(oop o) {
22722272
_threadObj = o;
22732273
_thread_tag = tag_for(_tag_map, _threadObj);
2274-
_tid = java_lang_Thread::thread_id(_threadObj);
2274+
_tid = static_cast<jlong>(java_lang_Thread::thread_id(_threadObj));
22752275

22762276
_is_top_frame = true;
22772277
_depth = 0;
@@ -2819,7 +2819,7 @@ inline bool VM_HeapWalkOperation::collect_stack_refs(JavaThread* java_thread,
28192819
return false;
28202820
}
28212821
// no last java frame but there may be JNI locals
2822-
blk->set_context(tag_for(_tag_map, threadObj), java_lang_Thread::thread_id(threadObj), 0, (jmethodID)nullptr);
2822+
blk->set_context(tag_for(_tag_map, threadObj), static_cast<jlong>(java_lang_Thread::thread_id(threadObj)), 0, (jmethodID)nullptr);
28232823
java_thread->active_handles()->oops_do(blk);
28242824
return !blk->stopped();
28252825
}

src/hotspot/share/prims/jvmtiThreadState.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ JvmtiVTMSTransitionDisabler::start_VTMS_transition(jthread vthread, bool is_moun
444444

445445
// Do not allow suspends inside VTMS transitions.
446446
// Block while transitions are disabled or there are suspend requests.
447-
int64_t thread_id = java_lang_Thread::thread_id(vth()); // Cannot use oops while blocked.
447+
ThreadID thread_id = java_lang_Thread::thread_id(vth()); // Cannot use oops while blocked.
448448

449449
if (_VTMS_transition_disable_for_all_count > 0 ||
450450
java_lang_Thread::VTMS_transition_disable_count(vth()) > 0 ||
@@ -505,7 +505,7 @@ JvmtiVTMSTransitionDisabler::finish_VTMS_transition(jthread vthread, bool is_mou
505505
if (!sync_protocol_enabled()) {
506506
return;
507507
}
508-
int64_t thread_id = java_lang_Thread::thread_id(vt);
508+
ThreadID thread_id = java_lang_Thread::thread_id(vt);
509509

510510
// Unblock waiting VTMS transition disablers.
511511
if (_VTMS_transition_disable_for_one_count > 0 ||
@@ -706,7 +706,7 @@ JvmtiVTSuspender::register_all_vthreads_resume() {
706706

707707
void
708708
JvmtiVTSuspender::register_vthread_suspend(oop vt) {
709-
int64_t id = java_lang_Thread::thread_id(vt);
709+
ThreadID id = java_lang_Thread::thread_id(vt);
710710
MonitorLocker ml(JvmtiVTMSTransition_lock);
711711

712712
if (_SR_mode == SR_all) {
@@ -723,7 +723,7 @@ JvmtiVTSuspender::register_vthread_suspend(oop vt) {
723723

724724
void
725725
JvmtiVTSuspender::register_vthread_resume(oop vt) {
726-
int64_t id = java_lang_Thread::thread_id(vt);
726+
ThreadID id = java_lang_Thread::thread_id(vt);
727727
MonitorLocker ml(JvmtiVTMSTransition_lock);
728728

729729
if (_SR_mode == SR_all) {
@@ -743,7 +743,7 @@ JvmtiVTSuspender::register_vthread_resume(oop vt) {
743743
}
744744

745745
bool
746-
JvmtiVTSuspender::is_vthread_suspended(int64_t thread_id) {
746+
JvmtiVTSuspender::is_vthread_suspended(ThreadID thread_id) {
747747
bool suspend_is_needed =
748748
(_SR_mode == SR_all && !_not_suspended_list->contains(thread_id)) ||
749749
(_SR_mode == SR_ind && _suspended_list->contains(thread_id));

src/hotspot/share/prims/jvmtiThreadState.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ class JvmtiVTMSTransitionDisabler {
137137
// Used for Virtual Threads Suspend/Resume management.
138138
// It's a list of thread IDs.
139139
//
140-
class VirtualThreadList : public GrowableArrayCHeap<int64_t, mtServiceability> {
140+
class VirtualThreadList : public GrowableArrayCHeap<ThreadID, mtServiceability> {
141141
public:
142-
VirtualThreadList() : GrowableArrayCHeap<int64_t, mtServiceability>(0) {}
142+
VirtualThreadList() : GrowableArrayCHeap<ThreadID, mtServiceability>(0) {}
143143
void invalidate() { clear(); }
144144
};
145145

@@ -168,7 +168,7 @@ class JvmtiVTSuspender : AllStatic {
168168
static void register_vthread_suspend(oop vt);
169169
static void register_vthread_resume(oop vt);
170170
static bool is_vthread_suspended(oop vt);
171-
static bool is_vthread_suspended(int64_t thread_id);
171+
static bool is_vthread_suspended(ThreadID thread_id);
172172
};
173173

174174
///////////////////////////////////////////////////////////////

src/hotspot/share/prims/whitebox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,7 @@ WB_END
25352535
//
25362536
WB_ENTRY(void, WB_CheckThreadObjOfTerminatingThread(JNIEnv* env, jobject wb, jobject target_handle))
25372537
oop target_oop = JNIHandles::resolve_non_null(target_handle);
2538-
jlong tid = java_lang_Thread::thread_id(target_oop);
2538+
ThreadID tid = java_lang_Thread::thread_id(target_oop);
25392539
JavaThread* target = java_lang_Thread::thread(target_oop);
25402540

25412541
// Grab a ThreadsListHandle to protect the target thread whilst terminating

0 commit comments

Comments
 (0)