Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/CreateMirror/ArraysNewInstanceBug.java
40942 views
1
/*
2
* Copyright (c) 2017, 2019, 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
* @modules java.base/jdk.internal.misc
29
* @run main/othervm -Xcomp ArraysNewInstanceBug
30
*/
31
32
// This test crashes in compiled code with race, because the compiler generates code that assumes this ordering.
33
import java.lang.reflect.Array;
34
import java.io.File;
35
import java.net.URL;
36
import java.net.URLClassLoader;
37
38
public class ArraysNewInstanceBug implements Runnable {
39
static Class<?>[] classes;
40
41
int start;
42
43
ArraysNewInstanceBug(int start) {
44
this.start = start;
45
}
46
47
String[] result;
48
49
public void run() {
50
result = new String[classes.length];
51
System.err.print('.');
52
for (int i = start; i < classes.length; i++) {
53
result[i] = Array.newInstance(classes[i], 0).getClass().getName();
54
}
55
}
56
57
public static void main(String[] args) throws Throwable {
58
Class<?> c = ArraysNewInstanceBug.class;
59
ClassLoader apploader = c.getClassLoader();
60
File testClasses = new File(System.getProperty("test.classes"));
61
for (int iter = 0; iter < 10 ; iter++) { // 10 is enough to get it to crash on my machine.
62
System.err.print('[');
63
classes = new Class<?>[1000];
64
for (int i = 0; i < classes.length; i++) {
65
ClassLoader loader = new URLClassLoader(new URL[] { testClasses.toURI().toURL() }, apploader.getParent());
66
classes[i] = loader.loadClass(c.getSimpleName());
67
}
68
System.err.print(']');
69
System.err.print('(');
70
int threadCount = 64;
71
Thread[] threads = new Thread[threadCount];
72
for (int i = 0; i < threads.length; i++) {
73
threads[i] = new Thread(new ArraysNewInstanceBug(i));
74
}
75
for (int i = 0; i < threads.length; i++) {
76
threads[i].start();
77
}
78
for (int i = 0; i < threads.length; i++) {
79
threads[i].join();
80
}
81
System.err.print(')');
82
}
83
}
84
}
85
86