< prev index next >

test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java

Print this page




   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 /**
  25  * @test
  26  * @bug 8174994
  27  * @summary Test the clhsdb commands 'printmdo', 'printall' on a CDS enabled corefile.
  28  * @requires vm.cds
  29  * @requires vm.hasSA
  30  * @requires os.family != "windows"
  31  * @requires vm.flavor == "server"
  32  * @library /test/lib
  33  * @modules java.base/jdk.internal.misc
  34  * @run main/othervm/timeout=2400 -Xmx1g ClhsdbCDSCore
  35  */
  36 
  37 import java.util.List;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.Map;
  41 import java.util.HashMap;
  42 import jdk.test.lib.process.ProcessTools;
  43 import jdk.test.lib.Platform;
  44 import jdk.test.lib.process.OutputAnalyzer;
  45 import jdk.test.lib.cds.CDSTestUtils;
  46 import jdk.test.lib.cds.CDSOptions;
  47 import java.io.IOException;


  62     }
  63 }
  64 
  65 public class ClhsdbCDSCore {
  66 
  67     private static final String TEST_CDS_CORE_FILE_NAME = "cds_core_file";
  68     private static final String LOCATIONS_STRING = "location: ";
  69     private static final String RUN_SHELL_NO_LIMIT = "ulimit -c unlimited && ";
  70     private static final String SHARED_ARCHIVE_NAME = "ArchiveForClhsdbCDSCore.jsa";
  71     private static final String CORE_PATTERN_FILE_NAME = "/proc/sys/kernel/core_pattern";
  72 
  73     public static void main(String[] args) throws Exception {
  74         System.out.println("Starting ClhsdbCDSCore test");
  75         cleanup();
  76 
  77         try {
  78             CDSOptions opts = (new CDSOptions()).setArchiveName(SHARED_ARCHIVE_NAME);
  79             CDSTestUtils.createArchiveAndCheck(opts);
  80 
  81             String[] jArgs = {
  82                 "-Xmx512m",
  83                 "-XX:+UnlockDiagnosticVMOptions",
  84                 "-XX:SharedArchiveFile=" + SHARED_ARCHIVE_NAME,
  85                 "-XX:+CreateCoredumpOnCrash",
  86                 "-Xshare:auto",
  87                 "-XX:+ProfileInterpreter",
  88                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  89                 CrashApp.class.getName()
  90             };
  91 
  92             OutputAnalyzer crashOut;
  93             try {
  94                List<String> options = new ArrayList<>();
  95                options.addAll(Arrays.asList(jArgs));
  96                crashOut =
  97                    ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix(
  98                    RUN_SHELL_NO_LIMIT, options.toArray(new String[0])));
  99             } catch (Throwable t) {
 100                throw new Error("Can't execute the java cds process.", t);
 101             }
 102 


 139             ClhsdbLauncher test = new ClhsdbLauncher();
 140 
 141             // Ensure that UseSharedSpaces is turned on.
 142             List<String> cmds = List.of("flags UseSharedSpaces");
 143 
 144             String useSharedSpacesOutput = test.runOnCore(TEST_CDS_CORE_FILE_NAME, cmds,
 145                                                           null, null);
 146 
 147             if (useSharedSpacesOutput == null) {
 148                 // Output could be null due to attach permission issues.
 149                 cleanup();
 150                 throw new SkippedException("Could not determine the UseSharedSpaces value");
 151             }
 152 
 153             if (!useSharedSpacesOutput.contains("true")) {
 154                 // CDS archive is not mapped. Skip the rest of the test.
 155                 cleanup();
 156                 throw new SkippedException("The CDS archive is not mapped");
 157             }
 158 
 159             cmds = List.of("printmdo -a", "printall");
 160 
 161             Map<String, List<String>> expStrMap = new HashMap<>();
 162             Map<String, List<String>> unExpStrMap = new HashMap<>();
 163             expStrMap.put("printmdo -a", List.of(
 164                 "CounterData",
 165                 "BranchData"));
 166             unExpStrMap.put("printmdo -a", List.of(
 167                 "No suitable match for type of address"));
 168             expStrMap.put("printall", List.of(
 169                 "aload_0",
 170                 "_nofast_aload_0",
 171                 "_nofast_getfield",
 172                 "_nofast_putfield",
 173                 "Constant Pool of",
 174                 "public static void main(java.lang.String[])",
 175                 "Bytecode",
 176                 "invokevirtual",
 177                 "checkcast",
 178                 "Exception Table",
 179                 "invokedynamic"));
 180             unExpStrMap.put("printall", List.of(
 181                 "sun.jvm.hotspot.types.WrongTypeException",
 182                 "illegal code",
 183                 "Failure occurred at bci",
 184                 "No suitable match for type of address"));





 185             test.runOnCore(TEST_CDS_CORE_FILE_NAME, cmds, expStrMap, unExpStrMap);
 186         } catch (SkippedException e) {
 187             throw e;
 188         } catch (Exception ex) {
 189             throw new RuntimeException("Test ERROR " + ex, ex);
 190         }
 191         cleanup();
 192         System.out.println("Test PASSED");
 193     }
 194 
 195     // lets search for a few possible locations using process output and return existing location
 196     private static String getCoreFileLocation(String crashOutputString) {
 197         Asserts.assertTrue(crashOutputString.contains(LOCATIONS_STRING),
 198             "Output doesn't contain the location of core file.");
 199         String stringWithLocation = Arrays.stream(crashOutputString.split("\\r?\\n"))
 200             .filter(str -> str.contains(LOCATIONS_STRING))
 201             .findFirst()
 202             .get();
 203         stringWithLocation = stringWithLocation.substring(stringWithLocation
 204             .indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length());




   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 /**
  25  * @test
  26  * @bug 8174994 8200613
  27  * @summary Test the clhsdb commands 'printmdo', 'printall', 'jstack' on a CDS enabled corefile.
  28  * @requires vm.cds
  29  * @requires vm.hasSA
  30  * @requires os.family != "windows"
  31  * @requires vm.flavor == "server"
  32  * @library /test/lib
  33  * @modules java.base/jdk.internal.misc
  34  * @run main/othervm/timeout=2400 -Xmx1g ClhsdbCDSCore
  35  */
  36 
  37 import java.util.List;
  38 import java.util.ArrayList;
  39 import java.util.Arrays;
  40 import java.util.Map;
  41 import java.util.HashMap;
  42 import jdk.test.lib.process.ProcessTools;
  43 import jdk.test.lib.Platform;
  44 import jdk.test.lib.process.OutputAnalyzer;
  45 import jdk.test.lib.cds.CDSTestUtils;
  46 import jdk.test.lib.cds.CDSOptions;
  47 import java.io.IOException;


  62     }
  63 }
  64 
  65 public class ClhsdbCDSCore {
  66 
  67     private static final String TEST_CDS_CORE_FILE_NAME = "cds_core_file";
  68     private static final String LOCATIONS_STRING = "location: ";
  69     private static final String RUN_SHELL_NO_LIMIT = "ulimit -c unlimited && ";
  70     private static final String SHARED_ARCHIVE_NAME = "ArchiveForClhsdbCDSCore.jsa";
  71     private static final String CORE_PATTERN_FILE_NAME = "/proc/sys/kernel/core_pattern";
  72 
  73     public static void main(String[] args) throws Exception {
  74         System.out.println("Starting ClhsdbCDSCore test");
  75         cleanup();
  76 
  77         try {
  78             CDSOptions opts = (new CDSOptions()).setArchiveName(SHARED_ARCHIVE_NAME);
  79             CDSTestUtils.createArchiveAndCheck(opts);
  80 
  81             String[] jArgs = {

  82                 "-XX:+UnlockDiagnosticVMOptions",
  83                 "-XX:SharedArchiveFile=" + SHARED_ARCHIVE_NAME,
  84                 "-XX:+CreateCoredumpOnCrash",
  85                 "-Xshare:auto",
  86                 "-XX:+ProfileInterpreter",
  87                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
  88                 CrashApp.class.getName()
  89             };
  90 
  91             OutputAnalyzer crashOut;
  92             try {
  93                List<String> options = new ArrayList<>();
  94                options.addAll(Arrays.asList(jArgs));
  95                crashOut =
  96                    ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix(
  97                    RUN_SHELL_NO_LIMIT, options.toArray(new String[0])));
  98             } catch (Throwable t) {
  99                throw new Error("Can't execute the java cds process.", t);
 100             }
 101 


 138             ClhsdbLauncher test = new ClhsdbLauncher();
 139 
 140             // Ensure that UseSharedSpaces is turned on.
 141             List<String> cmds = List.of("flags UseSharedSpaces");
 142 
 143             String useSharedSpacesOutput = test.runOnCore(TEST_CDS_CORE_FILE_NAME, cmds,
 144                                                           null, null);
 145 
 146             if (useSharedSpacesOutput == null) {
 147                 // Output could be null due to attach permission issues.
 148                 cleanup();
 149                 throw new SkippedException("Could not determine the UseSharedSpaces value");
 150             }
 151 
 152             if (!useSharedSpacesOutput.contains("true")) {
 153                 // CDS archive is not mapped. Skip the rest of the test.
 154                 cleanup();
 155                 throw new SkippedException("The CDS archive is not mapped");
 156             }
 157 
 158             cmds = List.of("printmdo -a", "printall", "jstack -v");
 159 
 160             Map<String, List<String>> expStrMap = new HashMap<>();
 161             Map<String, List<String>> unExpStrMap = new HashMap<>();
 162             expStrMap.put("printmdo -a", List.of(
 163                 "CounterData",
 164                 "BranchData"));
 165             unExpStrMap.put("printmdo -a", List.of(
 166                 "No suitable match for type of address"));
 167             expStrMap.put("printall", List.of(
 168                 "aload_0",
 169                 "_nofast_aload_0",
 170                 "_nofast_getfield",
 171                 "_nofast_putfield",
 172                 "Constant Pool of",
 173                 "public static void main(java.lang.String[])",
 174                 "Bytecode",
 175                 "invokevirtual",
 176                 "checkcast",
 177                 "Exception Table",
 178                 "invokedynamic"));
 179             unExpStrMap.put("printall", List.of(
 180                 "sun.jvm.hotspot.types.WrongTypeException",
 181                 "illegal code",
 182                 "Failure occurred at bci",
 183                 "No suitable match for type of address"));
 184             expStrMap.put("jstack -v", List.of(
 185                 "Common-Cleaner",
 186                 "Method*"));
 187             unExpStrMap.put("jstack -v", List.of(
 188                 "sun.jvm.hotspot.debugger.UnmappedAddressException"));
 189             test.runOnCore(TEST_CDS_CORE_FILE_NAME, cmds, expStrMap, unExpStrMap);
 190         } catch (SkippedException e) {
 191             throw e;
 192         } catch (Exception ex) {
 193             throw new RuntimeException("Test ERROR " + ex, ex);
 194         }
 195         cleanup();
 196         System.out.println("Test PASSED");
 197     }
 198 
 199     // lets search for a few possible locations using process output and return existing location
 200     private static String getCoreFileLocation(String crashOutputString) {
 201         Asserts.assertTrue(crashOutputString.contains(LOCATIONS_STRING),
 202             "Output doesn't contain the location of core file.");
 203         String stringWithLocation = Arrays.stream(crashOutputString.split("\\r?\\n"))
 204             .filter(str -> str.contains(LOCATIONS_STRING))
 205             .findFirst()
 206             .get();
 207         stringWithLocation = stringWithLocation.substring(stringWithLocation
 208             .indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length());


< prev index next >