test/gc/metaspace/ClassMetaspaceSizeInJmapHeap.java

Wed, 06 Feb 2013 07:48:02 +0100

author
ehelin
date
Wed, 06 Feb 2013 07:48:02 +0100
changeset 4655
9a094d29af19
child 4856
8bf6338972ce
permissions
-rw-r--r--

8004924: NPG: jmap -heap output should contain ClassMetaspaceSize value
Reviewed-by: stefank, mgerdin

ehelin@4655 1 /*
ehelin@4655 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ehelin@4655 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ehelin@4655 4 *
ehelin@4655 5 * This code is free software; you can redistribute it and/or modify it
ehelin@4655 6 * under the terms of the GNU General Public License version 2 only, as
ehelin@4655 7 * published by the Free Software Foundation.
ehelin@4655 8 *
ehelin@4655 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ehelin@4655 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ehelin@4655 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ehelin@4655 12 * version 2 for more details (a copy is included in the LICENSE file that
ehelin@4655 13 * accompanied this code).
ehelin@4655 14 *
ehelin@4655 15 * You should have received a copy of the GNU General Public License version
ehelin@4655 16 * 2 along with this work; if not, write to the Free Software Foundation,
ehelin@4655 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ehelin@4655 18 *
ehelin@4655 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ehelin@4655 20 * or visit www.oracle.com if you need additional information or have any
ehelin@4655 21 * questions.
ehelin@4655 22 */
ehelin@4655 23
ehelin@4655 24 /*
ehelin@4655 25 * @test ClassMetaspaceSizeInJmapHeap
ehelin@4655 26 * @bug 8004924
ehelin@4655 27 * @summary Checks that jmap -heap contains the flag ClassMetaspaceSize
ehelin@4655 28 * @library /testlibrary
ehelin@4655 29 * @run main/othervm -XX:ClassMetaspaceSize=50m ClassMetaspaceSizeInJmapHeap
ehelin@4655 30 */
ehelin@4655 31
ehelin@4655 32 import com.oracle.java.testlibrary.*;
ehelin@4655 33 import java.nio.file.*;
ehelin@4655 34 import java.io.File;
ehelin@4655 35 import java.nio.charset.Charset;
ehelin@4655 36 import java.util.List;
ehelin@4655 37
ehelin@4655 38 public class ClassMetaspaceSizeInJmapHeap {
ehelin@4655 39 public static void main(String[] args) throws Exception {
ehelin@4655 40 String pid = Integer.toString(ProcessTools.getProcessId());
ehelin@4655 41
ehelin@4655 42 ProcessBuilder pb = new ProcessBuilder();
ehelin@4655 43 pb.command(JDKToolFinder.getJDKTool("jmap"), "-heap", pid);
ehelin@4655 44
ehelin@4655 45 File out = new File("ClassMetaspaceSizeInJmapHeap.stdout.txt");
ehelin@4655 46 pb.redirectOutput(out);
ehelin@4655 47
ehelin@4655 48 File err = new File("ClassMetaspaceSizeInJmapHeap.stderr.txt");
ehelin@4655 49 pb.redirectError(err);
ehelin@4655 50
ehelin@4655 51 run(pb);
ehelin@4655 52
ehelin@4655 53 OutputAnalyzer output = new OutputAnalyzer(read(out));
ehelin@4655 54 output.shouldContain("ClassMetaspaceSize = 52428800 (50.0MB)");
ehelin@4655 55 out.delete();
ehelin@4655 56 }
ehelin@4655 57
ehelin@4655 58 private static void run(ProcessBuilder pb) throws Exception {
ehelin@4655 59 Process p = pb.start();
ehelin@4655 60 p.waitFor();
ehelin@4655 61 int exitValue = p.exitValue();
ehelin@4655 62 if (exitValue != 0) {
ehelin@4655 63 throw new Exception("jmap -heap exited with error code: " + exitValue);
ehelin@4655 64 }
ehelin@4655 65 }
ehelin@4655 66
ehelin@4655 67 private static String read(File f) throws Exception {
ehelin@4655 68 Path p = f.toPath();
ehelin@4655 69 List<String> lines = Files.readAllLines(p, Charset.defaultCharset());
ehelin@4655 70
ehelin@4655 71 StringBuilder sb = new StringBuilder();
ehelin@4655 72 for (String line : lines) {
ehelin@4655 73 sb.append(line).append('\n');
ehelin@4655 74 }
ehelin@4655 75 return sb.toString();
ehelin@4655 76 }
ehelin@4655 77 }

mercurial