14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test TestShrinkDefragmentedHeap 26 * @bug 8038423 8129590 27 * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects 28 * 1. allocate small objects mixed with humongous ones 29 * "ssssHssssHssssHssssHssssHssssHssssH" 30 * 2. release all allocated object except the last humongous one 31 * "..................................H" 32 * 3. invoke gc and check that memory returned to the system (amount of committed memory got down) 33 * 34 * @library /testlibrary 35 * @modules java.base/jdk.internal.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", | 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test TestShrinkDefragmentedHeap 26 * @bug 8038423 8129590 27 * @summary Verify that heap shrinks after GC in the presence of fragmentation due to humongous objects 28 * 1. allocate small objects mixed with humongous ones 29 * "ssssHssssHssssHssssHssssHssssHssssH" 30 * 2. release all allocated object except the last humongous one 31 * "..................................H" 32 * 3. invoke gc and check that memory returned to the system (amount of committed memory got down) 33 * 34 * @library /test/lib 35 * @modules java.base/jdk.internal.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.process.OutputAnalyzer; 44 import jdk.test.lib.process.ProcessTools; 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", |