< prev index next >

hotspot/test/gc/TestSmallHeap.java

Print this page




  40 /* Note: It would be nice to verify the minimal supported heap size (2m) here,
  41  * but we align the heap size based on the card table size. And the card table
  42  * size is aligned based on the minimal pages size provided by the os. This
  43  * means that on most platforms, where the minimal page size is 4k, we get a
  44  * minimal heap size of 2m but on Solaris/Sparc we have a page size of 8k and
  45  * get a minimal heap size of 4m. And on platforms where the page size is 64k
  46  * we get a minimal heap size of 32m. We never use large pages for the card table.
  47  *
  48  * There is also no check in the VM for verifying that the maximum heap size
  49  * is larger than the supported minimal heap size. This means that specifying
  50  * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m or 32m).
  51  *
  52  * To work around these rather strange behaviors this test uses -Xmx2m but then
  53  * calculates what the expected heap size should be. The calculation is a
  54  * simplified version of the code in the VM. We assume that the card table will
  55  * use one page. Each byte in the card table corresponds to 512 bytes on the heap.
  56  * So, the expected heap size is page_size * 512.
  57  */
  58 
  59 import com.oracle.java.testlibrary.*;


  60 import static com.oracle.java.testlibrary.Asserts.*;

  61 import sun.hotspot.WhiteBox;
  62 import sun.management.ManagementFactoryHelper;
  63 
  64 public class TestSmallHeap {
  65 
  66     public static void main(String[] args) {
  67         WhiteBox wb = WhiteBox.getWhiteBox();
  68         int pageSize = wb.getVMPageSize();
  69         int heapBytesPerCard = 512;
  70         long expectedMaxHeap = pageSize * heapBytesPerCard;
  71         String maxHeap = ManagementFactoryHelper.getDiagnosticMXBean().getVMOption("MaxHeapSize").getValue();


  72         assertEQ(Long.parseLong(maxHeap), expectedMaxHeap);
  73     }
  74 }


  40 /* Note: It would be nice to verify the minimal supported heap size (2m) here,
  41  * but we align the heap size based on the card table size. And the card table
  42  * size is aligned based on the minimal pages size provided by the os. This
  43  * means that on most platforms, where the minimal page size is 4k, we get a
  44  * minimal heap size of 2m but on Solaris/Sparc we have a page size of 8k and
  45  * get a minimal heap size of 4m. And on platforms where the page size is 64k
  46  * we get a minimal heap size of 32m. We never use large pages for the card table.
  47  *
  48  * There is also no check in the VM for verifying that the maximum heap size
  49  * is larger than the supported minimal heap size. This means that specifying
  50  * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m or 32m).
  51  *
  52  * To work around these rather strange behaviors this test uses -Xmx2m but then
  53  * calculates what the expected heap size should be. The calculation is a
  54  * simplified version of the code in the VM. We assume that the card table will
  55  * use one page. Each byte in the card table corresponds to 512 bytes on the heap.
  56  * So, the expected heap size is page_size * 512.
  57  */
  58 
  59 import com.oracle.java.testlibrary.*;
  60 import com.sun.management.HotSpotDiagnosticMXBean;
  61 import java.lang.management.ManagementFactory;
  62 import static com.oracle.java.testlibrary.Asserts.*;
  63 
  64 import sun.hotspot.WhiteBox;

  65 
  66 public class TestSmallHeap {
  67 
  68     public static void main(String[] args) {
  69         WhiteBox wb = WhiteBox.getWhiteBox();
  70         int pageSize = wb.getVMPageSize();
  71         int heapBytesPerCard = 512;
  72         long expectedMaxHeap = pageSize * heapBytesPerCard;
  73         String maxHeap
  74             = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
  75                 .getVMOption("MaxHeapSize").getValue();
  76         assertEQ(Long.parseLong(maxHeap), expectedMaxHeap);
  77     }
  78 }
< prev index next >