/* * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Test for events: vm/code_cache/full vm/compiler/failure * * We verify that we should get at least one of each of the events listed above. * * NOTE! The test is usually able to trigger the events but not always. If an * event is received, the event is verified. If an event is missing, we do NOT * fail.
*/ /** * @test TestCodeSweeper * @key jfr * @requires vm.hasJFR * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:-SegmentedCodeCache -XX:+WhiteBoxAPI jdk.jfr.event.compiler.TestCodeSweeper
*/
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.