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
0 commit comments