diff options
author | jgodinez <none@none> | 2009-04-15 08:47:21 -0700 |
---|---|---|
committer | jgodinez <none@none> | 2009-04-15 08:47:21 -0700 |
commit | cae1240123e5933a4f3913af22c120b1703babc7 (patch) | |
tree | b96b00cdc4b96f847d5746e891d88716428a1528 /src | |
parent | d5367ebe0efaef8419e416a330b774ea4c877029 (diff) |
6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer
Reviewed-by: campbell, flar
Contributed-by: linuxhippy <linuxhippy@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/share/classes/sun/java2d/pipe/RenderBuffer.java | 36 | ||||
-rw-r--r-- | src/share/native/sun/java2d/pipe/RenderBuffer.c | 71 |
2 files changed, 11 insertions, 96 deletions
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; @@ -93,20 +93,6 @@ public class RenderBuffer { } /** - * 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; diff --git a/src/share/native/sun/java2d/pipe/RenderBuffer.c b/src/share/native/sun/java2d/pipe/RenderBuffer.c deleted file mode 100644 index fd6b5abd4..000000000 --- a/src/share/native/sun/java2d/pipe/RenderBuffer.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2005 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. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * 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. - */ - -#include "jni.h" -#include "jni_util.h" -#include "jlong.h" -#include <string.h> - -#include "sun_java2d_pipe_RenderBuffer.h" - -/** - * Note: The code in this file is nearly identical to that in - * java/nio/Bits.c... - */ - -#define MBYTE 1048576 - -JNIEXPORT void JNICALL -Java_sun_java2d_pipe_RenderBuffer_copyFromArray - (JNIEnv *env, jclass rb, - jobject srcArray, jlong srcPos, jlong dstAddr, jlong length) -{ - jbyte *bytes; - size_t size; - - while (length > 0) { - /* - * Copy no more than one megabyte at a time, to allow for GC. - * (Probably not an issue for STR, since our buffer size is likely - * much smaller than a megabyte, but just in case...) - */ - size = (size_t)(length > MBYTE ? MBYTE : length); - - bytes = (*env)->GetPrimitiveArrayCritical(env, srcArray, NULL); - if (bytes == NULL) { - JNU_ThrowInternalError(env, "Unable to get array"); - return; - } - - memcpy(jlong_to_ptr(dstAddr), bytes + srcPos, size); - - (*env)->ReleasePrimitiveArrayCritical(env, srcArray, - bytes, JNI_ABORT); - - length -= size; - dstAddr += size; - srcPos += size; - } -} |