publicstaticvoid main(String[] args) throws Throwable {
Asserts.assertTrue(BlobType.getAvailable().contains(BlobType.All), "Test does not support SegmentedCodeCache");
System.out.println("************************************************");
System.out.println("This test will warn that the code cache is full.");
System.out.println("That is expected and is the purpose of the test.");
System.out.println("************************************************");
Recording r = new Recording();
r.enable(pathFull);
r.enable(pathFailure);
r.start();
provokeEvents();
r.stop();
int countEventFull = 0; int countEventFailure = 0;
List<RecordedEvent> events = Events.fromRecording(r);
Events.hasEvents(events); for (RecordedEvent event : events) { switch (event.getEventType().getName()) { case pathFull:
countEventFull++;
verifyFullEvent(event); break; case pathFailure:
countEventFailure++;
verifyFailureEvent(event); break;
}
}
privatestaticboolean canAllocate(double size, long maxSize, MemoryPoolMXBean bean) { // Don't fill too much to have space for adapters. So, stop after crossing 95% and // don't allocate in case we'll cross 97% on next allocation. double used = bean.getUsage().getUsed(); return (used <= CACHE_USAGE_COEF * maxSize) &&
(used + size <= (CACHE_USAGE_COEF + 0.02d) * maxSize);
}
privatestaticvoid provokeEvents() throws NoSuchMethodException, InterruptedException { // Prepare for later, since we don't want to trigger any compilation // setting this up.
Method method = TestCodeSweeper.class.getDeclaredMethod(METHOD_NAME, newClass[] { RecordedEvent.class });
String directive = "[{ match: \"" + TestCodeSweeper.class.getName().replace('.', '/')
+ "." + METHOD_NAME + "\", " + "BackgroundCompilation: false }]";
// Fill up code heaps until they are almost full
ArrayList<Long> blobs = new ArrayList<>();
MemoryPoolMXBean bean = BlobType.All.getMemoryPool(); long max = bean.getUsage().getMax(); long headerSize = getHeaderSize(BlobType.All); long minAllocationUnit = Math.max(1, MIN_ALLOCATION - headerSize); long stopAt = max - minAllocationUnit; long addr = 0;
// First allocate big blobs to speed things up for (long size = 100_000 * minAllocationUnit; size > 0; size /= 10) { while (canAllocate(size, max, bean) &&
(addr = WHITE_BOX.allocateCodeBlob(size, BlobType.All.id)) != 0) {
blobs.add(addr);
}
}
// Now allocate small blobs until the heap is almost full while (bean.getUsage().getUsed() < stopAt &&
(addr = WHITE_BOX.allocateCodeBlob(SIZE, BlobType.All.id)) != 0) {
blobs.add(addr);
}
// Trigger the vm/code_cache/full event by compiling one more // method. This also triggers the vm/compiler/failure event.
Asserts.assertTrue(WHITE_BOX.addCompilerDirective(directive) == 1); try { if (!WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION)) {
WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_SIMPLE);
}
} finally {
WHITE_BOX.removeCompilerDirective(1);
}
// Verify startAddress <= commitedTopAddress <= reservedTopAddress. // Addresses may be so big that they overflow a long (treated as a // negative value), convert value to an octal string and compare the // string.
String startAddress = Long.toOctalString(Events.assertField(event, "startAddress").getValue());
String commitedTopAddress = Long.toOctalString(Events.assertField(event, "commitedTopAddress").getValue());
String reservedTopAddress = Long.toOctalString(Events.assertField(event, "reservedTopAddress").getValue());
Asserts.assertTrue(isOctalLessOrEqual(startAddress, commitedTopAddress), "startAddress<=commitedTopAddress: " + startAddress + "<=" + commitedTopAddress);
Asserts.assertTrue(isOctalLessOrEqual(commitedTopAddress, reservedTopAddress), "commitedTopAddress<=reservedTopAddress: " + commitedTopAddress + "<=" + reservedTopAddress);
}
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.