< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2018, 2019, 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  *


  30  * @build sun.hotspot.WhiteBox
  31  * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
  32  * @run main/othervm/native ReplaceCriticalClasses
  33  */
  34 
  35 import java.util.regex.Matcher;
  36 import java.util.regex.Pattern;
  37 import jdk.test.lib.cds.CDSTestUtils;
  38 import jdk.test.lib.cds.CDSOptions;
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 import sun.hotspot.WhiteBox;
  41 
  42 public class ReplaceCriticalClasses {
  43     public static void main(String args[]) throws Throwable {
  44         ReplaceCriticalClasses rcc = new ReplaceCriticalClasses();
  45         rcc.process(args);
  46     }
  47 
  48     public void process(String args[]) throws Throwable {
  49         if (args.length == 0) {
  50             // Dump the shared archive in case it was not generated during the JDK build.
  51             // Put the archive at separate file to avoid clashes with concurrent tests.
  52             CDSOptions opts = new CDSOptions()
  53                 .setXShareMode("dump")
  54                 .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
  55                 .setUseVersion(false)
  56                 .addSuffix("-showversion");
  57             CDSTestUtils.run(opts).assertNormalExit("");
  58 
  59             launchChildProcesses(getTests());
  60         } else if (args.length == 3 && args[0].equals("child")) {
  61             Class klass = Class.forName(args[2].replace("/", "."));
  62             if (args[1].equals("-shared")) {
  63                 testInChild(true, klass);
  64             } else if (args[1].equals("-notshared")) {
  65                 testInChild(false, klass);
  66             } else {
  67                 throw new RuntimeException("Unknown child exec option " + args[1]);
  68             }
  69             return;
  70         } else {
  71             throw new RuntimeException("Usage: @run main/othervm/native ReplaceCriticalClasses");
  72         }
  73     }
  74 
  75     public String[] getTests() {
  76         String tests[] = {
  77             // CDS should be disabled -- these critical classes will be replaced
  78             // because JvmtiExport::early_class_hook_env() is true.


 144         } else {
 145           klassName = args[args.length-1];
 146         }
 147         Class.forName(klassName.replace("/", ".")); // make sure it's a valid class
 148         final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
 149 
 150         // We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Locale,XXX,XXX".
 151         // The SimpleClassFileLoadHook agent would attempt to hook the java/util/Locale class
 152         // but leave the class file bytes unchanged (it replaces all bytes "XXX" with "XXX", i.e.,
 153         // a no-op). JVMTI doesn't check the class file bytes returned by the agent, so as long
 154         // as the agent returns a buffer, it will not load the class from CDS, and will instead
 155         // load the class by parsing the buffer.
 156         //
 157         // Note that for safety we don't change the contents of the class file bytes. If in the
 158         // future JVMTI starts checking the contents of the class file bytes, this test would need
 159         // to be updated. (You'd see the test case with java/util/Locale staring to fail).
 160         String agent = "-agentlib:SimpleClassFileLoadHook=" + early + klassName + ",XXX,XXX";
 161 
 162         CDSOptions opts = (new CDSOptions())
 163             .setXShareMode("auto")
 164             .setArchiveName(ReplaceCriticalClasses.class.getName() + ".jsa")
 165             .setUseVersion(false)
 166             .addSuffix("-showversion",
 167                        "-Xlog:cds",
 168                        "-XX:+UnlockDiagnosticVMOptions",
 169                        agent,
 170                        "-XX:+WhiteBoxAPI",
 171                        "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
 172 
 173         if (subgraph) {
 174             opts.addSuffix("-Xlog:cds,cds+heap");
 175         }
 176 
 177         opts.addSuffix("ReplaceCriticalClasses",
 178                        "child",
 179                        shared,
 180                        klassName);
 181 
 182         final boolean expectDisable = !early.equals("");
 183         final boolean checkSubgraph = subgraph;
 184         final boolean expectShared = shared.equals("-shared");


   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  *


  30  * @build sun.hotspot.WhiteBox
  31  * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
  32  * @run main/othervm/native ReplaceCriticalClasses
  33  */
  34 
  35 import java.util.regex.Matcher;
  36 import java.util.regex.Pattern;
  37 import jdk.test.lib.cds.CDSTestUtils;
  38 import jdk.test.lib.cds.CDSOptions;
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 import sun.hotspot.WhiteBox;
  41 
  42 public class ReplaceCriticalClasses {
  43     public static void main(String args[]) throws Throwable {
  44         ReplaceCriticalClasses rcc = new ReplaceCriticalClasses();
  45         rcc.process(args);
  46     }
  47 
  48     public void process(String args[]) throws Throwable {
  49         if (args.length == 0) {









  50             launchChildProcesses(getTests());
  51         } else if (args.length == 3 && args[0].equals("child")) {
  52             Class klass = Class.forName(args[2].replace("/", "."));
  53             if (args[1].equals("-shared")) {
  54                 testInChild(true, klass);
  55             } else if (args[1].equals("-notshared")) {
  56                 testInChild(false, klass);
  57             } else {
  58                 throw new RuntimeException("Unknown child exec option " + args[1]);
  59             }
  60             return;
  61         } else {
  62             throw new RuntimeException("Usage: @run main/othervm/native ReplaceCriticalClasses");
  63         }
  64     }
  65 
  66     public String[] getTests() {
  67         String tests[] = {
  68             // CDS should be disabled -- these critical classes will be replaced
  69             // because JvmtiExport::early_class_hook_env() is true.


 135         } else {
 136           klassName = args[args.length-1];
 137         }
 138         Class.forName(klassName.replace("/", ".")); // make sure it's a valid class
 139         final String subgraphInit = "initialize_from_archived_subgraph " + subgraphKlass;
 140 
 141         // We will pass an option like "-agentlib:SimpleClassFileLoadHook=java/util/Locale,XXX,XXX".
 142         // The SimpleClassFileLoadHook agent would attempt to hook the java/util/Locale class
 143         // but leave the class file bytes unchanged (it replaces all bytes "XXX" with "XXX", i.e.,
 144         // a no-op). JVMTI doesn't check the class file bytes returned by the agent, so as long
 145         // as the agent returns a buffer, it will not load the class from CDS, and will instead
 146         // load the class by parsing the buffer.
 147         //
 148         // Note that for safety we don't change the contents of the class file bytes. If in the
 149         // future JVMTI starts checking the contents of the class file bytes, this test would need
 150         // to be updated. (You'd see the test case with java/util/Locale staring to fail).
 151         String agent = "-agentlib:SimpleClassFileLoadHook=" + early + klassName + ",XXX,XXX";
 152 
 153         CDSOptions opts = (new CDSOptions())
 154             .setXShareMode("auto")
 155             .setUseSystemArchive(true)
 156             .setUseVersion(false)
 157             .addSuffix("-showversion",
 158                        "-Xlog:cds",
 159                        "-XX:+UnlockDiagnosticVMOptions",
 160                        agent,
 161                        "-XX:+WhiteBoxAPI",
 162                        "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"));
 163 
 164         if (subgraph) {
 165             opts.addSuffix("-Xlog:cds,cds+heap");
 166         }
 167 
 168         opts.addSuffix("ReplaceCriticalClasses",
 169                        "child",
 170                        shared,
 171                        klassName);
 172 
 173         final boolean expectDisable = !early.equals("");
 174         final boolean checkSubgraph = subgraph;
 175         final boolean expectShared = shared.equals("-shared");


< prev index next >