Author: mturk
Date: Mon Dec 7 07:35:12 2009
New Revision: 887855
URL: http://svn.apache.org/viewvc?rev=887855&view=rev
Log:
Use direct Pointer Addresses
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java?rev=887855&r1=887854&r2=887855&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
Mon Dec 7 07:35:12 2009
@@ -54,21 +54,21 @@
throws OutOfMemoryError, IllegalArgumentException,
IndexOutOfBoundsException;
- private static native ByteBuffer alloc4(Pointer ptr, long off, long len)
+ private static native ByteBuffer alloc4(long ptr, long len)
throws NullPointerException, IllegalArgumentException,
IndexOutOfBoundsException;
- private static native ByteBuffer alloc5(Pointer ptr)
+ private static native ByteBuffer alloc5(long ptr, long len)
throws NullPointerException;
- private static native ByteBuffer[] alloc6(Pointer ptr, long[] sizes,
+ private static native ByteBuffer[] alloc6(long ptr, long siz, long[]
sizes,
int off, int len)
throws OutOfMemoryError, IllegalArgumentException,
IndexOutOfBoundsException;
private static native long addr0(ByteBuffer buf);
- private static native ByteBuffer attach0(long mem, long offset, long
size)
+ private static native ByteBuffer attach0(long mem, long size)
throws NullPointerException, IllegalArgumentException;
private static native void copy0(ByteBuffer src, long srcPos, ByteBuffer
dst,
@@ -100,7 +100,14 @@
throws NullPointerException, IllegalArgumentException,
IndexOutOfBoundsException
{
- return alloc4(ptr, off, len);
+ if (ptr == null || ptr.POINTER == 0L)
+ throw new NullPointerException();
+ if (off < 0L || len < 1L)
+ throw new IllegalArgumentException();
+ if (off + len >= ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return alloc4(ptr.POINTER + off, len);
}
/**
@@ -120,7 +127,9 @@
public static ByteBuffer allocate(Pointer ptr)
throws NullPointerException
{
- return alloc5(ptr);
+ if (ptr == null || ptr.POINTER == 0L)
+ throw new NullPointerException();
+ return alloc5(ptr.POINTER, ptr.PLENGTH);
}
/**
@@ -158,7 +167,11 @@
throws NullPointerException, IllegalArgumentException,
IndexOutOfBoundsException
{
- return alloc6(ptr, sizes, off, len);
+ if (ptr == null || ptr.POINTER == 0L || sizes == null)
+ throw new NullPointerException();
+ if (off < 0 || len < 1)
+ throw new IllegalArgumentException();
+ return alloc6(ptr.POINTER, ptr.PLENGTH, sizes, off, len);
}
/**
@@ -191,7 +204,11 @@
throws NullPointerException, IllegalArgumentException,
IndexOutOfBoundsException
{
- return alloc6(ptr, sizes, 0, sizes.length);
+ if (ptr == null || ptr.POINTER == 0L || sizes == null)
+ throw new NullPointerException();
+ if (sizes.length < 1)
+ throw new IllegalArgumentException();
+ return alloc6(ptr.POINTER, ptr.PLENGTH, sizes, 0, sizes.length);
}
/**
@@ -429,7 +446,15 @@
public static ByteBuffer allocate(ByteBuffer buf, long offset, long size)
throws NullPointerException, IllegalArgumentException
{
- return attach0(addr0(buf), offset, size);
+ long mem = addr0(buf);
+ if (mem == 0L)
+ throw new NullPointerException();
+ if (offset < 0L || size < 1L)
+ throw new IllegalArgumentException();
+ long len = size(buf);
+ if (offset + size > len)
+ throw new IndexOutOfBoundsException();
+ return attach0(mem + offset, size);
}
/**
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c?rev=887855&r1=887854&r2=887855&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c Mon Dec 7
07:35:12 2009
@@ -244,59 +244,39 @@
}
ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc4)(ACR_JNISTDARGS,
- jobject src, jlong off,
- jlong siz)
+ jlong src, jlong siz)
{
- size_t so = (size_t)off;
- size_t ss = (size_t)siz;
- size_t sl;
- char *sp = (char *)ACR_PointerGet(_E, src, &sl);
+ size_t ss = (size_t)siz;
+ char *sp = J2P(src, char *);
UNREFERENCED_O;
- if (!sp) {
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
- return NULL;
- }
- if (off < 0L || siz < 1L) {
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINVAL, 0);
- return NULL;
- }
- if ((so + ss) > sl) {
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
- return NULL;
- }
-
- return (*_E)->NewDirectByteBuffer(_E, sp + so, ss);
+ return (*_E)->NewDirectByteBuffer(_E, sp, ss);
}
ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc5)(ACR_JNISTDARGS,
- jobject src)
+ jlong src, jlong len)
{
- size_t sl;
- void *sp = ACR_PointerGet(_E, src, &sl);
+ size_t sl = (size_t)len;
+ void *sp = J2P(src, void *);
UNREFERENCED_O;
- if (!sp) {
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
- return NULL;
- }
return (*_E)->NewDirectByteBuffer(_E, sp, sl);
}
ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc6)(ACR_JNISTDARGS,
- jobject ptr,
+ jlong ptr, jlong siz,
jlongArray sizes,
jint off, jint len)
{
jint i;
jlong *ia;
jsize is;
- size_t sl;
+ size_t sl = (size_t)siz;
size_t sz = 0;
jobjectArray rv = NULL;
- char *sp = (char *)ACR_PointerGet(_E, ptr, &sl);
+ char *sp = J2P(ptr, char *);
UNREFERENCED_O;
@@ -375,29 +355,13 @@
ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, attach0)(ACR_JNISTDARGS,
jlong addr,
- jlong offset,
jlong size)
{
char *mem = J2P(addr, char *);
UNREFERENCED_O;
- if (!mem) {
- ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
- ACR_EISNULL);
- return NULL;
- }
- if (size < 1) {
- ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
- ACR_EINVALSIZ);
- return NULL;
- }
- if (offset < 0) {
- ACR_ThrowException(_E, THROW_FMARK, ACR_EX_EINVAL,
- ACR_EINVALSIZ);
- return NULL;
- }
- return (*_E)->NewDirectByteBuffer(_E, mem + (size_t)offset, size);
+ return (*_E)->NewDirectByteBuffer(_E, mem, size);
}
ACR_JNI_EXPORT_DECLARE(void, NioByteBuffer, free)(ACR_JNISTDARGS, jobject bb)