Skip to content

Commit f636674

Browse files
committed
8344247: Move objectWaiter field to VirtualThread instance
Reviewed-by: dholmes, coleenp
1 parent de6e013 commit f636674

12 files changed

+53
-76
lines changed

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,7 @@ int java_lang_VirtualThread::_next_offset;
20522052
int java_lang_VirtualThread::_onWaitingList_offset;
20532053
int java_lang_VirtualThread::_notified_offset;
20542054
int java_lang_VirtualThread::_timeout_offset;
2055+
int java_lang_VirtualThread::_objectWaiter_offset;
20552056

20562057
#define VTHREAD_FIELDS_DO(macro) \
20572058
macro(static_vthread_scope_offset, k, "VTHREAD_SCOPE", continuationscope_signature, true); \
@@ -2067,6 +2068,7 @@ int java_lang_VirtualThread::_timeout_offset;
20672068
void java_lang_VirtualThread::compute_offsets() {
20682069
InstanceKlass* k = vmClasses::VirtualThread_klass();
20692070
VTHREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2071+
VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
20702072
}
20712073

20722074
bool java_lang_VirtualThread::is_instance(oop obj) {
@@ -2182,6 +2184,22 @@ JavaThreadStatus java_lang_VirtualThread::map_state_to_thread_status(int state)
21822184
return status;
21832185
}
21842186

