233 throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " + 234 v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize); 235 } 236 } 237 238 /** 239 * Verify whether the VM respects the given maximum heap size in MB for the 240 * GC specified. 241 * @param gcflag The garbage collector to test as command line flag. E.g. -XX:+UseG1GC 242 * @param maxHeapSize the maximum heap size to verify, in MB. 243 */ 244 public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception { 245 final long K = 1024; 246 247 MinInitialMaxValues v = new MinInitialMaxValues(); 248 getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v); 249 250 long expectedHeapSize = align_up(maxHeapsize * K * K, v.maxAlignment); 251 long actualHeapSize = v.maxHeapSize; 252 253 if (actualHeapSize > expectedHeapSize) { 254 throw new RuntimeException("Heap has " + actualHeapSize + 255 " bytes, expected to be less than " + expectedHeapSize); 256 } 257 } 258 259 private static long getFlagValue(String flag, String where) { 260 Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where); 261 if (!m.find()) { 262 throw new RuntimeException("Could not find value for flag " + flag + " in output string"); 263 } 264 String match = m.group(); 265 return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length())); 266 } 267 268 private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception { 269 if (contains) { 270 output.shouldContain(message); 271 } else { 272 output.shouldNotContain(message); | 233 throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " + 234 v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize); 235 } 236 } 237 238 /** 239 * Verify whether the VM respects the given maximum heap size in MB for the 240 * GC specified. 241 * @param gcflag The garbage collector to test as command line flag. E.g. -XX:+UseG1GC 242 * @param maxHeapSize the maximum heap size to verify, in MB. 243 */ 244 public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception { 245 final long K = 1024; 246 247 MinInitialMaxValues v = new MinInitialMaxValues(); 248 getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v); 249 250 long expectedHeapSize = align_up(maxHeapsize * K * K, v.maxAlignment); 251 long actualHeapSize = v.maxHeapSize; 252 253 // bug 8027915 & 8027960: compensate for some cases of large pages 254 if (gcflag.equals("-XX:+UseParallelOldGC")) { 255 int numberOfSpaces = 4; 256 expectedHeapSize = Math.max(expectedHeapSize, numberOfSpaces * v.minAlignment); 257 } 258 259 if (actualHeapSize > expectedHeapSize) { 260 throw new RuntimeException("Heap has " + actualHeapSize + 261 " bytes, expected to be less than " + expectedHeapSize); 262 } 263 } 264 265 private static long getFlagValue(String flag, String where) { 266 Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where); 267 if (!m.find()) { 268 throw new RuntimeException("Could not find value for flag " + flag + " in output string"); 269 } 270 String match = m.group(); 271 return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length())); 272 } 273 274 private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception { 275 if (contains) { 276 output.shouldContain(message); 277 } else { 278 output.shouldNotContain(message); |