1 /* 2 * Copyright (c) 2020, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 /* 27 * @test id=passive 28 * @requires vm.gc.Shenandoah 29 * @library /test/lib 30 * 31 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 32 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 33 * -XX:+ShenandoahDegeneratedGC 34 * -Dtarget=10000 35 * TestDynamicSoftMaxHeapSize 36 * 37 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 38 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive 39 * -XX:-ShenandoahDegeneratedGC 40 * -Dtarget=10000 41 * TestDynamicSoftMaxHeapSize 42 */ 43 44 /* 45 * @test id=aggressive 46 * @requires vm.gc.Shenandoah 47 * @library /test/lib 48 * 49 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 50 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive 51 * -Dtarget=1000 52 * TestDynamicSoftMaxHeapSize 53 */ 54 55 /* 56 * @test id=adaptive 57 * @requires vm.gc.Shenandoah 58 * @library /test/lib 59 * 60 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 61 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive 62 * -Dtarget=10000 63 * TestDynamicSoftMaxHeapSize 64 */ 65 66 /* 67 * @test id=generational 68 * @requires vm.gc.Shenandoah 69 * @library /test/lib 70 * 71 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 72 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational 73 * -Dtarget=10000 74 * TestDynamicSoftMaxHeapSize 75 */ 76 77 /* 78 * @test id=static 79 * @requires vm.gc.Shenandoah 80 * @library /test/lib 81 * 82 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 83 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static 84 * -Dtarget=10000 85 * TestDynamicSoftMaxHeapSize 86 */ 87 88 /* 89 * @test id=compact 90 * @requires vm.gc.Shenandoah 91 * @library /test/lib 92 * 93 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 94 * -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact 95 * -Dtarget=1000 96 * TestDynamicSoftMaxHeapSize 97 */ 98 99 /* 100 * @test id=iu-aggressive 101 * @requires vm.gc.Shenandoah 102 * @library /test/lib 103 * 104 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 105 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive 106 * -Dtarget=1000 107 * TestDynamicSoftMaxHeapSize 108 */ 109 110 /* 111 * @test id=iu 112 * @requires vm.gc.Shenandoah 113 * @library /test/lib 114 * 115 * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions 116 * -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu 117 * -Dtarget=10000 118 * TestDynamicSoftMaxHeapSize 119 */ 120 121 import java.util.Random; 122 import jdk.test.lib.Utils; 123 import jdk.test.lib.process.OutputAnalyzer; 124 import jdk.test.lib.process.ProcessTools; 125 import jdk.test.lib.dcmd.PidJcmdExecutor; 126 127 public class TestDynamicSoftMaxHeapSize { 128 129 static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation 130 static final long STRIDE = 10_000_000; 131 132 static volatile Object sink; 133 134 public static void main(String[] args) throws Exception { 135 long count = TARGET_MB * 1024 * 1024 / 16; 136 Random r = Utils.getRandomInstance(); 137 PidJcmdExecutor jcmd = new PidJcmdExecutor(); 138 139 for (long c = 0; c < count; c += STRIDE) { 140 // Sizes specifically include heaps below Xms and above Xmx to test saturation code. 141 jcmd.execute("VM.set_flag SoftMaxHeapSize " + r.nextInt(768*1024*1024), true); 142 for (long s = 0; s < STRIDE; s++) { 143 sink = new Object(); 144 } 145 Thread.sleep(1); 146 } 147 } 148 149 }