You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/06/26 13:26:03 UTC
svn commit: r788658 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ main/native/shared/
test/org/apache/commons/runtime/
Author: mturk
Date: Fri Jun 26 11:26:03 2009
New Revision: 788658
URL: http://svn.apache.org/viewvc?rev=788658&view=rev
Log:
Add memory to/from primitive array copy methods
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java?rev=788658&r1=788657&r2=788658&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Fri Jun 26 11:26:03 2009
@@ -470,7 +470,8 @@
private static native long[] array4(Pointer ptr, long offset, int length)
throws IndexOutOfBoundsException, OutOfMemoryError;
/**
- * Return the {@code ptr} memory area from {@code src} to {@code long} array.
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code long} array.
*
* @param ptr {@code Pointer} whose content to use.
* @param offset starting position in {@code longs} in the memory.
@@ -497,4 +498,355 @@
return array4(ptr, offset, length);
}
+ private static native void acpy0(Pointer src, long srcPos, byte[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the memory area from {@code src} pointer to array
+ * pointed by {@code dst}.
+ *
+ * @param src source memory {@code Pointer}.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code array}.
+ * @param dstPos starting position in the destination array.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(Pointer src, long srcPos, byte[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null || src.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy0(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy1(Pointer src, long srcPos, char[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the memory area from {@code src} pointer to array
+ * pointed by {@code dst}.
+ *
+ * @param src source memory {@code Pointer}.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code array}.
+ * @param dstPos starting position in the destination array.
+ * @param length the number of chars to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(Pointer src, long srcPos, char[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null || src.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy1(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy2(Pointer src, long srcPos, short[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the memory area from {@code src} pointer to array
+ * pointed by {@code dst}.
+ *
+ * @param src source memory {@code Pointer}.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code array}.
+ * @param dstPos starting position in the destination array.
+ * @param length the number of shorts to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(Pointer src, long srcPos, short[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null || src.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy2(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy3(Pointer src, long srcPos, int[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the memory area from {@code src} pointer to array
+ * pointed by {@code dst}.
+ *
+ * @param src source memory {@code Pointer}.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code array}.
+ * @param dstPos starting position in the destination array.
+ * @param length the number of ints to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(Pointer src, long srcPos, int[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null || src.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy3(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy4(Pointer src, long srcPos, long[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the memory area from {@code src} pointer to array
+ * pointed by {@code dst}.
+ *
+ * @param src source memory {@code Pointer}.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code array}.
+ * @param dstPos starting position in the destination array.
+ * @param length the number of longs to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(Pointer src, long srcPos, long[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null || src.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy4(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy0(byte[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the array pointed by {@code src} to the memory area
+ * pointed by {@code dst} pointer.
+ *
+ * @param src source {@code array}.
+ * @param srcPos starting position in the source array.
+ * @param dst source memory {@code Pointer}.
+ * @param dstPos starting position in the source memory.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(byte[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (dst == null || dst.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy0(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy1(char[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the array pointed by {@code src} to the memory area
+ * pointed by {@code dst} pointer.
+ *
+ * @param src source {@code array}.
+ * @param srcPos starting position in the source array.
+ * @param dst source memory {@code Pointer}.
+ * @param dstPos starting position in the source memory.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(char[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (dst == null || dst.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy1(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy2(short[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the array pointed by {@code src} to the memory area
+ * pointed by {@code dst} pointer.
+ *
+ * @param src source {@code array}.
+ * @param srcPos starting position in the source array.
+ * @param dst source memory {@code Pointer}.
+ * @param dstPos starting position in the source memory.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(short[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (dst == null || dst.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy2(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy3(int[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the array pointed by {@code src} to the memory area
+ * pointed by {@code dst} pointer.
+ *
+ * @param src source {@code array}.
+ * @param srcPos starting position in the source array.
+ * @param dst source memory {@code Pointer}.
+ * @param dstPos starting position in the source memory.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(int[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (dst == null || dst.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy3(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy4(long[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException;
+ /**
+ * Copy the array pointed by {@code src} to the memory area
+ * pointed by {@code dst} pointer.
+ *
+ * @param src source {@code array}.
+ * @param srcPos starting position in the source array.
+ * @param dst source memory {@code Pointer}.
+ * @param dstPos starting position in the source memory.
+ * @param length the number of bytes to be copied.
+ *
+ * @throws IllegalArgumentException if the {@code srcPos} or
+ * {@code dstPos} is {@code negative} or {@code length}
+ * is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} or {@code dst} is
+ * {@code null}.
+ */
+ public static void copy(long[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (dst == null || dst.IsNull())
+ throw new NullPointerException();
+ else if (srcPos < 0 || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy4(src, srcPos, dst, dstPos, length);
+ }
+
}
+
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=788658&r1=788657&r2=788658&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Fri Jun 26 11:26:03 2009
@@ -71,10 +71,7 @@
public long sizeof()
{
- if (PLENGTH > 0)
- return PLENGTH;
- else
- return 4;
+ return PLENGTH;
}
private static native int peek0(int addr);
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=788658&r1=788657&r2=788658&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java Fri Jun 26 11:26:03 2009
@@ -27,8 +27,8 @@
class Pointer64 extends Pointer {
private long CLEANUP;
- protected long POINTER;
- protected long PLENGTH;
+ private long POINTER;
+ private long PLENGTH;
protected Pointer64()
{
@@ -70,10 +70,7 @@
public long sizeof()
{
- if (PLENGTH > 0)
- return PLENGTH;
- else
- return 8;
+ return PLENGTH;
}
private static native int peek0(long addr);
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=788658&r1=788657&r2=788658&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Jun 26 11:26:03 2009
@@ -589,3 +589,185 @@
}
return oa;
}
+
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy0)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jbyteArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jbyte *p = (jbyte *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jbyte)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetByteArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy1)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jcharArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jchar *p = (jchar *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jchar)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetCharArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy2)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jshortArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jshort *p = (jshort *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jshort)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetShortArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy3)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jintArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jint *p = (jint *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jint)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetIntArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy4)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jlongArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jlong *p = (jlong *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jlong)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetLongArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy0)(ACR_JNISTDARGS, jbyteArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jbyte *p = (jbyte *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jbyte)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetByteArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy1)(ACR_JNISTDARGS, jcharArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jchar *p = (jchar *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jchar)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetCharArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy2)(ACR_JNISTDARGS, jshortArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jshort *p = (jshort *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jshort)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetShortArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy3)(ACR_JNISTDARGS, jintArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jint *p = (jint *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jint)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetIntArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy4)(ACR_JNISTDARGS, jlongArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jlong *p = (jlong *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (((po + cs) * sizeof(jlong)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetLongArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=788658&r1=788657&r2=788658&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri Jun 26 11:26:03 2009
@@ -343,6 +343,36 @@
p.free();
}
+ public void testArrayCopy()
+ throws Throwable
+ {
+ Pointer p = Memory.calloc(1000);
+ assertNotNull("Pointer", p);
+ Memory.set(p, 0, 1000, 0xFF);
+ p.poke(1, 23);
+ byte ba[] = new byte[16];
+ Memory.copy(p, 1, ba, 0, 8);
+ assertEquals("Value", (byte)23, ba[0]);
+ assertEquals("Value", (byte)0xFF, ba[1]);
+
+ p.free();
+ }
+
+ public void testCharArrayCopy()
+ throws Throwable
+ {
+ Pointer p = Memory.calloc(1000);
+ assertNotNull("Pointer", p);
+ Memory.set(p, 0, 1000, 0xFF);
+ p.poke(2, 0x23);
+ p.poke(3, 0x23);
+ char ca[] = new char[16];
+ Memory.copy(p, 1, ca, 0, 8);
+ assertEquals("Value", (char)0x2323, ca[0]);
+ assertEquals("Value", (char)0xFFFF, ca[1]);
+
+ p.free();
+ }
}