Skip to content

Commit 8344179

Browse files
committed
Review comments
1 parent e011e19 commit 8344179

File tree

4 files changed

+19
-56
lines changed

4 files changed

+19
-56
lines changed

test/hotspot/jtreg/runtime/Monitor/MonitorWithDeadObjectTest.java

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
*/
2424

2525
/*
26+
* @bug 8320515
2627
* @summary This test checks that ObjectMonitors with dead objects don't
2728
cause asserts, crashes, or failures when various sub-systems
2829
in the JVM find them.
29-
* @requires os.family != "windows"
30+
* @requires os.family != "windows" & os.family != "aix"
3031
* @library /testlibrary /test/lib
3132
* @modules jdk.management
3233
*/
@@ -42,25 +43,17 @@
4243
*/
4344

4445
/*
45-
* @test id=DumpThreadsAfterDetachBeforeJoin
46+
* @test id=DumpThreadsAfterDetach
4647
* @run main/othervm/native MonitorWithDeadObjectTest 2
4748
*/
4849

49-
/*
50-
* @test id=DumpThreadsAfterDetachAfterJoin
51-
* @run main/othervm/native MonitorWithDeadObjectTest 3
52-
*/
53-
5450
import java.lang.management.ManagementFactory;
5551
import java.lang.management.ThreadMXBean;
5652

