11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 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 TestStressG1Humongous 26 * @key gc 27 * @key stress 28 * @summary Stress G1 by humongous allocations in situation near OOM 29 * @requires vm.gc.G1 30 * @requires !vm.flightRecorder 31 * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=4m 32 * -Dtimeout=120 -Dthreads=3 -Dhumongoussize=1.1 -Dregionsize=4 TestStressG1Humongous 33 * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=16m 34 * -Dtimeout=120 -Dthreads=5 -Dhumongoussize=2.1 -Dregionsize=16 TestStressG1Humongous 35 * @run main/othervm/timeout=200 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=32m 36 * -Dtimeout=120 -Dthreads=4 -Dhumongoussize=0.6 -Dregionsize=32 TestStressG1Humongous 37 * @run main/othervm/timeout=700 -Xlog:gc=debug -Xmx1g -XX:+UseG1GC -XX:G1HeapRegionSize=1m 38 * -Dtimeout=600 -Dthreads=7 -Dhumongoussize=0.6 -Dregionsize=1 TestStressG1Humongous 39 */ 40 41 import java.util.ArrayList; 42 import java.util.List; 43 import java.util.Collections; 44 import java.util.concurrent.CountDownLatch; 45 import java.util.concurrent.atomic.AtomicInteger; 46 47 public class TestStressG1Humongous { 48 49 // Timeout in seconds 50 private static final int TIMEOUT = Integer.getInteger("timeout", 60); 51 private static final int THREAD_COUNT = Integer.getInteger("threads", 2); 52 private static final int REGION_SIZE = Integer.getInteger("regionsize", 1) * 1024 * 1024; 53 private static final int HUMONGOUS_SIZE = (int) (REGION_SIZE * Double.parseDouble(System.getProperty("humongoussize", "1.5"))); 54 private static final int NUMBER_OF_FREE_REGIONS = 2; 55 56 private volatile boolean isRunning; 57 private final Thread[] threads; 58 private final AtomicInteger alocatedObjectsCount; 59 private CountDownLatch countDownLatch; 60 public static final List<Object> GARBAGE = Collections.synchronizedList(new ArrayList<>()); 61 62 public static void main(String[] args) throws InterruptedException { 63 new TestStressG1Humongous().run(); 64 } 65 66 public TestStressG1Humongous() { 67 isRunning = true; 68 threads = new Thread[THREAD_COUNT]; 69 alocatedObjectsCount = new AtomicInteger(0); 70 } 71 72 private void run() throws InterruptedException { 73 new Thread(new Timer()).start(); 74 int checkedAmountOfHObjects = getExpectedAmountOfObjects(); 75 while (isRunning()) { 76 countDownLatch = new CountDownLatch(THREAD_COUNT); 77 startAllocationThreads(checkedAmountOfHObjects); 78 countDownLatch.await(); 79 GARBAGE.clear(); 80 System.out.println("Allocated " + alocatedObjectsCount.get() + " objects."); 81 alocatedObjectsCount.set(0); 82 } 83 System.out.println("Done!"); 84 } 85 86 /** | 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 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 TestStressG1Humongous 26 * @key gc 27 * @key stress 28 * @summary Stress G1 by humongous allocations in situation near OOM 29 * @requires vm.gc.G1 30 * @requires !vm.flightRecorder 31 * @library /test/lib 32 * @modules java.base/jdk.internal.misc 33 * @run driver/timeout=1300 TestStressG1Humongous 34 */ 35 36 import java.util.ArrayList; 37 import java.util.List; 38 import java.util.Collections; 39 import java.util.concurrent.CountDownLatch; 40 import java.util.concurrent.atomic.AtomicInteger; 41 42 import jdk.test.lib.Platform; 43 import jdk.test.lib.Utils; 44 import jdk.test.lib.process.ProcessTools; 45 import jdk.test.lib.process.OutputAnalyzer; 46 47 public class TestStressG1Humongous{ 48 49 public static void main(String[] args) throws Exception { 50 // Limit heap size on 32-bit platforms 51 int heapSize = Platform.is32bit() ? 512 : 1024; 52 // Heap size, region size, threads, humongous size, timeout 53 run(heapSize, 4, 3, 1.1, 120); 54 run(heapSize, 16, 5, 2.1, 120); 55 run(heapSize, 32, 4, 0.6, 120); 56 run(heapSize, 1, 7, 0.6, 600); 57 } 58 59 private static void run(int heapSize, int regionSize, int threads, double humongousSize, int timeout) 60 throws Exception { 61 ArrayList<String> options = new ArrayList<>(); 62 Collections.addAll(options, Utils.getTestJavaOpts()); 63 Collections.addAll(options, 64 "-Xlog:gc=debug", 65 "-Xmx" + heapSize + "m", 66 "-XX:+UseG1GC", 67 "-XX:G1HeapRegionSize=" + regionSize + "m", 68 "-Dtimeout=" + timeout, 69 "-Dthreads=" + threads, 70 "-Dhumongoussize=" + humongousSize, 71 "-Dregionsize=" + regionSize, 72 TestStressG1HumongousImpl.class.getName() 73 ); 74 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options.toArray(new String[options.size()])); 75 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 76 output.shouldHaveExitValue(0); 77 } 78 } 79 80 class TestStressG1HumongousImpl { 81 // Timeout in seconds 82 private static final int TIMEOUT = Integer.getInteger("timeout", 60); 83 private static final int THREAD_COUNT = Integer.getInteger("threads", 2); 84 private static final int REGION_SIZE = Integer.getInteger("regionsize", 1) * 1024 * 1024; 85 private static final int HUMONGOUS_SIZE = (int) (REGION_SIZE * Double.parseDouble(System.getProperty("humongoussize", "1.5"))); 86 private static final int NUMBER_OF_FREE_REGIONS = 2; 87 88 private volatile boolean isRunning; 89 private final Thread[] threads; 90 private final AtomicInteger alocatedObjectsCount; 91 private CountDownLatch countDownLatch; 92 public static final List<Object> GARBAGE = Collections.synchronizedList(new ArrayList<>()); 93 94 public static void main(String[] args) throws InterruptedException { 95 new TestStressG1HumongousImpl().run(); 96 } 97 98 public TestStressG1HumongousImpl() { 99 isRunning = true; 100 threads = new Thread[THREAD_COUNT]; 101 alocatedObjectsCount = new AtomicInteger(0); 102 } 103 104 private void run() throws InterruptedException { 105 new Thread(new Timer()).start(); 106 int checkedAmountOfHObjects = getExpectedAmountOfObjects(); 107 while (isRunning()) { 108 countDownLatch = new CountDownLatch(THREAD_COUNT); 109 startAllocationThreads(checkedAmountOfHObjects); 110 countDownLatch.await(); 111 GARBAGE.clear(); 112 System.out.println("Allocated " + alocatedObjectsCount.get() + " objects."); 113 alocatedObjectsCount.set(0); 114 } 115 System.out.println("Done!"); 116 } 117 118 /** |