Path: blob/master/test/hotspot/jtreg/gc/g1/TestSharedArchiveWithPreTouch.java
40942 views
/*1* Copyright (c) 2016, 2020, 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*/2223package gc.g1;2425/**26* @test27* @bug 816970328* @summary Verifies that dumping and loading a CDS archive succeeds with AlwaysPreTouch29* @requires vm.gc.G130* @requires vm.cds31* @library /test/lib32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.g1.TestSharedArchiveWithPreTouch35*/3637import java.util.List;38import java.util.ArrayList;39import java.util.Arrays;4041import jdk.test.lib.Platform;42import jdk.test.lib.process.ProcessTools;43import jdk.test.lib.process.OutputAnalyzer;4445public class TestSharedArchiveWithPreTouch {46public static void main(String[] args) throws Exception {47final String ArchiveFileName = "./SharedArchiveWithPreTouch.jsa";4849final List<String> BaseOptions = Arrays.asList(new String[] {"-XX:+UseG1GC", "-XX:+AlwaysPreTouch",50"-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + ArchiveFileName });5152ProcessBuilder pb;5354List<String> dump_args = new ArrayList<String>(BaseOptions);5556if (Platform.is64bit()) {57dump_args.addAll(0, Arrays.asList(new String[] { "-XX:+UseCompressedClassPointers", "-XX:+UseCompressedOops" }));58}59dump_args.addAll(Arrays.asList(new String[] { "-Xshare:dump", "-Xlog:cds" }));6061pb = ProcessTools.createJavaProcessBuilder(dump_args);62OutputAnalyzer output = new OutputAnalyzer(pb.start());63try {64output.shouldContain("Loading classes to share");65output.shouldHaveExitValue(0);6667List<String> load_args = new ArrayList<String>(BaseOptions);6869if (Platform.is64bit()) {70load_args.addAll(0, Arrays.asList(new String[] { "-XX:+UseCompressedClassPointers", "-XX:+UseCompressedOops" }));71}72load_args.addAll(Arrays.asList(new String[] { "-Xshare:on", "-version" }));7374pb = ProcessTools.createJavaProcessBuilder(load_args.toArray(new String[0]));75output = new OutputAnalyzer(pb.start());76output.shouldContain("sharing");77output.shouldHaveExitValue(0);78} catch (RuntimeException e) {79// Report 'passed' if CDS was turned off.80output.shouldContain("Unable to use shared archive");81output.shouldHaveExitValue(1);82}83}84}858687