23 */ 24 25 package gc.g1.humongousObjects; 26 27 import jdk.test.lib.Asserts; 28 import sun.hotspot.WhiteBox; 29 30 /** 31 * @test TestHumongousThreshold 32 * @summary Checks that objects larger than half a region are allocated as humongous 33 * @requires vm.gc=="G1" | vm.gc=="null" 34 * @library /testlibrary /../../test/lib 35 * @modules java.management 36 * @build sun.hotspot.WhiteBox 37 * gc.g1.humongousObjects.Helpers 38 * gc.g1.humongousObjects.TestHumongousThreshold 39 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 40 * sun.hotspot.WhiteBox$WhiteBoxPermission 41 * 42 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 43 * -XX:G1HeapRegionSize=1M 44 * gc.g1.humongousObjects.TestHumongousThreshold 45 * 46 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 47 * -XX:G1HeapRegionSize=2M 48 * gc.g1.humongousObjects.TestHumongousThreshold 49 * 50 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 51 * -XX:G1HeapRegionSize=4M 52 * gc.g1.humongousObjects.TestHumongousThreshold 53 * 54 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 55 * -XX:G1HeapRegionSize=8M 56 * gc.g1.humongousObjects.TestHumongousThreshold 57 * 58 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 59 * -XX:G1HeapRegionSize=16M 60 * gc.g1.humongousObjects.TestHumongousThreshold 61 * 62 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 63 * -XX:G1HeapRegionSize=32M 64 * gc.g1.humongousObjects.TestHumongousThreshold 65 * 66 */ 67 68 public class TestHumongousThreshold { 69 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 70 private static final int REGION_SIZE = WHITE_BOX.g1RegionSize(); 71 private static final int MAX_CONTINUOUS_SIZE_CHECK = 129; 72 private static final int NON_HUMONGOUS_DIVIDER = 10; 73 74 /** 75 * The method allocates byte[] with specified size and checks that: 76 * 1. byte[] is allocated as we specified in expectedHumongous. 77 * 2. byte[] is allocated as humongous if its size is large than a half of region and non-humongous otherwise. 78 * It uses WB to obtain the size of created byte[]. Only objects larger than half of region are expected 79 * to be humongous. 80 * 81 * @param arraySize size of allocation 82 * @param expectedHumongous expected humongous/non-humongous allocation 83 * @return allocated byte array | 23 */ 24 25 package gc.g1.humongousObjects; 26 27 import jdk.test.lib.Asserts; 28 import sun.hotspot.WhiteBox; 29 30 /** 31 * @test TestHumongousThreshold 32 * @summary Checks that objects larger than half a region are allocated as humongous 33 * @requires vm.gc=="G1" | vm.gc=="null" 34 * @library /testlibrary /../../test/lib 35 * @modules java.management 36 * @build sun.hotspot.WhiteBox 37 * gc.g1.humongousObjects.Helpers 38 * gc.g1.humongousObjects.TestHumongousThreshold 39 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 40 * sun.hotspot.WhiteBox$WhiteBoxPermission 41 * 42 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 43 * -XX:G1HeapRegionSize=1M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 44 * gc.g1.humongousObjects.TestHumongousThreshold 45 * 46 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 47 * -XX:G1HeapRegionSize=2M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 48 * gc.g1.humongousObjects.TestHumongousThreshold 49 * 50 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 51 * -XX:G1HeapRegionSize=4M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 52 * gc.g1.humongousObjects.TestHumongousThreshold 53 * 54 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 55 * -XX:G1HeapRegionSize=8M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 56 * gc.g1.humongousObjects.TestHumongousThreshold 57 * 58 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 59 * -XX:G1HeapRegionSize=16M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 60 * gc.g1.humongousObjects.TestHumongousThreshold 61 * 62 * @run main/othervm -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 63 * -XX:G1HeapRegionSize=32M -XX:+PrintGCDetails -XX:+PrintHeapAtGC 64 * gc.g1.humongousObjects.TestHumongousThreshold 65 * 66 */ 67 68 public class TestHumongousThreshold { 69 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 70 private static final int REGION_SIZE = WHITE_BOX.g1RegionSize(); 71 private static final int MAX_CONTINUOUS_SIZE_CHECK = 129; 72 private static final int NON_HUMONGOUS_DIVIDER = 10; 73 74 /** 75 * The method allocates byte[] with specified size and checks that: 76 * 1. byte[] is allocated as we specified in expectedHumongous. 77 * 2. byte[] is allocated as humongous if its size is large than a half of region and non-humongous otherwise. 78 * It uses WB to obtain the size of created byte[]. Only objects larger than half of region are expected 79 * to be humongous. 80 * 81 * @param arraySize size of allocation 82 * @param expectedHumongous expected humongous/non-humongous allocation 83 * @return allocated byte array |