Skip to content

Commit b0f59f6

Browse files
committed
8373127: Update nsk/monitoring tests to support virtual thread factory testing
Reviewed-by: kevinw, amenkov
1 parent 2596608 commit b0f59f6

7 files changed

Lines changed: 87 additions & 40 deletions

File tree

test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryUsage/from/from001/TestDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -43,6 +43,7 @@
4343
* 5014783 Move ThreadState class from java.lang.management to java.lang
4444
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
4545
*
46+
* @requires test.thread.factory != "Virtual"
4647
* @library /vmTestbase
4748
* /test/lib
4849
* @run main/othervm nsk.monitoring.MemoryUsage.from.from001 -testMode=server

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadInfo/from_c/from_c001/TestDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -43,6 +43,7 @@
4343
* 5014783 Move ThreadState class from java.lang.management to java.lang
4444
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
4545
*
46+
* @requires test.thread.factory != "Virtual"
4647
* @library /vmTestbase
4748
* /test/lib
4849
* @run main/othervm nsk.monitoring.ThreadInfo.from_c.from_c001 -testMode=server -MBeanServer=custom

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadInfo/getLockName/getlockname001/TestDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -47,6 +47,7 @@
4747
* Updated according to:
4848
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
4949
*
50+
* @requires test.thread.factory != "Virtual"
5051
* @library /vmTestbase
5152
* /test/lib
5253
* @run main/othervm nsk.monitoring.ThreadInfo.getLockName.getlockname001

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadInfo/getLockOwnerName/getlockownername001/TestDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -42,6 +42,7 @@
4242
* Updated according to:
4343
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
4444
*
45+
* @requires test.thread.factory != "Virtual"
4546
* @library /vmTestbase
4647
* /test/lib
4748
* @run main/othervm nsk.monitoring.ThreadInfo.getLockOwnerName.getlockownername001

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadInfo/isInNative/isinnative001/TestDescription.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 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
@@ -41,6 +41,7 @@
4141
* Updated according to:
4242
* 5024531 Fix MBeans design flaw that restricts to use JMX CompositeData
4343
*
44+
* @requires test.thread.factory != "Virtual"
4445
* @library /vmTestbase
4546
* /test/lib
4647
* @run main/othervm nsk.monitoring.ThreadInfo.isInNative.isinnative001

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadMXBean/GetThreadAllocatedBytes/BaseBehaviorTest.java

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 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
@@ -59,16 +59,30 @@ public void run() {
5959
+ "return -1 if ThreadAllocatedMemoryEnabled is set to false. "
6060
+ "Received : " + result);
6161
threadMXBean.setThreadAllocatedMemoryEnabled(true);
62-
// Expect >= 0 value for current thread
62+
// Expect >= 0 value for current platform thread.
6363
result = threadMXBean.getCurrentThreadAllocatedBytes();
64-
if (result < 0)
65-
throw new TestFailure("Failure! getCurrentThreadAllocatedBytes() should "
66-
+ "return >= 0 value for current thread. Received : " + result);
67-
// Expect >= 0 value for current thread from getThreadAllocatedBytes(id)
64+
if (Thread.currentThread().isVirtual()) {
65+
if (result != -1)
66+
throw new TestFailure("Failure! getCurrentThreadAllocatedBytes() should "
67+
+ "return -1 for virtual thread. "
68+
+ "Received : " + result);
69+
} else {
70+
if (result < 0)
71+
throw new TestFailure("Failure! getCurrentThreadAllocatedBytes() should "
72+
+ "return >= 0 value for current thread. Received : " + result);
73+
}
74+
// Expect >= 0 value for current iplatform thread from getThreadAllocatedBytes(id).
6875
result = threadMXBean.getThreadAllocatedBytes(Thread.currentThread().getId());
69-
if (result < 0)
70-
throw new TestFailure("Failure! getThreadAllocatedBytes(id) should "
71-
+ "return >= 0 value for current thread. Received : " + result);
76+
if (Thread.currentThread().isVirtual()) {
77+
if (result != -1)
78+
throw new TestFailure("Failure! getThreadAllocatedBytes(id) should "
79+
+ "return -1 for virtual thread. "
80+
+ "Received : " + result);
81+
} else {
82+
if (result < 0)
83+
throw new TestFailure("Failure! getThreadAllocatedBytes(id) should "
84+
+ "return >= 0 value for current thread. Received : " + result);
85+
}
7286

