< prev index next >

test/hotspot/jtreg/gc/arguments/TestAggressiveHeap.java

Print this page




  36 import javax.management.MBeanServer;
  37 import javax.management.ObjectName;
  38 
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 import jdk.test.lib.process.ProcessTools;
  41 
  42 public class TestAggressiveHeap {
  43 
  44     public static void main(String args[]) throws Exception {
  45         if (canUseAggressiveHeapOption()) {
  46             testFlag();
  47         }
  48     }
  49 
  50     // Note: Not a normal boolean flag; -XX:-AggressiveHeap is invalid.
  51     private static final String option = "-XX:+AggressiveHeap";
  52 
  53     // Option requires at least 256M, else error during option processing.
  54     private static final long minMemory = 256 * 1024 * 1024;
  55 





  56     // bool UseParallelGC = true {product} {command line}
  57     private static final String parallelGCPattern =
  58         " *bool +UseParallelGC *= *true +\\{product\\} *\\{command line\\}";
  59 
  60     private static void testFlag() throws Exception {
  61         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  62             option, "-XX:+PrintFlagsFinal", "-version");
  63 
  64         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  65 
  66         output.shouldHaveExitValue(0);
  67 
  68         String value = output.firstMatch(parallelGCPattern);
  69         if (value == null) {
  70             throw new RuntimeException(
  71                 option + " didn't set UseParallelGC as if from command line");
  72         }
  73     }
  74 
  75     private static boolean haveRequiredMemory() throws Exception {
  76         MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  77         ObjectName os = new ObjectName("java.lang", "type", "OperatingSystem");
  78         Object attr = server.getAttribute(os, "TotalPhysicalMemorySize");
  79         String value = attr.toString();
  80         long memory = Long.parseLong(value);
  81         return memory >= minMemory;
  82     }


  36 import javax.management.MBeanServer;
  37 import javax.management.ObjectName;
  38 
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 import jdk.test.lib.process.ProcessTools;
  41 
  42 public class TestAggressiveHeap {
  43 
  44     public static void main(String args[]) throws Exception {
  45         if (canUseAggressiveHeapOption()) {
  46             testFlag();
  47         }
  48     }
  49 
  50     // Note: Not a normal boolean flag; -XX:-AggressiveHeap is invalid.
  51     private static final String option = "-XX:+AggressiveHeap";
  52 
  53     // Option requires at least 256M, else error during option processing.
  54     private static final long minMemory = 256 * 1024 * 1024;
  55 
  56     // Setting the heap to half of the physical memory is not suitable for
  57     // a test environment with many tests running concurrently, setting to
  58     // half of the required size instead.
  59     private static final String heapSizeOption = "-Xmx128M";
  60 
  61     // bool UseParallelGC = true {product} {command line}
  62     private static final String parallelGCPattern =
  63         " *bool +UseParallelGC *= *true +\\{product\\} *\\{command line\\}";
  64 
  65     private static void testFlag() throws Exception {
  66         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  67             option, heapSizeOption, "-XX:+PrintFlagsFinal", "-version");
  68 
  69         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  70 
  71         output.shouldHaveExitValue(0);
  72 
  73         String value = output.firstMatch(parallelGCPattern);
  74         if (value == null) {
  75             throw new RuntimeException(
  76                 option + " didn't set UseParallelGC as if from command line");
  77         }
  78     }
  79 
  80     private static boolean haveRequiredMemory() throws Exception {
  81         MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  82         ObjectName os = new ObjectName("java.lang", "type", "OperatingSystem");
  83         Object attr = server.getAttribute(os, "TotalPhysicalMemorySize");
  84         String value = attr.toString();
  85         long memory = Long.parseLong(value);
  86         return memory >= minMemory;
  87     }
< prev index next >