提交 2a2f84c4 编写于 作者: J jgodinez

6827989: Use Unsafe.copyMemory for array->Unsafe copy operations in RenderBuffer

Reviewed-by: campbell, flar
Contributed-by: Nlinuxhippy <linuxhippy@gmail.com>
上级 9696b4e5
......@@ -125,7 +125,6 @@ FILES_2D_c = \
FourByteAbgrPre.c \
BufferedMaskBlit.c \
BufferedRenderPipe.c \
RenderBuffer.c \
ShapeSpanIterator.c \
SpanClipRenderer.c \
awt_ImageRep.c \
......
......@@ -70,7 +70,6 @@ FILES_c = \
FourByteAbgrPre.c \
BufferedMaskBlit.c \
BufferedRenderPipe.c \
RenderBuffer.c \
ShapeSpanIterator.c \
SpanClipRenderer.c \
SurfaceData.c \
......
......@@ -65,7 +65,6 @@ SUNWprivate_1.1 {
Java_sun_awt_image_ShortComponentRaster_initIDs;
Java_sun_java2d_pipe_BufferedMaskBlit_enqueueTile;
Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans;
Java_sun_java2d_pipe_RenderBuffer_copyFromArray;
Java_sun_java2d_pipe_SpanClipRenderer_eraseTile;
Java_sun_java2d_pipe_SpanClipRenderer_fillTile;
Java_sun_java2d_pipe_ShapeSpanIterator_addSegment;
......
......@@ -117,7 +117,6 @@ SUNWprivate_1.1 {
Java_sun_java2d_loops_MaskBlit_MaskBlit;
Java_sun_java2d_loops_MaskFill_MaskFill;
Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans;
Java_sun_java2d_pipe_RenderBuffer_copyFromArray;
Java_sun_java2d_pipe_SpanClipRenderer_initIDs;
sun_awt_image_GifImageDecoder_initIDs;
......
......@@ -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;
......
/*
* 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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册