6892265: System.arraycopy unable to reference elements beyond Integer.MAX_VALUE bytes
Summary: Use size_t type cast to widen int values in typeArrayKlass::copy_array().
Reviewed-by: never, jcoomes
--- a/hotspot/src/share/vm/oops/typeArrayKlass.cpp Wed Jul 05 17:03:51 2017 +0200
+++ b/hotspot/src/share/vm/oops/typeArrayKlass.cpp Thu Dec 03 14:20:22 2009 -0800
@@ -123,16 +123,16 @@
|| (((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);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/6892265/Test.java Thu Dec 03 14:20:22 2009 -0800
@@ -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");
+ }
+
+}