-
Notifications
You must be signed in to change notification settings - Fork 176
8387540: [lworld] ForceEarlyReturnVoid should fail with OPAQUE_FRAME if target thread's top frame is value class constructor #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c2e7e2
Initial commit
AlanBateman a6237fa
Test cleanup
AlanBateman d5e25db
Improve docs change
AlanBateman 16fb34f
Merge branch 'lworld' into ForceEarlyReturn
AlanBateman 9ce6052
Improve test, quality docs update to be for when preview features are…
AlanBateman 4caea25
Add more qualifcation to examples in OPAQUE_FRAME error
AlanBateman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 250 additions & 0 deletions
250
test/hotspot/jtreg/serviceability/jvmti/ForceEarlyReturn/ForceEarlyReturnValueClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,250 @@ | ||
| /* | ||
| * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @summary Test ForceEarlyReturnVoid when the target thread's top frame is a value class | ||
| * constructor, method or class initializer. | ||
| * @enablePreview | ||
| * @run junit/othervm/native --enable-native-access=ALL-UNNAMED -agentlib:ForceEarlyReturnValueClass ${test.main.class} | ||
| */ | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class ForceEarlyReturnValueClass { | ||
|
|
||
| private static final int JVMTI_ERROR_NONE = 0; | ||
| private static final int JVMTI_ERROR_OPAQUE_FRAME = 32; | ||
|
|
||
| /** | ||
| * Test that ForceEarlyReturnVoid fails with JVMTI_ERROR_OPAQUE_FRAME when the | ||
| * target thread's top frame is a value class constructor before super. | ||
| */ | ||
| @Test | ||
| void testForceEarlyReturnBeforeSuper() throws Exception { | ||
| class TestCase { | ||
| static volatile boolean initStarted; | ||
| static volatile boolean initFinished; | ||
| static volatile boolean stop; | ||
| static value class ValueClass { | ||
| ValueClass() { | ||
| TestCase.initStarted = true; | ||
| while (!TestCase.stop) {} | ||
| super(); | ||
| TestCase.initFinished = true; | ||
| } | ||
|
AlanBateman marked this conversation as resolved.
|
||
| } | ||
| } | ||
| Thread thread = Thread.ofPlatform().start(TestCase.ValueClass::new); | ||
| boolean suspended = false; | ||
| try { | ||
| // wait for target thread to start executing constructor | ||
| while (!TestCase.initStarted) { | ||
| Thread.sleep(10); | ||
| } | ||
| assertEquals(JVMTI_ERROR_NONE, suspendThread(thread)); | ||
| suspended = true; | ||
| assertTopFrame(thread, TestCase.ValueClass.class, "<init>"); | ||
| assertEquals(JVMTI_ERROR_OPAQUE_FRAME, forceEarlyReturnVoid(thread)); | ||
| } finally { | ||
| TestCase.stop = true; | ||
| if (suspended) resumeThread(thread); | ||
| thread.join(); | ||
| } | ||
| assertTrue(TestCase.initFinished); // constructor should have run to end | ||
| } | ||
|
|
||
| /** | ||
| * Test that ForceEarlyReturnVoid fails with JVMTI_ERROR_OPAQUE_FRAME when the | ||
| * target thread's top frame is a value class constructor after super. | ||
| * (This case may be allowed to succeed in the future) | ||
| */ | ||
| @Test | ||
| void testForceEarlyReturnAfterSuper() throws Exception { | ||
| class TestCase { | ||
| static volatile boolean afterSuperStarted; | ||
| static volatile boolean initFinished; | ||
| static volatile boolean stop; | ||
| static value class ValueClass { | ||
| ValueClass() { | ||
| super(); | ||
| TestCase.afterSuperStarted = true; | ||
| while (!TestCase.stop) {} | ||
| TestCase.initFinished = true; | ||
| } | ||
| } | ||
| } | ||
| Thread thread = Thread.ofPlatform().start(TestCase.ValueClass::new); | ||
| boolean suspended = false; | ||
| try { | ||
| // wait for target thread to start executing code after super | ||
| while (!TestCase.afterSuperStarted) { | ||
| Thread.sleep(10); | ||
| } | ||
| assertEquals(JVMTI_ERROR_NONE, suspendThread(thread)); | ||
| suspended = true; | ||
| assertTopFrame(thread, TestCase.ValueClass.class, "<init>"); | ||
| assertEquals(JVMTI_ERROR_OPAQUE_FRAME, forceEarlyReturnVoid(thread)); | ||
| } finally { | ||
| TestCase.stop = true; | ||
| if (suspended) resumeThread(thread); | ||
| thread.join(); | ||
| } | ||
| assertTrue(TestCase.initFinished); // constructor should have run to end | ||
| } | ||
|
|
||
| /** | ||
| * Test that ForceEarlyReturnVoid succeeds with the target thread's top frame is a | ||
| * method invoked from the constructor after super. | ||
| */ | ||
| @Test | ||
| void testForceEarlyReturnPostInit() throws Exception { | ||
| class TestCase { | ||
| static volatile boolean initFinished; | ||
| static volatile boolean postInitStarted; | ||
| static volatile boolean postInitFinished; | ||
| static volatile boolean stop; | ||
| static value class ValueClass { | ||
| ValueClass() { | ||
| super(); | ||
| postInit(); | ||
| TestCase.initFinished = true; | ||
| } | ||
| void postInit() { | ||
| TestCase.postInitStarted = true; | ||
| while (!TestCase.stop) {} | ||
| TestCase.postInitFinished = true; | ||
| } | ||
| } | ||
| } | ||
| Thread thread = Thread.ofPlatform().start(TestCase.ValueClass::new); | ||
| boolean suspended = false; | ||
| try { | ||
| // wait for target thread to start executing postInit method | ||
| while (!TestCase.postInitStarted) { | ||
| Thread.sleep(10); | ||
| } | ||
| assertEquals(JVMTI_ERROR_NONE, suspendThread(thread)); | ||
| assertTopFrame(thread, TestCase.ValueClass.class, "postInit"); | ||
| suspended = true; | ||
| assertEquals(JVMTI_ERROR_NONE, forceEarlyReturnVoid(thread)); | ||
| } finally { | ||
| TestCase.stop = true; | ||
| if (suspended) resumeThread(thread); | ||
| thread.join(); | ||
| } | ||
| assertFalse(TestCase.postInitFinished); // postInit should not have run to the end | ||
| assertTrue(TestCase.initFinished); // constructor should have run to end | ||
| } | ||
|
|
||
| /** | ||
| * Test that ForceEarlyReturnVoid succeeds with the target thread's top frame is a | ||
| * value class method. | ||
| */ | ||
| @Test | ||
| void testForceEarlyReturnMethod() throws Exception { | ||
| class TestCase { | ||
| static volatile boolean runStarted; | ||
| static volatile boolean runFinished; | ||
| static volatile boolean stop; | ||
| static value class ValueClass { | ||
| void run() { | ||
| TestCase.runStarted = true; | ||
| while (!TestCase.stop) {} | ||
| TestCase.runFinished = true; // should not get there | ||
| } | ||
| } | ||
| } | ||
| var valueObj = new TestCase.ValueClass(); | ||
| Thread thread = Thread.ofPlatform().start(valueObj::run); | ||
| boolean suspended = false; | ||
| try { | ||
| // wait for target thread to start executing method | ||
| while (!TestCase.runStarted) { | ||
| Thread.sleep(10); | ||
| } | ||
| assertEquals(JVMTI_ERROR_NONE, suspendThread(thread)); | ||
| suspended = true; | ||
| assertTopFrame(thread, TestCase.ValueClass.class, "run"); | ||
| assertEquals(JVMTI_ERROR_NONE, forceEarlyReturnVoid(thread)); | ||
| } finally { | ||
| TestCase.stop = true; | ||
| if (suspended) resumeThread(thread); | ||
| thread.join(); | ||
| } | ||
| assertFalse(TestCase.runFinished); // should not have run to the end | ||
| } | ||
|
|
||
| /** | ||
| * Test that ForceEarlyReturnVoid succeeds with the target thread's top frame is a | ||
| * value class clinit. | ||
| */ | ||
| @Test | ||
| void testForceEarlyReturnClassInitializer() throws Exception { | ||
| class TestCase { | ||
| static volatile boolean clinitStarted; | ||
| static volatile boolean stop; | ||
| static value class ValueClass { | ||
| static final boolean initialized; | ||
| static { | ||
| TestCase.clinitStarted = true; | ||
| while (!TestCase.stop) {} | ||
| initialized = true; // should not get there | ||
| } | ||
| } | ||
| } | ||
| Thread thread = Thread.ofPlatform().start(TestCase.ValueClass::new); | ||
| boolean suspended = false; | ||
| try { | ||
| // wait for target thread to start executing class initializer | ||
| while (!TestCase.clinitStarted) { | ||
| Thread.sleep(10); | ||
| } | ||
| assertEquals(JVMTI_ERROR_NONE, suspendThread(thread)); | ||
| suspended = true; | ||
| assertTopFrame(thread, TestCase.ValueClass.class, "<clinit>"); | ||
| assertEquals(JVMTI_ERROR_NONE, forceEarlyReturnVoid(thread)); | ||
| } finally { | ||
| TestCase.stop = true; | ||
| if (suspended) resumeThread(thread); | ||
| thread.join(); | ||
| } | ||
| assertFalse(TestCase.ValueClass.initialized); // should not have run to the end | ||
| } | ||
|
|
||
| /** | ||
| * Asserts that the given thread's top frame is the expected class/method. | ||
| */ | ||
| private void assertTopFrame(Thread thread, Class<?> clazz, String methodName) { | ||
| StackTraceElement[] stack = thread.getStackTrace(); | ||
| assertTrue(stack.length > 0); | ||
| assertEquals(clazz.getName(), stack[0].getClassName()); | ||
| assertEquals(methodName, stack[0].getMethodName()); | ||
| } | ||
|
|
||
| private static native int suspendThread(Thread thread); | ||
| private static native int resumeThread(Thread thread); | ||
| private static native int forceEarlyReturnVoid(Thread thread); | ||
| private static native int forceEarlyReturnObject(Thread thread, Object retObject); | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
test/hotspot/jtreg/serviceability/jvmti/ForceEarlyReturn/libForceEarlyReturnValueClass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| #include <string.h> | ||
| #include "jni.h" | ||
| #include "jvmti.h" | ||
|
|
||
| static jvmtiEnv *jvmti; | ||
|
|
||
| extern "C" { | ||
|
|
||
| extern JNIEXPORT jint JNICALL | ||
| Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { | ||
| jvmtiError err; | ||
| jvmtiCapabilities caps; | ||
|
|
||
| if (jvm->GetEnv((void **) &jvmti, JVMTI_VERSION) != JNI_OK) { | ||
| return JNI_ERR; | ||
| } | ||
|
|
||
| memset(&caps, 0, sizeof(caps)); | ||
| caps.can_suspend = 1; | ||
| caps.can_force_early_return = 1; | ||
| err = jvmti->AddCapabilities( &caps); | ||
| if (err != JVMTI_ERROR_NONE) { | ||
| return JNI_ERR; | ||
| } | ||
|
|
||
| return JNI_OK; | ||
| } | ||
|
|
||
| JNIEXPORT jint Java_ForceEarlyReturnValueClass_suspendThread(JNIEnv *env, jclass ignore, jthread target) { | ||
| return (jint) jvmti->SuspendThread(target); | ||
| } | ||
|
|
||
| JNIEXPORT jint Java_ForceEarlyReturnValueClass_resumeThread(JNIEnv *env, jclass ignore, jthread target) { | ||
| return (jint) jvmti->ResumeThread(target); | ||
| } | ||
|
|
||
| JNIEXPORT jint Java_ForceEarlyReturnValueClass_forceEarlyReturnVoid(JNIEnv *env, jclass ignore, jthread target) { | ||
| return (jint) jvmti->ForceEarlyReturnVoid(target); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.