Path: blob/master/test/hotspot/jtreg/runtime/CompressedOops/UseCompressedOops.java
40942 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802286526* @summary Tests for different combination of UseCompressedOops options27* @library /test/lib28* @modules java.base/jdk.internal.misc29* java.management30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. UseCompressedOops33*/34import java.util.ArrayList;35import java.util.Collections;36import jdk.test.lib.Platform;37import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.process.OutputAnalyzer;39import sun.hotspot.gc.GC;4041import sun.hotspot.code.Compiler;4243public class UseCompressedOops {4445public static void main(String[] args) throws Exception {46testCompressedOopsModesGCs();47if (!Platform.isOSX() && !Platform.isAix()) {48testCompressedOopsModesGCs("-XX:+UseLargePages");49}50}5152public static void testCompressedOopsModesGCs(String... flags) throws Exception {53ArrayList<String> args = new ArrayList<>();54Collections.addAll(args, flags);5556// Test default.57testCompressedOopsModes(args);58// Test GCs.59testCompressedOopsModes(args, "-XX:+UseG1GC");60testCompressedOopsModes(args, "-XX:+UseSerialGC");61testCompressedOopsModes(args, "-XX:+UseParallelGC");62if (GC.Shenandoah.isSupported()) {63testCompressedOopsModes(args, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseShenandoahGC");64}65}6667public static void testCompressedOopsModes(ArrayList<String> flags1, String... flags2) throws Exception {68ArrayList<String> args = new ArrayList<>();69args.addAll(flags1);70Collections.addAll(args, flags2);7172if (Platform.is64bit()) {73// Explicitly turn off compressed oops74testCompressedOops(args, "-XX:-UseCompressedOops", "-Xmx32m")75.shouldNotContain("Compressed Oops")76.shouldHaveExitValue(0);7778// Compressed oops should be on by default79testCompressedOops(args, "-Xmx32m")80.shouldContain("Compressed Oops mode")81.shouldHaveExitValue(0);8283// Explicly enabling compressed oops84testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32m")85.shouldContain("Compressed Oops mode")86.shouldHaveExitValue(0);8788// Skip the following seven test cases if we're on OSX or Windows.89//90// OSX doesn't seem to care about HeapBaseMinAddress. Windows memory91// locations are affected by ASLR.92if (!Platform.isOSX() && !Platform.isWindows()) {9394// Larger than 4gb heap should result in zero based with shift 395testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx5g")96.shouldContain("Zero based")97.shouldContain("Oop shift amount: 3")98.shouldHaveExitValue(0);99100// Larger than 3gb heap and HeapBaseMinAddress=1g should result in zero based with shift 3101testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx3200m", "-XX:HeapBaseMinAddress=1g")102.shouldContain("Zero based")103.shouldContain("Oop shift amount: 3")104.shouldHaveExitValue(0);105106// Small heap above 4gb should result in zero based with shift 3107testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32m", "-XX:HeapBaseMinAddress=4g")108.shouldContain("Zero based")109.shouldContain("Oop shift amount: 3")110.shouldHaveExitValue(0);111112// Small heap above 32gb should result in non-zero based with shift 3113testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32m", "-XX:HeapBaseMinAddress=32g")114.shouldContain("Non-zero disjoint base")115.shouldContain("Oop shift amount: 3")116.shouldHaveExitValue(0);117118// Small heap above 32gb should result in non-zero based with shift 3119testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32m", "-XX:HeapBaseMinAddress=72704m")120.shouldContain("Non-zero based")121.shouldContain("Oop shift amount: 3")122.shouldHaveExitValue(0);123124// 32gb heap with heap base above 64gb and object alignment set to 16 bytes should result125// in non-zero based with shift 4126testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32g", "-XX:ObjectAlignmentInBytes=16",127"-XX:HeapBaseMinAddress=64g")128.shouldContain("Non-zero disjoint base")129.shouldContain("Oop shift amount: 4")130.shouldHaveExitValue(0);131132// 32gb heap with object alignment set to 16 bytes should result in zero based with shift 4133testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32g", "-XX:ObjectAlignmentInBytes=16")134.shouldContain("Zero based")135.shouldContain("Oop shift amount: 4")136.shouldHaveExitValue(0);137}138139// This is a pathologic case for the heap allocation algorithm. Regression test.140// HeapBaseMinAddress must be 2g and should not be set on the command line.141testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx2g")142.shouldNotContain("Max heap size too large for Compressed Oops")143.shouldHaveExitValue(0);144testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx29g", "-XX:CompressedClassSpaceSize=1g")145.shouldNotContain("Max heap size too large for Compressed Oops")146.shouldHaveExitValue(0);147148// Explicitly enabling compressed oops with 32gb heap should result a warning149testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32g")150.shouldContain("Max heap size too large for Compressed Oops")151.shouldHaveExitValue(0);152153// 32gb heap should not result a warning154testCompressedOops(args, "-Xmx32g")155.shouldNotContain("Max heap size too large for Compressed Oops")156.shouldHaveExitValue(0);157158// Explicitly enabling compressed oops with 32gb heap and object159// alignment set to 8 byte should result a warning160testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32g", "-XX:ObjectAlignmentInBytes=8")161.shouldContain("Max heap size too large for Compressed Oops")162.shouldHaveExitValue(0);163164// 64gb heap and object alignment set to 16 bytes should result in a warning165testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx64g", "-XX:ObjectAlignmentInBytes=16")166.shouldContain("Max heap size too large for Compressed Oops")167.shouldHaveExitValue(0);168169} else {170// Compressed oops should only apply to 64bit platforms171testCompressedOops(args, "-XX:+UseCompressedOops", "-Xmx32m")172.shouldContain("Unrecognized VM option 'UseCompressedOops'")173.shouldHaveExitValue(1);174}175}176177private static OutputAnalyzer testCompressedOops(ArrayList<String> flags1, String... flags2) throws Exception {178ArrayList<String> args = new ArrayList<>();179180// Always run with these two:181args.add("-Xlog:gc+heap+coops=trace");182args.add("-Xms32m");183184// Add the extra flags185args.addAll(flags1);186Collections.addAll(args, flags2);187188args.add("-version");189190ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);191return new OutputAnalyzer(pb.start());192}193}194195196