8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
authormchernov
Thu, 03 Mar 2016 16:12:38 +0300
changeset 37061 f4f1c40edfd9
parent 37055 3ea6a0d5a78c
child 37062 5a26bcf87c57
8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current Reviewed-by: jmasa, dfazunen
hotspot/test/gc/g1/plab/TestPLABResize.java
hotspot/test/gc/g1/plab/lib/AppPLABResize.java
hotspot/test/gc/g1/plab/lib/LogParser.java
--- a/hotspot/test/gc/g1/plab/TestPLABResize.java	Thu Mar 10 08:54:43 2016 +0100
+++ b/hotspot/test/gc/g1/plab/TestPLABResize.java	Thu Mar 03 16:12:38 2016 +0300
@@ -122,29 +122,23 @@
                 .collect(Collectors.toCollection(ArrayList::new));
 
         // Check that desired plab size was changed during iterations.
-        // It should decrease during first half of iterations
-        // and increase after.
-        List<Long> decreasedPlabs = plabSizes.subList(testCase.getIterations(), testCase.getIterations() * 2);
-        List<Long> increasedPlabs = plabSizes.subList(testCase.getIterations() * 2, testCase.getIterations() * 3);
+        // The test case does 3 rounds of allocations.  The second round of N allocations and GC's
+        // has a decreasing size of allocations so that iterations N to 2*N -1 will be of decreasing size.
+        // The third round with iterations 2*N to 3*N -1 has increasing sizes of allocation.
+        long startDesiredPLABSize = plabSizes.get(testCase.getIterations());
+        long endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2 - 1);
 
