< prev index next >

test/gc/g1/plab/TestPLABResize.java

Print this page




  25  * @test TestPLABResize
  26  * @bug 8141278 8141141
  27  * @summary Test for PLAB resizing
  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.LogParser
  35  *        gc.g1.plab.lib.MemoryConsumer
  36  *        gc.g1.plab.lib.PLABUtils
  37  *        gc.g1.plab.lib.AppPLABResize
  38  * @ignore 8150183
  39  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  40  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  41  * @run main gc.g1.plab.TestPLABResize
  42  */
  43 package gc.g1.plab;
  44 
  45 import java.util.ArrayList;
  46 import java.util.Arrays;
  47 import java.util.List;
  48 import java.util.Map;
  49 import java.util.stream.Collectors;
  50 import java.io.PrintStream;
  51 
  52 import gc.g1.plab.lib.LogParser;
  53 import gc.g1.plab.lib.PLABUtils;
  54 import gc.g1.plab.lib.AppPLABResize;

  55 
  56 import jdk.test.lib.OutputAnalyzer;
  57 import jdk.test.lib.ProcessTools;
  58 
  59 /**
  60  * Test for PLAB resizing.
  61  */
  62 public class TestPLABResize {
  63 
  64     private static final int OBJECT_SIZE_SMALL = 10;
  65     private static final int OBJECT_SIZE_MEDIUM = 70;
  66     private static final int OBJECT_SIZE_HIGH = 150;
  67     private static final int GC_NUM_SMALL = 1;
  68     private static final int GC_NUM_MEDIUM = 3;
  69     private static final int GC_NUM_HIGH = 7;
  70     private static final int WASTE_PCT_SMALL = 10;
  71     private static final int WASTE_PCT_MEDIUM = 20;
  72     private static final int WASTE_PCT_HIGH = 30;
  73 
  74     private static final int ITERATIONS_SMALL = 3;
  75     private static final int ITERATIONS_MEDIUM = 5;
  76     private static final int ITERATIONS_HIGH = 8;
  77 


  78     private final static TestCase[] TEST_CASES = {
  79         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_SMALL, GC_NUM_SMALL, ITERATIONS_MEDIUM),
  80         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_MEDIUM, GC_NUM_HIGH, ITERATIONS_SMALL),
  81         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH),
  82         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_SMALL, GC_NUM_HIGH, ITERATIONS_MEDIUM),
  83         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_MEDIUM, GC_NUM_SMALL, ITERATIONS_SMALL),
  84         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH),
  85         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_SMALL, GC_NUM_HIGH, ITERATIONS_MEDIUM),
  86         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_MEDIUM, GC_NUM_SMALL, ITERATIONS_SMALL),
  87         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH)
  88     };
  89 
  90     public static void main(String[] args) throws Throwable {
  91         for (TestCase testCase : TEST_CASES) {
  92             testCase.print(System.out);
  93             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
  94             options.add(AppPLABResize.class.getName());
  95             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
  96             if (out.getExitValue() != 0) {
  97                 System.out.println(out.getOutput());
  98                 throw new RuntimeException("Exit code is not 0");
  99             }
 100             checkResults(out.getOutput(), testCase);
 101         }
 102     }
 103 
 104     /**
 105      * Checks testing results.
 106      * Expected results - desired PLAB size is decreased and increased during promotion to Survivor.
 107      *
 108      * @param output - VM output
 109      * @param testCase
 110      */
 111     private static void checkResults(String output, TestCase testCase) {
 112         final LogParser log = new LogParser(output);
 113         final Map<Long, Map<LogParser.ReportType, Map<String, Long>>> entries = log.getEntries();
 114 
 115         final ArrayList<Long> plabSizes = entries.entrySet()
 116                 .stream()
 117                 .map(item -> {
 118                     return item.getValue()
 119                             .get(LogParser.ReportType.SURVIVOR_STATS)
 120                             .get("actual");
 121                 })
 122                 .collect(Collectors.toCollection(ArrayList::new));
 123 
 124         // Check that desired plab size was changed during iterations.
 125         // The test case does 3 rounds of allocations.  The second round of N allocations and GC's
 126         // has a decreasing size of allocations so that iterations N to 2*N -1 will be of decreasing size.
 127         // The third round with iterations 2*N to 3*N -1 has increasing sizes of allocation.
 128         long startDesiredPLABSize = plabSizes.get(testCase.getIterations());
 129         long endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2 - 1);
 130 
 131         if (startDesiredPLABSize < endDesiredPLABSize) {
 132             System.out.println(output);
 133             throw new RuntimeException("Test failed! Expect that initial PLAB size should be greater than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
 134         }
 135 
 136         startDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2);
 137         endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 3 - 1);
 138 
 139         if (startDesiredPLABSize > endDesiredPLABSize) {
 140             System.out.println(output);
 141             throw new RuntimeException("Test failed! Expect that initial PLAB size should be less than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
 142         }




  25  * @test TestPLABResize
  26  * @bug 8141278 8141141
  27  * @summary Test for PLAB resizing
  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.LogParser
  35  *        gc.g1.plab.lib.MemoryConsumer
  36  *        gc.g1.plab.lib.PLABUtils
  37  *        gc.g1.plab.lib.AppPLABResize
  38  * @ignore 8150183
  39  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  40  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  41  * @run main gc.g1.plab.TestPLABResize
  42  */
  43 package gc.g1.plab;
  44 

  45 import java.util.Arrays;
  46 import java.util.List;

  47 import java.util.stream.Collectors;
  48 import java.io.PrintStream;
  49 
  50 import gc.g1.plab.lib.LogParser;
  51 import gc.g1.plab.lib.PLABUtils;
  52 import gc.g1.plab.lib.AppPLABResize;
  53 import gc.g1.plab.lib.PlabReport;
  54 
  55 import jdk.test.lib.OutputAnalyzer;
  56 import jdk.test.lib.ProcessTools;
  57 
  58 /**
  59  * Test for PLAB resizing.
  60  */
  61 public class TestPLABResize {
  62 
  63     private static final int OBJECT_SIZE_SMALL = 10;
  64     private static final int OBJECT_SIZE_MEDIUM = 70;
  65     private static final int OBJECT_SIZE_HIGH = 150;
  66     private static final int GC_NUM_SMALL = 1;
  67     private static final int GC_NUM_MEDIUM = 3;
  68     private static final int GC_NUM_HIGH = 7;
  69     private static final int WASTE_PCT_SMALL = 10;
  70     private static final int WASTE_PCT_MEDIUM = 20;
  71     private static final int WASTE_PCT_HIGH = 30;
  72 
  73     private static final int ITERATIONS_SMALL = 3;
  74     private static final int ITERATIONS_MEDIUM = 5;
  75     private static final int ITERATIONS_HIGH = 8;
  76 
  77     private static final String PLAB_SIZE_FIELD_NAME = "actual";
  78 
  79     private final static TestCase[] TEST_CASES = {
  80         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_SMALL, GC_NUM_SMALL, ITERATIONS_MEDIUM),
  81         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_MEDIUM, GC_NUM_HIGH, ITERATIONS_SMALL),
  82         new TestCase(WASTE_PCT_SMALL, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH),
  83         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_SMALL, GC_NUM_HIGH, ITERATIONS_MEDIUM),
  84         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_MEDIUM, GC_NUM_SMALL, ITERATIONS_SMALL),
  85         new TestCase(WASTE_PCT_MEDIUM, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH),
  86         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_SMALL, GC_NUM_HIGH, ITERATIONS_MEDIUM),
  87         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_MEDIUM, GC_NUM_SMALL, ITERATIONS_SMALL),
  88         new TestCase(WASTE_PCT_HIGH, OBJECT_SIZE_HIGH, GC_NUM_MEDIUM, ITERATIONS_HIGH)
  89     };
  90 
  91     public static void main(String[] args) throws Throwable {
  92         for (TestCase testCase : TEST_CASES) {
  93             testCase.print(System.out);
  94             List<String> options = PLABUtils.prepareOptions(testCase.toOptions());
  95             options.add(AppPLABResize.class.getName());
  96             OutputAnalyzer out = ProcessTools.executeTestJvm(options.toArray(new String[options.size()]));
  97             if (out.getExitValue() != 0) {
  98                 System.out.println(out.getOutput());
  99                 throw new RuntimeException("Exit code is not 0");
 100             }
 101             checkResults(out.getOutput(), testCase);
 102         }
 103     }
 104 
 105     /**
 106      * Checks testing results.
 107      * Expected results - desired PLAB size is decreased and increased during promotion to Survivor.
 108      *
 109      * @param output - VM output
 110      * @param testCase
 111      */
 112     private static void checkResults(String output, TestCase testCase) {
 113         final LogParser log = new LogParser(output);
 114         final PlabReport report = log.getEntries();
 115 
 116         final List<Long> plabSizes = report.entryStream()
 117                 .map(item -> item.getValue()


 118                         .get(LogParser.ReportType.SURVIVOR_STATS)
 119                         .get(PLAB_SIZE_FIELD_NAME)
 120                 )
 121                 .collect(Collectors.toList());
 122 
 123         // Check that desired plab size was changed during iterations.
 124         // The test case does 3 rounds of allocations.  The second round of N allocations and GC's
 125         // has a decreasing size of allocations so that iterations N to 2*N -1 will be of decreasing size.
 126         // The third round with iterations 2*N to 3*N -1 has increasing sizes of allocation.
 127         long startDesiredPLABSize = plabSizes.get(testCase.getIterations());
 128         long endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2 - 1);
 129 
 130         if (startDesiredPLABSize < endDesiredPLABSize) {
 131             System.out.println(output);
 132             throw new RuntimeException("Test failed! Expect that initial PLAB size should be greater than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
 133         }
 134 
 135         startDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2);
 136         endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 3 - 1);
 137 
 138         if (startDesiredPLABSize > endDesiredPLABSize) {
 139             System.out.println(output);
 140             throw new RuntimeException("Test failed! Expect that initial PLAB size should be less than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
 141         }


< prev index next >