Path: blob/master/test/hotspot/jtreg/serviceability/sa/ClhsdbScanOops.java
41149 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*/2223/**24* @test25* @bug 819298526* @summary Test the clhsdb 'scanoops' command27* @requires vm.gc.Parallel28* @requires vm.hasSA29* @library /test/lib30* @run main/othervm/timeout=1200 ClhsdbScanOops UseParallelGC31*/3233/**34* @test35* @bug 819298536* @summary Test the clhsdb 'scanoops' command37* @requires vm.gc.Serial38* @requires vm.hasSA39* @library /test/lib40* @run main/othervm/timeout=1200 ClhsdbScanOops UseSerialGC41*/4243import java.util.HashMap;44import java.util.List;45import java.util.Map;46import java.util.ArrayList;47import jdk.test.lib.Utils;48import jdk.test.lib.apps.LingeredApp;49import jtreg.SkippedException;5051public class ClhsdbScanOops {5253private static void testWithGcType(String gc) throws Exception {5455LingeredApp theApp = null;5657try {58ClhsdbLauncher test = new ClhsdbLauncher();59theApp = LingeredApp.startApp(gc);6061System.out.println ("Started LingeredApp with the GC option " + gc +62" and pid " + theApp.getPid());6364// Run the 'universe' command to get the address ranges65List<String> cmds = List.of("universe");6667String universeOutput = test.run(theApp.getPid(), cmds, null, null);6869cmds = new ArrayList<String>();70Map<String, List<String>> expStrMap = new HashMap<>();71Map<String, List<String>> unExpStrMap = new HashMap<>();7273String startAddress = null;74String endAddress = null;75String[] snippets = null;7677if (gc.contains("UseParallelGC")) {78snippets = universeOutput.split("eden = ");79} else {80snippets = universeOutput.split("eden \\[");81}82String[] words = snippets[1].split(",");83// Get the addresses from Eden84startAddress = words[0].replace("[", "");85endAddress = words[1];86String cmd = "scanoops " + startAddress + " " + endAddress;87cmds.add(cmd);8889expStrMap.put(cmd, List.of90("java/lang/Object", "java/lang/Class", "java/lang/Thread",91"java/lang/String", "\\[B", "\\[I"));9293// Test the 'type' option also94// scanoops <start addr> <end addr> java/lang/String95// Ensure that only the java/lang/String oops are printed.96cmd = cmd + " java/lang/String";97cmds.add(cmd);98expStrMap.put(cmd, List.of("java/lang/String"));99unExpStrMap.put(cmd, List.of("java/lang/Thread"));100101test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap);102} catch (SkippedException e) {103throw e;104} catch (Exception ex) {105throw new RuntimeException("Test ERROR " + ex, ex);106} finally {107LingeredApp.stopApp(theApp);108}109}110111public static void main(String[] args) throws Exception {112String gc = args[0];113System.out.println("Starting the ClhsdbScanOops test");114testWithGcType("-XX:+" + gc);115System.out.println("Test PASSED");116}117}118119120