1 /*
 2  * Copyright Amazon.com Inc. or its affiliates. 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  * @test id=compact-headers
26  * @summary With compact object headers the max TLAB size must be strictly below a
27  *          region, so a region-sized object can never be served from a TLAB (which
28  *          would bypass the humongous path). The cap is only observable indirectly:
29  *          a region-sized -XX:TLABSize is rejected at startup under compact headers,
30  *          but accepted without them (where the max TLAB equals the region size).
31  * @bug 8387285
32  * @requires vm.gc.Shenandoah
33  * @library /test/lib
34  * @modules java.base/jdk.internal.misc
35  *          java.management
36  * @run driver TestCompactHeaderTLABSize
37  */
38 
39 import jdk.test.lib.process.ProcessTools;
40 import jdk.test.lib.process.OutputAnalyzer;
41 
42 public class TestCompactHeaderTLABSize {
43 
44     // Minimum Shenandoah region size; the only size at which the un-capped max TLAB
45     // would otherwise equal the region size.
46     static final String REGION_SIZE = "256K";
47 
48     public static void main(String[] args) throws Exception {
49         // With compact object headers, the max TLAB is capped one word below the
50         // region, so requesting a region-sized TLAB must be rejected at startup.
51         OutputAnalyzer coh = ProcessTools.executeLimitedTestJava(
52                 "-XX:+UnlockExperimentalVMOptions",
53                 "-XX:+UnlockDiagnosticVMOptions",
54                 "-XX:+UseShenandoahGC",
55                 "-XX:+UseCompactObjectHeaders",
56                 "-XX:ShenandoahRegionSize=" + REGION_SIZE,
57                 "-XX:TLABSize=" + REGION_SIZE,
58                 "-Xmx512m",
59                 "-version");
60         coh.shouldContain("must be less than or equal to ergonomic TLAB maximum size");
61         coh.shouldHaveExitValue(1);
62 
63         // Without compact object headers there is no hash-code expansion, so the max
64         // TLAB equals the region size and the same region-sized TLAB is accepted.
65         OutputAnalyzer noCoh = ProcessTools.executeLimitedTestJava(
66                 "-XX:+UnlockExperimentalVMOptions",
67                 "-XX:+UnlockDiagnosticVMOptions",
68                 "-XX:+UseShenandoahGC",
69                 "-XX:-UseCompactObjectHeaders",
70                 "-XX:ShenandoahRegionSize=" + REGION_SIZE,
71                 "-XX:TLABSize=" + REGION_SIZE,
72                 "-Xmx512m",
73                 "-version");
74         noCoh.shouldHaveExitValue(0);
75 
76         // Under compact headers, a TLAB one word below the region is still accepted:
77         // the cap is exactly one (object-aligned) word, not an arbitrary reduction.
78         OutputAnalyzer atCap = ProcessTools.executeLimitedTestJava(
79                 "-XX:+UnlockExperimentalVMOptions",
80                 "-XX:+UnlockDiagnosticVMOptions",
81                 "-XX:+UseShenandoahGC",
82                 "-XX:+UseCompactObjectHeaders",
83                 "-XX:ShenandoahRegionSize=" + REGION_SIZE,
84                 "-XX:TLABSize=" + (256 * 1024 - 8), // one HeapWord below the region
85                 "-Xmx512m",
86                 "-version");
87         atCap.shouldHaveExitValue(0);
88     }
89 }