Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
ccdd279
Allow virtual threads to unmount while holding monitors
pchilano Oct 15, 2024
54813cd
Allow virtual threads to unmount when blocked on synchronized
pchilano Oct 16, 2024
21c3353
Allow virtual threads to unmount when blocked on Object.wait()
pchilano Oct 16, 2024
9baaff9
Test changes + JFR Updates + Library code changes
pchilano Oct 16, 2024
6a81ccd
Add PPC64 support
pchilano Oct 18, 2024
32840de
RISC-V: Avoid return misprediction
pchilano Oct 21, 2024
5c76442
Adjust comment in JavaThread.hpp
pchilano Oct 21, 2024
8c196ac
Adjust spacing in test JfrEvents.java
pchilano Oct 21, 2024
2ddbb3c
Revert and simplify changes to c1_Runtime1 on aarch64 and riscv
pchilano Oct 21, 2024
06f3732
Fix comments in c2 locking paths
pchilano Oct 21, 2024
f8616a5
remove usage of frame::metadata_words in possibly_adjust_frame()
pchilano Oct 21, 2024
fbd0cad
Fix typo in jvmtiExport.cpp
pchilano Oct 21, 2024
4cec62a
Move frame::saved_thread_address() to platform dependent files
pchilano Oct 21, 2024
23d1a2b
Fix comments in objectMonitor.hpp
pchilano Oct 21, 2024
81e5c6d
Make lea with RIP-relative addressing more general
pchilano Oct 22, 2024
b6bc98e
Address David's comments to ObjectMonitor.hpp
pchilano Oct 23, 2024
d43c084
Clear oops when thawing lockstack + add thaw_lockstack()
pchilano Oct 23, 2024
ab087a5
Fix comment in Thread.java
pchilano Oct 23, 2024
e232b7f
Rename timedWaitNonce to timedWaitSeqNo
pchilano Oct 23, 2024
baf7ffa
Minor fixes in inc/dec_held_monitor_count on aarch64 and riscv
pchilano Oct 23, 2024
0ebc3e9
Skip printing tid when not available
pchilano Oct 24, 2024
03ba6df
Fix comment in objectMonitor.hpp and javaThread.hpp
pchilano Oct 24, 2024
13353fd
Remove ObjectMonitor::set_owner_from_BasicLock()
pchilano Oct 24, 2024
d40d382
Rename nonce/nounce to seqNo in VirtualThread class
pchilano Oct 24, 2024
34362b9
Fix comments in javaThread.hpp and Thread.java
pchilano Oct 24, 2024
c7a82c4
Rename set/has_owner_anonymous to set/has_anonymous_owner
pchilano Oct 24, 2024
1785501
Fix JvmtiUnmountBeginMark
pchilano Oct 25, 2024
0308ee4
Add comments for Coleen
pchilano Oct 25, 2024
3479dba
Move condition to new line in nmethod::preserve_callee_argument_oops
pchilano Oct 25, 2024
d6313cf
Add/fix comments for David
pchilano Oct 25, 2024
4a9c030
remove interruptible check from conditional in Object::wait
pchilano Oct 25, 2024
66d5385
Restore use of atPointA in test StopThreadTest.java
pchilano Oct 25, 2024
7df17a3
Rename inflating_thread to locking_thread
pchilano Oct 28, 2024
1ff336b
Make member functions in ObjectWaiter const
pchilano Oct 28, 2024
c513ae3
add authenticate_return_address() in StubAssembler::epilogue
pchilano Oct 28, 2024
7cb4cff
Simplify set last_sp in prepare_freeze_interpreted_top_frame
pchilano Oct 28, 2024
bd918fa
extra suggestion to prepare_freeze_interpreted_top_frame
pchilano Oct 28, 2024
33cf05f
Remove generate_cont_resume_monitor_operation() + comment in ObjectSy…
pchilano Oct 28, 2024
fc9aa07
Fix vmStructs definitions
pchilano Oct 28, 2024
056d21e
Fix comment in VThreadWaitReenter
pchilano Oct 28, 2024
3e8b4fe
Improve comment in SharedRuntime::generate_native_wrapper
pchilano Oct 29, 2024
e4b0020
add assert in ThawBase::recurse_thaw_interpreted_frame
pchilano Oct 29, 2024
0f3b902
Add comments for Dean + move reload result_handler in generate_native…
pchilano Oct 29, 2024
1b695e5
Fix comment in continuation.hpp
pchilano Oct 30, 2024
9fd4c03
Add klass_name check for is_object_wait0
pchilano Oct 30, 2024
63003d3
Rename oopCont + fix in JvmtiUnmountBeginMark
pchilano Oct 30, 2024
749e30e
Add comment in call_VM_preemptable
pchilano Oct 30, 2024
aa682de
SmallRegisterMap::instance() fix + comment typo
pchilano Oct 30, 2024
0951dfe
Fix typos in comments
pchilano Oct 30, 2024
e342980
Comments for Dean
pchilano Oct 31, 2024
9f086c5
Add ObjectMonitor::successor() method + use ThreadIdentifier::initial()
pchilano Oct 31, 2024
12213a7
Use frame::sender_sp_offset in continuationFreezeThaw_riscv.inline.hpp
pchilano Oct 31, 2024
d09575f
Explicitly pass tmp register to inc/dec_held_monitor_count + use stat…
pchilano Oct 31, 2024
c92cb6b
Comment in FreezeBase::recurse_freeze + renames in continuation.hpp
pchilano Oct 31, 2024
aa263f5
Remove redundant assert in ObjectMonitor::VThreadEpilog
pchilano Oct 31, 2024
7354f60
Remove assignments in preempt_kind enum
pchilano Oct 31, 2024
e5a9ce2
add comment to ThreadService::find_deadlocks_at_safepoint
pchilano Oct 31, 2024
60e4325
Merge branch 'master' into JDK-8338383
pchilano Nov 1, 2024
0f0f71a
Remove oop clearing in transfer_lockstack + pass _barriers as argument
pchilano Nov 1, 2024
dac94da
Add comment in X509TrustManagerImpl.java
pchilano Nov 1, 2024
113fb3d
Fix comments for David
pchilano Nov 1, 2024
33eb638
Revert fixes after 8343132
pchilano Nov 1, 2024
52c2664
Use lazySubmitRunContinuation when blocking
pchilano Nov 1, 2024
9752ece
Remove ThawBase::possibly_adjust_frame()
pchilano Nov 2, 2024
1f3cfce
Fix issue with unmounted virtual thread when dumping heap
pchilano Nov 3, 2024
1139631
Update comment block in objectMonitor.cpp
pchilano Nov 3, 2024
b3de8f6
Use freeze_result consistently
pchilano Nov 4, 2024
fbd43e5
Improve JFR pinned reason in event
pchilano Nov 4, 2024
e18b2be
Revert suggestion to ThawBase::new_stack_frame
pchilano Nov 5, 2024
b6ed182
Rename waitTimeout/set_waitTimeout accessors
pchilano Nov 5, 2024
79189f9
Add oopDesc::has_klass_gap() check
pchilano Nov 5, 2024
81434a2
Fix s390x failures
pchilano Nov 5, 2024
e5c18ba
Fix return miss prediction in generate_native_entry for riscv
pchilano Nov 5, 2024
124efa0
Fixes to JFR metadata.xml
pchilano Nov 5, 2024
c0c7e6c
Use ThreadIdentifier::initial() in ObjectMonitor::owner_from()
pchilano Nov 5, 2024
6a3f5f3
Add ReflectionCallerCacheTest.java to test/jdk/ProblemList-Xcomp.txt
pchilano Nov 6, 2024
2001fba
Update comment for _cont_fastpath
pchilano Nov 6, 2024
89d6dc7
Add --enable-native-access=ALL-UNNAMED to SynchronizedNative.java
pchilano Nov 6, 2024
678676a
Move load of _lock_id in C2_MacroAssembler::fast_lock
pchilano Nov 6, 2024
211c6c8
Use is_top_frame boolean in FreezeBase::check_valid_fast_path()
pchilano Nov 6, 2024
37e3017
Use JvmtiVTMSTransitionDisabler::VTMS_vthread_mount/unmount
pchilano Nov 5, 2024
f27c59c
Add @requires vm.continuations to CancelTimerWithContention.java
pchilano Nov 7, 2024
5210f0c
Merge branch 'master' into JDK-8338383
pchilano Nov 7, 2024
62b16c6
Use get_method_name + copyright revert in jvmtiThreadState.cpp
pchilano Nov 7, 2024
1814e33
Add ObjectWaiter::at_monitorenter
pchilano Nov 8, 2024
3cdb8f8
Fix in JvmtiEnvBase::get_locked_objects_in_frame()
pchilano Nov 8, 2024
3ce6663
Merge branch 'master' into JDK-8338383
pchilano Nov 8, 2024
97a8a82
Pass -XX:-UseCompactObjectHeaders in test JNIMonitor.java
pchilano Nov 11, 2024
5878759
Test StopThreadTest.java: fix operator in condition + improve names
pchilano Nov 11, 2024
0fe6046
Merge branch 'master' into JDK-8338383
pchilano Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame&
// fp always points to the address above the pushed return pc. We need correct address.
? frame_sp + fsize - frame::sender_sp_offset
// we need to re-read fp because it may be an oop and we might have fixed the frame.
: *(intptr_t**)(hf.sp() - frame::sender_sp_offset);
: *(intptr_t**)(hf.sp() - 2);
}
// TODO PERF : this computes deopt state; is it necessary?
return frame(frame_sp, frame_sp, fp, hf.pc(), hf.cb(), hf.oop_map(), false);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,11 +2103,11 @@ void java_lang_VirtualThread::set_notified(oop vthread, jboolean value) {
vthread->bool_field_put_volatile(_notified_offset, value);
}

