Skip to content

Commit 2801bc6

Browse files
author
Serguei Spitsyn
committed
8346460: NotifyFramePop should return JVMTI_ERROR_DUPLICATE
Reviewed-by: cjplummer, amenkov
1 parent ceae2b9 commit 2801bc6

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/hotspot/share/prims/jvmti.xml

+3
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,9 @@ err = (*jvmti)->Deallocate(jvmti, stack_info);
30843084
<error id="JVMTI_ERROR_THREAD_NOT_SUSPENDED">
30853085
Thread was not suspended and was not the current thread.
30863086
</error>
3087+
<error id="JVMTI_ERROR_DUPLICATE">
3088+
There is already a frame pop event request at the specified depth.
3089+
</error>
30873090
</errors>
30883091
</function>
30893092

src/hotspot/share/prims/jvmtiEnvBase.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,11 @@ JvmtiEnvBase::set_frame_pop(JvmtiThreadState* state, javaVFrame* jvf, jint depth
13591359
}
13601360
assert(jvf->frame_pointer() != nullptr, "frame pointer mustn't be null");
13611361
int frame_number = (int)get_frame_count(jvf);
1362-
state->env_thread_state((JvmtiEnvBase*)this)->set_frame_pop(frame_number);
1362+
JvmtiEnvThreadState* ets = state->env_thread_state(this);
1363+
if (ets->is_frame_pop(frame_number)) {
1364+
return JVMTI_ERROR_DUPLICATE;
1365+
}
1366+
ets->set_frame_pop(frame_number);
13631367
return JVMTI_ERROR_NONE;
13641368
}
13651369

test/hotspot/jtreg/serviceability/jvmti/vthread/MethodExitTest/libMethodExitTest.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, 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
@@ -452,13 +452,25 @@ VirtualThreadMount(jvmtiEnv *jvmti, ...) {
452452
mname = get_method_name(jvmti, jni, method);
453453
cname = get_method_class_name(jvmti, jni, method);
454454

455+
print_frame_event_info(jvmti, jni, thread, method, "VirtualThreadMount", ++vthread_mounted_count);
456+
455457
LOG("\nHit #%d: VirtualThreadMount #%d: enabling FramePop for method: %s::%s on virtual thread: %p\n",
456-
brkptBreakpointHit, ++vthread_mounted_count, cname, mname, (void*)thread);
458+
brkptBreakpointHit, vthread_mounted_count, cname, mname, (void*)thread);
457459

458460
err = jvmti->NotifyFramePop(thread, 0);
459461
check_jvmti_status(jni, err, "VirtualThreadMount: error in JVMTI NotifyFramePop");
460462

461-
print_frame_event_info(jvmti, jni, thread, method, "VirtualThreadMount", vthread_mounted_count);
463+
LOG("\nHit #%d: VirtualThreadMount #%d: enabling duplicated FramePop for method: %s::%s on virtual thread: %p\n",
464+
brkptBreakpointHit, vthread_mounted_count, cname, mname, (void*)thread);
465+
466+
err = jvmti->NotifyFramePop(thread, 0);
467+
if (err == JVMTI_ERROR_DUPLICATE) {
468+
LOG("NotifyFramePop at VirtualThreadUnmount event returned expected JVMTI_ERROR_DUPLICATE\n");
469+
} else {
470+
LOG("Failed: NotifyFramePop at VirtualThreadUnmount returned %s(%d) instead of expected JVMTI_ERROR_DUPLICATE\n",
471+
TranslateError(err), err);
472+
jni->FatalError("NotifyFramePop error: expected error code JVMTI_ERROR_DUPLICATE");
473+
}
462474

463475
// Test SetThreadLocalStorage for virtual thread.
464476
err = jvmti->SetThreadLocalStorage(thread, tls_data2);
@@ -497,13 +509,7 @@ VirtualThreadUnmount(jvmtiEnv *jvmti, ...) {
497509
mname = get_method_name(jvmti, jni, method);
498510
cname = get_method_class_name(jvmti, jni, method);
499511

500-
LOG("\nHit #%d: VirtualThreadUnmount #%d: enabling FramePop for method: %s::%s on virtual thread: %p\n",
501-
brkptBreakpointHit, ++vthread_unmounted_count, cname, mname, (void*)thread);
502-
503-
err = jvmti->NotifyFramePop(thread, 0);
504-
check_jvmti_status(jni, err, "VirtualThreadUnmount: error in JVMTI NotifyFramePop");
505-
506-
print_frame_event_info(jvmti, jni, thread, method, "VirtualThreadUnmount", vthread_unmounted_count);
512+
print_frame_event_info(jvmti, jni, thread, method, "VirtualThreadUnmount", ++vthread_unmounted_count);
507513

508514
deallocate(jvmti, jni, (void*)mname);
509515
deallocate(jvmti, jni, (void*)cname);

0 commit comments

Comments
 (0)