Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/7100935/TestConjointAtomicArraycopy.java
32284 views
/*1* Copyright 2011 SAP AG. 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 TestConjointAtomicArraycopy25* @bug 710093526* @summary verify that oops are copied element-wise atomic27* @run main/othervm -Xint TestConjointAtomicArraycopy28* @run main/othervm -Xcomp -Xbatch TestConjointAtomicArraycopy29* @author [email protected]30*/3132public class TestConjointAtomicArraycopy {3334static volatile Object [] testArray = new Object [4];3536static short[] a1 = new short[8];37static short[] a2 = new short[8];38static short[] a3 = new short[8];3940static volatile boolean keepRunning = true;4142static void testOopsCopy() throws InterruptedException{4344}4546public static void main(String[] args ) throws InterruptedException{47for (int i = 0; i < testArray.length; i++){48testArray[i] = new String("A");49}5051Thread writer = new Thread (new Runnable(){52public void run(){53for (int i = 0 ; i < 1000000; i++) {54System.arraycopy(testArray, 1, testArray, 0, 3);55testArray[2] = new String("a");56}57}58});5960Thread reader = new Thread( new Runnable(){61public void run(){62while (keepRunning){63String name = testArray[2].getClass().getName();64if(!(name.endsWith("String"))){65throw new RuntimeException("got wrong class name");66}67}68}69});70keepRunning = true;71reader.start();72writer.start();73writer.join();74keepRunning = false;75reader.join();76}77}787980