From cae1240123e5933a4f3913af22c120b1703babc7 Mon Sep 17 00:00:00 2001 From: jgodinez Date: Wed, 15 Apr 2009 08:47:21 -0700 Subject: 6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer Reviewed-by: campbell, flar Contributed-by: linuxhippy --- .../classes/sun/java2d/pipe/RenderBuffer.java | 36 +++++++--------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'src/share/classes/sun/java2d') diff --git a/src/share/classes/sun/java2d/pipe/RenderBuffer.java b/src/share/classes/sun/java2d/pipe/RenderBuffer.java index 62026e490..f0b8069a5 100644 --- a/src/share/classes/sun/java2d/pipe/RenderBuffer.java +++ b/src/share/classes/sun/java2d/pipe/RenderBuffer.java @@ -63,7 +63,7 @@ public class RenderBuffer { * (This value can be adjusted if the cost of JNI downcalls is reduced * in a future release.) */ - private static final int COPY_FROM_ARRAY_THRESHOLD = 28; + private static final int COPY_FROM_ARRAY_THRESHOLD = 6; protected final Unsafe unsafe; protected final long baseAddress; @@ -92,20 +92,6 @@ public class RenderBuffer { return baseAddress; } - /** - * Copies length bytes from the Java-level srcArray to the native - * memory located at dstAddr. Note that this method performs no bounds - * checking. Verification that the copy will not result in memory - * corruption should be done by the caller prior to invocation. - * - * @param srcArray the source array - * @param srcPos the starting position of the source array (in bytes) - * @param dstAddr pointer to the destination block of native memory - * @param length the number of bytes to copy from source to destination - */ - private static native void copyFromArray(Object srcArray, long srcPos, - long dstAddr, long length); - /** * The behavior (and names) of the following methods are nearly * identical to their counterparts in the various NIO Buffer classes. @@ -147,9 +133,9 @@ public class RenderBuffer { public RenderBuffer put(byte[] x, int offset, int length) { if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_BYTE; + long offsetInBytes = offset * SIZEOF_BYTE + Unsafe.ARRAY_BYTE_BASE_OFFSET; long lengthInBytes = length * SIZEOF_BYTE; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -178,9 +164,9 @@ public class RenderBuffer { public RenderBuffer put(short[] x, int offset, int length) { // assert (position() % SIZEOF_SHORT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_SHORT; + long offsetInBytes = offset * SIZEOF_SHORT + Unsafe.ARRAY_SHORT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_SHORT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -215,9 +201,9 @@ public class RenderBuffer { public RenderBuffer put(int[] x, int offset, int length) { // assert (position() % SIZEOF_INT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_INT; + long offsetInBytes = offset * SIZEOF_INT + Unsafe.ARRAY_INT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_INT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -246,9 +232,9 @@ public class RenderBuffer { public RenderBuffer put(float[] x, int offset, int length) { // assert (position() % SIZEOF_FLOAT == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_FLOAT; + long offsetInBytes = offset * SIZEOF_FLOAT + Unsafe.ARRAY_FLOAT_BASE_OFFSET; long lengthInBytes = length * SIZEOF_FLOAT; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; @@ -277,9 +263,9 @@ public class RenderBuffer { public RenderBuffer put(long[] x, int offset, int length) { // assert (position() % SIZEOF_LONG == 0); if (length > COPY_FROM_ARRAY_THRESHOLD) { - long offsetInBytes = offset * SIZEOF_LONG; + long offsetInBytes = offset * SIZEOF_LONG + Unsafe.ARRAY_LONG_BASE_OFFSET; long lengthInBytes = length * SIZEOF_LONG; - copyFromArray(x, offsetInBytes, curAddress, lengthInBytes); + unsafe.copyMemory(x, offsetInBytes, null, curAddress, lengthInBytes); position(position() + lengthInBytes); } else { int end = offset + length; -- cgit v1.2.3