Path: blob/master/test/hotspot/jtreg/gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java
40942 views
/*1* Copyright (c) 2013, 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.metaspace;2425/**26* @test CompressedClassSpaceSizeInJmapHeap27* @bug 800492428* @summary Checks that jmap -heap contains the flag CompressedClassSpaceSize29* @requires vm.hasSA30* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true31* @library /test/lib32* @modules java.base/jdk.internal.misc33* java.management34* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:CompressedClassSpaceSize=48m gc.metaspace.CompressedClassSpaceSizeInJmapHeap35*/3637import jdk.test.lib.JDKToolLauncher;38import jdk.test.lib.process.OutputAnalyzer;39import jdk.test.lib.process.ProcessTools;40import jdk.test.lib.SA.SATestUtils;41import java.nio.file.*;42import java.io.File;43import java.nio.charset.Charset;44import java.util.List;4546public class CompressedClassSpaceSizeInJmapHeap {47// Note that on some platforms it may require root privileges to run this test.48public static void main(String[] args) throws Exception {49SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.5051String pid = Long.toString(ProcessTools.getProcessId());5253JDKToolLauncher jmap = JDKToolLauncher.create("jhsdb")54.addToolArg("jmap")55.addToolArg("--heap")56.addToolArg("--pid")57.addToolArg(pid);58ProcessBuilder pb = SATestUtils.createProcessBuilder(jmap);5960File out = new File("CompressedClassSpaceSizeInJmapHeap.stdout.txt");61pb.redirectOutput(out);6263File err = new File("CompressedClassSpaceSizeInJmapHeap.stderr.txt");64pb.redirectError(err);6566run(pb);6768OutputAnalyzer output = new OutputAnalyzer(read(out));69output.shouldContain("CompressedClassSpaceSize = 50331648 (48.0MB)");70out.delete();71}7273private static void run(ProcessBuilder pb) throws Exception {74Process p = pb.start();75p.waitFor();76int exitValue = p.exitValue();77if (exitValue != 0) {78throw new Exception("jmap -heap exited with error code: " + exitValue);79}80}8182private static String read(File f) throws Exception {83Path p = f.toPath();84List<String> lines = Files.readAllLines(p, Charset.defaultCharset());8586StringBuilder sb = new StringBuilder();87for (String line : lines) {88sb.append(line).append('\n');89}90return sb.toString();91}92}939495