1 /* 2 * Copyright (c) 2020, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 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 /* 26 * @test id=passive 27 * @requires vm.gc.Shenandoah 28 * @library /test/lib 29 * 30 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 31 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 32 * -XX:+ShenandoahDegeneratedGC 33 * -Dtarget=10000 34 * TestDynamicSoftMaxHeapSize 35 * 36 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 37 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 38 * -XX:-ShenandoahDegeneratedGC 39 * -Dtarget=10000 40 * TestDynamicSoftMaxHeapSize 41 */ 42 43 /* 44 * @test id=aggressive 45 * @requires vm.gc.Shenandoah 46 * @library /test/lib 47 * 48 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 49 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 50 * -Dtarget=1000 51 * TestDynamicSoftMaxHeapSize 52 */ 53 54 /* 55 * @test id=adaptive 56 * @requires vm.gc.Shenandoah 57 * @library /test/lib 58 * 59 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 60 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 61 * -Dtarget=10000 62 * TestDynamicSoftMaxHeapSize 63 */ 64 65 /* 66 * @test id=static 67 * @requires vm.gc.Shenandoah 68 * @library /test/lib 69 * 70 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 71 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static 72 * -Dtarget=10000 73 * TestDynamicSoftMaxHeapSize 74 */ 75 76 /* 77 * @test id=compact 78 * @requires vm.gc.Shenandoah 79 * @library /test/lib 80 * 81 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 82 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 83 * -Dtarget=1000 84 * TestDynamicSoftMaxHeapSize 85 */ 86 87 import java.util.Random; 88 import jdk.test.lib.Utils; 89 import jdk.test.lib.process.OutputAnalyzer; 90 import jdk.test.lib.process.ProcessTools; 91 import jdk.test.lib.dcmd.PidJcmdExecutor; 92 93 public class TestDynamicSoftMaxHeapSize { 94 95 static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation 96 static final long STRIDE = 10_000_000; 97 98 static volatile Object sink; 99 100 public static void main(String[] args) throws Exception { 101 long count = TARGET_MB * 1024 * 1024 / 16; 102 Random r = Utils.getRandomInstance(); 103 PidJcmdExecutor jcmd = new PidJcmdExecutor(); 104 105 for (long c = 0; c < count; c += STRIDE) { 106 // Sizes specifically include heaps below Xms and above Xmx to test saturation code. 107 jcmd.execute("VM.set_flag SoftMaxHeapSize " + r.nextInt(768*1024*1024), true); 108 for (long s = 0; s < STRIDE; s++) { 109 sink = new Object(); 110 } 111 Thread.sleep(1); 112 } 113 } 114 115 }