Path: blob/master/test/hotspot/jtreg/runtime/CreateMirror/ArraysNewInstanceBug.java
40942 views
/*1* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test ArraysNewInstanceBug25* @bug 818239726* @summary race in setting array_klass field for component mirror with mirror update for klass27* @modules java.base/jdk.internal.misc28* @run main/othervm -Xcomp ArraysNewInstanceBug29*/3031// This test crashes in compiled code with race, because the compiler generates code that assumes this ordering.32import java.lang.reflect.Array;33import java.io.File;34import java.net.URL;35import java.net.URLClassLoader;3637public class ArraysNewInstanceBug implements Runnable {38static Class<?>[] classes;3940int start;4142ArraysNewInstanceBug(int start) {43this.start = start;44}4546String[] result;4748public void run() {49result = new String[classes.length];50System.err.print('.');51for (int i = start; i < classes.length; i++) {52result[i] = Array.newInstance(classes[i], 0).getClass().getName();53}54}5556public static void main(String[] args) throws Throwable {57Class<?> c = ArraysNewInstanceBug.class;58ClassLoader apploader = c.getClassLoader();59File testClasses = new File(System.getProperty("test.classes"));60for (int iter = 0; iter < 10 ; iter++) { // 10 is enough to get it to crash on my machine.61System.err.print('[');62classes = new Class<?>[1000];63for (int i = 0; i < classes.length; i++) {64ClassLoader loader = new URLClassLoader(new URL[] { testClasses.toURI().toURL() }, apploader.getParent());65classes[i] = loader.loadClass(c.getSimpleName());66}67System.err.print(']');68System.err.print('(');69int threadCount = 64;70Thread[] threads = new Thread[threadCount];71for (int i = 0; i < threads.length; i++) {72threads[i] = new Thread(new ArraysNewInstanceBug(i));73}74for (int i = 0; i < threads.length; i++) {75threads[i].start();76}77for (int i = 0; i < threads.length; i++) {78threads[i].join();79}80System.err.print(')');81}82}83}848586