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.util.List; 47 import jdk.test.lib.Asserts; 48 import jdk.test.lib.cds.CDSOptions; 49 import jdk.test.lib.process.OutputAnalyzer; 50 import jdk.test.lib.process.ProcessTools; 51 52 public class RedefineClassTest { 53 public static String bootClasses[] = { 54 "RedefineClassApp$Intf", 55 "RedefineClassApp$Bar", 56 "sun.hotspot.WhiteBox", 57 }; 58 public static String appClasses[] = { 59 "RedefineClassApp", 60 "RedefineClassApp$Foo", 61 }; 62 public static String sharedClasses[] = TestCommon.concat(bootClasses, appClasses); 63 64 public static String agentClasses[] = { 65 "InstrumentationClassFileTransformer", 66 "InstrumentationRegisterClassFileTransformer", 67 "Util", 68 }; 69 70 public static void main(String[] args) throws Throwable { 71 runTest(); 72 } 73 74 public static void runTest() throws Throwable { 75 String bootJar = 76 ClassFileInstaller.writeJar("RedefineClassBoot.jar", bootClasses); 77 String appJar = 78 ClassFileInstaller.writeJar("RedefineClassApp.jar", appClasses); 79 String agentJar = 80 ClassFileInstaller.writeJar("InstrumentationAgent.jar", 81 ClassFileInstaller.Manifest.fromSourceFile("InstrumentationAgent.mf"), 82 agentClasses); 83 84 String bootCP = "-Xbootclasspath/a:" + bootJar; 85 86 String agentCmdArg; 87 agentCmdArg = "-javaagent:" + agentJar; 88 89 TestCommon.testDump(appJar, sharedClasses, bootCP, "-Xlog:gc+region=trace"); 90 91 OutputAnalyzer out = TestCommon.execAuto("-cp", appJar, 92 bootCP, 93 "-XX:+UnlockDiagnosticVMOptions", 94 "-XX:+WhiteBoxAPI", 95 "-Xlog:gc+region=trace,cds=info", 96 agentCmdArg, 97 "RedefineClassApp", bootJar, appJar); 98 out.reportDiagnosticSummary(); 99 100 CDSOptions opts = (new CDSOptions()).setXShareMode("auto"); 101 TestCommon.checkExec(out, opts); 102 } 103 } 104