Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java
32284 views
/*1* Copyright (c) 2014, 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* @library /testlibrary28* @build com.oracle.java.testlibrary.* UnresolvedClassAgent29* @run main TestRedefineWithUnresolvedClass30*/3132import java.io.File;33import java.util.Arrays;3435import com.oracle.java.testlibrary.OutputAnalyzer;36import com.oracle.java.testlibrary.ProcessTools;3738public class TestRedefineWithUnresolvedClass {3940final static String slash = File.separator;41final static String testClasses = System.getProperty("test.classes") + slash;4243public static void main(String... args) throws Throwable {44// delete this class to cause a NoClassDefFoundError45File unresolved = new File(testClasses, "MyUnresolvedClass.class");46if (unresolved.exists() && !unresolved.delete()) {47throw new Exception("Could not delete: " + unresolved);48}4950// build the javaagent51buildJar("UnresolvedClassAgent");5253// launch a VM with the javaagent54launchTest();55}5657private static void buildJar(String jarName) throws Throwable {58String testSrc = System.getProperty("test.src", "?") + slash;5960String jarPath = String.format("%s%s.jar", testClasses, jarName);61String manifestPath = String.format("%s%s.mf", testSrc, jarName);62String className = String.format("%s.class", jarName);6364String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className};6566System.out.println("Running jar " + Arrays.toString(args));67sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");68if (!jarTool.run(args)) {69throw new Exception("jar failed: args=" + Arrays.toString(args));70}71}7273private static void launchTest() throws Throwable {74String[] args = {75"-javaagent:" + testClasses + "UnresolvedClassAgent.jar",76"-Dtest.classes=" + testClasses,77"UnresolvedClassAgent" };78OutputAnalyzer output = ProcessTools.executeTestJvm(args);79output.shouldHaveExitValue(0);80}81}828384