test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java

Fri, 11 Oct 2013 13:48:02 +0200

author
sla
date
Fri, 11 Oct 2013 13:48:02 +0200
changeset 5886
cd7ea1d79dac
parent 5845
8ef918538e22
child 5947
c51cd6af7e61
permissions
-rw-r--r--

8026199: serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java Compilation failed
Summary: Fixed a compilation failure due to changed method name
Reviewed-by: sla, jbachorik
Contributed-by: fredrik.arvidsson@oracle.com

sla@5845 1 /*
sla@5845 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
sla@5845 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sla@5845 4 *
sla@5845 5 * This code is free software; you can redistribute it and/or modify it
sla@5845 6 * under the terms of the GNU General Public License version 2 only, as
sla@5845 7 * published by the Free Software Foundation.
sla@5845 8 *
sla@5845 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sla@5845 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sla@5845 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sla@5845 12 * version 2 for more details (a copy is included in the LICENSE file that
sla@5845 13 * accompanied this code).
sla@5845 14 *
sla@5845 15 * You should have received a copy of the GNU General Public License version
sla@5845 16 * 2 along with this work; if not, write to the Free Software Foundation,
sla@5845 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sla@5845 18 *
sla@5845 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sla@5845 20 * or visit www.oracle.com if you need additional information or have any
sla@5845 21 * questions.
sla@5845 22 */
sla@5845 23
sla@5845 24 import java.io.BufferedReader;
sla@5845 25 import java.io.File;
sla@5845 26 import java.io.FileNotFoundException;
sla@5845 27 import java.io.FileReader;
sla@5845 28 import java.io.IOException;
sla@5845 29 import java.io.Reader;
sla@5845 30 import java.nio.CharBuffer;
sla@5845 31 import java.util.Arrays;
sla@5845 32 import java.util.Scanner;
sla@5845 33
sla@5845 34 import com.oracle.java.testlibrary.Asserts;
sla@5845 35 import com.oracle.java.testlibrary.JDKToolFinder;
sla@5845 36 import com.oracle.java.testlibrary.JDKToolLauncher;
sla@5845 37 import com.oracle.java.testlibrary.OutputAnalyzer;
sla@5845 38 import com.oracle.java.testlibrary.Platform;
sla@5845 39 import com.oracle.java.testlibrary.ProcessTools;
sla@5845 40
sla@5845 41 /*
sla@5845 42 * @test
sla@5845 43 * @bug 6313383
sla@5845 44 * @key regression
sla@5845 45 * @summary Regression test for hprof export issue due to large heaps (>2G)
sla@5845 46 * @library /testlibrary
sla@5845 47 * @compile JMapHProfLargeHeapProc.java
sla@5845 48 * @run main JMapHProfLargeHeapTest
sla@5845 49 */
sla@5845 50
sla@5845 51 public class JMapHProfLargeHeapTest {
sla@5845 52 private static final String HEAP_DUMP_FILE_NAME = "heap.hprof";
sla@5845 53 private static final String HPROF_HEADER_1_0_1 = "JAVA PROFILE 1.0.1";
sla@5845 54 private static final String HPROF_HEADER_1_0_2 = "JAVA PROFILE 1.0.2";
sla@5845 55 private static final long M = 1024L;
sla@5845 56 private static final long G = 1024L * M;
sla@5845 57
sla@5845 58 public static void main(String[] args) throws Exception {
sla@5845 59 // If we are on MacOSX, test if JMap tool is signed, otherwise return
sla@5845 60 // since test will fail with privilege error.
sla@5845 61 if (Platform.isOSX()) {
sla@5886 62 String jmapToolPath = JDKToolFinder.getTestJDKTool("jmap");
sla@5845 63 ProcessBuilder codesignProcessBuilder = new ProcessBuilder(
sla@5845 64 "codesign", "-v", jmapToolPath);
sla@5845 65 Process codesignProcess = codesignProcessBuilder.start();
sla@5845 66 OutputAnalyzer analyser = new OutputAnalyzer(codesignProcess);
sla@5845 67 try {
sla@5845 68 analyser.shouldNotContain("code object is not signed at all");
sla@5845 69 System.out.println("Signed jmap found at: " + jmapToolPath);
sla@5845 70 } catch (Exception e) {
sla@5845 71 // Abort since we can't know if the test will work
sla@5845 72 System.out
sla@5845 73 .println("Test aborted since we are on MacOSX and the jmap tool is not signed.");
sla@5845 74 return;
sla@5845 75 }
sla@5845 76 }
sla@5845 77
sla@5845 78 // Small heap 22 megabytes, should create 1.0.1 file format
sla@5845 79 testHProfFileFormat("-Xmx1g", 22 * M, HPROF_HEADER_1_0_1);
sla@5845 80
sla@5845 81 /**
sla@5845 82 * This test was deliberately commented out since the test system lacks
sla@5845 83 * support to handle the requirements for this kind of heap size in a
sla@5845 84 * good way. If or when it becomes possible to run this kind of tests in
sla@5845 85 * the test environment the test should be enabled again.
sla@5845 86 * */
sla@5845 87 // Large heap 2,2 gigabytes, should create 1.0.2 file format
sla@5845 88 // testHProfFileFormat("-Xmx4g", 2 * G + 2 * M, HPROF_HEADER_1_0_2);
sla@5845 89 }
sla@5845 90
sla@5845 91 private static void testHProfFileFormat(String vmArgs, long heapSize,
sla@5845 92 String expectedFormat) throws Exception, IOException,
sla@5845 93 InterruptedException, FileNotFoundException {
sla@5845 94 ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(
sla@5845 95 vmArgs, "JMapHProfLargeHeapProc", String.valueOf(heapSize));
sla@5845 96 procBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
sla@5845 97 Process largeHeapProc = procBuilder.start();
sla@5845 98
sla@5845 99 try (Scanner largeHeapScanner = new Scanner(
sla@5845 100 largeHeapProc.getInputStream());) {
sla@5845 101 String pidstring = null;
sla@5845 102 while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
sla@5845 103 Thread.sleep(500);
sla@5845 104 }
sla@5845 105 int pid = Integer.parseInt(pidstring.substring(4,
sla@5845 106 pidstring.length() - 1));
sla@5845 107 System.out.println("Extracted pid: " + pid);
sla@5845 108
sla@5845 109 JDKToolLauncher jMapLauncher = JDKToolLauncher
sla@5886 110 .createUsingTestJDK("jmap");
sla@5845 111 jMapLauncher.addToolArg("-dump:format=b,file=" + pid + "-"
sla@5845 112 + HEAP_DUMP_FILE_NAME);
sla@5845 113 jMapLauncher.addToolArg(String.valueOf(pid));
sla@5845 114
sla@5845 115 ProcessBuilder jMapProcessBuilder = new ProcessBuilder(
sla@5845 116 jMapLauncher.getCommand());
sla@5845 117 System.out.println("jmap command: "
sla@5845 118 + Arrays.toString(jMapLauncher.getCommand()));
sla@5845 119
sla@5845 120 Process jMapProcess = jMapProcessBuilder.start();
sla@5845 121 OutputAnalyzer analyzer = new OutputAnalyzer(jMapProcess);
sla@5845 122 analyzer.shouldHaveExitValue(0);
sla@5845 123 analyzer.shouldContain(pid + "-" + HEAP_DUMP_FILE_NAME);
sla@5845 124 analyzer.shouldContain("Heap dump file created");
sla@5845 125
sla@5845 126 largeHeapProc.getOutputStream().write('\n');
sla@5845 127
sla@5845 128 File dumpFile = new File(pid + "-" + HEAP_DUMP_FILE_NAME);
sla@5845 129 Asserts.assertTrue(dumpFile.exists(), "Heap dump file not found.");
sla@5845 130
sla@5845 131 try (Reader reader = new BufferedReader(new FileReader(dumpFile))) {
sla@5845 132 CharBuffer buf = CharBuffer.allocate(expectedFormat.length());
sla@5845 133 reader.read(buf);
sla@5845 134 buf.clear();
sla@5845 135 Asserts.assertEQ(buf.toString(), expectedFormat,
sla@5845 136 "Wrong file format. Expected '" + expectedFormat
sla@5845 137 + "', but found '" + buf.toString() + "'");
sla@5845 138 }
sla@5845 139
sla@5845 140 System.out.println("Success!");
sla@5845 141
sla@5845 142 } finally {
sla@5845 143 largeHeapProc.destroyForcibly();
sla@5845 144 }
sla@5845 145 }
sla@5845 146 }

mercurial