test/gc/arguments/TestMaxHeapSizeTools.java
Print this page
*** 23,32 ****
--- 23,34 ----
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
+ import java.util.Collections;
+ import java.util.List;
import com.oracle.java.testlibrary.*;
import sun.hotspot.WhiteBox;
class ErgoArgsPrinter {
*** 39,50 ****
final class MinInitialMaxValues {
public long minHeapSize;
public long initialHeapSize;
public long maxHeapSize;
! public long minAlignment;
! public long maxAlignment;
}
class TestMaxHeapSizeTools {
public static void checkMinInitialMaxHeapFlags(String gcflag) throws Exception {
--- 41,52 ----
final class MinInitialMaxValues {
public long minHeapSize;
public long initialHeapSize;
public long maxHeapSize;
! public long spaceAlignment;
! public long heapAlignment;
}
class TestMaxHeapSizeTools {
public static void checkMinInitialMaxHeapFlags(String gcflag) throws Exception {
*** 179,231 ****
output.shouldHaveExitValue(0);
return output;
}
! private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception {
! OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false);
// the output we watch for has the following format:
//
! // "Minimum heap X Initial heap Y Maximum heap Z Min alignment A Max Alignment B"
//
// where A, B, X, Y and Z are sizes in bytes.
// Unfortunately there is no other way to retrieve the minimum heap size and
// the alignments.
!
! Matcher m = Pattern.compile("Minimum heap \\d+ Initial heap \\d+ Maximum heap \\d+ Min alignment \\d+ Max alignment \\d+").
! matcher(output.getStdout());
if (!m.find()) {
throw new RuntimeException("Could not find heap size string.");
}
String match = m.group();
// actual values
val.minHeapSize = valueAfter(match, "Minimum heap ");
val.initialHeapSize = valueAfter(match, "Initial heap ");
val.maxHeapSize = valueAfter(match, "Maximum heap ");
! val.minAlignment = valueAfter(match, "Min alignment ");
! val.maxAlignment = valueAfter(match, "Max alignment ");
}
/**
* Verify whether the VM automatically synchronizes minimum and initial heap size if only
* one is given for the GC specified.
*/
public static void checkErgonomics(String[] args, long[] newoldsize,
long expectedMin, long expectedInitial) throws Exception {
MinInitialMaxValues v = new MinInitialMaxValues();
! getMinInitialMaxHeap(args, v);
! if ((expectedMin != -1) && (align_up(expectedMin, v.minAlignment) != v.minHeapSize)) {
throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize +
" differs from expected minimum heap size of " + expectedMin);
}
! if ((expectedInitial != -1) && (align_up(expectedInitial, v.minAlignment) != v.initialHeapSize)) {
throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize +
" differs from expected initial heap size of " + expectedInitial);
}
// always check the invariant min <= initial <= max heap size
--- 181,240 ----
output.shouldHaveExitValue(0);
return output;
}
! private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val, Boolean[] parallelGC) throws Exception {
! List<String> argsList = new ArrayList<>();
! Collections.addAll(argsList, args);
! Collections.addAll(argsList, "-XX:+PrintFlagsFinal");
!
! OutputAnalyzer output = runWhiteBoxTest(argsList.toArray(new String[0]), ErgoArgsPrinter.class.getName(), new String[0], false);
! String stdOut = output.getStdout();
!
! parallelGC[0] = FlagsValue.getFlagBoolValue(stdOut, "UseParallelGC");
// the output we watch for has the following format:
//
! // "Minimum heap X Initial heap Y Maximum heap Z Space alignment A Heap alignment B"
//
// where A, B, X, Y and Z are sizes in bytes.
// Unfortunately there is no other way to retrieve the minimum heap size and
// the alignments.
! Matcher m = Pattern.
! compile("Minimum heap \\d+ Initial heap \\d+ Maximum heap \\d+ Space alignment \\d+ Heap alignment \\d+").
! matcher(stdOut);
if (!m.find()) {
throw new RuntimeException("Could not find heap size string.");
}
String match = m.group();
// actual values
val.minHeapSize = valueAfter(match, "Minimum heap ");
val.initialHeapSize = valueAfter(match, "Initial heap ");
val.maxHeapSize = valueAfter(match, "Maximum heap ");
! val.spaceAlignment = valueAfter(match, "Space alignment ");
! val.heapAlignment = valueAfter(match, "Heap alignment ");
}
/**
* Verify whether the VM automatically synchronizes minimum and initial heap size if only
* one is given for the GC specified.
*/
public static void checkErgonomics(String[] args, long[] newoldsize,
long expectedMin, long expectedInitial) throws Exception {
MinInitialMaxValues v = new MinInitialMaxValues();
! getMinInitialMaxHeap(args, v, new Boolean[1]);
! if ((expectedMin != -1) && (align_up(expectedMin, v.spaceAlignment) != v.minHeapSize)) {
throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize +
" differs from expected minimum heap size of " + expectedMin);
}
! if ((expectedInitial != -1) && (align_up(expectedInitial, v.spaceAlignment) != v.initialHeapSize)) {
throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize +
" differs from expected initial heap size of " + expectedInitial);
}
// always check the invariant min <= initial <= max heap size
*** 243,256 ****
*/
public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception {
final long K = 1024;
MinInitialMaxValues v = new MinInitialMaxValues();
! getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v);
- long expectedHeapSize = align_up(maxHeapsize * K * K, v.maxAlignment);
long actualHeapSize = v.maxHeapSize;
if (actualHeapSize > expectedHeapSize) {
throw new RuntimeException("Heap has " + actualHeapSize +
" bytes, expected to be less than " + expectedHeapSize);
}
--- 252,270 ----
*/
public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception {
final long K = 1024;
MinInitialMaxValues v = new MinInitialMaxValues();
! Boolean[] parallelGC = new Boolean[1];
! getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v, parallelGC);
long actualHeapSize = v.maxHeapSize;
+ long expectedHeapSize = align_up(maxHeapsize * K * K, v.heapAlignment);
+ if (parallelGC[0] = true) {
+ int numberOfSpaces = 4;
+ expectedHeapSize = Math.max(expectedHeapSize, numberOfSpaces * v.spaceAlignment);
+ }
if (actualHeapSize > expectedHeapSize) {
throw new RuntimeException("Heap has " + actualHeapSize +
" bytes, expected to be less than " + expectedHeapSize);
}