Skip to content

Commit 3c26fdd

Browse files
committed
Backport c90cd2c0608d250434bff7013360b8388d9854b3
1 parent 23901f3 commit 3c26fdd

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, 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
@@ -55,7 +55,7 @@
5555
* When test thread has finish execution debugger suspends thread and call command for this thread, INVALID_THREAD
5656
* error is expected, then, debugger resumes test thread and call command again, INVALID_THREAD error should
5757
* be returned in reply.
58-
* - debuggee starts test thread which executes infinite loop in native method, debugger calls command for
58+
* - debuggee starts test thread which executes loop in native method, debugger calls command for
5959
* this thread(without suspending) and expects THREAD_NOT_SUSPENDED error. Then, debugger suspends this thread
6060
* and calls command again, OPAQUE_FRAME error is expected.
6161
* - debugger creates ThreadStartEventRequest with suspend policy 'JDWP.SuspendPolicy.ALL' and forces debuggee start new thread.
@@ -248,6 +248,9 @@ public void doTest() {
248248
// suspended thread in native, expect OPAQUE_FRAME error
249249
sendCommand(threadID, value, true, JDWP.Error.OPAQUE_FRAME);
250250

251+
// signal native method to exit; the thread will be actually suspended
252+
pipe.println(forceEarlyReturn002a.COMMAND_EXIT_THREAD_IN_NATIVE);
253+
251254
// create request for ThreadStart event
252255
int requestID = createThreadStartEventRequest();
253256

test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002a.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, 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
@@ -40,6 +40,8 @@ public class forceEarlyReturn002a extends AbstractJDWPDebuggee {
4040

4141
public final static String COMMAND_STOP_THREAD_IN_NATIVE = "stopInNative";
4242

43+
public final static String COMMAND_EXIT_THREAD_IN_NATIVE = "exitInNative";
44+
4345
public final static String COMMAND_START_NEW_THREAD = "startNewThread";
4446

4547
public boolean parseCommand(String command) {
@@ -49,6 +51,10 @@ public boolean parseCommand(String command) {
4951
if (command.equals(COMMAND_STOP_THREAD_IN_NATIVE)) {
5052
stopThreadInNative();
5153

54+
return true;
55+
} else if (command.equals(COMMAND_EXIT_THREAD_IN_NATIVE)) {
56+
exitThreadInNative();
57+
5258
return true;
5359
} else if (command.equals(COMMAND_START_NEW_THREAD)) {
5460
testNewThread.start();
@@ -95,6 +101,8 @@ public void run() {
95101

96102
private static native int nativeMethod(Object object);
97103

104+
private static native void exitThreadInNative();
105+
98106
public static void main(String args[]) {
99107
new forceEarlyReturn002a().doTest(args);
100108
}

test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/libforceEarlyReturn002a.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, 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
@@ -23,23 +23,46 @@
2323

2424
#include "jni.h"
2525

26+
#if defined(_WIN32)
27+
#include <windows.h>
28+
#else
29+
#include <unistd.h>
30+
#endif
31+
32+
#include <atomic>
33+
2634
extern "C" {
2735

36+
static std::atomic<bool> wait_in_native(true);
37+
38+
static void delay(int seconds) {
39+
#if defined(_WIN32)
40+
Sleep(1000L * seconds);
41+
#else
42+
sleep(seconds);
43+
#endif
44+
}
2845

2946
JNIEXPORT jint JNICALL
3047
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_nativeMethod(JNIEnv *env, jobject classObject, jobject object)
3148
{
32-
static volatile int dummy_counter = 0;
3349
// notify another thread that thread in native method
3450
jclass klass = env->GetObjectClass(object);
3551
jfieldID field = env->GetFieldID(klass, "threadInNative", "Z");
3652
env->SetBooleanField(object, field, 1);
3753

3854
// execute infinite loop to be sure that thread in native method
39-
while (dummy_counter == 0) {}
55+
while (wait_in_native) {
56+
delay(1);
57+
}
4058

41-
// Should not reach here
4259
return 0;
4360
}
4461

62+
JNIEXPORT void JNICALL
63+
Java_nsk_jdwp_ThreadReference_ForceEarlyReturn_forceEarlyReturn002_forceEarlyReturn002a_exitThreadInNative(JNIEnv *env, jobject classObject)
64+
{
65+
wait_in_native = false;
66+
}
67+
4568
}

0 commit comments

Comments
 (0)