Mercurial > hg > graal-jvmci-8
annotate test/gc/metaspace/G1AddMetaspaceDependency.java @ 23004:9a23a160ca57
8077674: BSD build failures due to undefined macros
Reviewed-by: dsamersoff, kbarrett, hseigel
author | dholmes |
---|---|
date | Mon, 04 May 2015 23:23:37 -0400 |
parents | f967da7f0c3c |
children |
rev | line source |
---|---|
9075
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
1 /* |
22981
f967da7f0c3c
8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
jwilhelm
parents:
12347
diff
changeset
|
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
9075
ba42fd5e00e6
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. |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
4 * |
ba42fd5e00e6
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 |
ba42fd5e00e6
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 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
8 * |
ba42fd5e00e6
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 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba42fd5e00e6
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 |
ba42fd5e00e6
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 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
13 * accompanied this code). |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
14 * |
ba42fd5e00e6
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 |
ba42fd5e00e6
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, |
ba42fd5e00e6
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. |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
18 * |
ba42fd5e00e6
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 |
ba42fd5e00e6
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 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
21 * questions. |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
22 */ |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
23 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
24 /* |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
25 * @test G1AddMetaspaceDependency |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
26 * @bug 8010196 |
22981
f967da7f0c3c
8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
jwilhelm
parents:
12347
diff
changeset
|
27 * @requires vm.gc=="G1" | vm.gc=="null" |
9075
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
28 * @summary Checks that we don't get locking problems when adding metaspace dependencies with the G1 update buffer monitor |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
29 * @run main/othervm -XX:+UseG1GC -XX:G1UpdateBufferSize=1 G1AddMetaspaceDependency |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
30 */ |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
31 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
32 import java.io.InputStream; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
33 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
34 public class G1AddMetaspaceDependency { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
35 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
36 static byte[] getClassBytes(String name) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
37 byte[] b = null; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
38 try (InputStream is = ClassLoader.getSystemResourceAsStream(name)) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
39 byte[] tmp = new byte[is.available()]; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
40 is.read(tmp); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
41 b = tmp; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
42 } finally { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
43 if (b == null) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
44 throw new RuntimeException("Unable to load class file"); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
45 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
46 return b; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
47 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
48 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
49 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
50 static final String a_name = G1AddMetaspaceDependency.class.getName() + "$A"; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
51 static final String b_name = G1AddMetaspaceDependency.class.getName() + "$B"; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
52 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
53 public static void main(String... args) throws Exception { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
54 final byte[] a_bytes = getClassBytes(a_name + ".class"); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
55 final byte[] b_bytes = getClassBytes(b_name + ".class"); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
56 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
57 for (int i = 0; i < 1000; i += 1) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
58 runTest(a_bytes, b_bytes); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
59 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
60 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
61 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
62 static class Loader extends ClassLoader { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
63 private final String myClass; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
64 private final byte[] myBytes; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
65 private final String friendClass; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
66 private final ClassLoader friendLoader; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
67 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
68 Loader(String myClass, byte[] myBytes, |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
69 String friendClass, ClassLoader friendLoader) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
70 this.myClass = myClass; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
71 this.myBytes = myBytes; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
72 this.friendClass = friendClass; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
73 this.friendLoader = friendLoader; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
74 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
75 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
76 Loader(String myClass, byte[] myBytes) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
77 this(myClass, myBytes, null, null); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
78 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
79 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
80 @Override |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
81 public Class<?> loadClass(String name) throws ClassNotFoundException { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
82 Class<?> c = findLoadedClass(name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
83 if (c != null) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
84 return c; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
85 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
86 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
87 if (name.equals(friendClass)) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
88 return friendLoader.loadClass(name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
89 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
90 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
91 if (name.equals(myClass)) { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
92 c = defineClass(name, myBytes, 0, myBytes.length); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
93 resolveClass(c); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
94 return c; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
95 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
96 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
97 return findSystemClass(name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
98 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
99 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
100 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
101 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
102 private static void runTest(final byte[] a_bytes, final byte[] b_bytes) throws Exception { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
103 Loader a_loader = new Loader(a_name, a_bytes); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
104 Loader b_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
105 Loader c_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
106 Loader d_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
107 Loader e_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
108 Loader f_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
109 Loader g_loader = new Loader(b_name, b_bytes, a_name, a_loader); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
110 |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
111 Class<?> c; |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
112 c = b_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
113 c = c_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
114 c = d_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
115 c = e_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
116 c = f_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
117 c = g_loader.loadClass(b_name); |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
118 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
119 public class A { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
120 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
121 class B extends A { |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
122 } |
ba42fd5e00e6
8010196: NPG: Internal Error: Metaspace allocation lock -- possible deadlock
mgerdin
parents:
diff
changeset
|
123 } |