-
Bug
-
Resolution: Fixed
-
P3
-
6, 7u4
-
b91
-
generic
-
generic
The test ResetPeakMemoryUsage fails when the G1 GC is used. The failure looks like this:
java.lang.RuntimeException: Before allocation: used = 0 expected to be > After allocation: used = 0
at ResetPeakMemoryUsage.main(ResetPeakMemoryUsage.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
at java.lang.Thread.run(Thread.java:717)
The culprit is the following line:
final long largeArraySize = (usage0.getMax() - usage0.getUsed()) / 10;
G1's pools return -1 for their max size (which according to the spec means undefined). However, the test does not check for that which causes largeArraySize to be calculated as 0. As a result, when the array is allocated, the allocation request is not large, does not go into the old gen, and the old gen does not grow. This causes the exception to be thrown.
To be extra sure the problem is as described above, I hard-coded largeArraySize to be 1M and the test run successfully.
java.lang.RuntimeException: Before allocation: used = 0 expected to be > After allocation: used = 0
at ResetPeakMemoryUsage.main(ResetPeakMemoryUsage.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
at java.lang.Thread.run(Thread.java:717)
The culprit is the following line:
final long largeArraySize = (usage0.getMax() - usage0.getUsed()) / 10;
G1's pools return -1 for their max size (which according to the spec means undefined). However, the test does not check for that which causes largeArraySize to be calculated as 0. As a result, when the array is allocated, the allocation request is not large, does not go into the old gen, and the old gen does not grow. This causes the exception to be thrown.
To be extra sure the problem is as described above, I hard-coded largeArraySize to be 1M and the test run successfully.