< prev index next >

test/hotspot/jtreg/compiler/codegen/TestOopCmp.java

Print this page
rev 59189 : imported patch hotspot


  43 import sun.hotspot.WhiteBox;
  44 
  45 public class TestOopCmp {
  46 
  47     private static Object nullObj = null;
  48 
  49     public static boolean nullTest(Object o) {
  50         if (o == nullObj) {
  51             return true;
  52         } else {
  53             return false;
  54         }
  55     }
  56 
  57     public static void main(String args[]) {
  58 
  59         WhiteBox WB = WhiteBox.getWhiteBox();
  60 
  61         // The test is started with -XX:HeapBaseMinAddress=0x700000000 and a
  62         // small heap of only 4mb. This works pretty reliable and at least on
  63         // Linux/Windows/Solaris we will get a heap starting at 0x700000000.
  64         // The test also runs with -XX:+UseSerialGC which means that we'll get
  65         // eden starting at 0x700000000.
  66         // Calling 'System.gc()' will clean up all the objects from eden, so if
  67         // eden starts at 0x700000000 the first allocation right after the
  68         // system GC will be allcoated right at address 0x700000000.
  69         System.gc();
  70         String s = new String("I'm not null!!!");
  71         if (WB.getObjectAddress(s) == 0x700000000L) {
  72             System.out.println("Got object at address 0x700000000");
  73         }
  74 
  75         // We call 'nullTest()' with the newly allocated String object. If it was
  76         // allocated at 0x700000000, its 32 least-significant bits will be 0 and a
  77         // 32-bit comparison with 'nullObj' (which is 'null') will yield true and
  78         // result in a test failure.
  79         // If the code generated for 'nullTest()' correctly performs a 64-bit
  80         // comparison or if we didn't manage to allcoate 's' at 0x700000000 the
  81         // test will always succeed.
  82         for (int i = 0; i < 30_000; i++) {
  83             if (nullTest(s)) {


  43 import sun.hotspot.WhiteBox;
  44 
  45 public class TestOopCmp {
  46 
  47     private static Object nullObj = null;
  48 
  49     public static boolean nullTest(Object o) {
  50         if (o == nullObj) {
  51             return true;
  52         } else {
  53             return false;
  54         }
  55     }
  56 
  57     public static void main(String args[]) {
  58 
  59         WhiteBox WB = WhiteBox.getWhiteBox();
  60 
  61         // The test is started with -XX:HeapBaseMinAddress=0x700000000 and a
  62         // small heap of only 4mb. This works pretty reliable and at least on
  63         // Linux/Windows we will get a heap starting at 0x700000000.
  64         // The test also runs with -XX:+UseSerialGC which means that we'll get
  65         // eden starting at 0x700000000.
  66         // Calling 'System.gc()' will clean up all the objects from eden, so if
  67         // eden starts at 0x700000000 the first allocation right after the
  68         // system GC will be allcoated right at address 0x700000000.
  69         System.gc();
  70         String s = new String("I'm not null!!!");
  71         if (WB.getObjectAddress(s) == 0x700000000L) {
  72             System.out.println("Got object at address 0x700000000");
  73         }
  74 
  75         // We call 'nullTest()' with the newly allocated String object. If it was
  76         // allocated at 0x700000000, its 32 least-significant bits will be 0 and a
  77         // 32-bit comparison with 'nullObj' (which is 'null') will yield true and
  78         // result in a test failure.
  79         // If the code generated for 'nullTest()' correctly performs a 64-bit
  80         // comparison or if we didn't manage to allcoate 's' at 0x700000000 the
  81         // test will always succeed.
  82         for (int i = 0; i < 30_000; i++) {
  83             if (nullTest(s)) {
< prev index next >