< prev index next >

test/gc/g1/plab/TestPLABPromotion.java

Print this page
rev 10336 : [mq]: 8141141-young-and-old-gen-stats-are-similar-in-output


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24  /*
  25  * @test TestPLABPromotion
  26  * @bug 8141278
  27  * @summary Test PLAB promotion
  28  * @requires vm.gc=="G1" | vm.gc=="null"
  29  * @requires vm.opt.FlightRecorder != true
  30  * @library /testlibrary /../../test/lib /
  31  * @modules java.management
  32  * @build ClassFileInstaller
  33  *        sun.hotspot.WhiteBox
  34  *        gc.g1.plab.lib.MemoryConsumer
  35  *        gc.g1.plab.lib.LogParser
  36  *        gc.g1.plab.lib.AppPLABPromotion
  37  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  38  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  39  * @run main/timeout=240 gc.g1.plab.TestPLABPromotion
  40  */
  41 package gc.g1.plab;
  42 
  43 import java.util.List;
  44 import java.util.Map;
  45 import java.util.Arrays;
  46 import java.io.PrintStream;


 113         for (TestCase testCase : TEST_CASES) {
 114             // What we going to check.
 115             testCase.print(System.out);
 116             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
 117             options.add(AppPLABPromotion.class.getName());
 118             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
 119             if (out.getExitValue() != 0) {
 120                 System.out.println(out.getOutput());
 121                 throw new RuntimeException("Expect exit code 0.");
 122             }
 123             checkResults(out.getOutput(), testCase);
 124         }
 125     }
 126 
 127     private static void checkResults(String output, TestCase testCase) {
 128         long plabAllocatedSurvivor;
 129         long directAllocatedSurvivor;
 130         long plabAllocatedOld;
 131         long directAllocatedOld;
 132         long memAllocated = testCase.getMemToFill();
 133         long wordSize = Platform.is32bit() ? 4l : 8l;
 134         LogParser logParser = new LogParser(output);
 135 
 136         Map<String, Long> survivorStats = getPlabStats(logParser, LogParser.ReportType.SURVIVOR_STATS, GC_ID_SURVIVOR_STATS);
 137         Map<String, Long> oldStats = getPlabStats(logParser, LogParser.ReportType.OLD_STATS, GC_ID_OLD_STATS);
 138 
 139         plabAllocatedSurvivor = wordSize * survivorStats.get("used");
 140         directAllocatedSurvivor = wordSize * survivorStats.get("direct_allocated");
 141         plabAllocatedOld = wordSize * oldStats.get("used");
 142         directAllocatedOld = wordSize * oldStats.get("direct_allocated");
 143 
 144         System.out.printf("Survivor PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedSurvivor, directAllocatedSurvivor, memAllocated);
 145         System.out.printf("Old      PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedOld, directAllocatedOld, memAllocated);
 146 
 147         // Unreachable objects case
 148         if (testCase.isDeadObjectCase()) {
 149             // No dead objects should be promoted
 150             if (!(checkRatio(plabAllocatedSurvivor, memAllocated) && checkRatio(directAllocatedSurvivor, memAllocated))) {
 151                 System.out.println(output);
 152                 throw new RuntimeException("Unreachable objects should not be allocated using PLAB or direct allocated to Survivor");
 153             }
 154             if (!(checkRatio(plabAllocatedOld, memAllocated) && checkRatio(directAllocatedOld, memAllocated))) {
 155                 System.out.println(output);
 156                 throw new RuntimeException("Unreachable objects should not be allocated using PLAB or direct allocated to Old");
 157             }
 158         } else {
 159             // Live objects case
 160             if (testCase.isPromotedByPLAB()) {
 161                 // All live small objects should be promoted using PLAB
 162                 if (!checkDifferenceRatio(plabAllocatedSurvivor, memAllocated)) {


 204     }
 205 
 206     /**
 207      * Returns true if difference of checkedValue and controlValue is less than
 208      * MEM_DIFFERENCE_PCT percent of controlValue.
 209      *
 210      * @param checkedValue - checked value
 211      * @param controlValue - referent value
 212      * @return true if difference of checkedValue and controlValue is less than
 213      * MEM_DIFFERENCE_PCT percent of controlValue
 214      */
 215     private static boolean checkDifferenceRatio(long checkedValue, long controlValue) {
 216         return (Math.abs(checkedValue - controlValue) / controlValue) * 100L < MEM_DIFFERENCE_PCT;
 217     }
 218 
 219     private static Map<String, Long> getPlabStats(LogParser logParser, LogParser.ReportType type, long gc_id) {
 220 
 221         Map<String, Long> survivorStats = logParser.getEntries()
 222                 .get(gc_id)
 223                 .get(type);



 224         return survivorStats;
 225     }
 226 
 227     /**
 228      * Description of one test case.
 229      */
 230     private static class TestCase {
 231 
 232         private final int wastePct;
 233         private final int plabSize;
 234         private final int chunkSize;
 235         private final int parGCThreads;
 236         private final int edenSize;
 237         private final boolean plabIsFixed;
 238         private final boolean objectsAreReachable;
 239         private final boolean promotedByPLAB;
 240 
 241         /**
 242          * @param wastePct
 243          * ParallelGCBufferWastePct




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24  /*
  25  * @test TestPLABPromotion
  26  * @bug 8141278 8141141
  27  * @summary Test PLAB promotion
  28  * @requires vm.gc=="G1" | vm.gc=="null"
  29  * @requires vm.opt.FlightRecorder != true
  30  * @library /testlibrary /../../test/lib /
  31  * @modules java.management
  32  * @build ClassFileInstaller
  33  *        sun.hotspot.WhiteBox
  34  *        gc.g1.plab.lib.MemoryConsumer
  35  *        gc.g1.plab.lib.LogParser
  36  *        gc.g1.plab.lib.AppPLABPromotion
  37  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  38  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  39  * @run main/timeout=240 gc.g1.plab.TestPLABPromotion
  40  */
  41 package gc.g1.plab;
  42 
  43 import java.util.List;
  44 import java.util.Map;
  45 import java.util.Arrays;
  46 import java.io.PrintStream;


 113         for (TestCase testCase : TEST_CASES) {
 114             // What we going to check.
 115             testCase.print(System.out);
 116             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
 117             options.add(AppPLABPromotion.class.getName());
 118             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
 119             if (out.getExitValue() != 0) {
 120                 System.out.println(out.getOutput());
 121                 throw new RuntimeException("Expect exit code 0.");
 122             }
 123             checkResults(out.getOutput(), testCase);
 124         }
 125     }
 126 
 127     private static void checkResults(String output, TestCase testCase) {
 128         long plabAllocatedSurvivor;
 129         long directAllocatedSurvivor;
 130         long plabAllocatedOld;
 131         long directAllocatedOld;
 132         long memAllocated = testCase.getMemToFill();

 133         LogParser logParser = new LogParser(output);
 134 
 135         Map<String, Long> survivorStats = getPlabStats(logParser, LogParser.ReportType.SURVIVOR_STATS, GC_ID_SURVIVOR_STATS);
 136         Map<String, Long> oldStats = getPlabStats(logParser, LogParser.ReportType.OLD_STATS, GC_ID_OLD_STATS);
 137 
 138         plabAllocatedSurvivor = survivorStats.get("used");
 139         directAllocatedSurvivor = survivorStats.get("direct allocated");
 140         plabAllocatedOld = oldStats.get("used");
 141         directAllocatedOld = oldStats.get("direct allocated");
 142 
 143         System.out.printf("Survivor PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedSurvivor, directAllocatedSurvivor, memAllocated);
 144         System.out.printf("Old      PLAB allocated:%17d Direct allocated: %17d Mem consumed:%17d%n", plabAllocatedOld, directAllocatedOld, memAllocated);
 145 
 146         // Unreachable objects case
 147         if (testCase.isDeadObjectCase()) {
 148             // No dead objects should be promoted
 149             if (!(checkRatio(plabAllocatedSurvivor, memAllocated) && checkRatio(directAllocatedSurvivor, memAllocated))) {
 150                 System.out.println(output);
 151                 throw new RuntimeException("Unreachable objects should not be allocated using PLAB or direct allocated to Survivor");
 152             }
 153             if (!(checkRatio(plabAllocatedOld, memAllocated) && checkRatio(directAllocatedOld, memAllocated))) {
 154                 System.out.println(output);
 155                 throw new RuntimeException("Unreachable objects should not be allocated using PLAB or direct allocated to Old");
 156             }
 157         } else {
 158             // Live objects case
 159             if (testCase.isPromotedByPLAB()) {
 160                 // All live small objects should be promoted using PLAB
 161                 if (!checkDifferenceRatio(plabAllocatedSurvivor, memAllocated)) {


 203     }
 204 
 205     /**
 206      * Returns true if difference of checkedValue and controlValue is less than
 207      * MEM_DIFFERENCE_PCT percent of controlValue.
 208      *
 209      * @param checkedValue - checked value
 210      * @param controlValue - referent value
 211      * @return true if difference of checkedValue and controlValue is less than
 212      * MEM_DIFFERENCE_PCT percent of controlValue
 213      */
 214     private static boolean checkDifferenceRatio(long checkedValue, long controlValue) {
 215         return (Math.abs(checkedValue - controlValue) / controlValue) * 100L < MEM_DIFFERENCE_PCT;
 216     }
 217 
 218     private static Map<String, Long> getPlabStats(LogParser logParser, LogParser.ReportType type, long gc_id) {
 219 
 220         Map<String, Long> survivorStats = logParser.getEntries()
 221                 .get(gc_id)
 222                 .get(type);
 223 for (Map.Entry<String, Long> e: survivorStats.entrySet()) {
 224   System.err.println(e.getKey() + "@" + e.getValue());
 225 }
 226         return survivorStats;
 227     }
 228 
 229     /**
 230      * Description of one test case.
 231      */
 232     private static class TestCase {
 233 
 234         private final int wastePct;
 235         private final int plabSize;
 236         private final int chunkSize;
 237         private final int parGCThreads;
 238         private final int edenSize;
 239         private final boolean plabIsFixed;
 240         private final boolean objectsAreReachable;
 241         private final boolean promotedByPLAB;
 242 
 243         /**
 244          * @param wastePct
 245          * ParallelGCBufferWastePct


< prev index next >