jdk/test/hotspot/jtreg/runtime/cds/appcds/TestZGCWithCDS.java
Thomas Stuefe da296cbea1 8363996: Obsolete UseCompressedClassPointers
Reviewed-by: rkennke, kvn, adinn, dholmes, mdoerr, iklam, fyang
2026-03-26 11:08:48 +00:00

128 lines
5.0 KiB
Java

/*
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test id=COH
* @bug 8232069
* @requires vm.cds
* @requires vm.bits == 64
* @requires vm.gc.Z
* @requires vm.gc.Serial
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @compile test-classes/Hello.java
* @comment Only run if COH is unset or enabled.
* @requires vm.opt.UseCompactObjectHeaders != "false"
* @comment Driver sets compressed oops/class pointers, jtreg overrides will cause problems.
Only run the test if the flags are not set via the command line.
* @requires vm.opt.UseCompressedOops == null
* @run driver TestZGCWithCDS true
*/
/*
* @test id=NO-COH
* @bug 8232069
* @requires vm.cds
* @requires vm.bits == 64
* @requires vm.gc.Z
* @requires vm.gc.Serial
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @compile test-classes/Hello.java
* @comment Only run if COH is unset or disabled.
* @requires vm.opt.UseCompactObjectHeaders != "true"
* @comment Driver sets compressed oops/class pointers, jtreg overrides will cause problems.
Only run the test if the flags are not set via the command line.
* @requires vm.opt.UseCompressedOops == null
* @run driver TestZGCWithCDS false
*/
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
public class TestZGCWithCDS {
public final static String HELLO = "Hello World";
public final static String UNABLE_TO_USE_ARCHIVE = "Unable to use shared archive.";
public final static String ERR_MSG = "The saved state of UseCompressedOops (0) is different from runtime (1), CDS will be disabled.";
public static void main(String... args) throws Exception {
boolean compactHeadersOn = Boolean.valueOf(args[0]);
String compactHeaders = "-XX:" + (compactHeadersOn ? "+" : "-") + "UseCompactObjectHeaders";
String helloJar = JarBuilder.build("hello", "Hello");
System.out.println("0. Dump with ZGC");
OutputAnalyzer out = TestCommon
.dump(helloJar,
new String[] {"Hello"},
"-XX:+UseZGC",
compactHeaders,
"-Xlog:cds");
out.shouldContain("Dumping shared data to file:");
out.shouldHaveExitValue(0);
System.out.println("Run with same args of dump");
out = TestCommon
.exec(helloJar,
"-XX:+UseZGC",
compactHeaders,
"-Xlog:cds",
"Hello");
out.shouldContain(HELLO);
out.shouldHaveExitValue(0);
System.out.println("Run with ZGC, +UseCompressedOops");
out = TestCommon
.exec(helloJar,
"-XX:-UseZGC",
"-XX:+UseCompressedOops", // in case turned off by vmoptions
compactHeaders,
"-Xlog:cds",
"Hello");
out.shouldContain(UNABLE_TO_USE_ARCHIVE);
out.shouldContain(ERR_MSG);
out.shouldHaveExitValue(1);
System.out.println("Run with SerialGC, -UseCompressedOops");
out = TestCommon
.exec(helloJar,
"-XX:+UseSerialGC",
"-XX:-UseCompressedOops",
compactHeaders,
"-Xlog:cds",
"Hello");
out.shouldContain(HELLO);
out.shouldHaveExitValue(0);
System.out.println("Run with SerialGC, +UseCompressedOops");
out = TestCommon
.exec(helloJar,
"-XX:+UseSerialGC",
"-XX:+UseCompressedOops",
compactHeaders,
"-Xlog:cds",
"Hello");
out.shouldContain(UNABLE_TO_USE_ARCHIVE);
out.shouldContain(ERR_MSG);
out.shouldHaveExitValue(1);
}
}