Mercurial > hg > graal-jvmci-8
comparison test/runtime/CreateMirror/ArraysNewInstanceBug.java @ 24157:f4e6ddeb5b6f jvmci-0.31
race in field updates when creating ArrayKlasses can lead to crash (JDK-8182397)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jul 2017 19:44:11 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
24156:28d2f9c907b4 | 24157:f4e6ddeb5b6f |
---|---|
1 /* | |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 /* | |
25 * @test ArraysNewInstanceBug | |
26 * @bug 8182397 | |
27 * @summary race in setting array_klass field for component mirror with mirror update for klass | |
28 * @run main/othervm -Xcomp ArraysNewInstanceBug | |
29 */ | |
30 | |
31 // This test crashes in compiled code with race, because the compiler generates code that assumes this ordering. | |
32 import java.lang.reflect.Array; | |
33 import java.net.URL; | |
34 import java.net.URLClassLoader; | |
35 | |
36 public class ArraysNewInstanceBug implements Runnable { | |
37 static Class<?>[] classes; | |
38 | |
39 int start; | |
40 | |
41 ArraysNewInstanceBug(int start) { | |
42 this.start = start; | |
43 } | |
44 | |
45 String[] result; | |
46 | |
47 public void run() { | |
48 result = new String[classes.length]; | |
49 System.err.print('.'); | |
50 for (int i = start; i < classes.length; i++) { | |
51 result[i] = Array.newInstance(classes[i], 0).getClass().getName(); | |
52 } | |
53 } | |
54 | |
55 public static void main(String[] args) throws Throwable { | |
56 Class<?> c = ArraysNewInstanceBug.class; | |
57 ClassLoader apploader = c.getClassLoader(); | |
58 for (int iter = 0; iter < 10 ; iter++) { // 10 is enough to get it to crash on my machine. | |
59 System.err.print('['); | |
60 classes = new Class<?>[1000]; | |
61 String urlpath = "file://" + System.getProperty("test.classes") + "/"; | |
62 for (int i = 0; i < classes.length; i++) { | |
63 ClassLoader loader = new URLClassLoader(new URL[] { new URL(urlpath) }, apploader.getParent()); | |
64 classes[i] = loader.loadClass(c.getSimpleName()); | |
65 } | |
66 System.err.print(']'); | |
67 System.err.print('('); | |
68 int threadCount = 64; | |
69 Thread[] threads = new Thread[threadCount]; | |
70 for (int i = 0; i < threads.length; i++) { | |
71 threads[i] = new Thread(new ArraysNewInstanceBug(i)); | |
72 } | |
73 for (int i = 0; i < threads.length; i++) { | |
74 threads[i].start(); | |
75 } | |
76 for (int i = 0; i < threads.length; i++) { | |
77 threads[i].join(); | |
78 } | |
79 System.err.print(')'); | |
80 } | |
81 } | |
82 } |