publicstaticboolean nullTest(Object o) { if (o == nullObj) { returntrue;
} else { returnfalse;
}
}
publicstaticvoid main(String args[]) {
WhiteBox WB = WhiteBox.getWhiteBox();
// The test is started with -XX:HeapBaseMinAddress=0x700000000 and a // small heap of only 4mb. This works pretty reliable and at least on // Linux/Windows we will get a heap starting at 0x700000000. // The test also runs with -XX:+UseSerialGC which means that we'll get // eden starting at 0x700000000. // Calling 'System.gc()' will clean up all the objects from eden, so if // eden starts at 0x700000000 the first allocation right after the // system GC will be allcoated right at address 0x700000000.
System.gc();
String s = new String("I'm not null!!!"); if (WB.getObjectAddress(s) == 0x700000000L) {
System.out.println("Got object at address 0x700000000");
}
// We call 'nullTest()' with the newly allocated String object. If it was // allocated at 0x700000000, its 32 least-significant bits will be 0 and a // 32-bit comparison with 'nullObj' (which is 'null') will yield true and // result in a test failure. // If the code generated for 'nullTest()' correctly performs a 64-bit // comparison or if we didn't manage to allcoate 's' at 0x700000000 the // test will always succeed. for (int i = 0; i < 30_000; i++) { if (nullTest(s)) { thrownew RuntimeException("Comparing non-null object with null returned 'true'");
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.