< prev index next >

test/jdk/java/lang/instrument/GetObjectSizeIntrinsicsTest.java

Print this page

284  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
285  *
286  * @run main/othervm/timeout=240 -Xmx8g
287  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
288  *                   -Xbatch -XX:TieredStopAtLevel=1
289  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
290  *
291  * @run main/othervm/timeout=180 -Xmx8g
292  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
293  *                   -Xbatch -XX:-TieredCompilation
294  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
295  */
296 
297 import java.util.*;
298 
299 import jdk.test.lib.Platform;
300 import jdk.test.whitebox.WhiteBox;
301 
302 public class GetObjectSizeIntrinsicsTest extends ASimpleInstrumentationTestCase {
303 

304     static final Boolean COMPRESSED_OOPS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedOops");
305     static final long REF_SIZE = (COMPRESSED_OOPS == null || COMPRESSED_OOPS == true) ? 4 : 8;
306 
307     static final Long align = WhiteBox.getWhiteBox().getIntVMFlag("ObjectAlignmentInBytes");
308     static final int OBJ_ALIGN = (align == null ? 8 : align.intValue());
309 
310     static final int SMALL_ARRAY_SIZE = 1024;
311 
312     // These should overflow 4G size boundary
313     static final int LARGE_INT_ARRAY_SIZE = 1024*1024*1024 + 1024;
314     static final int LARGE_OBJ_ARRAY_SIZE = (4096/(int)REF_SIZE)*1024*1024 + 1024;
315 
316     static final boolean CCP = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
317     static final int ARRAY_HEADER_SIZE = CCP ? 16 : (Platform.is64bit() ? 20 : 16);
318 
319     final String mode;
320 
321     public GetObjectSizeIntrinsicsTest(String name, String mode) {
322         super(name);
323         this.mode = mode;

357         testSize_newSmallIntArray();
358         testSize_localSmallIntArray();
359         testSize_fieldSmallIntArray();
360 
361         testSize_newSmallObjArray();
362         testSize_localSmallObjArray();
363         testSize_fieldSmallObjArray();
364 
365         if (mode.equals("large")) {
366             testSize_localLargeIntArray();
367             testSize_localLargeObjArray();
368         }
369 
370         testNulls();
371     }
372 
373     private static long roundUp(long v, long a) {
374         return (v + a - 1) / a * a;
375     }
376 










377     private void testSize_newObject() {
378         long expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
379         for (int c = 0; c < ITERS; c++) {
380             assertEquals(expected, fInst.getObjectSize(new Object()));
381         }
382     }
383 
384     private void testSize_localObject() {
385         long expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
386         Object o = new Object();
387         for (int c = 0; c < ITERS; c++) {
388             assertEquals(expected, fInst.getObjectSize(o));
389         }
390     }
391 
392     static Object staticO = new Object();
393 
394     private void testSize_fieldObject() {
395         long expected = roundUp(Platform.is64bit() ? 16 : 8, OBJ_ALIGN);
396         for (int c = 0; c < ITERS; c++) {
397             assertEquals(expected, fInst.getObjectSize(staticO));
398         }
399     }
400 
401     private void testSize_newSmallIntArray() {
402         long expected = roundUp(4L*SMALL_ARRAY_SIZE + ARRAY_HEADER_SIZE, OBJ_ALIGN);
403         for (int c = 0; c < ITERS; c++) {
404             assertEquals(expected, fInst.getObjectSize(new int[SMALL_ARRAY_SIZE]));
405         }
406     }
407 
408     private void testSize_localSmallIntArray() {
409         int[] arr = new int[SMALL_ARRAY_SIZE];
410         long expected = roundUp(4L*SMALL_ARRAY_SIZE + ARRAY_HEADER_SIZE, OBJ_ALIGN);
411         for (int c = 0; c < ITERS; c++) {
412             assertEquals(expected, fInst.getObjectSize(arr));
413         }
414     }
415 

284  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
285  *
286  * @run main/othervm/timeout=240 -Xmx8g
287  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
288  *                   -Xbatch -XX:TieredStopAtLevel=1
289  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
290  *
291  * @run main/othervm/timeout=180 -Xmx8g
292  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -XX:+WhiteBoxAPI -Xbootclasspath/a:.
293  *                   -Xbatch -XX:-TieredCompilation
294  *                   -javaagent:basicAgent.jar GetObjectSizeIntrinsicsTest GetObjectSizeIntrinsicsTest large
295  */
296 
297 import java.util.*;
298 
299 import jdk.test.lib.Platform;
300 import jdk.test.whitebox.WhiteBox;
301 
302 public class GetObjectSizeIntrinsicsTest extends ASimpleInstrumentationTestCase {
303 
304     private static final boolean COMPACT_HEADERS = Platform.is64bit() && WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompactObjectHeaders");
305     static final Boolean COMPRESSED_OOPS = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedOops");
306     static final long REF_SIZE = (COMPRESSED_OOPS == null || COMPRESSED_OOPS == true) ? 4 : 8;
307 
308     static final Long align = WhiteBox.getWhiteBox().getIntVMFlag("ObjectAlignmentInBytes");
309     static final int OBJ_ALIGN = (align == null ? 8 : align.intValue());
310 
311     static final int SMALL_ARRAY_SIZE = 1024;
312 
313     // These should overflow 4G size boundary
314     static final int LARGE_INT_ARRAY_SIZE = 1024*1024*1024 + 1024;
315     static final int LARGE_OBJ_ARRAY_SIZE = (4096/(int)REF_SIZE)*1024*1024 + 1024;
316 
317     static final boolean CCP = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
318     static final int ARRAY_HEADER_SIZE = CCP ? 16 : (Platform.is64bit() ? 20 : 16);
319 
320     final String mode;
321 
322     public GetObjectSizeIntrinsicsTest(String name, String mode) {
323         super(name);
324         this.mode = mode;

358         testSize_newSmallIntArray();
359         testSize_localSmallIntArray();
360         testSize_fieldSmallIntArray();
361 
362         testSize_newSmallObjArray();
363         testSize_localSmallObjArray();
364         testSize_fieldSmallObjArray();
365 
366         if (mode.equals("large")) {
367             testSize_localLargeIntArray();
368             testSize_localLargeObjArray();
369         }
370 
371         testNulls();
372     }
373 
374     private static long roundUp(long v, long a) {
375         return (v + a - 1) / a * a;
376     }
377 
378     private static long expectedSmallObjSize() {
379         long size;
380         if (!Platform.is64bit() || COMPACT_HEADERS) {
381             size = 8;
382         } else {
383             size = 16;
384         }
385         return roundUp(size, OBJ_ALIGN);
386     }
387 
388     private void testSize_newObject() {
389         long expected = expectedSmallObjSize();
390         for (int c = 0; c < ITERS; c++) {
391             assertEquals(expected, fInst.getObjectSize(new Object()));
392         }
393     }
394 
395     private void testSize_localObject() {
396         long expected = expectedSmallObjSize();
397         Object o = new Object();
398         for (int c = 0; c < ITERS; c++) {
399             assertEquals(expected, fInst.getObjectSize(o));
400         }
401     }
402 
403     static Object staticO = new Object();
404 
405     private void testSize_fieldObject() {
406         long expected = expectedSmallObjSize();
407         for (int c = 0; c < ITERS; c++) {
408             assertEquals(expected, fInst.getObjectSize(staticO));
409         }
410     }
411 
412     private void testSize_newSmallIntArray() {
413         long expected = roundUp(4L*SMALL_ARRAY_SIZE + ARRAY_HEADER_SIZE, OBJ_ALIGN);
414         for (int c = 0; c < ITERS; c++) {
415             assertEquals(expected, fInst.getObjectSize(new int[SMALL_ARRAY_SIZE]));
416         }
417     }
418 
419     private void testSize_localSmallIntArray() {
420         int[] arr = new int[SMALL_ARRAY_SIZE];
421         long expected = roundUp(4L*SMALL_ARRAY_SIZE + ARRAY_HEADER_SIZE, OBJ_ALIGN);
422         for (int c = 0; c < ITERS; c++) {
423             assertEquals(expected, fInst.getObjectSize(arr));
424         }
425     }
426 
< prev index next >