Skip to content

Commit 6bddeb7

Browse files
committed
8238761: Asynchronous handshakes
Reviewed-by: pchilanomate, dcubed, dholmes, coleenp, sspitsyn
1 parent 6d19fe6 commit 6bddeb7

24 files changed

+975
-375
lines changed

src/hotspot/share/memory/iterator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@ class Thread;
4444
class Closure : public StackObj { };
4545

4646
// Thread iterator
47-
class ThreadClosure: public Closure {
47+
class ThreadClosure {
4848
public:
4949
virtual void do_thread(Thread* thread) = 0;
5050
};

src/hotspot/share/prims/jvmtiEnv.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count
12131213
} else {
12141214
// get owned monitors info with handshake
12151215
GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1216-
bool executed = Handshake::execute_direct(&op, java_thread);
1217-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1216+
Handshake::execute(&op, java_thread);
1217+
err = op.result();
12181218
}
12191219
jint owned_monitor_count = owned_monitors_list->length();
12201220
if (err == JVMTI_ERROR_NONE) {
@@ -1258,8 +1258,8 @@ JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_i
12581258
} else {
12591259
// get owned monitors info with handshake
12601260
GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1261-
bool executed = Handshake::execute_direct(&op, java_thread);
1262-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1261+
Handshake::execute(&op, java_thread);
1262+
err = op.result();
12631263
}
12641264

12651265
jint owned_monitor_count = owned_monitors_list->length();
@@ -1302,8 +1302,8 @@ JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_p
13021302
} else {
13031303
// get contended monitor information with handshake
13041304
GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr);
1305-
bool executed = Handshake::execute_direct(&op, java_thread);
1306-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1305+
Handshake::execute(&op, java_thread);
1306+
err = op.result();
13071307
}
13081308
return err;
13091309
} /* end GetCurrentContendedMonitor */
@@ -1540,8 +1540,8 @@ JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_fram
15401540
} else {
15411541
// Get stack trace with handshake.
15421542
GetStackTraceClosure op(this, start_depth, max_frame_count, frame_buffer, count_ptr);
1543-
bool executed = Handshake::execute_direct(&op, java_thread);
1544-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1543+
Handshake::execute(&op, java_thread);
1544+
err = op.result();
15451545
}
15461546

15471547
return err;
@@ -1585,8 +1585,8 @@ JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list
15851585
}
15861586

15871587
GetSingleStackTraceClosure op(this, current_thread, *thread_list, max_frame_count);
1588-
bool executed = Handshake::execute_direct(&op, java_thread);
1589-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1588+
Handshake::execute(&op, java_thread);
1589+
err = op.result();
15901590
if (err == JVMTI_ERROR_NONE) {
15911591
*stack_info_ptr = op.stack_info();
15921592
}
@@ -1623,8 +1623,8 @@ JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) {
16231623
} else {
16241624
// get java stack frame count with handshake.
16251625
GetFrameCountClosure op(this, state, count_ptr);
1626-
bool executed = Handshake::execute_direct(&op, java_thread);
1627-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1626+
Handshake::execute(&op, java_thread);
1627+
err = op.result();
16281628
}
16291629
return err;
16301630
} /* end GetFrameCount */
@@ -1721,10 +1721,9 @@ JvmtiEnv::PopFrame(JavaThread* java_thread) {
17211721
state->update_for_pop_top_frame();
17221722
} else {
17231723
UpdateForPopTopFrameClosure op(state);
1724-
bool executed = Handshake::execute_direct(&op, java_thread);
1725-
jvmtiError err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1726-
if (err != JVMTI_ERROR_NONE) {
1727-
return err;
1724+
Handshake::execute(&op, java_thread);
1725+
if (op.result() != JVMTI_ERROR_NONE) {
1726+
return op.result();
17281727
}
17291728
}
17301729
}
@@ -1756,8 +1755,8 @@ JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* metho
17561755
} else {
17571756
// JVMTI get java stack frame location via direct handshake.
17581757
GetFrameLocationClosure op(this, depth, method_ptr, location_ptr);
1759-
bool executed = Handshake::execute_direct(&op, java_thread);
1760-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1758+
Handshake::execute(&op, java_thread);
1759+
err = op.result();
17611760
}
17621761
return err;
17631762
} /* end GetFrameLocation */
@@ -1805,8 +1804,8 @@ JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) {
18051804
state->env_thread_state(this)->set_frame_pop(frame_number);
18061805
} else {
18071806
SetFramePopClosure op(this, state, depth);
1808-
bool executed = Handshake::execute_direct(&op, java_thread);
1809-
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1807+
Handshake::execute(&op, java_thread);
1808+
err = op.result();
18101809
}
18111810
return err;
18121811
} /* end NotifyFramePop */

src/hotspot/share/prims/jvmtiEnvBase.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,9 @@ JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
649649

650650
jvmtiError
651651
JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
652-
JavaThread *current_jt = JavaThread::current();
653-
assert(current_jt == java_thread ||
654-
current_jt == java_thread->active_handshaker(),
655-
"call by myself or at direct handshake");
652+
Thread *current_thread = Thread::current();
653+
assert(java_thread->is_handshake_safe_for(current_thread),
654+
"call by myself or at handshake");
656655
oop obj = NULL;
657656
// The ObjectMonitor* can't be async deflated since we are either
658657
// at a safepoint or the calling thread is operating on itself so
@@ -676,8 +675,8 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
676675
if (obj == NULL) {
677676
*monitor_ptr = NULL;
678677
} else {
679-
HandleMark hm(current_jt);
680-
Handle hobj(current_jt, obj);
678+
HandleMark hm(current_thread);
679+
Handle hobj(current_thread, obj);
681680
*monitor_ptr = jni_reference(calling_thread, hobj);
682681
}
683682
return JVMTI_ERROR_NONE;
@@ -687,15 +686,19 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
687686
jvmtiError
688687
JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
689688
GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
689+
// Note:
690+
// calling_thread is the thread that requested the list of monitors for java_thread.
691+
// java_thread is the thread owning the monitors.
692+
// current_thread is the thread executing this code, can be a non-JavaThread (e.g. VM Thread).
693+
// And they all may be different threads.
690694
jvmtiError err = JVMTI_ERROR_NONE;
691-
JavaThread *current_jt = JavaThread::current();
692-
assert(current_jt == java_thread ||
693-
current_jt == java_thread->active_handshaker(),
694-
"call by myself or at direct handshake");
695+
Thread *current_thread = Thread::current();
696+
assert(java_thread->is_handshake_safe_for(current_thread),
697+
"call by myself or at handshake");
695698

696699
if (java_thread->has_last_Java_frame()) {
697-
ResourceMark rm(current_jt);
698-
HandleMark hm(current_jt);
700+
ResourceMark rm(current_thread);
701+
HandleMark hm(current_thread);
699702
RegisterMap reg_map(java_thread);
700703

701704
int depth = 0;
@@ -819,9 +822,8 @@ JvmtiEnvBase::get_stack_trace(JavaThread *java_thread,
819822
uint32_t debug_bits = 0;
820823
#endif
821824
Thread *current_thread = Thread::current();
822-
assert(current_thread == java_thread ||
823-
SafepointSynchronize::is_at_safepoint() ||
824-
current_thread == java_thread->active_handshaker(),
825+
assert(SafepointSynchronize::is_at_safepoint() ||
826+
java_thread->is_handshake_safe_for(current_thread),
825827
"call by myself / at safepoint / at handshake");
826828
int count = 0;
827829
if (java_thread->has_last_Java_frame()) {
@@ -903,9 +905,8 @@ JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth,
903905
uint32_t debug_bits = 0;
904906
#endif
905907
Thread* current_thread = Thread::current();
906-
assert(current_thread == java_thread ||
907-
current_thread == java_thread->active_handshaker(),
908-
"call by myself or at direct handshake");
908+
assert(java_thread->is_handshake_safe_for(current_thread),
909+
"call by myself or at handshake");
909910
ResourceMark rm(current_thread);
910911

911912
vframe *vf = vframeFor(java_thread, depth);
@@ -1159,9 +1160,8 @@ void
11591160
MultipleStackTracesCollector::fill_frames(jthread jt, JavaThread *thr, oop thread_oop) {
11601161
#ifdef ASSERT
11611162
Thread *current_thread = Thread::current();
1162-
assert(current_thread == thr ||
1163-
SafepointSynchronize::is_at_safepoint() ||
1164-
current_thread == thr->active_handshaker(),
1163+
assert(SafepointSynchronize::is_at_safepoint() ||
1164+
thr->is_handshake_safe_for(current_thread),
11651165
"call by myself / at safepoint / at handshake");
11661166
#endif
11671167

@@ -1305,7 +1305,7 @@ VM_GetAllStackTraces::doit() {
13051305
// HandleMark must be defined in the caller only.
13061306
// It is to keep a ret_ob_h handle alive after return to the caller.
13071307
jvmtiError
1308-
JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
1308+
JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
13091309
jvalue value, TosState tos, Handle* ret_ob_h) {
13101310
ResourceMark rm(current_thread);
13111311

@@ -1368,7 +1368,7 @@ JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_threa
13681368

13691369
jvmtiError
13701370
JvmtiEnvBase::force_early_return(JavaThread* java_thread, jvalue value, TosState tos) {
1371-
JavaThread* current_thread = JavaThread::current();
1371+
Thread* current_thread = Thread::current();
13721372
HandleMark hm(current_thread);
13731373
uint32_t debug_bits = 0;
13741374

0 commit comments

Comments
 (0)