author | ccheung |
Fri, 04 Oct 2013 21:00:43 -0700 | |
changeset 20384 | 49bfb2ec8f8f |
parent 20313 | 27b50af2ba5a |
child 27692 | 11c231c781dc |
permissions | -rw-r--r-- |
16684
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
1 |
/* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
4 |
* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
8 |
* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
13 |
* accompanied this code). |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
14 |
* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
18 |
* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
21 |
* questions. |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
22 |
*/ |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
23 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
24 |
/* |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
25 |
* @test G1AddMetaspaceDependency |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
26 |
* @bug 8010196 |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
27 |
* @summary Checks that we don't get locking problems when adding metaspace dependencies with the G1 update buffer monitor |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
28 |
* @run main/othervm -XX:+UseG1GC -XX:G1UpdateBufferSize=1 G1AddMetaspaceDependency |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
29 |
*/ |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
30 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
31 |
import java.io.InputStream; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
32 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
33 |
public class G1AddMetaspaceDependency { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
34 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
35 |
static byte[] getClassBytes(String name) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
36 |
byte[] b = null; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
37 |
try (InputStream is = ClassLoader.getSystemResourceAsStream(name)) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
38 |
byte[] tmp = new byte[is.available()]; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
39 |
is.read(tmp); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
40 |
b = tmp; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
41 |
} finally { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
42 |
if (b == null) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
43 |
throw new RuntimeException("Unable to load class file"); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
44 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
45 |
return b; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
46 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
47 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
48 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
49 |
static final String a_name = G1AddMetaspaceDependency.class.getName() + "$A"; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
50 |
static final String b_name = G1AddMetaspaceDependency.class.getName() + "$B"; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
51 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
52 |
public static void main(String... args) throws Exception { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
53 |
final byte[] a_bytes = getClassBytes(a_name + ".class"); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
54 |
final byte[] b_bytes = getClassBytes(b_name + ".class"); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
55 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
56 |
for (int i = 0; i < 1000; i += 1) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
57 |
runTest(a_bytes, b_bytes); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
58 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
59 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
60 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
61 |
static class Loader extends ClassLoader { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
62 |
private final String myClass; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
63 |
private final byte[] myBytes; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
64 |
private final String friendClass; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
65 |
private final ClassLoader friendLoader; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
66 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
67 |
Loader(String myClass, byte[] myBytes, |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
68 |
String friendClass, ClassLoader friendLoader) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
69 |
this.myClass = myClass; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
70 |
this.myBytes = myBytes; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
71 |
this.friendClass = friendClass; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
72 |
this.friendLoader = friendLoader; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
73 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
74 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
75 |
Loader(String myClass, byte[] myBytes) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
76 |
this(myClass, myBytes, null, null); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
77 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
78 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
79 |
@Override |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
80 |
public Class<?> loadClass(String name) throws ClassNotFoundException { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
81 |
Class<?> c = findLoadedClass(name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
82 |
if (c != null) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
83 |
return c; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
84 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
85 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
86 |
if (name.equals(friendClass)) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
87 |
return friendLoader.loadClass(name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
88 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
89 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
90 |
if (name.equals(myClass)) { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
91 |
c = defineClass(name, myBytes, 0, myBytes.length); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
92 |
resolveClass(c); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
93 |
return c; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
94 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
95 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
96 |
return findSystemClass(name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
97 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
98 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
99 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
100 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
101 |
private static void runTest(final byte[] a_bytes, final byte[] b_bytes) throws Exception { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
102 |
Loader a_loader = new Loader(a_name, a_bytes); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
103 |
Loader b_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
104 |
Loader c_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
105 |
Loader d_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
106 |
Loader e_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
107 |
Loader f_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
108 |
Loader g_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
109 |
|
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
110 |
Class<?> c; |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
111 |
c = b_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
112 |
c = c_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
113 |
c = d_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
114 |
c = e_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
115 |
c = f_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
116 |
c = g_loader.loadClass(b_name); |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
117 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
118 |
public class A { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
119 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
120 |
class B extends A { |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
121 |
} |
2af47517ffbd
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
122 |
} |