Skip to content
Permalink
Browse files
Merge
  • Loading branch information
AlanBateman committed Mar 17, 2021
2 parents 9d766df + d4fcf0f commit 75545183bbf39eb2bf3c3f2c0febb979f83001d3
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 137 deletions.
@@ -3907,8 +3907,14 @@ JVM_ENTRY(void, JVM_VirtualThreadMountEnd(JNIEnv* env, jobject vthread, jboolean

if (first_mount) {
// thread start
if (JvmtiExport::should_post_vthread_scheduled()) {
JvmtiExport::post_vthread_scheduled(vthread);
if (JvmtiExport::can_support_virtual_threads()) {
if (JvmtiExport::should_post_vthread_start()) {
JvmtiExport::post_vthread_start(vthread);
}
} else { // compatibility for vthread unaware agents: legacy thread_start
if (JvmtiExport::should_post_thread_life()) {
JvmtiExport::post_thread_start(thread);
}
}
oop ct_oop = thread->threadObj();
jobject cthread = JNIHandles::make_local(thread, ct_oop);
@@ -3934,8 +3940,14 @@ JVM_ENTRY(void, JVM_VirtualThreadUnmountEnd(JNIEnv* env, jobject vthread))
JVM_END

JVM_ENTRY(void, JVM_VirtualThreadTerminated(JNIEnv* env, jobject vthread))
if (JvmtiExport::should_post_vthread_terminated()) {
JvmtiExport::post_vthread_terminated(vthread);
if (JvmtiExport::can_support_virtual_threads()) {
if (JvmtiExport::should_post_vthread_end()) {
JvmtiExport::post_vthread_end(vthread);
}
} else { // compatibility for vthread unaware agents: legacy thread_end
if (JvmtiExport::should_post_thread_life()) {
JvmtiExport::post_thread_end(thread);
}
}
oop ct_oop = thread->threadObj();
jobject cthread = JNIHandles::make_local(thread, ct_oop);
@@ -10603,8 +10603,8 @@ myInit() {
<functionlink id="GetLocalFloat"></functionlink>
<functionlink id="GetLocalDouble"></functionlink>
and the following events can be enabled:
<eventlink id="VirtualThreadScheduled"></eventlink>,
<eventlink id="VirtualThreadTerminated"></eventlink>,
<eventlink id="VirtualThreadStart"></eventlink>,
<eventlink id="VirtualThreadEnd"></eventlink>,
<eventlink id="VirtualThreadMounted"></eventlink> and
<eventlink id="VirtualThreadUnmounted"></eventlink>.
</description>
@@ -12940,10 +12940,10 @@ myInit() {
</parameters>
</event>

<event label="Virtual Thread Scheduled"
id="VirtualThreadScheduled" const="JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED" filtered="thread" num="87" phase="start" since="14">
<event label="Virtual Thread Start"
id="VirtualThreadStart" const="JVMTI_EVENT_VIRTUAL_THREAD_START" filtered="thread" num="87" phase="start" since="14">
<description>
Virtual thread scheduled events are generated before its initial method executes.
Virtual thread started events are generated before its initial method executes.
<p/>
The event is sent on the <paramlink id="thread"></paramlink>.
</description>
@@ -12963,16 +12963,16 @@ myInit() {
<param id="virtual_thread">
<jthread/>
<description>
Virtual thread scheduled for execution.
Virtual thread started for execution.
</description>
</param>
</parameters>
</event>

<event label="Virtual Thread Terminated"
id="VirtualThreadTerminated" const="JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED" filtered="thread" num="88" phase="start" since="14">
<event label="Virtual Thread End"
id="VirtualThreadEnd" const="JVMTI_EVENT_VIRTUAL_THREAD_END" filtered="thread" num="88" phase="start" since="14">
<description>
Virtual thread terminated events are generated after its initial method has finished execution.
Virtual thread end events are generated after its initial method has finished execution.
<p/>
The event is sent on the <paramlink id="thread"></paramlink>.
</description>
@@ -12992,7 +12992,7 @@ myInit() {
<param id="virtual_thread">
<jthread/>
<description>
Virtual thread being terminated.
Virtual thread being ended.
</description>
</param>
</parameters>
@@ -88,16 +88,16 @@ static const jlong OBJECT_FREE_BIT = (((jlong)1) << (JVMTI_EVENT_OBJECT_FREE -
static const jlong RESOURCE_EXHAUSTED_BIT = (((jlong)1) << (JVMTI_EVENT_RESOURCE_EXHAUSTED - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VM_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_VM_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong SAMPLED_OBJECT_ALLOC_BIT = (((jlong)1) << (JVMTI_EVENT_SAMPLED_OBJECT_ALLOC - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_SCHEDULED_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_TERMINATED_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_START_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_START - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_END_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_END - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_MOUNTED_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_MOUNTED - TOTAL_MIN_EVENT_TYPE_VAL));
static const jlong VTHREAD_UNMOUNTED_BIT = (((jlong)1) << (JVMTI_EVENT_VIRTUAL_THREAD_UNMOUNTED - TOTAL_MIN_EVENT_TYPE_VAL));

// bits for extension events
static const jlong CLASS_UNLOAD_BIT = (((jlong)1) << (EXT_EVENT_CLASS_UNLOAD - TOTAL_MIN_EVENT_TYPE_VAL));


static const jlong VTHREAD_BITS = VTHREAD_SCHEDULED_BIT | VTHREAD_TERMINATED_BIT | VTHREAD_MOUNTED_BIT | VTHREAD_UNMOUNTED_BIT;
static const jlong VTHREAD_BITS = VTHREAD_START_BIT | VTHREAD_END_BIT | VTHREAD_MOUNTED_BIT | VTHREAD_UNMOUNTED_BIT;
static const jlong MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT |
MONITOR_WAIT_BIT | MONITOR_WAITED_BIT;
static const jlong EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT;
@@ -673,8 +673,8 @@ JvmtiEventControllerPrivate::recompute_enabled() {
JvmtiExport::set_should_post_compiled_method_unload((any_env_thread_enabled & COMPILED_METHOD_UNLOAD_BIT) != 0);
JvmtiExport::set_should_post_vm_object_alloc((any_env_thread_enabled & VM_OBJECT_ALLOC_BIT) != 0);
JvmtiExport::set_should_post_sampled_object_alloc((any_env_thread_enabled & SAMPLED_OBJECT_ALLOC_BIT) != 0);
JvmtiExport::set_should_post_vthread_scheduled((any_env_thread_enabled & VTHREAD_SCHEDULED_BIT) != 0);
JvmtiExport::set_should_post_vthread_terminated((any_env_thread_enabled & VTHREAD_TERMINATED_BIT) != 0);
JvmtiExport::set_should_post_vthread_start((any_env_thread_enabled & VTHREAD_START_BIT) != 0);
JvmtiExport::set_should_post_vthread_end((any_env_thread_enabled & VTHREAD_END_BIT) != 0);
JvmtiExport::set_should_post_vthread_mounted((any_env_thread_enabled & VTHREAD_MOUNTED_BIT) != 0);
JvmtiExport::set_should_post_vthread_unmounted((any_env_thread_enabled & VTHREAD_UNMOUNTED_BIT) != 0);

@@ -1283,8 +1283,8 @@ bool JvmtiExport::_should_post_resource_exhausted = fals
bool JvmtiExport::_should_post_vm_object_alloc = false;
bool JvmtiExport::_should_post_sampled_object_alloc = false;
bool JvmtiExport::_should_post_on_exceptions = false;
bool JvmtiExport::_should_post_vthread_scheduled = false;
bool JvmtiExport::_should_post_vthread_terminated = false;
bool JvmtiExport::_should_post_vthread_start = false;
bool JvmtiExport::_should_post_vthread_end = false;
bool JvmtiExport::_should_post_vthread_mounted = false;
bool JvmtiExport::_should_post_vthread_unmounted = false;

@@ -1471,7 +1471,7 @@ void JvmtiExport::post_thread_start(JavaThread *thread) {
EVT_TRACE(JVMTI_EVENT_THREAD_START, ("[%s] Evt Thread Start event sent",
JvmtiTrace::safe_get_thread_name(thread) ));

JvmtiThreadEventMark jem(thread);
JvmtiVirtualThreadEventMark jem(thread);
JvmtiJavaThreadEventTransition jet(thread);
jvmtiEventThreadStart callback = env->callbacks()->ThreadStart;
if (callback != NULL) {
@@ -1509,7 +1509,7 @@ void JvmtiExport::post_thread_end(JavaThread *thread) {
EVT_TRACE(JVMTI_EVENT_THREAD_END, ("[%s] Evt Thread End event sent",
JvmtiTrace::safe_get_thread_name(thread) ));

JvmtiThreadEventMark jem(thread);
JvmtiVirtualThreadEventMark jem(thread);
JvmtiJavaThreadEventTransition jet(thread);
jvmtiEventThreadEnd callback = env->callbacks()->ThreadEnd;
if (callback != NULL) {
@@ -1521,32 +1521,32 @@ void JvmtiExport::post_thread_end(JavaThread *thread) {
}


void JvmtiExport::post_vthread_scheduled(jobject vthread) {
void JvmtiExport::post_vthread_start(jobject vthread) {
if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
return;
}
EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED, ("[%p] Trg Virtual Thread Scheduled event triggered", vthread));
EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_START, ("[%p] Trg Virtual Thread Start event triggered", vthread));

JavaThread *cur_thread = JavaThread::current();
JvmtiThreadState *state = cur_thread->jvmti_thread_state();
if (state == NULL) {
return;
}

if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED)) {
if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_START)) {
JvmtiEnvThreadStateIterator it(state);

for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
JvmtiEnv *env = ets->get_env();
if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
continue;
}
if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED)) {
EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_SCHEDULED, ("[%p] Evt Virtual Thread Scheduled event sent", vthread));
if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_START)) {
EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_START, ("[%p] Evt Virtual Thread Start event sent", vthread));

JvmtiVirtualThreadEventMark jem(cur_thread);
JvmtiJavaThreadEventTransition jet(cur_thread);
jvmtiEventVirtualThreadScheduled callback = env->callbacks()->VirtualThreadScheduled;
jvmtiEventVirtualThreadStart callback = env->callbacks()->VirtualThreadStart;
if (callback != NULL) {
(*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
}
@@ -1555,32 +1555,32 @@ void JvmtiExport::post_vthread_scheduled(jobject vthread) {
}
}

void JvmtiExport::post_vthread_terminated(jobject vthread) {
void JvmtiExport::post_vthread_end(jobject vthread) {
if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
return;
}
EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED, ("[%p] Trg Virtual Thread Terminated event triggered", vthread));
EVT_TRIG_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_END, ("[%p] Trg Virtual Thread End event triggered", vthread));

JavaThread *cur_thread = JavaThread::current();
JvmtiThreadState *state = cur_thread->jvmti_thread_state();
if (state == NULL) {
return;
}

if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED)) {
if (state->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_END)) {
JvmtiEnvThreadStateIterator it(state);

for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
JvmtiEnv *env = ets->get_env();
if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
continue;
}
if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED)) {
EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_TERMINATED, ("[%p] Evt Virtual Thread Terminated event sent", vthread));
if (ets->is_enabled(JVMTI_EVENT_VIRTUAL_THREAD_END)) {
EVT_TRACE(JVMTI_EVENT_VIRTUAL_THREAD_END, ("[%p] Evt Virtual Thread End event sent", vthread));

JvmtiVirtualThreadEventMark jem(cur_thread);
JvmtiJavaThreadEventTransition jet(cur_thread);
jvmtiEventVirtualThreadTerminated callback = env->callbacks()->VirtualThreadTerminated;
jvmtiEventVirtualThreadEnd callback = env->callbacks()->VirtualThreadEnd;
if (callback != NULL) {
(*callback)(env->jvmti_external(), jem.jni_env(), vthread);
}
@@ -132,8 +132,8 @@ class JvmtiExport : public AllStatic {
JVMTI_SUPPORT_FLAG(should_post_vm_object_alloc)
JVMTI_SUPPORT_FLAG(should_post_sampled_object_alloc)

JVMTI_SUPPORT_FLAG(should_post_vthread_scheduled)
JVMTI_SUPPORT_FLAG(should_post_vthread_terminated)
JVMTI_SUPPORT_FLAG(should_post_vthread_start)
JVMTI_SUPPORT_FLAG(should_post_vthread_end)
JVMTI_SUPPORT_FLAG(should_post_vthread_mounted)
JVMTI_SUPPORT_FLAG(should_post_vthread_unmounted)

@@ -342,8 +342,8 @@ class JvmtiExport : public AllStatic {
static void post_thread_start (JavaThread *thread) NOT_JVMTI_RETURN;
static void post_thread_end (JavaThread *thread) NOT_JVMTI_RETURN;

static void post_vthread_scheduled (jthread vthread) NOT_JVMTI_RETURN;
static void post_vthread_terminated (jthread vthread) NOT_JVMTI_RETURN;
static void post_vthread_start (jthread vthread) NOT_JVMTI_RETURN;
static void post_vthread_end (jthread vthread) NOT_JVMTI_RETURN;
static void post_vthread_mounted (jthread vthread) NOT_JVMTI_RETURN;
static void post_vthread_unmounted (jthread vthread) NOT_JVMTI_RETURN;

@@ -239,8 +239,8 @@ eventText(int i)
CASE_RETURN_TEXT(EI_VM_INIT)
CASE_RETURN_TEXT(EI_VM_DEATH)
CASE_RETURN_TEXT(EI_GC_FINISH)
CASE_RETURN_TEXT(EI_VIRTUAL_THREAD_SCHEDULED)
CASE_RETURN_TEXT(EI_VIRTUAL_THREAD_TERMINATED)
CASE_RETURN_TEXT(EI_VIRTUAL_THREAD_START)
CASE_RETURN_TEXT(EI_VIRTUAL_THREAD_END)
default: return "EVENT_unknown";
}
}
@@ -1289,8 +1289,8 @@ enableEvents(HandlerNode *node)
case EI_VM_DEATH:
case EI_CLASS_PREPARE:
case EI_GC_FINISH:
case EI_VIRTUAL_THREAD_SCHEDULED:
case EI_VIRTUAL_THREAD_TERMINATED:
case EI_VIRTUAL_THREAD_START:
case EI_VIRTUAL_THREAD_END:
return error;

case EI_FIELD_ACCESS:
@@ -1350,8 +1350,8 @@ disableEvents(HandlerNode *node)
case EI_VM_DEATH:
case EI_CLASS_PREPARE:
case EI_GC_FINISH:
case EI_VIRTUAL_THREAD_SCHEDULED:
case EI_VIRTUAL_THREAD_TERMINATED:
case EI_VIRTUAL_THREAD_START:
case EI_VIRTUAL_THREAD_END:
return error;

case EI_FIELD_ACCESS:

0 comments on commit 7554518

Please sign in to comment.