Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 78774 invoked from network); 7 Dec 2009 07:35:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Dec 2009 07:35:36 -0000 Received: (qmail 70819 invoked by uid 500); 7 Dec 2009 07:35:35 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 70704 invoked by uid 500); 7 Dec 2009 07:35:35 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 70695 invoked by uid 99); 7 Dec 2009 07:35:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Dec 2009 07:35:35 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Dec 2009 07:35:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1A0AC23889D7; Mon, 7 Dec 2009 07:35:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r887855 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/NioByteBuffer.java native/shared/nbb.c Date: Mon, 07 Dec 2009 07:35:13 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091207073513.1A0AC23889D7@eris.apache.org> 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)