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