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 15:03:25 UTC
svn commit: r788684 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/Memory.java native/shared/memory.c
Author: mturk
Date: Fri Jun 26 13:03:25 2009
New Revision: 788684
URL: http://svn.apache.org/viewvc?rev=788684&view=rev
Log:
Implement two missing primitive array types
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
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=788684&r1=788683&r2=788684&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 13:03:25 2009
@@ -472,6 +472,64 @@
return array4(ptr, offset, length);
}
+ private static native float[] array5(Pointer ptr, long offset, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code float} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code floats} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code long} array with values from {@code src} memory area.
+ *
+ * @throws IllegalArgumentException if the {@code offset}
+ * 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 ptr} is {@code null}.
+ * @throws OutOfMemoryError if memory cannot be dipicated.
+ */
+ public static float[] toFloatArray(Pointer ptr, long offset, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, OutOfMemoryError
+ {
+ if (offset < 0L || length < 1)
+ throw new IllegalArgumentException();
+
+ return array5(ptr, offset, length);
+ }
+
+ private static native double[] array6(Pointer ptr, long offset, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code double} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code doubles} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code long} array with values from {@code src} memory area.
+ *
+ * @throws IllegalArgumentException if the {@code offset}
+ * 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 ptr} is {@code null}.
+ * @throws OutOfMemoryError if memory cannot be dipicated.
+ */
+ public static double[] toDoubleArray(Pointer ptr, long offset, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, OutOfMemoryError
+ {
+ if (offset < 0L || length < 1)
+ throw new IllegalArgumentException();
+
+ return array6(ptr, offset, length);
+ }
+
private static native void acpy0(Pointer src, long srcPos, byte[] dst,
int dstPos, int length)
throws IndexOutOfBoundsException;
@@ -637,6 +695,72 @@
acpy4(src, srcPos, dst, dstPos, length);
}
+ private static native void acpy5(Pointer src, long srcPos, float[] 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, float[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (srcPos < 0L || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy5(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy6(Pointer src, long srcPos, double[] 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, double[] dst,
+ int dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (srcPos < 0L || dstPos < 0 || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > dst.length)
+ throw new IndexOutOfBoundsException();
+ acpy6(src, srcPos, dst, dstPos, length);
+ }
+
private static native void pcpy0(byte[] src, int srcPos, Pointer dst,
long dstPos, int length)
throws IndexOutOfBoundsException;
@@ -802,5 +926,71 @@
pcpy4(src, srcPos, dst, dstPos, length);
}
+ private static native void pcpy5(float[] 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(float[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (srcPos < 0 || dstPos < 0L || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy5(src, srcPos, dst, dstPos, length);
+ }
+
+ private static native void pcpy6(double[] 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(double[] src, int srcPos, Pointer dst,
+ long dstPos, int length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (srcPos < 0 || dstPos < 0L || length == 0)
+ throw new IllegalArgumentException();
+ else if ((dstPos + length) > src.length)
+ throw new IndexOutOfBoundsException();
+ pcpy6(src, srcPos, dst, dstPos, length);
+ }
+
}
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=788684&r1=788683&r2=788684&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 13:03:25 2009
@@ -626,6 +626,54 @@
return oa;
}
+ACR_JNI_EXPORT_DECLARE(jfloatArray, Memory, array5)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jint size)
+{
+ jlongArray oa;
+ size_t pl;
+ size_t dn = (size_t)poff;
+ size_t cs = (size_t)size;
+ jfloat *p = (jfloat *)ACR_PointerGet(_E, ptr, &pl);
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return NULL;
+ }
+ if (((poff + cs) * sizeof(jfloat)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return NULL;
+ }
+ oa = (*_E)->NewFloatArray(_E, cs);
+ if (oa) {
+ (*_E)->SetFloatArrayRegion(_E, oa, 0, cs, p + dn);
+ }
+ return oa;
+}
+
+ACR_JNI_EXPORT_DECLARE(jdoubleArray, Memory, array6)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jint size)
+{
+ jlongArray oa;
+ size_t pl;
+ size_t dn = (size_t)poff;
+ size_t cs = (size_t)size;
+ jdouble *p = (jdouble *)ACR_PointerGet(_E, ptr, &pl);
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return NULL;
+ }
+ if (((poff + cs) * sizeof(jdouble)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return NULL;
+ }
+ oa = (*_E)->NewDoubleArray(_E, cs);
+ if (oa) {
+ (*_E)->SetDoubleArrayRegion(_E, oa, 0, cs, p + dn);
+ }
+ return oa;
+}
+
ACR_JNI_EXPORT_DECLARE(void, Memory, acpy0)(ACR_JNISTDARGS, jobject ptr,
jlong poff, jbyteArray dst,
@@ -737,6 +785,50 @@
(*_E)->SetLongArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
}
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy5)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jfloatArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jfloat *p = (jfloat *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return;
+ }
+ if (((po + cs) * sizeof(jfloat)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetFloatArrayRegion(_E, dst, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, acpy6)(ACR_JNISTDARGS, jobject ptr,
+ jlong poff, jdoubleArray dst,
+ jint off, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jdouble *p = (jdouble *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return;
+ }
+ if (((po + cs) * sizeof(jdouble)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->SetDoubleArrayRegion(_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)
@@ -847,3 +939,47 @@
(*_E)->GetLongArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
}
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy5)(ACR_JNISTDARGS, jfloatArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jfloat *p = (jfloat *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return;
+ }
+ if (((po + cs) * sizeof(jfloat)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetFloatArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+
+ACR_JNI_EXPORT_DECLARE(void, Memory, pcpy6)(ACR_JNISTDARGS, jdoubleArray src,
+ jint off, jobject ptr,
+ jlong poff, jint len)
+{
+ size_t pl;
+ size_t po = (size_t)poff;
+ size_t cs = (size_t)len;
+ jdouble *p = (jdouble *)ACR_PointerGet(_E, ptr, &pl);
+
+ UNREFERENCED_O;
+
+ if (!p) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+ return;
+ }
+ if (((po + cs) * sizeof(jdouble)) > pl) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+ return;
+ }
+ (*_E)->GetDoubleArrayRegion(_E, src, (jsize)off, (jsize)len, p + po);
+}
+