annotate test/serviceability/jvmti/UnresolvedClassAgent.java @ 21812:d25a7e8695dc

Merge
author asaha
date Tue, 14 Oct 2014 11:38:53 -0700
parents 53094b350323
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17696
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
1 /*
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
4 *
53094b350323 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
53094b350323 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
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
7 * published by the Free Software Foundation.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
8 *
53094b350323 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
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
53094b350323 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
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
13 * accompanied this code).
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
14 *
53094b350323 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
53094b350323 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,
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
18 *
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53094b350323 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
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
21 * questions.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
22 */
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
23
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
24 import java.io.DataInputStream;
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
25 import java.io.File;
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
26 import java.io.FileInputStream;
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
27 import java.lang.instrument.ClassDefinition;
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
28 import java.lang.instrument.Instrumentation;
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
29
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
30 /*
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
31 * This class is present during compilation, but will be deleted before execution.
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
32 */
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
33 class MyUnresolvedClass {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
34 static void bar() {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
35 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
36 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
37
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
38 class MyRedefinedClass {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
39 static void foo() {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
40 MyUnresolvedClass.bar();
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
41 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
42 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
43
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
44 public class UnresolvedClassAgent {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
45 public static void main(String... args) {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
46 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
47
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
48 public static void premain(String args, Instrumentation inst) throws Exception {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
49 try {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
50 MyRedefinedClass.foo();
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
51 } catch(NoClassDefFoundError err) {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
52 System.out.println("NoClassDefFoundError (expected)");
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
53 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
54
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
55 File f = new File(System.getProperty("test.classes"), "MyRedefinedClass.class");
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
56 byte[] buf = new byte[(int)f.length()];
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
57 try (DataInputStream dis = new DataInputStream(new FileInputStream(f))) {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
58 dis.readFully(buf);
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
59 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
60 ClassDefinition cd = new ClassDefinition(MyRedefinedClass.class, buf);
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
61 inst.redefineClasses(new ClassDefinition[] {cd});
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
62
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
63 try {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
64 MyRedefinedClass.foo();
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
65 } catch(NoClassDefFoundError err) {
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
66 System.out.println("NoClassDefFoundError (expected again)");
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
67 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
68 }
53094b350323 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
69 }