< prev index next >

test/gc/g1/TestShrinkDefragmentedHeap.java

Print this page
rev 8624 : 8129590: TestShrinkDefragmentedHeap.java runs out of memory
Reviewed-by:


  34  * @library /testlibrary
  35  * @modules java.base/sun.misc
  36  *          java.management/sun.management
  37  */
  38 import java.lang.management.ManagementFactory;
  39 import java.lang.management.MemoryUsage;
  40 import java.util.ArrayList;
  41 import java.util.List;
  42 import static jdk.test.lib.Asserts.*;
  43 import jdk.test.lib.ProcessTools;
  44 import jdk.test.lib.OutputAnalyzer;
  45 import com.sun.management.HotSpotDiagnosticMXBean;
  46 
  47 public class TestShrinkDefragmentedHeap {
  48     // Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap
  49     // together with humongous regions. So if there are a lot of old regions in the lower part of the heap,
  50     // the humongous regions will be allocated in the upper part of the heap anyway.
  51     // To avoid this the Eden needs to be big enough to fit all the small objects.
  52     private static final int INITIAL_HEAP_SIZE  = 200 * 1024 * 1024;
  53     private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024;

  54     private static final int REGION_SIZE        = 1 * 1024 * 1024;
  55 
  56     public static void main(String[] args) throws Exception, Throwable {
  57         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  58                 "-XX:InitialHeapSize=" + INITIAL_HEAP_SIZE,
  59                 "-Xmn" + MINIMAL_YOUNG_SIZE,

  60                 "-XX:MinHeapFreeRatio=10",
  61                 "-XX:MaxHeapFreeRatio=11",
  62                 "-XX:+UseG1GC",
  63                 "-XX:G1HeapRegionSize=" + REGION_SIZE,
  64                 "-XX:-ExplicitGCInvokesConcurrent",
  65                 "-verbose:gc",
  66                 GCTest.class.getName()
  67         );
  68 
  69         OutputAnalyzer output = ProcessTools.executeProcess(pb);
  70         output.shouldHaveExitValue(0);
  71     }
  72 
  73     static class GCTest {
  74 
  75         private static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
  76         private static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
  77         private static final String NEW_SIZE_FLAG_NAME = "NewSize";
  78 
  79         private static final ArrayList<ArrayList<byte[]>> garbage = new ArrayList<>();




  34  * @library /testlibrary
  35  * @modules java.base/sun.misc
  36  *          java.management/sun.management
  37  */
  38 import java.lang.management.ManagementFactory;
  39 import java.lang.management.MemoryUsage;
  40 import java.util.ArrayList;
  41 import java.util.List;
  42 import static jdk.test.lib.Asserts.*;
  43 import jdk.test.lib.ProcessTools;
  44 import jdk.test.lib.OutputAnalyzer;
  45 import com.sun.management.HotSpotDiagnosticMXBean;
  46 
  47 public class TestShrinkDefragmentedHeap {
  48     // Since we store all the small objects, they become old and old regions are also allocated at the bottom of the heap
  49     // together with humongous regions. So if there are a lot of old regions in the lower part of the heap,
  50     // the humongous regions will be allocated in the upper part of the heap anyway.
  51     // To avoid this the Eden needs to be big enough to fit all the small objects.
  52     private static final int INITIAL_HEAP_SIZE  = 200 * 1024 * 1024;
  53     private static final int MINIMAL_YOUNG_SIZE = 190 * 1024 * 1024;
  54     private static final int MAXIMUM_HEAP_SIZE  = 256 * 1024 * 1024;
  55     private static final int REGION_SIZE        = 1 * 1024 * 1024;
  56 
  57     public static void main(String[] args) throws Exception, Throwable {
  58         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  59                 "-XX:InitialHeapSize=" + INITIAL_HEAP_SIZE,
  60                 "-Xmn" + MINIMAL_YOUNG_SIZE,
  61                 "-Xmx" + MAXIMUM_HEAP_SIZE,
  62                 "-XX:MinHeapFreeRatio=10",
  63                 "-XX:MaxHeapFreeRatio=11",
  64                 "-XX:+UseG1GC",
  65                 "-XX:G1HeapRegionSize=" + REGION_SIZE,
  66                 "-XX:-ExplicitGCInvokesConcurrent",
  67                 "-verbose:gc",
  68                 GCTest.class.getName()
  69         );
  70 
  71         OutputAnalyzer output = ProcessTools.executeProcess(pb);
  72         output.shouldHaveExitValue(0);
  73     }
  74 
  75     static class GCTest {
  76 
  77         private static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
  78         private static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
  79         private static final String NEW_SIZE_FLAG_NAME = "NewSize";
  80 
  81         private static final ArrayList<ArrayList<byte[]>> garbage = new ArrayList<>();


< prev index next >