diff --git a/src/share/vm/oops/typeArrayKlass.cpp b/src/share/vm/oops/typeArrayKlass.cpp index 68d67f1ccf6eb00440a8be982edd476b65610e47..b9ccd0cbc294539c46745d51c758a48988cf5998 100644 --- a/src/share/vm/oops/typeArrayKlass.cpp +++ b/src/share/vm/oops/typeArrayKlass.cpp @@ -123,16 +123,16 @@ void typeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) { THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); } + // Check zero copy + if (length == 0) + return; // This is an attempt to make the copy_array fast. - // NB: memmove takes care of overlapping memory segments. - // Potential problem: memmove is not guaranteed to be word atomic - // Revisit in Merlin int l2es = log2_element_size(); int ihs = array_header_in_bytes() / wordSize; - char* src = (char*) ((oop*)s + ihs) + (src_pos << l2es); - char* dst = (char*) ((oop*)d + ihs) + (dst_pos << l2es); - memmove(dst, src, length << l2es); + char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es); + char* dst = (char*) ((oop*)d + ihs) + ((size_t)dst_pos << l2es); + Copy::conjoint_memory_atomic(src, dst, (size_t)length << l2es); } diff --git a/test/compiler/6892265/Test.java b/test/compiler/6892265/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..1b5d6daa9e12c0198c1deacba74d67ac60f9e5e1 --- /dev/null +++ b/test/compiler/6892265/Test.java @@ -0,0 +1,65 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ + +/** + * @test + * @bug 6892265 + * @summary System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes + * + * @run main/othervm Test + */ + +public class Test { + static final int NCOPY = 1; + static final int OVERFLOW = 1; + static int[] src2 = new int[NCOPY]; + static int[] dst2; + + static void test() { + int N; + int SIZE; + + N = Integer.MAX_VALUE/4 + OVERFLOW; + System.arraycopy(src2, 0, dst2, N, NCOPY); + System.arraycopy(dst2, N, src2, 0, NCOPY); + } + + public static void main(String[] args) { + try { + dst2 = new int[NCOPY + Integer.MAX_VALUE/4 + OVERFLOW]; + } catch (OutOfMemoryError e) { + System.exit(95); // Not enough memory + } + System.out.println("warmup"); + for (int i=0; i <11000; i++) { + test(); + } + System.out.println("start"); + for (int i=0; i <1000; i++) { + test(); + } + System.out.println("finish"); + } + +}