test/gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 28,39 ****
* @library /testlibrary
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:CompressedClassSpaceSize=50m CompressedClassSpaceSizeInJmapHeap
*/
import com.oracle.java.testlibrary.*;
- import java.nio.file.*;
- import java.io.File;
import java.nio.charset.Charset;
import java.util.List;
public class CompressedClassSpaceSizeInJmapHeap {
public static void main(String[] args) throws Exception {
--- 28,37 ----
*** 51,88 ****
JDKToolLauncher jmap = JDKToolLauncher.create("jmap")
.addToolArg("-heap")
.addToolArg(pid);
ProcessBuilder pb = new ProcessBuilder(jmap.getCommand());
! File out = new File("CompressedClassSpaceSizeInJmapHeap.stdout.txt");
! pb.redirectOutput(out);
!
! File err = new File("CompressedClassSpaceSizeInJmapHeap.stderr.txt");
! pb.redirectError(err);
!
! run(pb);
!
! OutputAnalyzer output = new OutputAnalyzer(read(out));
output.shouldContain("CompressedClassSpaceSize = 52428800 (50.0MB)");
- out.delete();
- }
-
- private static void run(ProcessBuilder pb) throws Exception {
- Process p = pb.start();
- p.waitFor();
- int exitValue = p.exitValue();
- if (exitValue != 0) {
- throw new Exception("jmap -heap exited with error code: " + exitValue);
- }
- }
-
- private static String read(File f) throws Exception {
- Path p = f.toPath();
- List<String> lines = Files.readAllLines(p, Charset.defaultCharset());
-
- StringBuilder sb = new StringBuilder();
- for (String line : lines) {
- sb.append(line).append('\n');
- }
- return sb.toString();
}
}
--- 49,58 ----
JDKToolLauncher jmap = JDKToolLauncher.create("jmap")
.addToolArg("-heap")
.addToolArg(pid);
ProcessBuilder pb = new ProcessBuilder(jmap.getCommand());
! OutputAnalyzer output = new OutputAnalyzer(pb.start());
! output.shouldHaveExitValue(0);
output.shouldContain("CompressedClassSpaceSize = 52428800 (50.0MB)");
}
}