Sat, 23 Mar 2013 09:16:37 +0100
8009408: gc/metaspace/ClassMetaspaceSizeInJmapHeap.java fails with "exit code 1"
Reviewed-by: brutisso, sla, ctornqvi
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@4856 | 42 | JDKToolLauncher jmap = JDKToolLauncher.create("jmap") |
ehelin@4856 | 43 | .addToolArg("-heap") |
ehelin@4856 | 44 | .addToolArg(pid); |
ehelin@4856 | 45 | ProcessBuilder pb = new ProcessBuilder(jmap.getCommand()); |
ehelin@4655 | 46 | |
ehelin@4655 | 47 | File out = new File("ClassMetaspaceSizeInJmapHeap.stdout.txt"); |
ehelin@4655 | 48 | pb.redirectOutput(out); |
ehelin@4655 | 49 | |
ehelin@4655 | 50 | File err = new File("ClassMetaspaceSizeInJmapHeap.stderr.txt"); |
ehelin@4655 | 51 | pb.redirectError(err); |
ehelin@4655 | 52 | |
ehelin@4655 | 53 | run(pb); |
ehelin@4655 | 54 | |
ehelin@4655 | 55 | OutputAnalyzer output = new OutputAnalyzer(read(out)); |
ehelin@4655 | 56 | output.shouldContain("ClassMetaspaceSize = 52428800 (50.0MB)"); |
ehelin@4655 | 57 | out.delete(); |
ehelin@4655 | 58 | } |
ehelin@4655 | 59 | |
ehelin@4655 | 60 | private static void run(ProcessBuilder pb) throws Exception { |
ehelin@4655 | 61 | Process p = pb.start(); |
ehelin@4655 | 62 | p.waitFor(); |
ehelin@4655 | 63 | int exitValue = p.exitValue(); |
ehelin@4655 | 64 | if (exitValue != 0) { |
ehelin@4655 | 65 | throw new Exception("jmap -heap exited with error code: " + exitValue); |
ehelin@4655 | 66 | } |
ehelin@4655 | 67 | } |
ehelin@4655 | 68 | |
ehelin@4655 | 69 | private static String read(File f) throws Exception { |
ehelin@4655 | 70 | Path p = f.toPath(); |
ehelin@4655 | 71 | List<String> lines = Files.readAllLines(p, Charset.defaultCharset()); |
ehelin@4655 | 72 | |
ehelin@4655 | 73 | StringBuilder sb = new StringBuilder(); |
ehelin@4655 | 74 | for (String line : lines) { |
ehelin@4655 | 75 | sb.append(line).append('\n'); |
ehelin@4655 | 76 | } |
ehelin@4655 | 77 | return sb.toString(); |
ehelin@4655 | 78 | } |
ehelin@4655 | 79 | } |