< prev index next >

test/hotspot/jtreg/gc/shenandoah/TestDynamicSoftMaxHeapSize.java

Print this page

  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 /*
 88  * @test id=iu-aggressive
 89  * @requires vm.gc.Shenandoah
 90  * @library /test/lib
 91  *
 92  * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 93  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
 94  *      -Dtarget=1000

 95  *      TestDynamicSoftMaxHeapSize

 96  */
 97 
 98 /*
 99  * @test id=iu
100  * @requires vm.gc.Shenandoah
101  * @library /test/lib
102  *
103  * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
104  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
105  *      -Dtarget=10000
106  *      TestDynamicSoftMaxHeapSize




107  */
108 
109 import java.util.Random;
110 import jdk.test.lib.Utils;
111 import jdk.test.lib.process.OutputAnalyzer;
112 import jdk.test.lib.process.ProcessTools;
113 import jdk.test.lib.dcmd.PidJcmdExecutor;
114 





115 public class TestDynamicSoftMaxHeapSize {



116 
117     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation
118     static final long STRIDE = 10_000_000;

119 
120     static volatile Object sink;



121 
122     public static void main(String[] args) throws Exception {
123         long count = TARGET_MB * 1024 * 1024 / 16;
124         Random r = Utils.getRandomInstance();
125         PidJcmdExecutor jcmd = new PidJcmdExecutor();
126 
127         for (long c = 0; c < count; c += STRIDE) {
128             // Sizes specifically include heaps below Xms and above Xmx to test saturation code.
129             jcmd.execute("VM.set_flag SoftMaxHeapSize " + r.nextInt(768*1024*1024), true);
130             for (long s = 0; s < STRIDE; s++) {
131                 sink = new Object();



















132             }
133             Thread.sleep(1);
134         }
135     }
136 















137 }

  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=satb-adaptive
 28  * @requires vm.gc.Shenandoah
 29  * @library /test/lib
 30  *
 31  * @run main/othervm -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 32  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000
 33  *      -XX:ShenandoahGCMode=satb
 34  *      -XX:+ShenandoahDegeneratedGC
 35  *      -XX:ShenandoahGCHeuristics=adaptive
 36  *      TestDynamicSoftMaxHeapSize
 37  *





 38  */
 39 
 40 /**
 41  * @test id=satb-aggressive
 42  * @requires vm.gc.Shenandoah
 43  * @library /test/lib
 44  *
 45  * @run main/othervm -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 46  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000
 47  *      -XX:ShenandoahGCMode=satb
 48  *      -XX:+ShenandoahDegeneratedGC
 49  *      -XX:ShenandoahGCHeuristics=aggressive
 50  *      TestDynamicSoftMaxHeapSize
 51  *
 52  */
 53 
 54 /**
 55  * @test id=satb-compact
 56  * @requires vm.gc.Shenandoah
 57  * @library /test/lib
 58  *
 59  * @run main/othervm -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 60  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000
 61  *      -XX:ShenandoahGCMode=satb
 62  *      -XX:+ShenandoahDegeneratedGC
 63  *      -XX:ShenandoahGCHeuristics=compact
 64  *      TestDynamicSoftMaxHeapSize
 65  *
 66  */
 67 
 68 /**
 69  * @test id=satb-static
 70  * @requires vm.gc.Shenandoah
 71  * @library /test/lib
 72  *
 73  * @run main/othervm -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 74  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000
 75  *      -XX:ShenandoahGCMode=satb
 76  *      -XX:+ShenandoahDegeneratedGC
 77  *      -XX:ShenandoahGCHeuristics=static
 78  *      TestDynamicSoftMaxHeapSize
 79  *
 80  */
 81 
 82 /**
 83  * @test id=passive
 84  * @requires vm.gc.Shenandoah
 85  * @library /test/lib
 86  *
 87  * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 88  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 89  *      -XX:+ShenandoahDegeneratedGC
 90  *      -Dtarget=10000
 91  *      TestDynamicSoftMaxHeapSize
 92  *
 93  * @run main/othervm -Xms16m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 94  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 95  *      -XX:-ShenandoahDegeneratedGC
 96  *      -Dtarget=10000
 97  *      TestDynamicSoftMaxHeapSize
 98  */
 99 
