99 assertEquals(-1L, allocated);
100 });
101 }
102
103 /**
104 * Test that ThreadMXBean.getThreadAllocatedBytes(long[]) returns -1 for
105 * elements that correspond to a virtual thread.
106 */
107 @Test
108 void testGetThreadAllocatedBytes3() {
109 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
110 assumeTrue(bean.isThreadAllocatedMemorySupported(),
111 "Thread memory allocation measurement not supported");
112
113 Thread vthread = Thread.startVirtualThread(LockSupport::park);
114 try {
115 long tid0 = Thread.currentThread().threadId();
116 long tid1 = vthread.threadId();
117 long[] tids = new long[] { tid0, tid1 };
118 long[] allocated = bean.getThreadAllocatedBytes(tids);
119 assertTrue(allocated[0] >= 0L);
120 assertEquals(-1L, allocated[1]);
121 } finally {
122 LockSupport.unpark(vthread);
123 }
124 }
125
126 /**
127 * Test that ThreadMXBean.getThreadCpuTime(long[]) returns -1 for
128 * elements that correspond to a virtual thread.
129 */
130 @Test
131 void testGetThreadCpuTime() {
132 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
133 assumeTrue(bean.isThreadCpuTimeSupported(), "Thread CPU time measurement not supported");
134
135 Thread vthread = Thread.startVirtualThread(LockSupport::park);
136 try {
137 long tid0 = Thread.currentThread().threadId();
138 long tid1 = vthread.threadId();
139 long[] tids = new long[] { tid0, tid1 };
140 long[] cpuTimes = bean.getThreadCpuTime(tids);
141 assertTrue(cpuTimes[0] >= 0L);
142 assertEquals(-1L, cpuTimes[1]);
143 } finally {
144 LockSupport.unpark(vthread);
145 }
146 }
147
148 /**
149 * Test that ThreadMXBean.getThreadUserTime(long[])returns -1 for
150 * elements that correspond to a virtual thread.
151 */
152 @Test
153 void testGetThreadUserTime() {
154 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
155 assumeTrue(bean.isThreadCpuTimeSupported(), "Thread CPU time measurement not supported");
156
157 Thread vthread = Thread.startVirtualThread(LockSupport::park);
158 try {
159 long tid0 = Thread.currentThread().threadId();
160 long tid1 = vthread.threadId();
161 long[] tids = new long[] { tid0, tid1 };
162 long[] userTimes = bean.getThreadUserTime(tids);
163 assertTrue(userTimes[0] >= 0L);
164 assertEquals(-1L, userTimes[1]);
165 } finally {
166 LockSupport.unpark(vthread);
167 }
168 }
169 }
|
99 assertEquals(-1L, allocated);
100 });
101 }
102
103 /**
104 * Test that ThreadMXBean.getThreadAllocatedBytes(long[]) returns -1 for
105 * elements that correspond to a virtual thread.
106 */
107 @Test
108 void testGetThreadAllocatedBytes3() {
109 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
110 assumeTrue(bean.isThreadAllocatedMemorySupported(),
111 "Thread memory allocation measurement not supported");
112
113 Thread vthread = Thread.startVirtualThread(LockSupport::park);
114 try {
115 long tid0 = Thread.currentThread().threadId();
116 long tid1 = vthread.threadId();
117 long[] tids = new long[] { tid0, tid1 };
118 long[] allocated = bean.getThreadAllocatedBytes(tids);
119 if (Thread.currentThread().isVirtual()) {
120 assertEquals(-1L, allocated[0]);
121 } else {
122 assertTrue(allocated[0] >= 0L);
123 }
124 assertEquals(-1L, allocated[1]);
125 } finally {
126 LockSupport.unpark(vthread);
127 }
128 }
129
130 /**
131 * Test that ThreadMXBean.getThreadCpuTime(long[]) returns -1 for
132 * elements that correspond to a virtual thread.
133 */
134 @Test
135 void testGetThreadCpuTime() {
136 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
137 assumeTrue(bean.isThreadCpuTimeSupported(), "Thread CPU time measurement not supported");
138
139 Thread vthread = Thread.startVirtualThread(LockSupport::park);
140 try {
141 long tid0 = Thread.currentThread().threadId();
142 long tid1 = vthread.threadId();
143 long[] tids = new long[] { tid0, tid1 };
144 long[] cpuTimes = bean.getThreadCpuTime(tids);
145 if (Thread.currentThread().isVirtual()) {
146 assertEquals(-1L, cpuTimes[0]);
147 } else {
148 assertTrue(cpuTimes[0] >= 0L);
149 }
150 assertEquals(-1L, cpuTimes[1]);
151 } finally {
152 LockSupport.unpark(vthread);
153 }
154 }
155
156 /**
157 * Test that ThreadMXBean.getThreadUserTime(long[])returns -1 for
158 * elements that correspond to a virtual thread.
159 */
160 @Test
161 void testGetThreadUserTime() {
162 ThreadMXBean bean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
163 assumeTrue(bean.isThreadCpuTimeSupported(), "Thread CPU time measurement not supported");
164
165 Thread vthread = Thread.startVirtualThread(LockSupport::park);
166 try {
167 long tid0 = Thread.currentThread().threadId();
168 long tid1 = vthread.threadId();
169 long[] tids = new long[] { tid0, tid1 };
170 long[] userTimes = bean.getThreadUserTime(tids);
171 if (Thread.currentThread().isVirtual()) {
172 assertEquals(-1L, userTimes[0]);
173 } else {
174 assertTrue(userTimes[0] >= 0L);
175 }
176 assertEquals(-1L, userTimes[1]);
177 } finally {
178 LockSupport.unpark(vthread);
179 }
180 }
181 }
|