hotspot/test/serviceability/jvmti/TestRedefineWithUnresolvedClass.java
author bpb
Wed, 16 Apr 2014 13:13:23 -0700
changeset 23935 4daeffbde72f
parent 23175 892220ab2ae1
child 24835 be963975e2f7
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23175
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     1
/*
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     4
 *
892220ab2ae1 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
892220ab2ae1 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
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
     8
 *
892220ab2ae1 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
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
892220ab2ae1 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
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    13
 * accompanied this code).
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    14
 *
892220ab2ae1 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
892220ab2ae1 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,
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    18
 *
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
892220ab2ae1 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
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    21
 * questions.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    22
 */
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    23
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    24
/*
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    25
 * @test
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    26
 * @summary Redefine a class with an UnresolvedClass reference in the constant pool.
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    27
 * @bug 8035150
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    28
 * @library /testlibrary
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    29
 * @build UnresolvedClassAgent com.oracle.java.testlibrary.ProcessTools com.oracle.java.testlibrary.OutputAnalyzer
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    30
 * @run main TestRedefineWithUnresolvedClass
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    31
 */
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    32
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    33
import java.io.File;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    34
import java.util.Arrays;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    35
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    36
import com.oracle.java.testlibrary.OutputAnalyzer;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    37
import com.oracle.java.testlibrary.ProcessTools;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    38
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    39
public class TestRedefineWithUnresolvedClass {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    40
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    41
    final static String slash = File.separator;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    42
    final static String testClasses = System.getProperty("test.classes") + slash;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    43
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    44
    public static void main(String... args) throws Throwable {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    45
        // delete this class to cause a NoClassDefFoundError
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    46
        File unresolved = new File(testClasses, "MyUnresolvedClass.class");
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    47
        if (unresolved.exists() && !unresolved.delete()) {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    48
            throw new Exception("Could not delete: " + unresolved);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    49
        }
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    50
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    51
        // build the javaagent
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    52
        buildJar("UnresolvedClassAgent");
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    53
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    54
        // launch a VM with the javaagent
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    55
        launchTest();
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    56
    }
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    57
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    58
    private static void buildJar(String jarName) throws Throwable {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    59
        String testSrc = System.getProperty("test.src", "?") + slash;
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    60
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    61
        String jarPath = String.format("%s%s.jar", testClasses, jarName);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    62
        String manifestPath = String.format("%s%s.mf", testSrc, jarName);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    63
        String className = String.format("%s.class", jarName);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    64
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    65
        String[] args = new String[] {"-cfm", jarPath, manifestPath, "-C", testClasses, className};
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    66
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    67
        System.out.println("Running jar " + Arrays.toString(args));
892220ab2ae1 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");
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    69
        if (!jarTool.run(args)) {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    70
            throw new Exception("jar failed: args=" + Arrays.toString(args));
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    71
        }
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    72
    }
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    73
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    74
    private static void launchTest() throws Throwable {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    75
        String[] args = {
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    76
            "-javaagent:" + testClasses + "UnresolvedClassAgent.jar",
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    77
            "-Dtest.classes=" + testClasses,
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    78
            "UnresolvedClassAgent" };
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    79
        OutputAnalyzer output = ProcessTools.executeTestJvm(args);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    80
        output.shouldHaveExitValue(0);
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    81
    }
892220ab2ae1 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
    82
}