/* * Copyright (c) 2016, 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 checks PLAB promotion of different size objects.
*/ publicclass TestPLABPromotion {
// GC ID with survivor PLAB statistics privatefinalstaticlong GC_ID_SURVIVOR_STATS = 1l; // GC ID with old PLAB statistics privatefinalstaticlong GC_ID_OLD_STATS = 2l;
for (TestCase testCase : TEST_CASES) { // What we going to check.
testCase.print(System.out);
List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
options.add(AppPLABPromotion.class.getName());
OutputAnalyzer out = ProcessTools.executeTestJvm(options);
PLABUtils.commonCheck(out);
output = out.getOutput();
checkResults(testCase);
}
}
privatestaticvoid checkResults(TestCase testCase) { long plabAllocatedSurvivor; long directAllocatedSurvivor; long plabAllocatedOld; long directAllocatedOld; long memAllocated = testCase.getMemToFill();
LogParser logParser = new LogParser(output);
System.out.printf("Survivor PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedSurvivor, directAllocatedSurvivor, memAllocated);
System.out.printf("Old PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedOld, directAllocatedOld, memAllocated);
// Unreachable objects case if (testCase.isDeadObjectCase()) {
checkDeadObjectsPromotion(plabAllocatedSurvivor, directAllocatedSurvivor, memAllocated);
checkDeadObjectsPromotion(plabAllocatedOld, directAllocatedOld, memAllocated);
} else { // Live objects case if (testCase.isPromotedByPLAB()) {
checkLiveObjectsPromotion(plabAllocatedSurvivor, memAllocated, "Expect that Survivor PLAB allocation are similar to all mem consumed");
checkLiveObjectsPromotion(plabAllocatedOld, memAllocated, "Expect that Old PLAB allocation are similar to all mem consumed");
} else { // All big objects should be directly allocated
checkLiveObjectsPromotion(directAllocatedSurvivor, memAllocated, "Expect that Survivor direct allocation are similar to all mem consumed");
checkLiveObjectsPromotion(directAllocatedOld, memAllocated, "Expect that Old direct allocation are similar to all mem consumed");
}
checkTotalPromotion(plabAllocatedSurvivor, directAllocatedSurvivor, memAllocated, "Expect that Survivor gen total allocation are similar to all mem consumed");
checkTotalPromotion(plabAllocatedOld, directAllocatedOld, memAllocated, "Expect that Old gen total allocation are similar to all mem consumed");
}
System.out.println("Test passed!");
}
privatestaticvoid checkTotalPromotion(long plabAllocatedSurvivor, long directAllocatedSurvivor, long memAllocated, String exceptionMessage) { // All promoted objects size should be similar to all consumed memory if (!checkDifferenceRatio(plabAllocatedSurvivor + directAllocatedSurvivor, memAllocated)) {
System.out.println(output); thrownew RuntimeException(exceptionMessage);
}
}
/** * Checks that live objects were promoted as expected. * @param plabAllocated * @param totalMemAllocated * @param exceptionMessage
*/ privatestaticvoid checkLiveObjectsPromotion(long plabAllocated, long totalMemAllocated, String exceptionMessage) { // All live small objects should be promoted using PLAB if (!checkDifferenceRatio(plabAllocated, totalMemAllocated)) {
System.out.println(output); thrownew RuntimeException(exceptionMessage);
}
}
/** * Checks that dead objects are not promoted. * @param plabPromoted promoted by PLAB * @param directlyPromoted * @param memoryAllocated total memory allocated
*/ privatestaticvoid checkDeadObjectsPromotion(long plabPromoted, long directlyPromoted, long memoryAllocated) { // No dead objects should be promoted if (!(checkRatio(plabPromoted, memoryAllocated) && checkRatio(directlyPromoted, memoryAllocated))) {
System.out.println(output); thrownew RuntimeException("Unreachable objects should not be allocated using PLAB or directly allocated to Survivor/Old");
}
}
/** * Checks that PLAB statistics contains expected fields. * @param info
*/ privatestaticvoid checkFields(PlabInfo info) { if (!info.checkFields(FIELDS_TO_EXTRACT)) {
System.out.println(output); thrownew RuntimeException("PLAB log does not contain expected fields");
}
}
/** * Returns true if checkedValue is less than MEM_DIFFERENCE_PCT percent of controlValue. * * @param checkedValue - checked value * @param controlValue - referent value * @return true if checkedValue is less than MEM_DIFFERENCE_PCT percent of controlValue
*/ privatestaticboolean checkRatio(long checkedValue, long controlValue) { return Math.abs(checkedValue * 100.0 / controlValue) < MEM_DIFFERENCE_PCT;
}
/** * Returns true if difference of checkedValue and controlValue is less than * MEM_DIFFERENCE_PCT percent of controlValue. * * @param checkedValue - checked value * @param controlValue - referent value * @return true if difference of checkedValue and controlValue is less than * MEM_DIFFERENCE_PCT percent of controlValue
*/ privatestaticboolean checkDifferenceRatio(long checkedValue, long controlValue) { return Math.abs((checkedValue - controlValue) * 100.0 / controlValue) < MEM_DIFFERENCE_PCT;
}
/** * Description of one test case.
*/ privatestaticclass TestCase {
/** * @return * true if we expect PLAB allocation * false if no
*/ publicboolean isPromotedByPLAB() { return promotedByPLAB;
}
/** * @return * true if it is test case for unreachable objects * false for live objects
*/ publicboolean isDeadObjectCase() { return !objectsAreReachable;
}
/** * Returns amount of memory to fill * * @return amount of memory
*/ publiclong getMemToFill() { return (long) (edenSize) * 1024l * 1024l / 2;
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 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.