< prev index next >

test/hotspot/jtreg/runtime/cds/serviceability/ReplaceCriticalClasses.java

Print this page

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -51,11 +51,12 @@
             // Put the archive at separate file to avoid clashes with concurrent tests.
             CDSOptions opts = new CDSOptions()
                 .setXShareMode("dump")
                 .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
                 .setUseVersion(false)
-                .addSuffix("-showversion");
+                .addSuffix("-showversion")
+                .addSuffix("-Xlog:cds");
             CDSTestUtils.run(opts).assertNormalExit("");
 
             launchChildProcesses(getTests());
         } else if (args.length == 3 && args[0].equals("child")) {
             Class klass = Class.forName(args[2].replace("/", "."));

@@ -78,24 +79,21 @@
             // because JvmtiExport::early_class_hook_env() is true.
             "-early -notshared java/lang/Object",
             "-early -notshared java/lang/String",
             "-early -notshared java/lang/Cloneable",
             "-early -notshared java/io/Serializable",
+            "-early -notshared java/lang/Module",
+            "-early -notshared java/lang/ModuleLayer",
 
             // CDS should not be disabled -- these critical classes cannot be replaced because
             // JvmtiExport::early_class_hook_env() is false.
             "java/lang/Object",
             "java/lang/String",
             "java/lang/Cloneable",
             "java/io/Serializable",
-
-            /* Try to replace classes that are used by the archived subgraph graphs.
-               The following test cases are in ReplaceCriticalClassesForSubgraphs.java.
-            "-early -notshared -subgraph java/lang/module/ResolvedModule jdk.internal.module.ArchivedModuleGraph",
-            "-early -notshared -subgraph java/lang/Long java.lang.Long$LongCache",
-            "-subgraph java/lang/Long java.lang.Long$LongCache",
-            */
+            "java/lang/Module",
+            "java/lang/ModuleLayer",
 
             // Replace classes that are loaded after JVMTI_PHASE_PRIMORDIAL. It's OK to replace
             // such
             // classes even when CDS is enabled. Nothing bad should happen.
             "-notshared java/util/Locale",

@@ -114,24 +112,27 @@
         }
     }
 
     static void launchChild(String args[]) throws Throwable {
         if (args.length < 1) {
-            throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> klassName subgraphKlass");
+            throw new RuntimeException("Invalid test case. Should be <-early> <-subgraph> <-notshared> <-nowhitebox> klassName subgraphKlass");
         }
         String klassName = null;
         String subgraphKlass = null;
         String early = "";
         boolean subgraph = false;
+        boolean whitebox = true;
         String shared = "-shared";
 
         for (int i=0; i<args.length-1; i++) {
             String opt = args[i];
             if (opt.equals("-early")) {
                 early = "-early,";
             } else if (opt.equals("-subgraph")) {
                 subgraph = true;
+            } else if (opt.equals("-nowhitebox")) {
+                whitebox = false;
             } else if (opt.equals("-notshared")) {
                 shared = opt;
             } else {
               if (!subgraph) {
                 throw new RuntimeException("Unknown option: " + opt);

@@ -164,14 +165,15 @@
             .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
             .setUseVersion(false)
             .addSuffix("-showversion",
                        "-Xlog:cds",
                        "-XX:+UnlockDiagnosticVMOptions",
-                       agent,
-                       "-XX:+WhiteBoxAPI",
+                       agent);
+        if (whitebox) {
+            opts.addSuffix("-XX:+WhiteBoxAPI",
                        "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
-
+        }
         if (subgraph) {
             opts.addSuffix("-Xlog:cds,cds+heap");
         }
 
         opts.addSuffix("ReplaceCriticalClasses",

@@ -189,28 +191,34 @@
                 }
                 if (checkSubgraph) {
                     if (expectShared) {
                         if (!out.getOutput().contains("UseSharedSpaces: Unable to map at required address in java heap")) {
                             out.shouldContain(subgraphInit);
+                            // If the subgraph is successfully initialized, the specified shared class must not be rewritten.
+                            out.shouldNotContain("Rewriting done.");
                         }
                     } else {
                       out.shouldNotContain(subgraphInit);
                     }
                 }
             });
     }
 
     static void testInChild(boolean shouldBeShared, Class klass) {
+        try {
         WhiteBox wb = WhiteBox.getWhiteBox();
 
         if (shouldBeShared && !wb.isSharedClass(klass)) {
             throw new RuntimeException(klass + " should be shared but but actually is not.");
         }
         if (!shouldBeShared && wb.isSharedClass(klass)) {
             throw new RuntimeException(klass + " should not be shared but actually is.");
         }
-        System.out.println("wb.isSharedClass(klass): " + wb.isSharedClass(klass) + " == " + shouldBeShared);
+            System.out.println("wb.isSharedClass(" + klass + "): " + wb.isSharedClass(klass) + " == " + shouldBeShared);
+        } catch (UnsatisfiedLinkError e) {
+            System.out.println("WhiteBox is disabled -- because test has -nowhitebox");
+        }
 
         String strings[] = {
             // interned strings from j.l.Object
             "@",
             "nanosecond timeout value out of range",
< prev index next >