-        Long prev = decreasedPlabs.get(0);
-        for (int index = 1; index < decreasedPlabs.size(); ++index) {
-            Long current = decreasedPlabs.get(index);
-            if (prev < current) {
-                System.out.println(output);
-                throw new RuntimeException("Test failed! Expect that previous PLAB size should be greater than current. Prev.size: " + prev + " Current size:" + current);
-            }
-            prev = current;
+        if (startDesiredPLABSize < endDesiredPLABSize) {
+            System.out.println(output);
+            throw new RuntimeException("Test failed! Expect that initial PLAB size should be greater than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
         }
 
-        prev = increasedPlabs.get(0);
-        for (int index = 1; index < increasedPlabs.size(); ++index) {
-            Long current = increasedPlabs.get(index);
-            if (prev > current) {
-                System.out.println(output);
-                throw new RuntimeException("Test failed! Expect that previous PLAB size should be less than current. Prev.size: " + prev + " Current size:" + current);
-            }
-            prev = current;
+        startDesiredPLABSize = plabSizes.get(testCase.getIterations() * 2);
+        endDesiredPLABSize = plabSizes.get(testCase.getIterations() * 3 - 1);
+
+        if (startDesiredPLABSize > endDesiredPLABSize) {
+            System.out.println(output);
+            throw new RuntimeException("Test failed! Expect that initial PLAB size should be less than checked. Initial size: " + startDesiredPLABSize + " Checked size:" + endDesiredPLABSize);
         }
 
         System.out.println("Test passed!");
@@ -195,7 +189,6 @@
             return Arrays.asList("-XX:ParallelGCThreads=" + parGCThreads,
                     "-XX:ParallelGCBufferWastePct=" + wastePct,
                     "-XX:+ResizePLAB",
-                    "-Dthreads=" + parGCThreads,
                     "-Dchunk.size=" + chunkSize,
                     "-Diterations=" + iterations,
                     "-XX:NewSize=16m",
--- a/hotspot/test/gc/g1/plab/lib/AppPLABResize.java	Thu Mar 10 08:54:43 2016 +0100
+++ b/hotspot/test/gc/g1/plab/lib/AppPLABResize.java	Thu Mar 03 16:12:38 2016 +0300
@@ -38,7 +38,6 @@
  * Expects the following properties to be set:
  * - iterations - amount of iteration per cycle.
  * - chunk.size - size of objects to be allocated
- * - threads - number of gc threads (-XX:ParallelGCThreads) to calculate PLAB sizes.
  */
 final public class AppPLABResize {
 
@@ -47,7 +46,6 @@
     // Defined by properties.
     private static final int ITERATIONS = Integer.getInteger("iterations");
     private static final long CHUNK = Long.getLong("chunk.size");
-    private static final int GC_THREADS = Integer.getInteger("threads");
 
     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
 
@@ -59,13 +57,13 @@
      */
     public static void main(String[] args) {
 
-        if (ITERATIONS == 0 || CHUNK == 0 || GC_THREADS == 0) {
+        if (ITERATIONS == 0 || CHUNK == 0) {
             throw new IllegalArgumentException("Properties should be set");
         }
 
         long wordSize = Platform.is32bit() ? 4l : 8l;
         // PLAB size is shared between threads.
-        long initialMemorySize = wordSize * GC_THREADS * MEM_ALLOC_WORDS;
+        long initialMemorySize = wordSize * MEM_ALLOC_WORDS;
 
         // Expect changing memory to half during all iterations.
         long memChangeStep = initialMemorySize / 2 / ITERATIONS;
--- a/hotspot/test/gc/g1/plab/lib/LogParser.java	Thu Mar 10 08:54:43 2016 +0100
+++ b/hotspot/test/gc/g1/plab/lib/LogParser.java	Thu Mar 03 16:12:38 2016 +0300
@@ -57,7 +57,8 @@
 
     private final String log;
 
-    private final Map<Long, Map<ReportType, Map<String,Long>>> reportHolder;
+    // Contains Map of PLAB statistics for given log.
+    private final Map<Long, Map<ReportType, Map<String, Long>>> report;
 
     // GC ID
     private static final Pattern GC_ID_PATTERN = Pattern.compile("\\[gc,plab\\s*\\] GC\\((\\d+)\\)");
@@ -65,7 +66,7 @@
     private static final Pattern PAIRS_PATTERN = Pattern.compile("\\w* \\w+:\\s+\\d+");
 
     /**
-     * Construct LogParser Object
+     * Construct LogParser object, parse log file with PLAB statistics and store it into report.
      *
      * @param log - VM Output
      */
@@ -74,43 +75,44 @@
             throw new IllegalArgumentException("Parameter log should not be null.");
         }
         this.log = log;
-        reportHolder = parseLines();
+        report = parseLines();
     }
 
     /**
-     * @return log which is being processed
+     * @return log which was processed
      */
     public String getLog() {
         return log;
     }
 
     /**
-     * Returns list of log entries.
+     * Returns the GC log entries for Survivor and Old stats.
+     * The entries are represented as a map of gcID to the StatMap.
      *
-     * @return list of Pair with ReportType and Map of parameters/values.
+     * @return The log entries for the Survivor and Old stats.
      */
-    public Map<Long,Map<ReportType, Map<String,Long>>> getEntries() {
-        return reportHolder;
+    public Map<Long, Map<ReportType, Map<String, Long>>> getEntries() {
+        return report;
     }
 
-    private Map<Long,Map<ReportType, Map<String,Long>>> parseLines() throws NumberFormatException {
+    private Map<Long, Map<ReportType, Map<String, Long>>> parseLines() throws NumberFormatException {
         Scanner lineScanner = new Scanner(log);
-        Map<Long,Map<ReportType, Map<String,Long>>> allocationStatistics = new HashMap<>();
+        Map<Long, Map<ReportType, Map<String, Long>>> allocationStatistics = new HashMap<>();
         Optional<Long> gc_id;
         while (lineScanner.hasNextLine()) {
             String line = lineScanner.nextLine();
             gc_id = getGcId(line);
-            if ( gc_id.isPresent() ) {
+            if (gc_id.isPresent()) {
                 Matcher matcher = PAIRS_PATTERN.matcher(line);
                 if (matcher.find()) {
-                    Map<ReportType,Map<String, Long>> oneReportItem;
+                    Map<ReportType, Map<String, Long>> oneReportItem;
                     ReportType reportType;
 
                     if (!allocationStatistics.containsKey(gc_id.get())) {
-                      allocationStatistics.put(gc_id.get(), new EnumMap<>(ReportType.class));
+                        allocationStatistics.put(gc_id.get(), new EnumMap<>(ReportType.class));
                     }
 
-                    if ( line.contains("Young") ) {
+                    if (line.contains("Young")) {
                         reportType = ReportType.SURVIVOR_STATS;
                     } else {
                         reportType = ReportType.OLD_STATS;
@@ -118,7 +120,7 @@
 
                     oneReportItem = allocationStatistics.get(gc_id.get());
                     if (!oneReportItem.containsKey(reportType)) {
-                      oneReportItem.put(reportType,new HashMap<String, Long>());
+                        oneReportItem.put(reportType, new HashMap<>());
                     }
 
                     // Extract all pairs from log.