Path: blob/master/test/hotspot/jtreg/resourcehogs/serviceability/sa/TestHeapDumpForLargeArray.java
41153 views
/*1* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.File;24import java.util.stream.Collectors;2526import jdk.test.lib.apps.LingeredApp;27import jdk.test.lib.JDKToolLauncher;28import jdk.test.lib.process.ProcessTools;29import jdk.test.lib.process.OutputAnalyzer;30import jdk.test.lib.SA.SATestUtils;31import jdk.test.lib.Utils;3233/**34* @test35* @library /test/lib36* @bug 817108437* @requires vm.hasSA & (vm.bits == "64" & os.maxMemory > 8g)38* @modules java.base/jdk.internal.misc39* jdk.hotspot.agent/sun.jvm.hotspot40* jdk.hotspot.agent/sun.jvm.hotspot.utilities41* jdk.hotspot.agent/sun.jvm.hotspot.oops42* jdk.hotspot.agent/sun.jvm.hotspot.debugger43* @run main/timeout=1800/othervm -Xmx8g TestHeapDumpForLargeArray44*/4546public class TestHeapDumpForLargeArray {4748private static LingeredAppWithLargeArray theApp = null;4950private static void attachAndDump(String heapDumpFileName,51long lingeredAppPid) throws Exception {5253JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");54launcher.addToolArg("jmap");55launcher.addToolArg("--binaryheap");56launcher.addToolArg("--dumpfile");57launcher.addToolArg(heapDumpFileName);58launcher.addToolArg("--pid");59launcher.addToolArg(Long.toString(lingeredAppPid));6061ProcessBuilder processBuilder = SATestUtils.createProcessBuilder(launcher);62System.out.println(63processBuilder.command().stream().collect(Collectors.joining(" ")));6465OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);66SAOutput.shouldHaveExitValue(0);67SAOutput.shouldNotContain("Heap segment size overflow");68SAOutput.shouldContain("truncating to");69SAOutput.shouldContain("heap written to");70SAOutput.shouldContain(heapDumpFileName);71System.out.println(SAOutput.getOutput());7273}7475public static void main (String... args) throws Exception {76SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.7778String heapDumpFileName = "LargeArrayHeapDump.bin";7980File heapDumpFile = new File(heapDumpFileName);81if (heapDumpFile.exists()) {82heapDumpFile.delete();83}8485try {86// Need to add the default arguments first to have explicit87// -Xmx8g last, otherwise test will fail if default88// arguments contain a smaller -Xmx.89String[] vmArgs = Utils.prependTestJavaOpts(90"-XX:+UsePerfData",91"-Xmx8g");9293theApp = new LingeredAppWithLargeArray();94LingeredApp.startAppExactJvmOpts(theApp, vmArgs);95attachAndDump(heapDumpFileName, theApp.getPid());96} finally {97LingeredApp.stopApp(theApp);98heapDumpFile.delete();99}100}101}102103104