50 } |
50 } |
51 |
51 |
52 public static void testMemoryBean(long initSize, long maxSize) { |
52 public static void testMemoryBean(long initSize, long maxSize) { |
53 MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); |
53 MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); |
54 long heapInit = memoryMXBean.getHeapMemoryUsage().getInit(); |
54 long heapInit = memoryMXBean.getHeapMemoryUsage().getInit(); |
|
55 long heapCommitted = memoryMXBean.getHeapMemoryUsage().getCommitted(); |
55 long heapMax = memoryMXBean.getHeapMemoryUsage().getMax(); |
56 long heapMax = memoryMXBean.getHeapMemoryUsage().getMax(); |
56 long nonHeapInit = memoryMXBean.getNonHeapMemoryUsage().getInit(); |
57 long nonHeapInit = memoryMXBean.getNonHeapMemoryUsage().getInit(); |
|
58 long nonHeapCommitted = memoryMXBean.getNonHeapMemoryUsage().getCommitted(); |
57 long nonHeapMax = memoryMXBean.getNonHeapMemoryUsage().getMax(); |
59 long nonHeapMax = memoryMXBean.getNonHeapMemoryUsage().getMax(); |
58 |
60 |
59 if (initSize > 0 && heapInit != initSize) { |
61 if (initSize > 0 && heapInit != initSize) { |
60 throw new IllegalStateException("Init heap size is wrong: " + heapInit + " vs " + initSize); |
62 throw new IllegalStateException("Init heap size is wrong: " + heapInit + " vs " + initSize); |
61 } |
63 } |
62 if (maxSize > 0 && heapMax != maxSize) { |
64 if (maxSize > 0 && heapMax != maxSize) { |
63 throw new IllegalStateException("Max heap size is wrong: " + heapMax + " vs " + maxSize); |
65 throw new IllegalStateException("Max heap size is wrong: " + heapMax + " vs " + maxSize); |
64 } |
66 } |
|
67 if (initSize > 0 && maxSize > 0 && initSize != maxSize && heapCommitted == heapMax) { |
|
68 throw new IllegalStateException("Init committed heap size is wrong: " + heapCommitted + |
|
69 " (init: " + initSize + ", max: " + maxSize + ")"); |
|
70 } |
65 } |
71 } |
66 } |
72 } |