TestConjointAtomicArraycopy.java revision 2846
828N/A/*
2362N/A * Copyright 2011 SAP AG. All Rights Reserved.
828N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
828N/A *
828N/A * This code is free software; you can redistribute it and/or modify it
828N/A * under the terms of the GNU General Public License version 2 only, as
828N/A * published by the Free Software Foundation.
828N/A *
828N/A * This code is distributed in the hope that it will be useful, but WITHOUT
828N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
828N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
828N/A * version 2 for more details (a copy is included in the LICENSE file that
828N/A * accompanied this code).
828N/A *
828N/A * You should have received a copy of the GNU General Public License version
828N/A * 2 along with this work; if not, write to the Free Software Foundation,
828N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
828N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
828N/A */
828N/A
828N/A/*
828N/A * @test TestConjointAtomicArraycopy
828N/A * @bug 7100935
828N/A * @summary verify that oops are copied element-wise atomic
828N/A * @run main/othervm -Xint TestConjointAtomicArraycopy
828N/A * @run main/othervm -Xcomp -Xbatch TestConjointAtomicArraycopy
828N/A * @author axel.siebenborn@sap.com
828N/A */
828N/A
828N/Apublic class TestConjointAtomicArraycopy {
828N/A
828N/A static volatile Object [] testArray = new Object [4];
828N/A
828N/A static short[] a1 = new short[8];
828N/A static short[] a2 = new short[8];
828N/A static short[] a3 = new short[8];
828N/A
828N/A static volatile boolean keepRunning = true;
828N/A
828N/A static void testOopsCopy() throws InterruptedException{
828N/A
828N/A }
828N/A
828N/A public static void main(String[] args ) throws InterruptedException{
828N/A for (int i = 0; i < testArray.length; i++){
828N/A testArray[i] = new String("A");
828N/A }
828N/A
828N/A Thread writer = new Thread (new Runnable(){
828N/A public void run(){
for (int i = 0 ; i < 1000000; i++) {
System.arraycopy(testArray, 1, testArray, 0, 3);
testArray[2] = new String("a");
}
}
});
Thread reader = new Thread( new Runnable(){
public void run(){
while (keepRunning){
String name = testArray[2].getClass().getName();
if(!(name.endsWith("String"))){
throw new RuntimeException("got wrong class name");
}
}
}
});
keepRunning = true;
reader.start();
writer.start();
writer.join();
keepRunning = false;
reader.join();
}
}