test/hotspot/jtreg/serviceability/sa/ClhsdbRegionDetailsScanOopsForG1.java
changeset 49463 ccb003941743
child 50791 b1e90a8a876c
equal deleted inserted replaced
49462:00992d4e8a23 49463:ccb003941743
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.util.HashMap;
       
    25 import java.util.List;
       
    26 import java.util.ArrayList;
       
    27 import java.util.Map;
       
    28 import jdk.test.lib.apps.LingeredApp;
       
    29 
       
    30 /*
       
    31  * @test
       
    32  * @bug 8175312
       
    33  * @summary Test clhsdb 'g1regiondetails' and 'scanoops' commands for G1GC
       
    34  * @library /test/lib
       
    35  * @requires (vm.bits == "64" & os.maxMemory > 8g)
       
    36  * @run main/othervm/timeout=2400 ClhsdbRegionDetailsScanOopsForG1
       
    37  */
       
    38 
       
    39 public class ClhsdbRegionDetailsScanOopsForG1 {
       
    40 
       
    41     public static void main(String[] args) throws Exception {
       
    42         System.out.println("Starting ClhsdbRegionDetailsScanOopsForG1 test");
       
    43 
       
    44         LingeredAppWithLargeStringArray theApp = null;
       
    45         try {
       
    46             ClhsdbLauncher test = new ClhsdbLauncher();
       
    47             List<String> vmArgs = new ArrayList<String>();
       
    48             vmArgs.add("-XX:+UseG1GC");
       
    49             vmArgs.add("-Xmx8g");
       
    50             vmArgs.add("-XX:G1HeapRegionSize=2m");
       
    51 
       
    52             theApp = new LingeredAppWithLargeStringArray();
       
    53             LingeredApp.startApp(vmArgs, theApp);
       
    54             System.out.println("Started LingeredAppWithLargeStringArray with pid " + theApp.getPid());
       
    55 
       
    56             List<String> cmds = List.of("g1regiondetails");
       
    57             Map<String, List<String>> expStrMap = new HashMap<>();
       
    58             Map<String, List<String>> unExpStrMap = new HashMap<>();
       
    59 
       
    60             // Test that the various types of regions are listed with the
       
    61             // 'g1regiondetails' command
       
    62             expStrMap.put("g1regiondetails", List.of(
       
    63                 "Region",
       
    64                 "Eden",
       
    65                 "Survivor",
       
    66                 "StartsHumongous",
       
    67                 "ContinuesHumongous",
       
    68                 "Free"));
       
    69             unExpStrMap.put("g1regiondetails", List.of("Unknown Region Type"));
       
    70             String regionDetailsOutput = test.run(theApp.getPid(), cmds,
       
    71                                                   expStrMap, unExpStrMap);
       
    72             if (regionDetailsOutput == null) {
       
    73                 // Output could be null due to attach permission issues
       
    74                 // and if we are skipping this.
       
    75                 LingeredApp.stopApp(theApp);
       
    76                 return;
       
    77             }
       
    78 
       
    79             // Test the output of 'scanoops' -- get the start and end addresses
       
    80             // from the StartsHumongous region. Ensure that it contains an
       
    81             // array of Strings.
       
    82             String[] snippets = regionDetailsOutput.split(":StartsHumongous");
       
    83             snippets = snippets[0].split("Region: ");
       
    84             String[] words = snippets[snippets.length - 1].split(",");
       
    85             // words[0] and words[1] represent the start and end addresses
       
    86             String cmd = "scanoops " + words[0] + " " + words[1];
       
    87             expStrMap = new HashMap<>();
       
    88             expStrMap.put(cmd, List.of("[Ljava/lang/String"));
       
    89             test.run(theApp.getPid(), List.of(cmd), expStrMap, null);
       
    90         } catch (Exception ex) {
       
    91             throw new RuntimeException("Test ERROR " + ex, ex);
       
    92         } finally {
       
    93             LingeredApp.stopApp(theApp);
       
    94         }
       
    95         System.out.println("Test PASSED");
       
    96     }
       
    97 }