/* * Copyright (c) 2016, 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.
*/
/** * The test starts the AppIHOP multiple times varying setting of MaxHeapSize, * IHOP and amount of memory to allocate. Then the test parses the GC log from * the app to check that Concurrent Mark Cycle was initiated only if needed * and at the right moment, defined by IHOP setting.
*/ publicclass TestIHOPStatic {
// Test case: // IHOP value, heap occupancy, heap size, expectation of message // Test cases for occupancy is greater than IHOP
runTest(30, 35, 64, true);
runTest(50, 55, 256, true);
runTest(60, 65, 64, true);
runTest(70, 75, 512, true);
// Test cases for big difference between occupancy and IHOP
runTest(30, 50, 256, true);
runTest(30, 70, 512, true);
runTest(50, 70, 256, true);
// Test cases for occupancy is less than IHOP
runTest(30, 25, 64, false);
runTest(50, 45, 256, false);
runTest(70, 65, 64, false);
runTest(70, 65, 512, false);
// Test cases for big difference between occupancy and IHOP
runTest(50, 30, 300, false);
runTest(70, 50, 160, false);
/** * Runs the test case. * * @param ihop IHOP value * @param pctToFill heap percentage to be filled * @param heapSize heap size for test * @param expectInitiationMessage * true - concurrent cycle initiation message is expected * false - message is not expected * * @throws Throwable
*/ privatestaticvoid runTest(int ihop, long pctToFill, long heapSize, boolean expectInitiationMessage) throws Throwable {
System.out.println("");
System.out.println("IHOP test:");
System.out.println(" InitiatingHeapOccupancyPercent : " + ihop);
System.out.println(" Part of heap to fill (percentage) : " + pctToFill);
System.out.println(" MaxHeapSize : " + heapSize);
System.out.println(" Expect for concurrent cycle initiation message : " + expectInitiationMessage);
List<String> options = new ArrayList<>();
Collections.addAll(options, Utils.getTestJavaOpts());
Collections.addAll(options, "-XX:InitiatingHeapOccupancyPercent=" + ihop, "-Dmemory.fill=" + (heapSize * 1024 * 1024 * pctToFill / 100), "-XX:MaxHeapSize=" + heapSize + "M", "-XX:InitialHeapSize=" + heapSize + "M"
);
Collections.addAll(options, COMMON_OPTIONS);
options.add(AppIHOP.class.getName());
OutputAnalyzer out = ProcessTools.executeTestJvm(options);
if (out.getExitValue() != 0) {
System.out.println(out.getOutput()); thrownew RuntimeException("IhopTest failed with exit code " + out.getExitValue());
}
checkResult(out, expectInitiationMessage);
}
/** * Checks execution results to ensure that concurrent cycle was initiated or * was not. * * @param out * @param expectInitiationMessage true - test expects for concurrent cycle initiation. * false - test does not expect for concurrent cycle initiation
*/ privatestaticvoid checkResult(OutputAnalyzer out, boolean expectInitiationMessage) { // Find expected messages
List<String> logItems = IhopUtils.getErgoInitiationMessages(out);
// Concurrent cycle was not initiated but was expected. if (logItems.isEmpty() && expectInitiationMessage) {
System.out.println(out.getOutput()); thrownew RuntimeException("Concurrent cycle was not initiated.");
}
IhopUtils.checkIhopLogValues(out);
}
staticclass AppIHOP {
/** * Simple class which fills part of memory and initiates GC. * To be executed in separate VM. * Expect next VM properties to be set: * memory.fill - amount of garbage to be created.
*/ privatestaticfinallong MEMORY_TO_FILL = Integer.getInteger("memory.fill"); privatefinalstaticint CHUNK_SIZE = 10000;
publicfinalstatic ArrayList<Object> STORAGE = new ArrayList<>();
// Calculate part of heap to be filled to achieve expected occupancy.
System.out.println("Mem to fill:" + MEMORY_TO_FILL); if (MEMORY_TO_FILL <= 0) { thrownew RuntimeException("Wrong memory size: " + MEMORY_TO_FILL);
} try {
createGarbage(MEMORY_TO_FILL);
} catch (OutOfMemoryError oome) { return;
} // Concurrent cycle initiation should start at end of Young GC cycle. // Will fill entire young gen with garbage to guarantee that Young GC was initiated. try {
createGarbage(TestIHOPStatic.YOUNG_SIZE);
} catch (OutOfMemoryError oome) {
}
}
privatestaticvoid createGarbage(long memToFill) { for (long i = 0; i < memToFill / CHUNK_SIZE; i++) {
STORAGE.add(newbyte[CHUNK_SIZE]);
}
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
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.