Wed, 19 Oct 2011 10:52:30 -0700
7100935: win32: memmove is not atomic but is used for pd_conjoint_*_atomic operations
Summary: replace the call to memmove by a simple copy loop
Reviewed-by: dholmes, kvn, never
Contributed-by: axel.siebenborn@sap.com, volker.simonis@gmail.com
1.1 --- a/src/cpu/sparc/vm/copy_sparc.hpp Mon Oct 17 21:38:29 2011 -0700 1.2 +++ b/src/cpu/sparc/vm/copy_sparc.hpp Wed Oct 19 10:52:30 2011 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -82,13 +82,35 @@ 1.11 } 1.12 1.13 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 1.14 - // FIXME 1.15 - (void)memmove(to, from, count << LogBytesPerShort); 1.16 + if (from > to) { 1.17 + while (count-- > 0) { 1.18 + // Copy forwards 1.19 + *to++ = *from++; 1.20 + } 1.21 + } else { 1.22 + from += count - 1; 1.23 + to += count - 1; 1.24 + while (count-- > 0) { 1.25 + // Copy backwards 1.26 + *to-- = *from--; 1.27 + } 1.28 + } 1.29 } 1.30 1.31 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 1.32 - // FIXME 1.33 - (void)memmove(to, from, count << LogBytesPerInt); 1.34 + if (from > to) { 1.35 + while (count-- > 0) { 1.36 + // Copy forwards 1.37 + *to++ = *from++; 1.38 + } 1.39 + } else { 1.40 + from += count - 1; 1.41 + to += count - 1; 1.42 + while (count-- > 0) { 1.43 + // Copy backwards 1.44 + *to-- = *from--; 1.45 + } 1.46 + } 1.47 } 1.48 1.49 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
2.1 --- a/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp Mon Oct 17 21:38:29 2011 -0700 2.2 +++ b/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp Wed Oct 19 10:52:30 2011 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -85,13 +85,35 @@ 2.11 } 2.12 2.13 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) { 2.14 - // FIXME 2.15 - (void)memmove(to, from, count << LogBytesPerShort); 2.16 + if (from > to) { 2.17 + while (count-- > 0) { 2.18 + // Copy forwards 2.19 + *to++ = *from++; 2.20 + } 2.21 + } else { 2.22 + from += count - 1; 2.23 + to += count - 1; 2.24 + while (count-- > 0) { 2.25 + // Copy backwards 2.26 + *to-- = *from--; 2.27 + } 2.28 + } 2.29 } 2.30 2.31 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) { 2.32 - // FIXME 2.33 - (void)memmove(to, from, count << LogBytesPerInt); 2.34 + if (from > to) { 2.35 + while (count-- > 0) { 2.36 + // Copy forwards 2.37 + *to++ = *from++; 2.38 + } 2.39 + } else { 2.40 + from += count - 1; 2.41 + to += count - 1; 2.42 + while (count-- > 0) { 2.43 + // Copy backwards 2.44 + *to-- = *from--; 2.45 + } 2.46 + } 2.47 } 2.48 2.49 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/runtime/7100935/TestConjointAtomicArraycopy.java Wed Oct 19 10:52:30 2011 -0700 3.3 @@ -0,0 +1,78 @@ 3.4 +/* 3.5 + * Copyright 2011 SAP AG. All Rights Reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test TestConjointAtomicArraycopy 3.29 + * @bug 7100935 3.30 + * @summary verify that oops are copied element-wise atomic 3.31 + * @run main/othervm -Xint TestConjointAtomicArraycopy 3.32 + * @run main/othervm -Xcomp -Xbatch TestConjointAtomicArraycopy 3.33 + * @author axel.siebenborn@sap.com 3.34 + */ 3.35 + 3.36 +public class TestConjointAtomicArraycopy { 3.37 + 3.38 + static volatile Object [] testArray = new Object [4]; 3.39 + 3.40 + static short[] a1 = new short[8]; 3.41 + static short[] a2 = new short[8]; 3.42 + static short[] a3 = new short[8]; 3.43 + 3.44 + static volatile boolean keepRunning = true; 3.45 + 3.46 + static void testOopsCopy() throws InterruptedException{ 3.47 + 3.48 + } 3.49 + 3.50 + public static void main(String[] args ) throws InterruptedException{ 3.51 + for (int i = 0; i < testArray.length; i++){ 3.52 + testArray[i] = new String("A"); 3.53 + } 3.54 + 3.55 + Thread writer = new Thread (new Runnable(){ 3.56 + public void run(){ 3.57 + for (int i = 0 ; i < 1000000; i++) { 3.58 + System.arraycopy(testArray, 1, testArray, 0, 3); 3.59 + testArray[2] = new String("a"); 3.60 + } 3.61 + } 3.62 + }); 3.63 + 3.64 + Thread reader = new Thread( new Runnable(){ 3.65 + public void run(){ 3.66 + while (keepRunning){ 3.67 + String name = testArray[2].getClass().getName(); 3.68 + if(!(name.endsWith("String"))){ 3.69 + throw new RuntimeException("got wrong class name"); 3.70 + } 3.71 + } 3.72 + } 3.73 + }); 3.74 + keepRunning = true; 3.75 + reader.start(); 3.76 + writer.start(); 3.77 + writer.join(); 3.78 + keepRunning = false; 3.79 + reader.join(); 3.80 + } 3.81 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/runtime/7100935/TestShortArraycopy.java Wed Oct 19 10:52:30 2011 -0700 4.3 @@ -0,0 +1,77 @@ 4.4 +/* 4.5 + * Copyright 2011 SAP AG. All Rights Reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test TestShortArraycopy 4.29 + * @bug 7100935 4.30 + * @summary verify that shorts are copied element-wise atomic. 4.31 + * @run main/othervm -Xint TestShortArraycopy 4.32 + * @run main/othervm -Xcomp -Xbatch TestShortArraycopy 4.33 + * @author volker.simonis@gmail.com 4.34 + */ 4.35 + 4.36 +public class TestShortArraycopy { 4.37 + 4.38 + static short[] a1 = new short[8]; 4.39 + static short[] a2 = new short[8]; 4.40 + static short[] a3 = new short[8]; 4.41 + 4.42 + static volatile boolean keepRunning = true; 4.43 + 4.44 + public static void main(String[] args) throws InterruptedException { 4.45 + 4.46 + for (int i = 0; i < a1.length ; i++) { 4.47 + a1[i] = (short)0xffff; 4.48 + a2[i] = (short)0xffff; 4.49 + a3[i] = (short)0x0000; 4.50 + } 4.51 + Thread reader = new Thread() { 4.52 + public void run() { 4.53 + while (keepRunning) { 4.54 + for (int j = 0; j < a1.length; j++) { 4.55 + short s = a1[j]; 4.56 + if (s != (short)0xffff && s != (short)0x0000) { 4.57 + System.out.println("Error: s = " + s); 4.58 + throw new RuntimeException("wrong result"); 4.59 + 4.60 + } 4.61 + } 4.62 + } 4.63 + } 4.64 + }; 4.65 + Thread writer = new Thread() { 4.66 + public void run() { 4.67 + for (int i = 0; i < 1000000; i++) { 4.68 + System.arraycopy(a2, 5, a1, 3, 3); 4.69 + System.arraycopy(a3, 5, a1, 3, 3); 4.70 + } 4.71 + } 4.72 + }; 4.73 + keepRunning = true; 4.74 + reader.start(); 4.75 + writer.start(); 4.76 + writer.join(); 4.77 + keepRunning = false; 4.78 + reader.join(); 4.79 + } 4.80 +}