test/hotspot/jtreg/serviceability/sa/TestHeapDumpForLargeArray.java
author rkennke
Mon, 10 Dec 2018 15:47:44 +0100
changeset 52925 9c18c9d839d3
parent 52797 55a05ed55768
child 53817 784537ff9c4e
permissions -rw-r--r--
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental) Reviewed-by: kvn, roland, shade, coleenp, lmesnik, pliden, jgeorge, ihse, erikj Contributed-by: Christine Flood <chf@redhat.com>, Aleksey Shipilev <shade@redhat.com>, Roland Westrelin <rwestrel@redhat.com>, Zhenygu Gu <zgu@redhat.com>, Andrew Haley <aph@redhat.com>, Andrew Dinn <adinn@redhat.com>, Mario Torre <mtorre@redhat.com>, Roman Kennke <rkennke@redhat.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43671
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     1
/*
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
43671
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     4
 *
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     8
 *
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    13
 * accompanied this code).
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    14
 *
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    18
 *
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    21
 * questions.
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    22
 */
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    23
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    24
import java.util.ArrayList;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    25
import java.util.List;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    26
import java.io.File;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    27
import java.nio.file.Files;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    28
import java.io.IOException;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    29
import java.io.BufferedInputStream;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    30
import java.util.stream.Collectors;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    31
import java.io.FileInputStream;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    32
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    33
import sun.jvm.hotspot.HotSpotAgent;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.*;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    35
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    36
import jdk.test.lib.apps.LingeredApp;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    37
import jdk.test.lib.JDKToolLauncher;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    38
import jdk.test.lib.JDKToolFinder;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    39
import jdk.test.lib.Platform;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    40
import jdk.test.lib.process.ProcessTools;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    41
import jdk.test.lib.process.OutputAnalyzer;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    42
import jdk.test.lib.Utils;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    43
import jdk.test.lib.Asserts;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    44
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47216
diff changeset
    45
/**
43671
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    46
 * @test
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    47
 * @library /test/lib
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    48
 * @bug 8171084
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47216
diff changeset
    49
 * @requires vm.hasSAandCanAttach & (vm.bits == "64" & os.maxMemory > 8g)
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 52797
diff changeset
    50
 * @requires vm.gc != "Shenandoah"
52797
55a05ed55768 8214484: ZGC: Exclude SA tests ClhsdbJhisto and TestHeapDumpFor*
pliden
parents: 50791
diff changeset
    51
 * @requires vm.gc != "Z"
43671
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    52
 * @modules java.base/jdk.internal.misc
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    53
 *          jdk.hotspot.agent/sun.jvm.hotspot
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    54
 *          jdk.hotspot.agent/sun.jvm.hotspot.utilities
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    55
 *          jdk.hotspot.agent/sun.jvm.hotspot.oops
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    56
 *          jdk.hotspot.agent/sun.jvm.hotspot.debugger
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    57
 * @run main/timeout=1800/othervm -Xmx8g TestHeapDumpForLargeArray
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    58
 */
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    59
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    60
public class TestHeapDumpForLargeArray {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    61
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    62
    private static LingeredAppWithLargeArray theApp = null;
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    63
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    64
    private static void attachAndDump(String heapDumpFileName,
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    65
                                      long lingeredAppPid) throws Exception {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    66
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    67
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    68
        launcher.addToolArg("jmap");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    69
        launcher.addToolArg("--binaryheap");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    70
        launcher.addToolArg("--dumpfile");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    71
        launcher.addToolArg(heapDumpFileName);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    72
        launcher.addToolArg("--pid");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    73
        launcher.addToolArg(Long.toString(lingeredAppPid));
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    74
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    75
        ProcessBuilder processBuilder = new ProcessBuilder();
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    76
        processBuilder.command(launcher.getCommand());
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    77
        System.out.println(
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    78
            processBuilder.command().stream().collect(Collectors.joining(" ")));
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    79
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    80
        OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    81
        SAOutput.shouldHaveExitValue(0);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    82
        SAOutput.shouldNotContain("Heap segment size overflow");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    83
        SAOutput.shouldContain("truncating to");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    84
        SAOutput.shouldContain("heap written to");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    85
        SAOutput.shouldContain(heapDumpFileName);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    86
        System.out.println(SAOutput.getOutput());
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    87
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    88
    }
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    89
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    90
    public static void main (String... args) throws Exception {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    91
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    92
        String heapDumpFileName = "LargeArrayHeapDump.bin";
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    93
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    94
        File heapDumpFile = new File(heapDumpFileName);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    95
        if (heapDumpFile.exists()) {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    96
            heapDumpFile.delete();
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    97
        }
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    98
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
    99
        try {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   100
            List<String> vmArgs = new ArrayList<String>();
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   101
            vmArgs.add("-XX:+UsePerfData");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   102
            vmArgs.add("-Xmx8g");
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   103
            vmArgs.addAll(Utils.getVmOptions());
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   104
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   105
            theApp = new LingeredAppWithLargeArray();
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   106
            LingeredApp.startApp(vmArgs, theApp);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   107
            attachAndDump(heapDumpFileName, theApp.getPid());
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   108
        } finally {
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   109
            LingeredApp.stopApp(theApp);
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   110
            heapDumpFile.delete();
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   111
        }
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   112
    }
a152f2d3320e 8171084: heapdump/JMapHeapCore fails with java.lang.RuntimeException: Heap segment size overflow
jgeorge
parents:
diff changeset
   113
}