Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/instrument/GetObjectSizeIntrinsicsTest.java
41149 views
1
/*
2
* Copyright (c) 2020, Red Hat, Inc. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8253525
27
* @summary Test for fInst.getObjectSize with 32-bit compressed oops
28
* @library /test/lib
29
*
30
* @build sun.hotspot.WhiteBox
31
* @run build GetObjectSizeIntrinsicsTest
32
* @run shell MakeJAR.sh basicAgent
33
*
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
*
36
* @run main/othervm -Xmx128m
37
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
38
* -Xint
39
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
40
*
41
* @run main/othervm -Xmx128m
42
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
43
* -Xbatch -XX:TieredStopAtLevel=1
44
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
45
*
46
* @run main/othervm -Xmx128m
47
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
48
* -Xbatch -XX:-TieredCompilation
49
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
50
*/
51
52
/*
53
* @test
54
* @summary Test for fInst.getObjectSize with zero-based compressed oops
55
* @library /test/lib
56
* @requires vm.bits == 64
57
*
58
* @build sun.hotspot.WhiteBox
59
* @run build GetObjectSizeIntrinsicsTest
60
* @run shell MakeJAR.sh basicAgent
61
*
62
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
63
*
64
* @run main/othervm -Xmx4g
65
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
66
* -Xint
67
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
68
*
69
* @run main/othervm -Xmx4g
70
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
71
* -Xbatch -XX:TieredStopAtLevel=1
72
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
73
*
74
* @run main/othervm -Xmx4g
75
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
76
* -Xbatch -XX:-TieredCompilation
77
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
78
*/
79
80
/*
81
* @test
82
* @summary Test for fInst.getObjectSize without compressed oops
83
* @library /test/lib
84
* @requires vm.bits == 64
85
*
86
* @build sun.hotspot.WhiteBox
87
* @run build GetObjectSizeIntrinsicsTest
88
* @run shell MakeJAR.sh basicAgent
89
*
90
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
91
*
92
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
93
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
94
* -Xint
95
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
96
*
97
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
98
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
99
* -Xbatch -XX:TieredStopAtLevel=1
100
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
101
*
102
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
103
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
104
* -Xbatch -XX:-TieredCompilation
105
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
106
*/
107
108
/*
109
* @test
110
* @summary Test for fInst.getObjectSize with 32-bit compressed oops
111
* @library /test/lib
112
* @requires vm.debug
113
*
114
* @build sun.hotspot.WhiteBox
115
* @run build GetObjectSizeIntrinsicsTest
116
* @run shell MakeJAR.sh basicAgent
117
*
118
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
119
*
120
* @run main/othervm -Xmx128m
121
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
122
* -XX:FastAllocateSizeLimit=0
123
* -Xint
124
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
125
*
126
* @run main/othervm -Xmx128m
127
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
128
* -XX:FastAllocateSizeLimit=0
129
* -Xbatch -XX:TieredStopAtLevel=1
130
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
131
*
132
* @run main/othervm -Xmx128m
133
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
134
* -XX:FastAllocateSizeLimit=0
135
* -Xbatch -XX:-TieredCompilation
136
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
137
*/
138
139
/*
140
* @test
141
* @summary Test for fInst.getObjectSize with zero-based compressed oops
142
* @library /test/lib
143
* @requires vm.bits == 64
144
* @requires vm.debug
145
*
146
* @build sun.hotspot.WhiteBox
147
* @run build GetObjectSizeIntrinsicsTest
148
* @run shell MakeJAR.sh basicAgent
149
*
150
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
151
*
152
* @run main/othervm -Xmx4g
153
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
154
* -XX:FastAllocateSizeLimit=0
155
* -Xint
156
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
157
*
158
* @run main/othervm -Xmx4g
159
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
160
* -XX:FastAllocateSizeLimit=0
161
* -Xbatch -XX:TieredStopAtLevel=1
162
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
163
*
164
* @run main/othervm -Xmx4g
165
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
166
* -XX:FastAllocateSizeLimit=0
167
* -Xbatch -XX:-TieredCompilation
168
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
169
*/
170
171
/*
172
* @test
173
* @summary Test for fInst.getObjectSize without compressed oops
174
* @library /test/lib
175
* @requires vm.bits == 64
176
* @requires vm.debug
177
*
178
* @build sun.hotspot.WhiteBox
179
* @run build GetObjectSizeIntrinsicsTest
180
* @run shell MakeJAR.sh basicAgent
181
*
182
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
183
*
184
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
185
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
186
* -XX:FastAllocateSizeLimit=0
187
* -Xint
188
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
189
*
190
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
191
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
192
* -XX:FastAllocateSizeLimit=0
193
* -Xbatch -XX:TieredStopAtLevel=1
194
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
195
*
196
* @run main/othervm -Xmx128m -XX:-UseCompressedOops
197
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
198
* -XX:FastAllocateSizeLimit=0
199
* -Xbatch -XX:-TieredCompilation
200
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
201
*/
202
203
/*
204
* @test
205
* @summary Test for fInst.getObjectSize with 32-bit compressed oops
206
* @library /test/lib
207
* @requires vm.bits == 64
208
* @requires vm.debug
209
*
210
* @build sun.hotspot.WhiteBox
211
* @run build GetObjectSizeIntrinsicsTest
212
* @run shell MakeJAR.sh basicAgent
213
*
214
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
215
*
216
* @run main/othervm -Xmx128m
217
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
218
* -XX:ObjectAlignmentInBytes=32
219
* -Xint
220
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
221
*
222
* @run main/othervm -Xmx128m
223
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
224
* -XX:ObjectAlignmentInBytes=32
225
* -Xbatch -XX:TieredStopAtLevel=1
226
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
227
*
228
* @run main/othervm -Xmx128m
229
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
230
* -XX:ObjectAlignmentInBytes=32
231
* -Xbatch -XX:-TieredCompilation
232
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
233
*/
234
235
/*
236
* @test
237
* @summary Test for fInst.getObjectSize with zero-based compressed oops
238
* @library /test/lib
239
* @requires vm.bits == 64
240
* @requires vm.debug
241
*
242
* @build sun.hotspot.WhiteBox
243
* @run build GetObjectSizeIntrinsicsTest
244
* @run shell MakeJAR.sh basicAgent
245
*
246
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
247
*
248
* @run main/othervm -Xmx4g
249
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
250
* -XX:ObjectAlignmentInBytes=32
251
* -Xint
252
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
253
*
254
* @run main/othervm -Xmx4g
255
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
256
* -XX:ObjectAlignmentInBytes=32
257
* -Xbatch -XX:TieredStopAtLevel=1
258
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
259
*
260
* @run main/othervm -Xmx4g
261
* -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
262
* -XX:ObjectAlignmentInBytes=32
263
* -Xbatch -XX:-TieredCompilation
264
* -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest
265
*/
266
267
import java.util.*;
268
269
import jdk.test.lib.Platform;
270
import sun.hotspot.WhiteBox;
271
272
public class GetObjectSizeIntrinsicsTest extends ASimpleInstrumentationTestCase {
273
274
static final Boolean compressedOops = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedOops");
275
static final int REF_SIZE = (compressedOops == null || compressedOops == true) ? 4 : 8;
276
277
static final Long align = WhiteBox.getWhiteBox().getIntxVMFlag("ObjectAlignmentInBytes");
278
static final int OBJ_ALIGN = (align == null ? 8 : align.intValue());
279
280
public GetObjectSizeIntrinsicsTest(String name) {
281
super(name);
282
}
283
284
public static void main(String[] args)throws Throwable {
285
new GetObjectSizeIntrinsicsTest(args[0]).runTest();
286
}
287
288
public static final int ITERS = 200_000;
289
290
public static void assertEquals(long expected, long actual) {
291
if (expected != actual) {
292
throw new IllegalStateException(
293
"Error: expected: " + expected + " (" + Long.toHexString(expected) +
294
"), actual: " + actual + " (" + Long.toHexString(actual) + ")");
295
}
296
}
297
298
public static void assertNotEquals(long notExpected, long actual) {
299
if (notExpected == actual) {
300
throw new IllegalStateException(
301
"Error: not expected: " + notExpected + " (" + Long.toHexString(notExpected) +
302
"), actual: " + actual + " (" + Long.toHexString(actual) + ")");
303
}
304
}
305
306
public static void assertFail() {
307
throw new IllegalStateException("Should not be here");
308
}
309
310
protected final void doRunTest() throws Throwable {
311
testSize_newObject();
312
testSize_localObject();
313
testSize_fieldObject();
314
315
testSize_newSmallByteArray();
316
testSize_localSmallByteArray();
317
testSize_fieldSmallByteArray();
318
319
testSize_newSmallObjArray();
320
testSize_localSmallObjArray();
321
testSize_fieldSmallObjArray();
322
323
testNulls();
324
}
325
326
private static int roundUp(int v, int a) {
327
return (v + a - 1) / a * a;
328
}
329
330
private void testSize_newObject() {
331
int expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
332
for (int c = 0; c < ITERS; c++) {
333
assertEquals(expected, fInst.getObjectSize(new Object()));
334
}
335
}
336
337
private void testSize_localObject() {
338
int expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
339
Object o = new Object();
340
for (int c = 0; c < ITERS; c++) {
341
assertEquals(expected, fInst.getObjectSize(o));
342
}
343
}
344
345
static Object staticO = new Object();
346
347
private void testSize_fieldObject() {
348
int expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
349
for (int c = 0; c < ITERS; c++) {
350
assertEquals(expected, fInst.getObjectSize(staticO));
351
}
352
}
353
354
private void testSize_newSmallByteArray() {
355
int expected = roundUp(1024 + 16, OBJ_ALIGN);
356
for (int c = 0; c < ITERS; c++) {
357
assertEquals(expected, fInst.getObjectSize(new byte[1024]));
358
}
359
}
360
361
private void testSize_localSmallByteArray() {
362
byte[] arr = new byte[1024];
363
int expected = roundUp(arr.length + 16, OBJ_ALIGN);
364
for (int c = 0; c < ITERS; c++) {
365
assertEquals(expected, fInst.getObjectSize(arr));
366
}
367
}
368
369
static byte[] smallArr = new byte[1024];
370
371
private void testSize_fieldSmallByteArray() {
372
int expected = roundUp(smallArr.length + 16, OBJ_ALIGN);
373
for (int c = 0; c < ITERS; c++) {
374
assertEquals(expected, fInst.getObjectSize(smallArr));
375
}
376
}
377
378
private void testSize_newSmallObjArray() {
379
int expected = roundUp(1024*REF_SIZE + 16, OBJ_ALIGN);
380
for (int c = 0; c < ITERS; c++) {
381
assertEquals(expected, fInst.getObjectSize(new Object[1024]));
382
}
383
}
384
385
private void testSize_localSmallObjArray() {
386
Object[] arr = new Object[1024];
387
int expected = roundUp(arr.length*REF_SIZE + 16, OBJ_ALIGN);
388
for (int c = 0; c < ITERS; c++) {
389
assertEquals(expected, fInst.getObjectSize(arr));
390
}
391
}
392
393
static Object[] smallObjArr = new Object[1024];
394
395
private void testSize_fieldSmallObjArray() {
396
int expected = roundUp(smallArr.length*REF_SIZE + 16, OBJ_ALIGN);
397
for (int c = 0; c < ITERS; c++) {
398
assertEquals(expected, fInst.getObjectSize(smallObjArr));
399
}
400
}
401
402
private void testNulls() {
403
for (int c = 0; c < ITERS; c++) {
404
try {
405
fInst.getObjectSize(null);
406
assertFail();
407
} catch (NullPointerException e) {
408
// expected
409
}
410
}
411
}
412
413
}
414
415