Skip to content

Commit a7f1b72

Browse files
committed
8210984: [TESTBUG] hs203t003 fails with "# ERROR: hs203t003.cpp, 218: NSK_CPP_STUB2 ( ResumeThread, jvmti, thread)"
Backport-of: c0fd523
1 parent 6d1c3c6 commit a7f1b72

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
174174
return JNI_OK;
175175
}
176176

177+
JNIEXPORT jboolean JNICALL
178+
Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_isSuspended(JNIEnv * jni,
179+
jclass clas,
180+
jthread thread) {
181+
jboolean retvalue;
182+
jint state;
183+
retvalue = JNI_FALSE;
184+
if ( ! NSK_JVMTI_VERIFY( NSK_CPP_STUB3(GetThreadState, jvmti, thread, &state) ) ) {
185+
nsk_printf(" Agent :: Error while getting thread state.\n");
186+
nsk_jvmti_agentFailed();
187+
} else {
188+
if ( state & JVMTI_THREAD_STATE_SUSPENDED) {
189+
retvalue = JNI_TRUE;
190+
}
191+
}
192+
return retvalue;
193+
}
177194

178195
JNIEXPORT jboolean JNICALL
179196
Java_nsk_jvmti_scenarios_hotswap_HS203_hs203t003_hs203t003_popThreadFrame(JNIEnv * jni,

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/hotswap/HS203/hs203t003/hs203t003.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
public class hs203t003 extends RedefineAgent {
6363

6464
public native boolean popThreadFrame(Thread thread);
65-
public native boolean resumeThread(Thread thread);
65+
public native boolean isSuspended(Thread thread);
66+
public native boolean resumeThread(Thread thread);
6667

6768

6869
public hs203t003(String[] arg) {
@@ -82,21 +83,37 @@ public boolean agentMethod() {
8283
MyThread mt = new MyThread();
8384
try {
8485
mt.start();
85-
// check if we can can pop the thread.
86-
// we can not do redefine/pop frame on run method.
86+
// Check if we can can pop the thread.
87+
// We can not do redefine/pop frame on run method.
8788
while (!MyThread.resume.get());
88-
// sleep for some few secs to get redefined.
89+
// Sleep for some few secs to get redefined.
8990
while (!isRedefined()) {
9091
if (!agentStatus()) {
9192
System.out.println("Failed to redefine class");
9293
return passed;
9394
}
9495
Thread.sleep(100);
9596
}
96-
popThreadFrame(mt); // pop the frame.
97-
resumeThread(mt); // resume the thread.
97+
// Wait for the thread to be suspended.
98+
while (!isSuspended(mt)) {
99+
if (!agentStatus()) {
100+
System.out.println("Failed to suspend thread");
101+
return passed;
102+
}
103+
Thread.sleep(100);
104+
}
105+
// Pop the frame.
106+
if (!popThreadFrame(mt)) {
107+
System.out.println("Failed to pop a frame = "
108+
+ mt.threadState);
109+
}
110+
// Resume the thread.
111+
if(!resumeThread(mt)) {
112+
System.out.println("Failed to resume the thread = "
113+
+ mt.threadState);
114+
}
115+
// Wait till the other thread completes its execution.
98116
mt.join();
99-
// wait till the other thread completes its execution.
100117
System.out.println("Thread state after popping/redefining = "
101118
+ mt.threadState);
102119
} catch(Exception ie) {

0 commit comments

Comments
 (0)