hotspot/test/gc/arguments/TestG1HeapRegionSize.java
author sangheki
Mon, 31 Aug 2015 11:51:29 -0700
changeset 32601 c5df671276bd
parent 30247 9925b07bba5b
child 32613 73bec9f941d7
permissions -rw-r--r--
8078555: GC: implement ranges (optionally constraints) for those flags that have them missing Summary: Add ranges and constraint functions for GC flags. Reviewed-by: jmasa, kbarrett, gziemski, ddmitriev, drwhite
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27886
diff changeset
     2
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     4
*
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     7
* published by the Free Software Foundation.
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     8
*
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    13
* accompanied this code).
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    14
*
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    18
*
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    21
* questions.
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    22
*/
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    23
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    24
/*
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    25
 * @test TestG1HeapRegionSize
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    26
 * @key gc
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    27
 * @bug 8021879
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    28
 * @requires vm.gc=="null" | vm.gc=="G1"
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    29
 * @summary Verify that the flag G1HeapRegionSize is updated properly
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27886
diff changeset
    30
 * @modules java.management/sun.management
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    31
 * @library /testlibrary
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    32
 * @run main TestG1HeapRegionSize
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    33
 */
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    34
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    35
import java.util.regex.Matcher;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    36
import java.util.regex.Pattern;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    37
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    38
import java.util.ArrayList;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    39
import java.util.Arrays;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    40
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    41
import jdk.test.lib.*;
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    42
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    43
public class TestG1HeapRegionSize {
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    44
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    45
  private static void checkG1HeapRegionSize(String[] flags, int expectedValue, int exitValue) throws Exception {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    46
    ArrayList<String> flagList = new ArrayList<String>();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    47
    flagList.addAll(Arrays.asList(flags));
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    48
    flagList.add("-XX:+UseG1GC");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    49
    flagList.add("-XX:+PrintFlagsFinal");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    50
    flagList.add("-version");
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    51
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    52
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flagList.toArray(new String[0]));
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    53
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    54
    output.shouldHaveExitValue(exitValue);
27886
79c703ddca55 8065749: [TESTBUG]: gc/arguments/TestG1HeapRegionSize.java fails at nightly
eistepan
parents: 27692
diff changeset
    55
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    56
    if (exitValue == 0) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    57
      String stdout = output.getStdout();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    58
      //System.out.println(stdout);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    59
      int flagValue = getFlagValue("G1HeapRegionSize", stdout);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    60
      if (flagValue != expectedValue) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    61
        throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + flagValue);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    62
      }
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    63
    }
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    64
  }
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    65
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    66
  private static int getFlagValue(String flag, String where) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    67
    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    68
    if (!m.find()) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    69
      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    70
    }
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    71
    String match = m.group();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    72
    return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    73
  }
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    74
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    75
  public static void main(String args[]) throws Exception {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    76
    final int M = 1024 * 1024;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    77
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    78
    checkG1HeapRegionSize(new String[] { "-Xmx64m"   /* default is 1m */        },  1*M, 0);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    79
    checkG1HeapRegionSize(new String[] { "-Xmx64m",  "-XX:G1HeapRegionSize=2m"  },  2*M, 0);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    80
    checkG1HeapRegionSize(new String[] { "-Xmx64m",  "-XX:G1HeapRegionSize=3m"  },  2*M, 0);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    81
    checkG1HeapRegionSize(new String[] { "-Xmx256m", "-XX:G1HeapRegionSize=32m" }, 32*M, 0);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    82
    checkG1HeapRegionSize(new String[] { "-Xmx256m", "-XX:G1HeapRegionSize=64m" }, 32*M, 1);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 30247
diff changeset
    83
  }
18999
a05f689a6c0c 8021879: G1: G1HeapRegionSize flag value not updated correctly
brutisso
parents:
diff changeset
    84
}