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  * @key randomness
 29  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
 30  * @requires vm.gc.Shenandoah
 31  * @library /test/lib
 32  *
 33  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 34  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 35  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 36  *      -XX:+ShenandoahVerify
 37  *      -XX:+ResizeTLAB
 38  *      TestResizeTLAB
 39  *
 40  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 41  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 42  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 43  *      -XX:+ShenandoahVerify
 44  *      -XX:-ResizeTLAB
 45  *      TestResizeTLAB
 46  *
 47  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 48  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 49  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 50  *      -XX:+ShenandoahVerify
 51  *      -XX:+ResizeTLAB
 52  *      TestResizeTLAB
 53  *
 54  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 55  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 56  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 57  *      -XX:+ShenandoahVerify
 58  *      -XX:-ResizeTLAB
 59  *      TestResizeTLAB
 60  */
 61 
 62 /*
 63  * @test id=aggressive
 64  * @key randomness
 65  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
 66  * @requires vm.gc.Shenandoah
 67  * @library /test/lib
 68  *
 69  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 70  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 71  *      -XX:+ShenandoahVerify
 72  *      -XX:+ResizeTLAB
 73  *      TestResizeTLAB
 74  *
 75  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 76  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 77  *      -XX:+ShenandoahVerify
 78  *      -XX:-ResizeTLAB
 79  *      TestResizeTLAB
 80  */
 81 
 82 /*
 83  * @test id=adaptive
 84  * @key randomness
 85  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
 86  * @requires vm.gc.Shenandoah
 87  * @library /test/lib
 88  *
 89  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 90  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 91  *      -XX:+ShenandoahVerify
 92  *      -XX:+ResizeTLAB
 93  *      TestResizeTLAB
 94  *
 95  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 96  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 97  *      -XX:+ShenandoahVerify
 98  *      -XX:-ResizeTLAB
 99  *      TestResizeTLAB
100  */
101 
102 /*
103  * @test id=generational
104  * @key randomness
105  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
106  * @requires vm.gc.Shenandoah
107  * @library /test/lib
108  *
109  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
110  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
111  *      -XX:+ShenandoahVerify
112  *      -XX:+ResizeTLAB
113  *      TestResizeTLAB
114  *
115  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
116  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
117  *      -XX:+ShenandoahVerify
118  *      -XX:-ResizeTLAB
119  *      TestResizeTLAB
120  */
121 
122 /*
123  * @test id=static
124  * @key randomness
125  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
126  * @requires vm.gc.Shenandoah
127  * @library /test/lib
128  *
129  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
130  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
131  *      -XX:+ShenandoahVerify
132  *      -XX:+ResizeTLAB
133  *      TestResizeTLAB
134  *
135  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
136  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
137  *      -XX:+ShenandoahVerify
138  *      -XX:-ResizeTLAB
139  *      TestResizeTLAB
140  */
141 
142 /*
143  * @test id=compact
144  * @key randomness
145  * @summary Test that Shenandoah is able to work with(out) resizeable TLABs
146  * @requires vm.gc.Shenandoah
147  * @library /test/lib
148  *
149  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
150  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
151  *      -XX:+ShenandoahVerify
152  *      -XX:+ResizeTLAB
153  *      TestResizeTLAB
154  *
155  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
156  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
157  *      -XX:+ShenandoahVerify
158  *      -XX:-ResizeTLAB
159  *      TestResizeTLAB
160  */
161 
162 import java.util.Random;
163 import jdk.test.lib.Utils;
164 
165 public class TestResizeTLAB {
166 
167     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation
168 
169     static volatile Object sink;
170 
171     public static void main(String[] args) throws Exception {
172         final int min = 0;
173         final int max = 384 * 1024;
174         long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
175 
176         Random r = Utils.getRandomInstance();
177         for (long c = 0; c < count; c++) {
178             sink = new int[min + r.nextInt(max - min)];
179         }
180     }
181 
182 }