7387
MXBeanTestThread thread = new MXBeanTestThread();
7488
long id = thread.getId();
@@ -79,11 +93,11 @@ public void run() {
7993
result = threadMXBean.getThreadAllocatedBytes(id);
8094
if (result != -1)
8195
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
82-
+ "return -1 for not started threads. Recieved : " + result);
96+
+ "return -1 for not started threads. Received : " + result);
8397
resultArr = threadMXBean.getThreadAllocatedBytes(idArr);
8498
if (resultArr[0] != -1)
8599
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
86-
+ "return -1 for not started threads. Recieved : " + resultArr[0]);
100+
+ "return -1 for not started threads. Received : " + resultArr[0]);
87101
BarrierHandler handler = startThreads(thread);
88102
try {
89103
handler.proceed();
@@ -93,23 +107,37 @@ public void run() {
93107
if (result != -1)
94108
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
95109
+ "return -1 if ThreadAllocatedMemoryEnabled is set to false. "
96-
+ "Recieved : " + result);
110+
+ "Received : " + result);
97111
resultArr = threadMXBean.getThreadAllocatedBytes(idArr);
98112
if (resultArr[0] != -1)
99113
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
100114
+ "return -1 if ThreadAllocatedMemoryEnabled is set to false. "
101-
+ "Recieved : " + resultArr[0]);
115+
+ "Received : " + resultArr[0]);
102116

103117
threadMXBean.setThreadAllocatedMemoryEnabled(true);
104118
// Expect >= 0 value for running threads
105119
result = threadMXBean.getThreadAllocatedBytes(id);
106-
if (result < 0)
107-
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
108-
+ "return > 0 value for RUNNING thread. Recieved : " + result);
120+
if (thread.isVirtual()) {
121+
if (result != -1)
122+
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
123+
+ "return -1 for virtual thread. "
124+
+ "Received : " + result);
125+
} else {
126+
if (result < 0)
127+
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
128+
+ "return > 0 value for RUNNING thread. Received : " + result);
129+
}
109130
resultArr = threadMXBean.getThreadAllocatedBytes(idArr);
110-
if (resultArr[0] < 0)
111-
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
112-
+ "return > 0 value for RUNNING thread. Recieved : " + resultArr[0]);
131+
if (thread.isVirtual()) {
132+
if (resultArr[0] != -1)
133+
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
134+
+ "return -1 for virtual thread. "
135+
+ "Received : " + resultArr[0]);
136+
} else {
137+
if (resultArr[0] < 0)
138+
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
139+
+ "return > 0 value for RUNNING thread. Received : " + resultArr[0]);
140+
}
113141
} finally {
114142
// Let thread finish
115143
handler.finish();
@@ -121,11 +149,11 @@ public void run() {
121149
result = threadMXBean.getThreadAllocatedBytes(id);
122150
if (result != -1)
123151
throw new TestFailure("Failure! getThreadAllocatedBytes(long id) should "
124-
+ "return -1 for finished threads. Recieved : " + result);
152+
+ "return -1 for finished threads. Received : " + result);
125153
resultArr = threadMXBean.getThreadAllocatedBytes(idArr);
126154
if (resultArr[0] != -1)
127155
throw new TestFailure("Failure! getThreadAllocatedBytes(long[] ids) should "
128-
+ "return -1 for finished threads. Recieved : " + resultArr[0]);
156+
+ "return -1 for finished threads. Received : " + resultArr[0]);
129157
log.info("BaseBehaviorTest passed.");
130158
}
131159

