// The source arrays that are placed on the heap in old gen. privatestaticint numArrays = 7000; privatestaticint arraySize = 508; // Size of a humongous byte array, a bit less than a 1M region. This makes sure // that we always create a cross-region reference when referencing it. privatestaticint byteArraySize = 1024*1023;
publicstaticvoid main(String[] args) {
WB = jdk.test.whitebox.WhiteBox.getWhiteBox(); for (int i = 0; i < 5; i++) {
runTest();
WB.fullGC();
}
}
// Spray the heap with random object arrays in the hope that we get one // at the proper place.
Object[][] arrays = new Object[numArrays][]; for (int i = 0; i < numArrays; i++) {
arrays[i] = new Object[arraySize];
}
// Make sure that everything is in old gen.
WB.fullGC();
// Find if we got an allocation at the right spot.
Object[] arrayWithCardMinus1 = findArray(arrays);
if (arrayWithCardMinus1 == null) {
System.out.println("Array with card -1 not found. Trying again."); return;
} else {
System.out.println("Array with card -1 found.");
}
System.out.println("Modifying the last card in the array with a new object in a different region..."); // Create a target object that is guaranteed to be in a different region. byte[] target = newbyte[byteArraySize];
// Modify the last entry of the object we found.
arrayWithCardMinus1[arraySize - 1] = target;
target = null; // Make sure that the dirty cards are flushed by doing a GC.
System.out.println("Doing a GC.");
WB.youngGC();
/** *Findsanreturnsanarraythatcontainsa(32bittruncated)cardwithvalue-1.
*/ privatestatic Object[] findArray(Object[][] arrays) { for (int i = 0; i < arrays.length; i++) {
Object[] target = arrays[i]; if (target == null) { continue;
}
WB.getObjectAddress(target); // startAddress not used finallong lastAddress = getObjectLastAddress(target); finalint card = getCardIndex32bit(lastAddress); if (card == -1) {
Object[] foundArray = target; return foundArray;
}
} returnnull;
}
}
Messung V0.5 in Prozent
¤ 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.0.12Bemerkung:
(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.