test/hotspot/jtreg/gc/TestSmallHeap.java
changeset 54638 9b8926bf85c1
parent 53523 4c5184c56dc2
child 59053 ba6c248cae19
equal deleted inserted replaced
54637:b71940f7fa96 54638:9b8926bf85c1
    24 package gc;
    24 package gc;
    25 
    25 
    26 /**
    26 /**
    27  * @test TestSmallHeap
    27  * @test TestSmallHeap
    28  * @bug 8067438 8152239
    28  * @bug 8067438 8152239
    29  * @requires vm.gc=="null"
       
    30  * @summary Verify that starting the VM with a small heap works
    29  * @summary Verify that starting the VM with a small heap works
    31  * @library /test/lib
    30  * @library /test/lib
    32  * @modules java.base/jdk.internal.misc
    31  * @modules java.base/jdk.internal.misc
    33  * @build sun.hotspot.WhiteBox
    32  * @build sun.hotspot.WhiteBox
    34  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    62 import jdk.test.lib.process.OutputAnalyzer;
    61 import jdk.test.lib.process.OutputAnalyzer;
    63 import jdk.test.lib.process.ProcessTools;
    62 import jdk.test.lib.process.ProcessTools;
    64 
    63 
    65 import java.util.LinkedList;
    64 import java.util.LinkedList;
    66 
    65 
       
    66 import jtreg.SkippedException;
    67 import sun.hotspot.WhiteBox;
    67 import sun.hotspot.WhiteBox;
       
    68 import sun.hotspot.gc.GC;
    68 
    69 
    69 public class TestSmallHeap {
    70 public class TestSmallHeap {
    70 
    71 
    71     public static void main(String[] args) throws Exception {
    72     public static void main(String[] args) throws Exception {
    72         // Do all work in the VM driving the test, the VM
    73         // Do all work in the VM driving the test, the VM
    74         // possible to avoid hitting an OOME.
    75         // possible to avoid hitting an OOME.
    75         WhiteBox wb = WhiteBox.getWhiteBox();
    76         WhiteBox wb = WhiteBox.getWhiteBox();
    76         int pageSize = wb.getVMPageSize();
    77         int pageSize = wb.getVMPageSize();
    77         int heapBytesPerCard = 512;
    78         int heapBytesPerCard = 512;
    78         long expectedMaxHeap = pageSize * heapBytesPerCard;
    79         long expectedMaxHeap = pageSize * heapBytesPerCard;
       
    80         boolean noneGCSupported = true;
    79 
    81 
    80         verifySmallHeapSize("-XX:+UseParallelGC", expectedMaxHeap);
    82         if (GC.Parallel.isSupported()) {
    81         verifySmallHeapSize("-XX:+UseSerialGC", expectedMaxHeap);
    83             noneGCSupported = false;
    82         verifySmallHeapSize("-XX:+UseG1GC", expectedMaxHeap);
    84             verifySmallHeapSize("-XX:+UseParallelGC", expectedMaxHeap);
    83         verifySmallHeapSize("-XX:+UseConcMarkSweepGC", expectedMaxHeap);
    85         }
       
    86         if (GC.Serial.isSupported()) {
       
    87             noneGCSupported = false;
       
    88             verifySmallHeapSize("-XX:+UseSerialGC", expectedMaxHeap);
       
    89         }
       
    90         if (GC.G1.isSupported()) {
       
    91             noneGCSupported = false;
       
    92             verifySmallHeapSize("-XX:+UseG1GC", expectedMaxHeap);
       
    93         }
       
    94         if (GC.ConcMarkSweep.isSupported()) {
       
    95             noneGCSupported = false;
       
    96             verifySmallHeapSize("-XX:+UseConcMarkSweepGC", expectedMaxHeap);
       
    97         }
       
    98         if (noneGCSupported) {
       
    99             throw new SkippedException("Skipping test because none of Parallel/Serial/G1/ConcMarkSweep is supported.");
       
   100         }
    84     }
   101     }
    85 
   102 
    86     private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
   103     private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
    87         long minMaxHeap = 4 * 1024 * 1024;
   104         long minMaxHeap = 4 * 1024 * 1024;
    88         LinkedList<String> vmOptions = new LinkedList<>();
   105         LinkedList<String> vmOptions = new LinkedList<>();