test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadMXBean/GetThreadCpuTime/BaseBehaviorTest.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 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
@@ -57,11 +57,11 @@ public void run() {
5757
resultArr = threadMXBean.getThreadCpuTime(idArr);
5858
if (resultArr[0] != -1)
5959
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
60-
+ "return -1 for not started threads. Recieved : " + resultArr[0]);
60+
+ "return -1 for not started threads. Received : " + resultArr[0]);
6161
resultArr = threadMXBean.getThreadUserTime(idArr);
6262
if (resultArr[0] != -1)
6363
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
64-
+ "return -1 for not started threads. Recieved : " + resultArr[0]);
64+
+ "return -1 for not started threads. Received : " + resultArr[0]);
6565
BarrierHandler handler = startThreads(thread);
6666
try {
6767
handler.proceed();
@@ -71,22 +71,36 @@ public void run() {
7171
if (resultArr[0] != -1)
7272
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
7373
+ "return -1 if threadCpuTimeEnabled is set to false. "
74-
+ "Recieved : " + resultArr[0]);
74+
+ "Received : " + resultArr[0]);
7575
resultArr = threadMXBean.getThreadUserTime(idArr);
7676
if (resultArr[0] != -1)
7777
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
7878
+ "return -1 if threadCpuTimeEnabled is set to false. "
79-
+ "Recieved : " + resultArr[0]);
79+
+ "Received : " + resultArr[0]);
8080
threadMXBean.setThreadCpuTimeEnabled(true);
81-
// Expect > 0 value for running threads
81+
// Expect > 0 value for running platform threads and -1 for virtual threads.
8282
resultArr = threadMXBean.getThreadCpuTime(idArr);
83-
if (resultArr[0] < 0)
84-
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
85-
+ "return > 0 value for RUNNING thread. Recieved : " + resultArr[0]);
83+
if (thread.isVirtual()) {
84+
if (resultArr[0] != -1)
85+
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
86+
+ "return -1 for virtual threads."
87+
+ "Received : " + resultArr[0]);
88+
} else {
89+
if (resultArr[0] < 0)
90+
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
91+
+ "return > 0 value for RUNNING thread. Received : " + resultArr[0]);
92+
}
8693
resultArr = threadMXBean.getThreadUserTime(idArr);
87-
if (resultArr[0] < 0)
88-
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
89-
+ "return > 0 value for RUNNING thread. Recieved : " + resultArr[0]);
94+
if (thread.isVirtual()) {
95+
if (resultArr[0] != -1)
96+
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
97+
+ "return -1 for virtual threads."
98+
+ "Received : " + resultArr[0]);
99+
} else {
100+
if (resultArr[0] < 0)
101+
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
102+
+ "return > 0 value for RUNNING thread. Received : " + resultArr[0]);
103+
}
90104
} finally {
91105
// Let thread finish
92106
handler.finish();
@@ -98,11 +112,11 @@ public void run() {
98112
resultArr = threadMXBean.getThreadCpuTime(idArr);
99113
if (resultArr[0] != -1)
100114
throw new TestFailure("Failure! getThreadCpuTime(long[] ids) should "
101-
+ "return -1 for finished threads. Recieved : " + resultArr[0]);
115+
+ "return -1 for finished threads. Received : " + resultArr[0]);
102116
resultArr = threadMXBean.getThreadUserTime(idArr);
103117
if (resultArr[0] != -1)
104118
throw new TestFailure("Failure! getThreadUserTime(long[] ids) should "
105-
+ "return -1 for finished threads. Recieved : " + resultArr[0]);
119+
+ "return -1 for finished threads. Received : " + resultArr[0]);
106120
log.info("BaseBehaviorTest passed.");
107121
}
108122

0 commit comments

Comments
 (0)