Path: blob/master/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestRedefineWithUnresolvedClass.java
41153 views
/*1* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Redefine a class with an UnresolvedClass reference in the constant pool.26* @bug 803515027* @requires vm.jvmti28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.compiler31* java.instrument32* java.management33* jdk.jartool/sun.tools.jar34* jdk.internal.jvmstat/sun.jvmstat.monitor35* @build UnresolvedClassAgent36* @run main TestRedefineWithUnresolvedClass37*/3839import java.io.File;40import java.util.Arrays;4142import jdk.test.lib.process.OutputAnalyzer;43import jdk.test.lib.process.ProcessTools;4445public class TestRedefineWithUnresolvedClass {4647final static String slash = File.separator;48final static String testClasses = System.getProperty("test.classes") + slash;4950public static void main(String... args) throws Throwable {51// delete this class to cause a NoClassDefFoundError52File unresolved = new File(testClasses, "MyUnresolvedClass.class");53if (unresolved.exists() && !unresolved.delete()) {54throw new Exception("Could not delete: " + unresolved);55}5657// build the javaagent58buildJar("UnresolvedClassAgent");5960// launch a VM with the javaagent61launchTest();62}6364private static void buildJar(String jarName) throws Throwable {65String testSrc = System.getProperty("test.src", "?") + slash;6667String jarPath = String.format("%s%s.jar", testClasses, jarName);68String manifestPath = String.format("%s%s.mf", testSrc, jarName);69String className = String.format("%s.class", jarName);7071String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className};7273System.out.println("Running jar " + Arrays.toString(args));74sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");75if (!jarTool.run(args)) {76throw new Exception("jar failed: args=" + Arrays.toString(args));77}78}7980private static void launchTest() throws Throwable {81OutputAnalyzer output = ProcessTools.executeTestJvm(82"-javaagent:" + testClasses + "UnresolvedClassAgent.jar",83"-Dtest.classes=" + testClasses,84"UnresolvedClassAgent");85output.shouldHaveExitValue(0);86}87}888990