annotate test/serviceability/jvmti/UnresolvedClassAgent.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
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 import java.io.DataInputStream;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
25 import java.io.File;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
26 import java.io.FileInputStream;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
27 import java.lang.instrument.ClassDefinition;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
28 import java.lang.instrument.Instrumentation;
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
29
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
30 /*
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
31 * This class is present during compilation, but will be deleted before execution.
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 class MyUnresolvedClass {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
34 static void bar() {
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 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
37
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
38 class MyRedefinedClass {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
39 static void foo() {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
40 MyUnresolvedClass.bar();
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
41 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
42 }
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 class UnresolvedClassAgent {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
45 public static void main(String... args) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
46 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
47
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
48 public static void premain(String args, Instrumentation inst) throws Exception {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
49 try {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
50 MyRedefinedClass.foo();
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
51 } catch(NoClassDefFoundError err) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
52 System.out.println("NoClassDefFoundError (expected)");
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
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
55 File f = new File(System.getProperty("test.classes"), "MyRedefinedClass.class");
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
56 byte[] buf = new byte[(int)f.length()];
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
57 try (DataInputStream dis = new DataInputStream(new FileInputStream(f))) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
58 dis.readFully(buf);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
59 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
60 ClassDefinition cd = new ClassDefinition(MyRedefinedClass.class, buf);
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
61 inst.redefineClasses(new ClassDefinition[] {cd});
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
62
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
63 try {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
64 MyRedefinedClass.foo();
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
65 } catch(NoClassDefFoundError err) {
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
66 System.out.println("NoClassDefFoundError (expected again)");
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
67 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
68 }
4c76be9856fc 8035150: ShouldNotReachHere() in ConstantPool::copy_entry_to
sla
parents:
diff changeset
69 }