2187+
ObjectMonitor* java_lang_VirtualThread::current_pending_monitor(oop vthread) {
2188+
ObjectWaiter* waiter = objectWaiter(vthread);
2189+
if (waiter != nullptr && waiter->at_monitorenter()) {
2190+
return waiter->monitor();
2191+
}
2192+
return nullptr;
2193+
}
2194+
2195+
ObjectMonitor* java_lang_VirtualThread::current_waiting_monitor(oop vthread) {
2196+
ObjectWaiter* waiter = objectWaiter(vthread);
2197+
if (waiter != nullptr && waiter->is_wait()) {
2198+
return waiter->monitor();
2199+
}
2200+
return nullptr;
2201+
}
2202+
21852203
bool java_lang_VirtualThread::is_preempted(oop vthread) {
21862204
oop continuation = java_lang_VirtualThread::continuation(vthread);
21872205
assert(continuation != nullptr, "vthread with no continuation");
@@ -2192,6 +2210,7 @@ bool java_lang_VirtualThread::is_preempted(oop vthread) {
21922210
#if INCLUDE_CDS
21932211
void java_lang_VirtualThread::serialize_offsets(SerializeClosure* f) {
21942212
VTHREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
2213+
VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET);
21952214
}
21962215
#endif
21972216

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
class JvmtiThreadState;
3939
class RecordComponent;
4040
class SerializeClosure;
41+
class ObjectWaiter;
42+
class ObjectMonitor;
4143

4244
#define CHECK_INIT(offset) assert(offset != 0, "should be initialized"); return offset;
4345

@@ -537,6 +539,8 @@ class java_lang_ThreadGroup : AllStatic {
537539

538540

539541
// Interface to java.lang.VirtualThread objects
542+
#define VTHREAD_INJECTED_FIELDS(macro) \
543+
macro(java_lang_VirtualThread, objectWaiter, intptr_signature, false)
540544

541545
class java_lang_VirtualThread : AllStatic {
542546
private:
@@ -549,6 +553,7 @@ class java_lang_VirtualThread : AllStatic {
549553
static int _notified_offset;
550554
static int _recheckInterval_offset;
551555
static int _timeout_offset;
556+
static int _objectWaiter_offset;
552557
JFR_ONLY(static int _jfr_epoch_offset;)
553558
public:
554559
enum {
@@ -600,6 +605,11 @@ class java_lang_VirtualThread : AllStatic {
600605
static void set_notified(oop vthread, jboolean value);
601606
static bool is_preempted(oop vthread);
602607
static JavaThreadStatus map_state_to_thread_status(int state);
608+
609+
static inline ObjectWaiter* objectWaiter(oop vthread);
610+
static inline void set_objectWaiter(oop vthread, ObjectWaiter* waiter);
611+
static ObjectMonitor* current_pending_monitor(oop vthread);
612+
static ObjectMonitor* current_waiting_monitor(oop vthread);
603613
};
604614

605615

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ inline oop java_lang_VirtualThread::vthread_scope() {
220220
return base->obj_field(static_vthread_scope_offset);
221221
}
222222

223+
inline ObjectWaiter* java_lang_VirtualThread::objectWaiter(oop vthread) {
224+
return (ObjectWaiter*)vthread->address_field(_objectWaiter_offset);
225+
}
226+
227+
inline void java_lang_VirtualThread::set_objectWaiter(oop vthread, ObjectWaiter* value) {
228+
vthread->address_field_put(_objectWaiter_offset, (address)value);
229+
}
230+
223231
#if INCLUDE_JFR
224232
inline u2 java_lang_Thread::jfr_epoch(oop ref) {
225233
return ref->short_field(_jfr_epoch_offset);

src/hotspot/share/classfile/javaClassesImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
STACKFRAMEINFO_INJECTED_FIELDS(macro) \
4141
MODULE_INJECTED_FIELDS(macro) \
4242
THREAD_INJECTED_FIELDS(macro) \
43+
VTHREAD_INJECTED_FIELDS(macro) \
4344
INTERNALERROR_INJECTED_FIELDS(macro) \
4445
STACKCHUNK_INJECTED_FIELDS(macro)
4546

src/hotspot/share/oops/stackChunkOop.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ class stackChunkOopDesc : public instanceOopDesc {
9898
inline uint8_t lockstack_size() const;
9999
inline void set_lockstack_size(uint8_t value);
100100

101-
inline ObjectWaiter* object_waiter() const;
102-
inline void set_object_waiter(ObjectWaiter* obj_waiter);
103-
104-
inline ObjectMonitor* current_pending_monitor() const;
105-
inline ObjectMonitor* current_waiting_monitor() const;
106-
107101
inline oop cont() const;
108102
template<typename P>
109103
inline oop cont() const;

src/hotspot/share/oops/stackChunkOop.inline.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ inline void stackChunkOopDesc::set_max_thawing_size(int value) {
9292
inline uint8_t stackChunkOopDesc::lockstack_size() const { return jdk_internal_vm_StackChunk::lockStackSize(as_oop()); }
9393
inline void stackChunkOopDesc::set_lockstack_size(uint8_t value) { jdk_internal_vm_StackChunk::set_lockStackSize(this, value); }
9494

95-
inline ObjectWaiter* stackChunkOopDesc::object_waiter() const { return (ObjectWaiter*)jdk_internal_vm_StackChunk::objectWaiter(as_oop()); }
96-
inline void stackChunkOopDesc::set_object_waiter(ObjectWaiter* obj) { jdk_internal_vm_StackChunk::set_objectWaiter(this, (address)obj); }
97-
9895
inline oop stackChunkOopDesc::cont() const { return jdk_internal_vm_StackChunk::cont(as_oop()); }
9996
inline void stackChunkOopDesc::set_cont(oop value) { jdk_internal_vm_StackChunk::set_cont(this, value); }
10097
template<typename P>
@@ -171,22 +168,6 @@ inline void stackChunkOopDesc::set_preempted(bool value) {
171168
set_flag(FLAG_PREEMPTED, value);
172169
}
173170

174-
inline ObjectMonitor* stackChunkOopDesc::current_pending_monitor() const {
175-
ObjectWaiter* waiter = object_waiter();
176-
if (waiter != nullptr && waiter->at_monitorenter()) {
177-
return waiter->monitor();
178-
}
179-
return nullptr;
180-
}
181-
182-
inline ObjectMonitor* stackChunkOopDesc::current_waiting_monitor() const {
183-
ObjectWaiter* waiter = object_waiter();
184-
if (waiter != nullptr && waiter->is_wait()) {
185-
return waiter->monitor();
186-
}
187-
return nullptr;
188-
}
189-
190171
inline bool stackChunkOopDesc::has_lockstack() const { return is_flag(FLAG_HAS_LOCKSTACK); }
191172
inline void stackChunkOopDesc::set_has_lockstack(bool value) { set_flag(FLAG_HAS_LOCKSTACK, value); }
192173

src/hotspot/share/prims/jvmtiEnvBase.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,7 @@ JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread
10801080
ObjectMonitor *mon = target->current_waiting_monitor();
10811081
if (mon != nullptr) wait_obj = mon->object();
10821082
} else {
1083-
assert(vthread != nullptr, "no vthread oop");
1084-
oop cont = java_lang_VirtualThread::continuation(vthread);
1085-
assert(cont != nullptr, "vthread with no continuation");
1086-
stackChunkOop chunk = jdk_internal_vm_Continuation::tail(cont);
1087-
assert(chunk != nullptr, "unmounted vthread should have a chunk");
1088-
ObjectMonitor *mon = chunk->current_waiting_monitor();
1083+
ObjectMonitor *mon = java_lang_VirtualThread::current_waiting_monitor(vthread);
10891084
if (mon != nullptr) wait_obj = mon->object();
10901085
}
10911086
}
@@ -1099,12 +1094,7 @@ JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread
10991094
ObjectMonitor *mon = target->current_pending_monitor();
11001095
if (mon != nullptr) pending_obj = mon->object();
11011096
} else {
1102-
assert(vthread != nullptr, "no vthread oop");
1103-
oop cont = java_lang_VirtualThread::continuation(vthread);
1104-
assert(cont != nullptr, "vthread with no continuation");
1105-
stackChunkOop chunk = jdk_internal_vm_Continuation::tail(cont);
1106-
assert(chunk != nullptr, "unmounted vthread should have a chunk");
1107-
ObjectMonitor *mon = chunk->current_pending_monitor();
1097+
ObjectMonitor *mon = java_lang_VirtualThread::current_pending_monitor(vthread);
11081098
if (mon != nullptr) pending_obj = mon->object();
11091099
}
11101100
}
@@ -2569,12 +2559,9 @@ GetCurrentContendedMonitorClosure::do_thread(Thread *target) {
25692559
void
25702560
GetCurrentContendedMonitorClosure::do_vthread(Handle target_h) {
25712561
if (_target_jt == nullptr) {
2572-
oop cont = java_lang_VirtualThread::continuation(target_h());
2573-
assert(cont != nullptr, "vthread with no continuation");
2574-
stackChunkOop chunk = jdk_internal_vm_Continuation::tail(cont);
2575-
assert(chunk != nullptr, "unmounted vthread should have a chunk");
2576-
if (chunk->current_pending_monitor() != nullptr) {
2577-
*_owned_monitor_ptr = JNIHandles::make_local(_calling_thread, chunk->current_pending_monitor()->object());
2562+
ObjectMonitor *mon = java_lang_VirtualThread::current_pending_monitor(target_h());
2563+
if (mon != nullptr) {
2564+
*_owned_monitor_ptr = JNIHandles::make_local(_calling_thread, mon->object());
25782565
}
25792566
_result = JVMTI_ERROR_NONE; // target virtual thread is unmounted
25802567
return;

src/hotspot/share/runtime/continuationFreezeThaw.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,6 @@ stackChunkOop Freeze<ConfigT>::allocate_chunk(size_t stack_size, int argsize_md)
15241524
assert(chunk->flags() == 0, "");
15251525
assert(chunk->is_gc_mode() == false, "");
15261526
assert(chunk->lockstack_size() == 0, "");
1527-
assert(chunk->object_waiter() == nullptr, "");
15281527

15291528
// fields are uninitialized
15301529
chunk->set_parent_access<IS_DEST_UNINITIALIZED>(_cont.last_nonempty_chunk());
@@ -2214,11 +2213,10 @@ NOINLINE intptr_t* Thaw<ConfigT>::thaw_slow(stackChunkOop chunk, Continuation::t
22142213

22152214
_preempted_case = chunk->preempted();
22162215
if (_preempted_case) {
2217-
if (chunk->object_waiter() != nullptr) {
2216+
ObjectWaiter* waiter = java_lang_VirtualThread::objectWaiter(_thread->vthread());
2217+
if (waiter != nullptr) {
22182218
// Mounted again after preemption. Resume the pending monitor operation,
22192219
// which will be either a monitorenter or Object.wait() call.
2220-
assert(chunk->current_pending_monitor() != nullptr || chunk->current_waiting_monitor() != nullptr, "");
2221-
ObjectWaiter* waiter = chunk->object_waiter();
22222220
ObjectMonitor* mon = waiter->monitor();
22232221
preempt_kind = waiter->is_wait() ? Continuation::freeze_on_wait : Continuation::freeze_on_monitorenter;
22242222

src/hotspot/share/runtime/continuationJavaClasses.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ int jdk_internal_vm_StackChunk::_bottom_offset;
8888
int jdk_internal_vm_StackChunk::_flags_offset;
8989
int jdk_internal_vm_StackChunk::_maxThawingSize_offset;
9090
int jdk_internal_vm_StackChunk::_lockStackSize_offset;
91-
int jdk_internal_vm_StackChunk::_objectWaiter_offset;
9291
int jdk_internal_vm_StackChunk::_cont_offset;
9392

9493
#define STACKCHUNK_FIELDS_DO(macro) \

src/hotspot/share/runtime/continuationJavaClasses.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class jdk_internal_vm_Continuation: AllStatic {
7676
macro(jdk_internal_vm_StackChunk, pc, intptr_signature, false) \
7777
macro(jdk_internal_vm_StackChunk, maxThawingSize, int_signature, false) \
7878
macro(jdk_internal_vm_StackChunk, lockStackSize, byte_signature, false) \
79-
macro(jdk_internal_vm_StackChunk, objectWaiter, intptr_signature, false) \
8079

8180
class jdk_internal_vm_StackChunk: AllStatic {
8281
friend class JavaClasses;
@@ -89,7 +88,6 @@ class jdk_internal_vm_StackChunk: AllStatic {
8988
static int _flags_offset;
9089
static int _maxThawingSize_offset;
9190
static int _lockStackSize_offset;
92-
static int _objectWaiter_offset;
9391
static int _cont_offset;
9492

9593

@@ -131,9 +129,6 @@ class jdk_internal_vm_StackChunk: AllStatic {
131129
static inline uint8_t lockStackSize(oop chunk);
132130
static inline void set_lockStackSize(oop chunk, uint8_t value);
133131

134-
static inline address objectWaiter(oop chunk);
135-
static inline void set_objectWaiter(oop chunk, address mon);
136-
137132
// cont oop's processing is essential for the chunk's GC protocol
138133
static inline oop cont(oop chunk);
139134
template<typename P>

0 commit comments

Comments
 (0)