Path: blob/master/test/hotspot/jtreg/runtime/7100935/TestShortArraycopy.java
40942 views
/*1* Copyright (c) 2011 SAP SE. 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 TestShortArraycopy25* @bug 710093526* @summary verify that shorts are copied element-wise atomic.27* @run main/othervm -Xint TestShortArraycopy28* @run main/othervm -Xcomp -Xbatch TestShortArraycopy29* @author [email protected]30*/3132public class TestShortArraycopy {3334static short[] a1 = new short[8];35static short[] a2 = new short[8];36static short[] a3 = new short[8];3738static volatile boolean keepRunning = true;3940public static void main(String[] args) throws InterruptedException {4142for (int i = 0; i < a1.length ; i++) {43a1[i] = (short)0xffff;44a2[i] = (short)0xffff;45a3[i] = (short)0x0000;46}47Thread reader = new Thread() {48public void run() {49while (keepRunning) {50for (int j = 0; j < a1.length; j++) {51short s = a1[j];52if (s != (short)0xffff && s != (short)0x0000) {53System.out.println("Error: s = " + s);54throw new RuntimeException("wrong result");5556}57}58}59}60};61Thread writer = new Thread() {62public void run() {63for (int i = 0; i < 1000000; i++) {64System.arraycopy(a2, 5, a1, 3, 3);65System.arraycopy(a3, 5, a1, 3, 3);66}67}68};69keepRunning = true;70reader.start();71writer.start();72writer.join();73keepRunning = false;74reader.join();75}76}777879