jlong java_lang_VirtualThread::waitTimeout(oop vthread) {
jlong java_lang_VirtualThread::timeout(oop vthread) {
return vthread->long_field(_timeout_offset);
}

void java_lang_VirtualThread::set_waitTimeout(oop vthread, jlong value) {
void java_lang_VirtualThread::set_timeout(oop vthread, jlong value) {
vthread->long_field_put(_timeout_offset, value);
}

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ class java_lang_VirtualThread : AllStatic {
static oop next(oop vthread);
static void set_next(oop vthread, oop next_vthread);
static bool set_onWaitingList(oop vthread, OopHandle& list_head);
static jlong waitTimeout(oop vthread);
static void set_waitTimeout(oop vthread, jlong value);
static jlong timeout(oop vthread);
static void set_timeout(oop vthread, jlong value);
static void set_notified(oop vthread, jboolean value);
static bool is_preempted(oop vthread);
static JavaThreadStatus map_state_to_thread_status(int state);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/include/jvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ JNIEXPORT void JNICALL
JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jboolean enter);

JNIEXPORT void JNICALL
JVM_VirtualThreadPinnedEvent(jint reasonCode, jstring reasonString);
JVM_VirtualThreadPinnedEvent(JNIEnv* env, jclass clazz, jstring op);

JNIEXPORT jobject JNICALL
JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored);
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/jfr/metadata/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
<Field type="ulong" name="id" label="Continuation ID" />
</Event>

<Event name="VirtualThreadPinned" category="Java Virtual Machine, Runtime" label="Virtual Thread Pinned" thread="true" stackTrace="true" startTime="false">
<Event name="VirtualThreadPinned" category="Java Virtual Machine, Runtime" label="Virtual Thread Pinned" thread="true" stackTrace="true">
<Field type="string" name="blockingOperation" label="Blocking operation" />
<Field type="string" name="pinnedReason" label="Pinned Reason" />
<Field type="Thread" name="carrierThread" label="Carrier Thread" />
</Event>
Expand Down
17 changes: 1 addition & 16 deletions src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,22 +1105,6 @@ void InstanceKlass::initialize_impl(TRAPS) {
}
wait = true;
jt->set_class_to_be_initialized(this);

#if INCLUDE_JFR
ContinuationEntry* ce = jt->last_continuation();
if (ce != nullptr && ce->is_virtual_thread()) {
EventVirtualThreadPinned e;
if (e.should_commit()) {
ResourceMark rm(jt);
char reason[256];
jio_snprintf(reason, sizeof reason, "Waiting for initialization of klass %s", external_name());
e.set_pinnedReason(reason);
e.set_carrierThread(JFR_JVM_THREAD_ID(THREAD));
e.commit();
}
}
#endif

ol.wait_uninterruptibly(jt);
jt->set_class_to_be_initialized(nullptr);
}
Expand Down Expand Up @@ -1619,6 +1603,7 @@ void InstanceKlass::call_class_initializer(TRAPS) {
THREAD->name());
}
if (h_method() != nullptr) {
ThreadInClassInitializer ticl(THREAD, this); // Track class being initialized
JavaCallArguments args; // No arguments
JavaValue result(T_VOID);
JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/share/prims/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,16 +3959,16 @@ JVM_ENTRY(void, JVM_VirtualThreadDisableSuspend(JNIEnv* env, jclass clazz, jbool
#endif
JVM_END

JVM_ENTRY_NO_ENV(void, JVM_VirtualThreadPinnedEvent(jint reasonCode, jstring reasonString))
JVM_ENTRY(void, JVM_VirtualThreadPinnedEvent(JNIEnv* env, jclass ignored, jstring op))
#if INCLUDE_JFR
EventVirtualThreadPinned e;
if (e.should_commit()) {
freeze_result result = THREAD->last_freeze_fail_result();
assert(result != freeze_ok, "sanity check");
EventVirtualThreadPinned event(UNTIMED);
event.set_starttime(THREAD->last_freeze_fail_time());
if (event.should_commit()) {
ResourceMark rm(THREAD);
// ignore reason code for now
const char *reason = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(reasonString));
e.set_pinnedReason(reason);
e.set_carrierThread(JFR_JVM_THREAD_ID(THREAD));
e.commit();
const char *str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(op));
THREAD->post_vthread_pinned_event(&event, str, result);
}
#endif
JVM_END
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/share/runtime/continuation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ JVM_END
class JvmtiUnmountBeginMark : public StackObj {
Handle _vthread;
JavaThread* _target;
int _preempt_result;
freeze_result _result;
bool _failed;

public:
JvmtiUnmountBeginMark(JavaThread* t) :
_vthread(t, t->vthread()), _target(t), _preempt_result(freeze_pinned_native), _failed(false) {
_vthread(t, t->vthread()), _target(t), _result(freeze_pinned_native), _failed(false) {
assert(!_target->is_in_VTMS_transition(), "must be");

if (JvmtiVTMSTransitionDisabler::VTMS_notify_jvmti_events()) {
Expand Down Expand Up @@ -101,7 +101,7 @@ class JvmtiUnmountBeginMark : public StackObj {
// been set while blocked in the allocation path during freeze.
bool jvmti_present = JvmtiVTMSTransitionDisabler::VTMS_notify_jvmti_events();

if (_preempt_result != freeze_ok) {
if (_result != freeze_ok) {
// Undo transition
if (jvmti_present) {
JvmtiVTMSTransitionDisabler::finish_VTMS_transition((jthread)_vthread.raw_value(), false);
Expand All @@ -120,7 +120,7 @@ class JvmtiUnmountBeginMark : public StackObj {
}
}
}
void set_preempt_result(int res) { _preempt_result = res; }
void set_result(freeze_result res) { _result = res; }
bool failed() { return _failed; }
};

Expand All @@ -141,7 +141,7 @@ static bool is_vthread_safe_to_preempt(JavaThread* target, oop vthread) {
return JVMTI_ONLY(is_vthread_safe_to_preempt_for_jvmti(target, vthread)) NOT_JVMTI(true);
}

typedef int (*FreezeContFnT)(JavaThread*, intptr_t*);
typedef freeze_result (*FreezeContFnT)(JavaThread*, intptr_t*);

static void verify_preempt_preconditions(JavaThread* target, oop continuation) {
assert(target == JavaThread::current(), "no support for external preemption");
Expand All @@ -153,7 +153,7 @@ static void verify_preempt_preconditions(JavaThread* target, oop continuation) {
assert(!target->has_pending_exception(), "");
}

int Continuation::try_preempt(JavaThread* target, oop continuation) {
freeze_result Continuation::try_preempt(JavaThread* target, oop continuation) {
verify_preempt_preconditions(target, continuation);

if (LockingMode == LM_LEGACY) {
Expand All @@ -166,9 +166,9 @@ int Continuation::try_preempt(JavaThread* target, oop continuation) {

JVMTI_ONLY(JvmtiUnmountBeginMark jubm(target);)
JVMTI_ONLY(if (jubm.failed()) return freeze_pinned_native;)
int res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(target, target->last_Java_sp());
freeze_result res = CAST_TO_FN_PTR(FreezeContFnT, freeze_preempt_entry())(target, target->last_Java_sp());
log_trace(continuations, preempt)("try_preempt: %d", res);
JVMTI_ONLY(jubm.set_preempt_result(res);)
JVMTI_ONLY(jubm.set_result(res);)
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/continuation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Continuation : AllStatic {
static int prepare_thaw(JavaThread* thread, bool return_barrier);
static address thaw_entry();

static int try_preempt(JavaThread* target, oop continuation);
static freeze_result try_preempt(JavaThread* target, oop continuation);

static ContinuationEntry* get_continuation_entry_for_continuation(JavaThread* thread, oop continuation);
static ContinuationEntry* get_continuation_entry_for_sp(JavaThread* thread, intptr_t* const sp);
Expand Down
23 changes: 13 additions & 10 deletions src/hotspot/share/runtime/continuationFreezeThaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void verify_continuation(oop continuation) { }
#endif

static freeze_result is_pinned0(JavaThread* thread, oop cont_scope, bool safepoint);
template<typename ConfigT, bool preempt> static inline int freeze_internal(JavaThread* current, intptr_t* const sp);
template<typename ConfigT, bool preempt> static inline freeze_result freeze_internal(JavaThread* current, intptr_t* const sp);

static inline int prepare_thaw_internal(JavaThread* thread, bool return_barrier);
template<typename ConfigT> static inline intptr_t* thaw_internal(JavaThread* thread, const Continuation::thaw_kind kind);
Expand All @@ -218,7 +218,7 @@ static JRT_BLOCK_ENTRY(int, freeze(JavaThread* current, intptr_t* sp))
current->set_cont_fastpath(nullptr);
}

return ConfigT::freeze(current, sp);
return checked_cast<int>(ConfigT::freeze(current, sp));
JRT_END

JRT_LEAF(int, Continuation::prepare_thaw(JavaThread* thread, bool return_barrier))
Expand Down Expand Up @@ -255,11 +255,11 @@ class Config {
typedef Config<oops, BarrierSetT> SelfT;
using OopT = std::conditional_t<oops == oop_kind::NARROW, narrowOop, oop>;

static int freeze(JavaThread* thread, intptr_t* const sp) {
static freeze_result freeze(JavaThread* thread, intptr_t* const sp) {
return freeze_internal<SelfT, false>(thread, sp);
}

static int freeze_preempt(JavaThread* thread, intptr_t* const sp) {
static freeze_result freeze_preempt(JavaThread* thread, intptr_t* const sp) {
return freeze_internal<SelfT, true>(thread, sp);
}

Expand Down Expand Up @@ -1412,7 +1412,9 @@ class StackChunkAllocator : public MemAllocator {

// zero out fields (but not the stack)
const size_t hs = oopDesc::header_size();
oopDesc::set_klass_gap(mem, 0);
if (oopDesc::has_klass_gap()) {
oopDesc::set_klass_gap(mem, 0);
}
Copy::fill_to_aligned_words(mem + hs, vmClasses::StackChunk_klass()->size_helper() - hs);

int bottom = (int)_stack_size - _argsize_md;
Expand Down Expand Up @@ -1666,16 +1668,17 @@ bool FreezeBase::check_valid_fast_path() {
}
#endif // ASSERT

static inline int freeze_epilog(ContinuationWrapper& cont) {
static inline freeze_result freeze_epilog(ContinuationWrapper& cont) {
verify_continuation(cont.continuation());
assert(!cont.is_empty(), "");

log_develop_debug(continuations)("=== End of freeze cont ### #" INTPTR_FORMAT, cont.hash());
return 0;
return freeze_ok;
}

static int freeze_epilog(JavaThread* thread, ContinuationWrapper& cont, freeze_result res) {
static freeze_result freeze_epilog(JavaThread* thread, ContinuationWrapper& cont, freeze_result res) {
if (UNLIKELY(res != freeze_ok)) {
JFR_ONLY(thread->set_last_freeze_fail_result(res);)
verify_continuation(cont.continuation());
log_develop_trace(continuations)("=== end of freeze (fail %d)", res);
return res;
Expand All @@ -1685,7 +1688,7 @@ static int freeze_epilog(JavaThread* thread, ContinuationWrapper& cont, freeze_r
return freeze_epilog(cont);
}

static int preempt_epilog(ContinuationWrapper& cont, freeze_result res, frame& old_last_frame) {
static freeze_result preempt_epilog(ContinuationWrapper& cont, freeze_result res, frame& old_last_frame) {
if (UNLIKELY(res != freeze_ok)) {
verify_continuation(cont.continuation());
log_develop_trace(continuations)("=== end of freeze (fail %d)", res);
Expand All @@ -1699,7 +1702,7 @@ static int preempt_epilog(ContinuationWrapper& cont, freeze_result res, frame& o
}

template<typename ConfigT, bool preempt>
static inline int freeze_internal(JavaThread* current, intptr_t* const sp) {
static inline freeze_result freeze_internal(JavaThread* current, intptr_t* const sp) {
assert(!current->has_pending_exception(), "");

#ifdef ASSERT
Expand Down
36 changes: 36 additions & 0 deletions src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ JavaThread::JavaThread(MemTag mem_tag) :
_parker(),

_class_to_be_initialized(nullptr),
_class_being_initialized(nullptr),

_SleepEvent(ParkEvent::Allocate(this)),

Expand Down Expand Up @@ -2327,3 +2328,38 @@ void JavaThread::add_oop_handles_for_release() {
_oop_handle_list = new_head;
Service_lock->notify_all();
}

#if INCLUDE_JFR
void JavaThread::set_last_freeze_fail_result(freeze_result result) {
assert(result != freeze_ok, "sanity check");
_last_freeze_fail_result = result;
_last_freeze_fail_time = Ticks::now();
}

// Post jdk.VirtualThreadPinned event
void JavaThread::post_vthread_pinned_event(EventVirtualThreadPinned* event, const char* op, freeze_result result) {
assert(result != freeze_ok, "sanity check");
if (event->should_commit()) {
char reason[256];
if (class_to_be_initialized() != nullptr) {
ResourceMark rm(this);
jio_snprintf(reason, sizeof reason, "Waited for initialization of %s by another thread",
class_to_be_initialized()->external_name());
event->set_pinnedReason(reason);
} else if (class_being_initialized() != nullptr) {
ResourceMark rm(this);
jio_snprintf(reason, sizeof(reason), "VM call to %s.<clinit> on stack",
class_being_initialized()->external_name());
event->set_pinnedReason(reason);
} else if (result == freeze_pinned_native) {
event->set_pinnedReason("Native or VM frame on stack");
} else {
jio_snprintf(reason, sizeof(reason), "Freeze or preempt failed (%d)", result);
event->set_pinnedReason(reason);
}
event->set_blockingOperation(op);
event->set_carrierThread(JFR_JVM_THREAD_ID(this));
event->commit();
}
}
#endif
37 changes: 37 additions & 0 deletions src/hotspot/share/runtime/javaThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "utilities/macros.hpp"
#if INCLUDE_JFR
#include "jfr/support/jfrThreadExtension.hpp"
#include "utilities/ticks.hpp"
#endif

class AsyncExceptionHandshake;
Expand Down Expand Up @@ -78,6 +79,8 @@ class javaVFrame;
class JavaThread;
typedef void (*ThreadFunction)(JavaThread*, TRAPS);

class EventVirtualThreadPinned;

class JavaThread: public Thread {
friend class VMStructs;
friend class JVMCIVMStructs;
Expand Down Expand Up @@ -1212,11 +1215,23 @@ class JavaThread: public Thread {
void set_class_to_be_initialized(InstanceKlass* k);
InstanceKlass* class_to_be_initialized() const;

// Track executing class initializer, see ThreadInClassInitializer
void set_class_being_initialized(InstanceKlass* k);
InstanceKlass* class_being_initialized() const;

private:
InstanceKlass* _class_to_be_initialized;
InstanceKlass* _class_being_initialized;

// java.lang.Thread.sleep support
ParkEvent * _SleepEvent;

#if INCLUDE_JFR
// Support for jdk.VirtualThreadPinned event
freeze_result _last_freeze_fail_result;
Ticks _last_freeze_fail_time;
#endif

public:
bool sleep(jlong millis);
bool sleep_nanos(jlong nanos);
Expand All @@ -1225,6 +1240,15 @@ class JavaThread: public Thread {
void interrupt();
bool is_interrupted(bool clear_interrupted);

#if INCLUDE_JFR
// Support for jdk.VirtualThreadPinned event
freeze_result last_freeze_fail_result() { return _last_freeze_fail_result; }
Ticks& last_freeze_fail_time() { return _last_freeze_fail_time; }
void set_last_freeze_fail_result(freeze_result result);
#endif
void post_vthread_pinned_event(EventVirtualThreadPinned* event, const char* op, freeze_result result) NOT_JFR_RETURN();


// This is only for use by JVMTI RawMonitorWait. It emulates the actions of
// the Java code in Object::wait which are not present in RawMonitorWait.
bool get_and_clear_interrupted();
Expand Down Expand Up @@ -1331,4 +1355,17 @@ class ThreadOnMonitorWaitedEvent {
~ThreadOnMonitorWaitedEvent() { JVMTI_ONLY(_thread->set_on_monitor_waited_event(false);) }
};

class ThreadInClassInitializer : public StackObj {
JavaThread* _thread;
InstanceKlass* _previous;
public:
ThreadInClassInitializer(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
_previous = _thread->class_being_initialized();
_thread->set_class_being_initialized(ik);
}
~ThreadInClassInitializer() {
_thread->set_class_being_initialized(_previous);
}
};

#endif // SHARE_RUNTIME_JAVATHREAD_HPP
Loading