annotate test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java @ 14648:4c76be9856fc

8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to Reviewed-by: dcubed, mgronlun
author sla
date Wed, 26 Feb 2014 15:47:44 +0100
parents
children 09f19d3de485
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14648
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
1 /*
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
4 *
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
7 * published by the Free Software Foundation.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
8 *
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
13 * accompanied this code).
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
14 *
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
18 *
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
21 * questions.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
22 */
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
23
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
24 /*
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
25 * @test
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
26 * @summary Redefine a class with an UnresolvedClass reference in the constant pool.
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
27 * @bug 8035150
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
28 * @library /testlibrary
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
29 * @build UnresolvedClassAgent com.oracle.java.testlibrary.ProcessTools com.oracle.java.testlibrary.OutputAnalyzer
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
30 * @run main TestRedefineWithUnresolvedClass
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
31 */
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
32
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
33 import java.io.File;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
34 import java.util.Arrays;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
35
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
36 import com.oracle.java.testlibrary.OutputAnalyzer;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
37 import com.oracle.java.testlibrary.ProcessTools;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
38
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
39 public class TestRedefineWithUnresolvedClass {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
40
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
41 final static String slash = File.separator;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
42 final static String testClasses = System.getProperty("test.classes") + slash;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
43
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
44 public static void main(String... args) throws Throwable {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
45 // delete this class to cause a NoClassDefFoundError
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
46 File unresolved = new File(testClasses, "MyUnresolvedClass.class");
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
47 if (unresolved.exists() && !unresolved.delete()) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
48 throw new Exception("Could not delete: " + unresolved);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
49 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
50
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
51 // build the javaagent
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
52 buildJar("UnresolvedClassAgent");
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
53
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
54 // launch a VM with the javaagent
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
55 launchTest();
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
56 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
57
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
58 private static void buildJar(String jarName) throws Throwable {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
59 String testSrc = System.getProperty("test.src", "?") + slash;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
60
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
61 String jarPath = String.format("%s%s.jar", testClasses, jarName);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
62 String manifestPath = String.format("%s%s.mf", testSrc, jarName);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
63 String className = String.format("%s.class", jarName);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
64
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
65 String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className};
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
66
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
67 System.out.println("Running jar " + Arrays.toString(args));
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
68 sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
69 if (!jarTool.run(args)) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
70 throw new Exception("jar failed: args=" + Arrays.toString(args));
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
71 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
72 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
73
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
74 private static void launchTest() throws Throwable {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
75 String[] args = {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
76 "-javaagent:" + testClasses + "UnresolvedClassAgent.jar",
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
77 "-Dtest.classes=" + testClasses,
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
78 "UnresolvedClassAgent" };
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
79 OutputAnalyzer output = ProcessTools.executeTestJvm(args);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
80 output.shouldHaveExitValue(0);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
81 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
82 }