100 /**
101  * @test id=generational
102  * @requires vm.gc.Shenandoah
103  * @library /test/lib
104  *
105  * @run main/othervm -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
106  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000
107  *      -XX:ShenandoahGCMode=generational
108  *      -XX:ShenandoahGCHeuristics=adaptive
109  *      TestDynamicSoftMaxHeapSize
110  *
111  */
112 
113 /**
114  * @test id=generational-softMaxHeapSizeValidation
115  * @requires vm.gc.Shenandoah
116  * @library /test/lib
117  *
118  * @run main/othervm -DvalidateSoftMaxHeap=true


119  *      TestDynamicSoftMaxHeapSize
120  *      -Xms100m -Xmx512m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
121  *      -XX:+UseShenandoahGC -Xlog:gc=info -Dtarget=10000 -DverifySoftMaxHeapValue=true
122  *      -XX:ShenandoahGCMode=generational
123  *      -XX:ShenandoahGCHeuristics=adaptive
124  */


125 import jdk.test.lib.Utils;
126 import jdk.test.lib.process.OutputAnalyzer;
127 import jdk.test.lib.process.ProcessTools;
128 import jdk.test.lib.dcmd.PidJcmdExecutor;
129 
130 import java.util.ArrayList;
131 import java.util.Arrays;
132 import java.util.List;
133 import java.util.Random;
134 
135 public class TestDynamicSoftMaxHeapSize {
136     static final int K = 1024;
137     static final int XMS_MB = 100;
138     static final int XMX_MB = 512;
139 
140     public static void main(String[] args) throws Exception {
141         if ("true".equals(System.getProperty("validateSoftMaxHeap"))) {
142             List<String> flagArgs = new ArrayList<>(Arrays.asList(args));
143 
144             int softMaxInMb = Utils.getRandomInstance().nextInt(XMS_MB, XMX_MB);
145             flagArgs.add("-DsoftMaxCapacity=" + softMaxInMb * K * K);
146             flagArgs.add("-Dtest.jdk=" + System.getProperty("test.jdk"));
147             flagArgs.add("-Dcompile.jdk=" + System.getProperty("compile.jdk"));
148 
149             flagArgs.add(SoftMaxWithExpectationTest.class.getName());
150 
151             ProcessBuilder genShenPbValidateFlag = ProcessTools.createLimitedTestJavaProcessBuilder(flagArgs);
152             OutputAnalyzer output = new OutputAnalyzer(genShenPbValidateFlag.start());
153             output.shouldHaveExitValue(0);
154             output.shouldContain(String.format("Soft Max Heap Size: %dM -> %dM", XMX_MB, softMaxInMb)); // By default, the soft max heap size is Xmx
155         } else {
156             SoftMaxSetFlagOnlyTest.test();
157         }
158     }
159 
160     public static class SoftMaxSetFlagOnlyTest {
161         static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation
162         static final long STRIDE = 10_000_000;
163 
164         static volatile Object sink;
165 
166         public static void test() throws Exception {
167             long count = TARGET_MB * 1024 * 1024 / 16;
168             Random r = Utils.getRandomInstance();
169             PidJcmdExecutor jcmd = new PidJcmdExecutor();
170 
171             for (long c = 0; c < count; c += STRIDE) {
172                 // Sizes specifically include heaps below Xms and above Xmx to test saturation code.
173                 jcmd.execute("VM.set_flag SoftMaxHeapSize " + r.nextInt(768*1024*1024), true);
174                 for (long s = 0; s < STRIDE; s++) {
175                     sink = new Object();
176                 }
177                 Thread.sleep(1);
178             }

179         }
180     }
181 
182     public static class SoftMaxWithExpectationTest {
183         static final long TOTAL = 100_000_000;
184 
185         static volatile Object sink;
186 
187         public static void main(String[] args) throws Exception {
188             int expectedSoftMaxHeapSize = Integer.getInteger("softMaxCapacity", 0);
189             PidJcmdExecutor jcmd = new PidJcmdExecutor();
190             jcmd.execute("VM.set_flag SoftMaxHeapSize " + expectedSoftMaxHeapSize, false);
191 
192             for (long s = 0; s < TOTAL; s++) {
193                 sink = new Object();
194             }
195         }
196     }
197 }
< prev index next >