< prev index next >

test/gc/g1/TestHumongousShrinkHeap.java

Print this page




  41 import java.util.List;
  42 import static jdk.test.lib.Asserts.*;
  43 
  44 public class TestHumongousShrinkHeap {
  45 
  46     public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
  47     public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
  48 
  49     private static final List<List<byte[]>> garbage = new ArrayList();
  50     private static final int REGION_SIZE = 1024 * 1024; // 1M
  51     private static final int LISTS_COUNT = 10;
  52     private static final int HUMON_SIZE = Math.round(.9f * REGION_SIZE);
  53     private static final long AVAILABLE_MEMORY
  54                               = Runtime.getRuntime().freeMemory();
  55     private static final int HUMON_COUNT
  56                              = (int) ((AVAILABLE_MEMORY / HUMON_SIZE)
  57             / LISTS_COUNT);
  58 
  59 
  60     public static void main(String[] args) {




  61         System.out.format("Running with %s max heap size. "
  62                 + "Will allocate humongous object of %s size %d times.%n",
  63                 MemoryUsagePrinter.humanReadableByteCount(AVAILABLE_MEMORY, false),
  64                 MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false),
  65                 HUMON_COUNT
  66         );
  67         new TestHumongousShrinkHeap().test();
  68     }
  69 
  70     private final void test() {
  71         System.gc();
  72         MemoryUsagePrinter.printMemoryUsage("init");
  73 
  74         allocate();
  75         MemoryUsagePrinter.printMemoryUsage("allocated");
  76         MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
  77 
  78         free();
  79         MemoryUsagePrinter.printMemoryUsage("free");
  80         MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();




  41 import java.util.List;
  42 import static jdk.test.lib.Asserts.*;
  43 
  44 public class TestHumongousShrinkHeap {
  45 
  46     public static final String MIN_FREE_RATIO_FLAG_NAME = "MinHeapFreeRatio";
  47     public static final String MAX_FREE_RATIO_FLAG_NAME = "MaxHeapFreeRatio";
  48 
  49     private static final List<List<byte[]>> garbage = new ArrayList();
  50     private static final int REGION_SIZE = 1024 * 1024; // 1M
  51     private static final int LISTS_COUNT = 10;
  52     private static final int HUMON_SIZE = Math.round(.9f * REGION_SIZE);
  53     private static final long AVAILABLE_MEMORY
  54                               = Runtime.getRuntime().freeMemory();
  55     private static final int HUMON_COUNT
  56                              = (int) ((AVAILABLE_MEMORY / HUMON_SIZE)
  57             / LISTS_COUNT);
  58 
  59 
  60     public static void main(String[] args) {
  61         if (HUMON_COUNT == 0) {
  62             System.out.println("Skipped. Heap is too small");
  63             return;
  64         }
  65         System.out.format("Running with %s max heap size. "
  66                 + "Will allocate humongous object of %s size %d times.%n",
  67                 MemoryUsagePrinter.humanReadableByteCount(AVAILABLE_MEMORY, false),
  68                 MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false),
  69                 HUMON_COUNT
  70         );
  71         new TestHumongousShrinkHeap().test();
  72     }
  73 
  74     private final void test() {
  75         System.gc();
  76         MemoryUsagePrinter.printMemoryUsage("init");
  77 
  78         allocate();
  79         MemoryUsagePrinter.printMemoryUsage("allocated");
  80         MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
  81 
  82         free();
  83         MemoryUsagePrinter.printMemoryUsage("free");
  84         MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();


< prev index next >