1 /*
   2  * Copyright (c) 2017, 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 
  25 /*
  26  * @test
  27  * @summary Redefine shared class. GC should not cause crash with cached resolved_references.
  28  * @library /test/lib /test/hotspot/jtreg/runtime/appcds /test/hotspot/jtreg/runtime/appcds/test-classes /test/hotspot/jtreg/runtime/appcds/jvmti
  29  * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
  30  * @requires vm.gc.G1
  31  * @requires vm.flavor != "minimal"
  32  * @requires (sun.arch.data.model != "32") & (os.family != "windows")
  33  * @modules java.base/jdk.internal.misc
  34  *          jdk.jartool/sun.tools.jar
  35  *          java.management
  36  * @build sun.hotspot.WhiteBox
  37  *        RedefineClassApp
  38  *        InstrumentationClassFileTransformer
  39  *        InstrumentationRegisterClassFileTransformer
  40  * @run main/othervm RedefineClassTest
  41  */
  42 
  43 import com.sun.tools.attach.VirtualMachine;
  44 import com.sun.tools.attach.VirtualMachineDescriptor;
  45 import java.io.File;
  46 import java.io.FileOutputStream;
  47 import java.util.List;
  48 import jdk.test.lib.Asserts;
  49 import jdk.test.lib.cds.CDSOptions;
  50 import jdk.test.lib.process.OutputAnalyzer;
  51 import jdk.test.lib.process.ProcessTools;
  52 
  53 public class RedefineClassTest {
  54     public static String bootClasses[] = {
  55         "RedefineClassApp$Intf",
  56         "RedefineClassApp$Bar",
  57         "sun.hotspot.WhiteBox",
  58     };
  59     public static String appClasses[] = {
  60         "RedefineClassApp",
  61         "RedefineClassApp$Foo",
  62     };
  63     public static String sharedClasses[] = TestCommon.concat(bootClasses, appClasses);
  64 
  65     public static String agentClasses[] = {
  66         "InstrumentationClassFileTransformer",
  67         "InstrumentationRegisterClassFileTransformer",
  68         "Util",
  69     };
  70 
  71     public static void main(String[] args) throws Throwable {
  72         runTest();
  73     }
  74 
  75     public static void runTest() throws Throwable {
  76         String bootJar =
  77             ClassFileInstaller.writeJar("RedefineClassBoot.jar", bootClasses);
  78         String appJar =
  79             ClassFileInstaller.writeJar("RedefineClassApp.jar", appClasses);
  80         String agentJar =
  81             ClassFileInstaller.writeJar("InstrumentationAgent.jar",
  82                                         ClassFileInstaller.Manifest.fromSourceFile("InstrumentationAgent.mf"),
  83                                         agentClasses);
  84 
  85         String bootCP = "-Xbootclasspath/a:" + bootJar;
  86 
  87         String agentCmdArg;
  88         agentCmdArg = "-javaagent:" + agentJar;
  89 
  90         TestCommon.testDump(appJar, sharedClasses, bootCP, "-Xlog:gc+region=trace");
  91 
  92         OutputAnalyzer out = TestCommon.execAuto("-cp", appJar,
  93                 bootCP,
  94                 "-XX:+UnlockDiagnosticVMOptions",
  95                 "-XX:+WhiteBoxAPI",
  96                 "-Xlog:gc+region=trace,cds=info",
  97                 agentCmdArg,
  98                "RedefineClassApp", bootJar, appJar);
  99         out.reportDiagnosticSummary();
 100 
 101         CDSOptions opts = (new CDSOptions()).setXShareMode("auto");
 102         TestCommon.checkExec(out, opts);
 103     }
 104 }
 105 
--- EOF ---