5753
public class MonitorWithDeadObjectTest {
5854
public static native void createMonitorWithDeadObject();
59-
public static native void createMonitorWithDeadObjectNoJoin();
6055
public static native void createMonitorWithDeadObjectDumpThreadsBeforeDetach();
6156

62-
public static native void joinTestThread();
63-
6457
static {
6558
System.loadLibrary("MonitorWithDeadObjectTest");
6659
}
@@ -72,7 +65,8 @@ private static void dumpThreadsWithLockedMonitors() {
7265

7366
private static void testDetachThread() {
7467
// Create an ObjectMonitor with a dead object from an
75-
// attached thread.
68+
// attached thread. This used to provoke an assert
69+
// in DetachCurrentThread.
7670
createMonitorWithDeadObject();
7771
}
7872

@@ -83,26 +77,13 @@ private static void testDumpThreadsBeforeDetach() {
8377
createMonitorWithDeadObjectDumpThreadsBeforeDetach();
8478
}
8579

86-
private static void testDumpThreadsAfterDetachBeforeJoin() {
87-
createMonitorWithDeadObjectNoJoin();
88-
89-
// After createMonitorWithDeadObjectNoJoin has been called, there's an
90-
// "owned" monitor with a dead object. The thread dumping code used to
91-
// not tolerate such a monitor and would assert. Run a thread dump
92-
// and make sure that it doesn't crash/assert.
93-
dumpThreadsWithLockedMonitors();
94-
95-
joinTestThread();
96-
}
97-
98-
private static void testDumpThreadsAfterDetachAfterJoin() {
99-
createMonitorWithDeadObjectNoJoin();
100-
joinTestThread();
80+
private static void testDumpThreadsAfterDetach() {
81+
createMonitorWithDeadObject();
10182

102-
// After createMonitorWithDeadObjectNoJoin has been called, there's an
103-
// "owned" monitor with a dead object. The thread dumping code used to
104-
// not tolerate such a monitor and would assert. Run a thread dump
105-
// and make sure that it doesn't crash/assert.
83+
// After createMonitorWithDeadObject has been called, there's an "owned"
84+
// monitor with a dead object. The thread dumping code used to not
85+
// tolerate such a monitor and would assert. Run a thread dump and make
86+
// sure that it doesn't crash/assert.
10687
dumpThreadsWithLockedMonitors();
10788
}
10889

@@ -111,8 +92,7 @@ public static void main(String[] args) throws Exception {
11192
switch (test) {
11293
case 0: testDetachThread(); break;
11394
case 1: testDumpThreadsBeforeDetach(); break;
114-
case 2: testDumpThreadsAfterDetachBeforeJoin(); break;
115-
case 3: testDumpThreadsAfterDetachAfterJoin(); break;
95+
case 2: testDumpThreadsAfterDetach(); break;
11696
default: throw new RuntimeException("Unknown test");
11797
};
11898
}

test/hotspot/jtreg/runtime/Monitor/libMonitorWithDeadObjectTest.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static void* create_monitor_with_dead_object_in_thread() {
127127
// assert that we didn't have "owned" monitors with dead objects. This
128128
// test provokes that situation and that asserts.
129129
if ((*jvm)->DetachCurrentThread(jvm) != JNI_OK) die("DetachCurrentThread");
130-
pthread_exit(NULL);
131130

132131
return NULL;
133132
}
@@ -146,45 +145,25 @@ static void* create_monitor_with_dead_object_and_dump_threads_in_thread() {
146145
thread_dump_with_locked_monitors(env);
147146

148147
if ((*jvm)->DetachCurrentThread(jvm) != JNI_OK) die("DetachCurrentThread");
149-
pthread_exit(NULL);
150148

151149
return NULL;
152150
}
153151

154152
JNIEXPORT void JNICALL Java_MonitorWithDeadObjectTest_createMonitorWithDeadObject(JNIEnv* env, jclass jc) {
155-
pthread_attr_t attr;
156153
void* ret;
157154

158155
(*env)->GetJavaVM(env, &jvm);
159156

160-
if (pthread_attr_init(&attr) != 0) die("pthread_attr_init");
161-
if (pthread_create(&attacher, &attr, create_monitor_with_dead_object_in_thread, NULL) != 0) die("pthread_create");
157+
if (pthread_create(&attacher, NULL, create_monitor_with_dead_object_in_thread, NULL) != 0) die("pthread_create");
162158
if (pthread_join(attacher, &ret) != 0) die("pthread_join");
163159
}
164160

165-
JNIEXPORT void JNICALL Java_MonitorWithDeadObjectTest_createMonitorWithDeadObjectNoJoin(JNIEnv* env, jclass jc) {
166-
pthread_attr_t attr;
167-
void* ret;
168-
169-
(*env)->GetJavaVM(env, &jvm);
170-
171-
if (pthread_attr_init(&attr) != 0) die("pthread_attr_init");
172-
if (pthread_create(&attacher, &attr, create_monitor_with_dead_object_in_thread, NULL) != 0) die("pthread_create");
173-
}
174-
175161
JNIEXPORT void JNICALL Java_MonitorWithDeadObjectTest_createMonitorWithDeadObjectDumpThreadsBeforeDetach(JNIEnv* env, jclass jc) {
176-
pthread_attr_t attr;
177162
void* ret;
178163

179164
(*env)->GetJavaVM(env, &jvm);
180165

181-
if (pthread_attr_init(&attr) != 0) die("pthread_attr_init");
182-
if (pthread_create(&attacher, &attr, create_monitor_with_dead_object_and_dump_threads_in_thread, NULL) != 0) die("pthread_create");
183-
if (pthread_join(attacher, &ret) != 0) die("pthread_join");
184-
}
185-
186-
JNIEXPORT void JNICALL Java_MonitorWithDeadObjectTest_joinTestThread(JNIEnv* env, jclass jc) {
187-
void* ret;
166+
if (pthread_create(&attacher, NULL, create_monitor_with_dead_object_and_dump_threads_in_thread, NULL) != 0) die("pthread_create");
188167
if (pthread_join(attacher, &ret) != 0) die("pthread_join");
189168
}
190169

test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo/GetOwnedMonitorInfoTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static void jniMonitorEnterAndLetObjectDie() {
5555
// assert when an owned monitor with a dead object was found.
5656
// Inject this situation into this test that performs other
5757
// GetOwnedMonitorInfo testing.
58-
Object obj = new Object() { public String toString() {return "";} };
58+
Object obj = new Object() {};
5959
jniMonitorEnter(obj);
6060
if (!Thread.holdsLock(obj)) {
6161
throw new RuntimeException("The object is not locked");
@@ -76,6 +76,8 @@ public static void runTest(boolean isVirtual, boolean jni) throws Exception {
7676
final GetOwnedMonitorInfoTest lock = new GetOwnedMonitorInfoTest();
7777

7878
Thread t1 = threadFactory.newThread(() -> {
79+
Thread.currentThread().setName("Worker-Thread");
80+
7981
if (jni) {
8082
jniMonitorEnterAndLetObjectDie();
8183
}

test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo/libGetOwnedMonitorInfoTest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include <stdio.h>
25+
#include <stdlib.h>
2526
#include <string.h>
2627
#include "jvmti.h"
2728
#include "jni.h"
@@ -268,6 +269,7 @@ JNIEXPORT void JNICALL
268269
Java_GetOwnedMonitorInfoTest_jniMonitorEnter(JNIEnv* env, jclass cls, jobject obj) {
269270
if ((*env)->MonitorEnter(env, obj) != 0) {
270271
fprintf(stderr, "MonitorEnter failed");
272+
exit(-1);
271273
}
272274
}
273275

0 commit comments

Comments
 (0)