ehelin@4655: /* ehelin@4655: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. ehelin@4655: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ehelin@4655: * ehelin@4655: * This code is free software; you can redistribute it and/or modify it ehelin@4655: * under the terms of the GNU General Public License version 2 only, as ehelin@4655: * published by the Free Software Foundation. ehelin@4655: * ehelin@4655: * This code is distributed in the hope that it will be useful, but WITHOUT ehelin@4655: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ehelin@4655: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ehelin@4655: * version 2 for more details (a copy is included in the LICENSE file that ehelin@4655: * accompanied this code). ehelin@4655: * ehelin@4655: * You should have received a copy of the GNU General Public License version ehelin@4655: * 2 along with this work; if not, write to the Free Software Foundation, ehelin@4655: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ehelin@4655: * ehelin@4655: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ehelin@4655: * or visit www.oracle.com if you need additional information or have any ehelin@4655: * questions. ehelin@4655: */ ehelin@4655: ehelin@4655: /* ehelin@4655: * @test ClassMetaspaceSizeInJmapHeap ehelin@4655: * @bug 8004924 ehelin@4655: * @summary Checks that jmap -heap contains the flag ClassMetaspaceSize ehelin@4655: * @library /testlibrary ehelin@4655: * @run main/othervm -XX:ClassMetaspaceSize=50m ClassMetaspaceSizeInJmapHeap ehelin@4655: */ ehelin@4655: ehelin@4655: import com.oracle.java.testlibrary.*; ehelin@4655: import java.nio.file.*; ehelin@4655: import java.io.File; ehelin@4655: import java.nio.charset.Charset; ehelin@4655: import java.util.List; ehelin@4655: ehelin@4655: public class ClassMetaspaceSizeInJmapHeap { ehelin@4655: public static void main(String[] args) throws Exception { ehelin@4655: String pid = Integer.toString(ProcessTools.getProcessId()); ehelin@4655: ehelin@4856: JDKToolLauncher jmap = JDKToolLauncher.create("jmap") ehelin@4856: .addToolArg("-heap") ehelin@4856: .addToolArg(pid); ehelin@4856: ProcessBuilder pb = new ProcessBuilder(jmap.getCommand()); ehelin@4655: ehelin@4655: File out = new File("ClassMetaspaceSizeInJmapHeap.stdout.txt"); ehelin@4655: pb.redirectOutput(out); ehelin@4655: ehelin@4655: File err = new File("ClassMetaspaceSizeInJmapHeap.stderr.txt"); ehelin@4655: pb.redirectError(err); ehelin@4655: ehelin@4655: run(pb); ehelin@4655: ehelin@4655: OutputAnalyzer output = new OutputAnalyzer(read(out)); ehelin@4655: output.shouldContain("ClassMetaspaceSize = 52428800 (50.0MB)"); ehelin@4655: out.delete(); ehelin@4655: } ehelin@4655: ehelin@4655: private static void run(ProcessBuilder pb) throws Exception { ehelin@4655: Process p = pb.start(); ehelin@4655: p.waitFor(); ehelin@4655: int exitValue = p.exitValue(); ehelin@4655: if (exitValue != 0) { ehelin@4655: throw new Exception("jmap -heap exited with error code: " + exitValue); ehelin@4655: } ehelin@4655: } ehelin@4655: ehelin@4655: private static String read(File f) throws Exception { ehelin@4655: Path p = f.toPath(); ehelin@4655: List lines = Files.readAllLines(p, Charset.defaultCharset()); ehelin@4655: ehelin@4655: StringBuilder sb = new StringBuilder(); ehelin@4655: for (String line : lines) { ehelin@4655: sb.append(line).append('\n'); ehelin@4655: } ehelin@4655: return sb.toString(); ehelin@4655: } ehelin@4655: }