--- old/src/java.base/share/native/libjava/Bits.c 2016-01-25 20:47:21.401311592 -0800 +++ new/src/java.base/share/native/libjava/Bits.c 2016-01-25 20:47:21.273247592 -0800 @@ -58,10 +58,10 @@ { jbyte *bytes; size_t size; - jshort *srcShort, *dstShort, *endShort; - jshort tmpShort; + jshort *srcShort, *endShort; + unsigned char* dst; - dstShort = (jshort *)jlong_to_ptr(dstAddr); + dst = jlong_to_ptr(dstAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -69,10 +69,12 @@ GETCRITICAL_OR_RETURN(bytes, env, src); srcShort = (jshort *)(bytes + srcPos); - endShort = srcShort + (size / sizeof(jshort)); + endShort = (jshort *)(bytes + srcPos + size); while (srcShort < endShort) { - tmpShort = *srcShort++; - *dstShort++ = SWAPSHORT(tmpShort); + jshort tmp = SWAPSHORT(*srcShort); + memcpy(dst, &tmp, sizeof(jshort)); + srcShort++; + dst += sizeof(jshort); } RELEASECRITICAL(bytes, env, src, JNI_ABORT); @@ -88,10 +90,10 @@ { jbyte *bytes; size_t size; - jshort *srcShort, *dstShort, *endShort; - jshort tmpShort; + jshort *dstShort; - srcShort = (jshort *)jlong_to_ptr(srcAddr); + unsigned char *src, *end; + src = jlong_to_ptr(srcAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -99,10 +101,12 @@ GETCRITICAL_OR_RETURN(bytes, env, dst); dstShort = (jshort *)(bytes + dstPos); - endShort = srcShort + (size / sizeof(jshort)); - while (srcShort < endShort) { - tmpShort = *srcShort++; - *dstShort++ = SWAPSHORT(tmpShort); + end = src + size; + while (src < end) { + jshort tmp; + memcpy(&tmp, src, sizeof(jshort)); + *dstShort++ = SWAPSHORT(tmp); + src += sizeof(jshort); } RELEASECRITICAL(bytes, env, dst, 0); @@ -118,10 +122,10 @@ { jbyte *bytes; size_t size; - jint *srcInt, *dstInt, *endInt; - jint tmpInt; + jint *srcInt, *endInt; + unsigned char *dst; - dstInt = (jint *)jlong_to_ptr(dstAddr); + dst = jlong_to_ptr(dstAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -129,10 +133,12 @@ GETCRITICAL_OR_RETURN(bytes, env, src); srcInt = (jint *)(bytes + srcPos); - endInt = srcInt + (size / sizeof(jint)); + endInt = (jint *)(bytes + srcPos + size); while (srcInt < endInt) { - tmpInt = *srcInt++; - *dstInt++ = SWAPINT(tmpInt); + jint tmp = SWAPINT(*srcInt); + memcpy(dst, &tmp, sizeof(jint)); + srcInt++; + dst += sizeof(jint); } RELEASECRITICAL(bytes, env, src, JNI_ABORT); @@ -148,10 +154,10 @@ { jbyte *bytes; size_t size; - jint *srcInt, *dstInt, *endInt; - jint tmpInt; + unsigned char *src, *end; + jint *dstInt; - srcInt = (jint *)jlong_to_ptr(srcAddr); + src = jlong_to_ptr(srcAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -159,10 +165,12 @@ GETCRITICAL_OR_RETURN(bytes, env, dst); dstInt = (jint *)(bytes + dstPos); - endInt = srcInt + (size / sizeof(jint)); - while (srcInt < endInt) { - tmpInt = *srcInt++; - *dstInt++ = SWAPINT(tmpInt); + end = src + size; + while (src < end) { + jint tmp; + memcpy(&tmp, src, sizeof(jint)); + *dstInt++ = SWAPINT(tmp); + src += sizeof(jint); } RELEASECRITICAL(bytes, env, dst, 0); @@ -178,10 +186,10 @@ { jbyte *bytes; size_t size; - jlong *srcLong, *dstLong, *endLong; - jlong tmpLong; + jlong *srcLong, *endLong; + unsigned char* dst; - dstLong = (jlong *)jlong_to_ptr(dstAddr); + dst = jlong_to_ptr(dstAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -189,10 +197,12 @@ GETCRITICAL_OR_RETURN(bytes, env, src); srcLong = (jlong *)(bytes + srcPos); - endLong = srcLong + (size / sizeof(jlong)); + endLong = (jlong *)(bytes + srcPos + size); while (srcLong < endLong) { - tmpLong = *srcLong++; - *dstLong++ = SWAPLONG(tmpLong); + jlong tmp = SWAPLONG(*srcLong); + memcpy(dst, &tmp, sizeof(jlong)); + srcLong++; + dst += sizeof(jlong); } RELEASECRITICAL(bytes, env, src, JNI_ABORT); @@ -208,10 +218,10 @@ { jbyte *bytes; size_t size; - jlong *srcLong, *dstLong, *endLong; - jlong tmpLong; + unsigned char *src, *end; + jlong *dstLong; - srcLong = (jlong *)jlong_to_ptr(srcAddr); + src = jlong_to_ptr(srcAddr); while (length > 0) { size = (length < MBYTE) ? (size_t)length : (size_t)MBYTE; @@ -219,10 +229,12 @@ GETCRITICAL_OR_RETURN(bytes, env, dst); dstLong = (jlong *)(bytes + dstPos); - endLong = srcLong + (size / sizeof(jlong)); - while (srcLong < endLong) { - tmpLong = *srcLong++; - *dstLong++ = SWAPLONG(tmpLong); + end = src + size; + while (src < end) { + jlong tmp; + memcpy(&tmp, src, sizeof(jlong)); + *dstLong++ = SWAPLONG(tmp); + src += sizeof(jlong); } RELEASECRITICAL(bytes, env, dst, 0); --- old/src/java.base/share/classes/java/nio/Bits.java 2016-01-25 20:47:21.401311592 -0800 +++ new/src/java.base/share/classes/java/nio/Bits.java 2016-01-25 20:47:21.273247592 -0800 @@ -819,18 +819,93 @@ copyToShortArray(srcAddr, dst, dstPos, length); } + /** + * Copy and byte swap 16-bit elements from a heap array to off-heap memory + * + * @param src + * the source array, must be a 16-bit primitive array type + * @param srcPos + * byte offset within source array of the first element to read + * @param dstAddr + * destination address + * @param length + * number of bytes to copy + */ static native void copyFromShortArray(Object src, long srcPos, long dstAddr, long length); + + /** + * Copy and byte swap 16-bit elements from off-heap memory to a heap array + * + * @param srcAddr + * source address + * @param dst + * destination array, must be a 16-bit primitive array type + * @param dstPos + * byte offset within the destination array of the first element to write + * @param length + * number of bytes to copy + */ static native void copyToShortArray(long srcAddr, Object dst, long dstPos, long length); + /** + * Copy and byte swap 32-bit elements from a heap array to off-heap memory + * + * @param src + * the source array, must be a 32-bit primitive array type + * @param srcPos + * byte offset within source array of the first element to read + * @param dstAddr + * destination address + * @param length + * number of bytes to copy + */ static native void copyFromIntArray(Object src, long srcPos, long dstAddr, long length); + + /** + * Copy and byte swap 32-bit elements from off-heap memory to a heap array + * + * @param srcAddr + * source address + * @param dst + * destination array, must be a 32-bit primitive array type + * @param dstPos + * byte offset within the destination array of the first element to write + * @param length + * number of bytes to copy + */ static native void copyToIntArray(long srcAddr, Object dst, long dstPos, long length); + /** + * Copy and byte swap 64-bit elements from a heap array to off-heap memory + * + * @param src + * the source array, must be a 64-bit primitive array type + * @param srcPos + * byte offset within source array of the first element to read + * @param dstAddr + * destination address + * @param length + * number of bytes to copy + */ static native void copyFromLongArray(Object src, long srcPos, long dstAddr, long length); + + /** + * Copy and byte swap 64-bit elements from off-heap memory to a heap array + * + * @param srcAddr + * source address + * @param dst + * destination array, must be a 64-bit primitive array type + * @param dstPos + * byte offset within the destination array of the first element to write + * @param length + * number of bytes to copy + */ static native void copyToLongArray(long srcAddr, Object dst, long dstPos, long length); --- old/make/lib/CoreLibraries.gmk 2016-01-25 20:47:21.401311592 -0800 +++ new/make/lib/CoreLibraries.gmk 2016-01-25 20:47:21.273247592 -0800 @@ -137,12 +137,6 @@ endif endif -ifeq ($(OPENJDK_TARGET_OS), linux) - ifeq ($(OPENJDK_TARGET_CPU), x86_64) - BUILD_LIBJAVA_Bits.c_CFLAGS := $(C_O_FLAG_NORM) - endif -endif - $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \ LIBRARY := java, \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \