Author: mturk
Date: Thu Jul 2 14:25:51 2009
New Revision: 790602
URL:
http://svn.apache.org/viewvc?rev=790602&view=revLog:
Rename Direct to Nio ByteBuffer
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
- copied, changed from r789654, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectByteBuffer.java
commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c
- copied, changed from r789654, commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java
- copied, changed from r789654, commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
Removed:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectByteBuffer.java
commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.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=790602&r1=790601&r2=790602&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 Thu Jul 2 14:25:51 2009
@@ -68,14 +68,14 @@
*
* Pointer ptr = Memory.malloc();
*
- * DirectByteBuffer b = DirectByteBuffer.allocate(ptr, size);
+ * NioByteBuffer b = NioByteBuffer.allocate(ptr, size);
*
* ...
*
* ptr.free();
*
* </pre>
- * The newly created {@code DirectyByteBuffer} holds the memory
+ * The newly created {@code NioByteBuffer} holds the memory
* area pointed by {@code Pointer} object and {@code Pointer}
* object holds a native pointer to a physical memory area location.
* When done the memory should be released by calling
Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java (from r789654, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectByteBuffer.java)
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectByteBuffer.java&r1=789654&r2=790602&rev=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java Thu Jul 2 14:25:51 2009
@@ -18,7 +18,7 @@
import java.nio.ByteBuffer;
-/** Manages direct ByteBuffers
+/** Manages NIO direct ByteBuffers
* <p>
* <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
* Any method call after free method was called might write or read from
@@ -27,14 +27,14 @@
* </p>
* <p>
* Using this class methods on ByteBuffers that were not created by
- * DirectByteBuffer.allocate methods will almost certainly crash the
+ * DirectNioByteBuffer.allocate methods will almost certainly crash the
* running JVM.
* </p>
* @since Runtime 1.0
*/
-public final class DirectByteBuffer {
+public final class NioByteBuffer {
- private DirectByteBuffer()
+ private NioByteBuffer()
{
// No class instance
}
@@ -171,7 +171,7 @@
* This method does the same as calling the:
* <pre>
*
- * DirectByteBuffer.allocate(ptr, sizes, 0, sizes.length);
+ * NioByteBuffer.allocate(ptr, sizes, 0, sizes.length);
*
* </pre>
* </p>
@@ -338,7 +338,7 @@
* This method does the same as calling the:
* <pre>
*
- * DirectByteBuffer.allocate(sizes, 0, sizes.length);
+ * NioByteBuffer.allocate(sizes, 0, sizes.length);
*
* </pre>
* </p>
@@ -369,7 +369,7 @@
* This method does the same as calling the:
* <pre>
*
- * DirectByteBuffer.allocateAndClear(sizes, 0, sizes.length);
+ * NioByteBuffer.allocateAndClear(sizes, 0, sizes.length);
*
* </pre>
* </p>
@@ -436,7 +436,7 @@
* <p>
* <b>Warning:</b><br/>
* Invoke this method only on ByteBuffers
- * that were created by {@code DirectByteBuffer.allocate} methods
+ * that were created by {@code NioByteBuffer.allocate} methods
* and only if the Buffer was not allocated from the {@code Pointer}
* object.
* </p>
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=790602&r1=790601&r2=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Jul 2 14:25:51 2009
@@ -83,6 +83,7 @@
$(SRCDIR)/shared/memory.$(OBJ) \
$(SRCDIR)/shared/modules.$(OBJ) \
$(SRCDIR)/shared/native.$(OBJ) \
+ $(SRCDIR)/shared/nbb.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
$(SRCDIR)/shared/object.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=790602&r1=790601&r2=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Thu Jul 2 14:25:51 2009
@@ -77,6 +77,7 @@
$(SRCDIR)/shared/memory.$(OBJ) \
$(SRCDIR)/shared/modules.$(OBJ) \
$(SRCDIR)/shared/native.$(OBJ) \
+ $(SRCDIR)/shared/nbb.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
$(SRCDIR)/shared/object.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
Copied: commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c (from r789654, commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c)
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c?p2=commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c&p1=commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c&r1=789654&r2=790602&rev=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c Thu Jul 2 14:25:51 2009
@@ -28,10 +28,10 @@
#include "acr_error.h"
/**
- * DirectByteBuffer utilities
+ * NioByteBuffer utilities
*/
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc0)(ACR_JNISTDARGS,
- jlong size)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc0)(ACR_JNISTDARGS,
+ jlong size)
{
void *mem;
size_t sz = (size_t)ACR_ALIGN_DEFAULT(size);
@@ -56,8 +56,8 @@
}
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc1)(ACR_JNISTDARGS,
- jlong size)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc1)(ACR_JNISTDARGS,
+ jlong size)
{
size_t sz = (size_t)ACR_ALIGN_DEFAULT((size));
void *mem;
@@ -82,9 +82,9 @@
}
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc2)(ACR_JNISTDARGS,
- jlongArray sizes,
- jint off, jint len)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc2)(ACR_JNISTDARGS,
+ jlongArray sizes,
+ jint off, jint len)
{
jint i;
jlong *ia;
@@ -163,9 +163,9 @@
return rv;
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc3)(ACR_JNISTDARGS,
- jlongArray sizes,
- jint off, jint len)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc3)(ACR_JNISTDARGS,
+ jlongArray sizes,
+ jint off, jint len)
{
jint i;
jlong *ia;
@@ -244,9 +244,9 @@
return rv;
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc4)(ACR_JNISTDARGS,
- jobject src, jlong off,
- jlong siz)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc4)(ACR_JNISTDARGS,
+ jobject src, jlong off,
+ jlong siz)
{
size_t so = (size_t)off;
size_t ss = (size_t)siz;
@@ -271,8 +271,8 @@
return (*_E)->NewDirectByteBuffer(_E, sp + so, ss);
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc5)(ACR_JNISTDARGS,
- jobject src)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc5)(ACR_JNISTDARGS,
+ jobject src)
{
size_t sl;
void *sp = ACR_PointerGet(_E, src, &sl);
@@ -286,10 +286,10 @@
return (*_E)->NewDirectByteBuffer(_E, sp, sl);
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, alloc6)(ACR_JNISTDARGS,
- jobject ptr,
- jlongArray sizes,
- jint off, jint len)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, alloc6)(ACR_JNISTDARGS,
+ jobject ptr,
+ jlongArray sizes,
+ jint off, jint len)
{
jint i;
jlong *ia;
@@ -374,10 +374,10 @@
return rv;
}
-ACR_JNI_EXPORT_DECLARE(jobject, DirectByteBuffer, attach0)(ACR_JNISTDARGS,
- jlong addr,
- jlong offset,
- jlong size)
+ACR_JNI_EXPORT_DECLARE(jobject, NioByteBuffer, attach0)(ACR_JNISTDARGS,
+ jlong addr,
+ jlong offset,
+ jlong size)
{
char *mem = J2P(addr, char *);
@@ -401,7 +401,7 @@
return (*_E)->NewDirectByteBuffer(_E, mem + (size_t)offset, size);
}
-ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, free)(ACR_JNISTDARGS, jobject bb)
+ACR_JNI_EXPORT_DECLARE(void, NioByteBuffer, free)(ACR_JNISTDARGS, jobject bb)
{
void *mem;
@@ -428,24 +428,24 @@
}
}
-ACR_JNI_EXPORT_DECLARE(jlong, DirectByteBuffer, addr0)(ACR_JNISTDARGS,
- jobject bb)
+ACR_JNI_EXPORT_DECLARE(jlong, NioByteBuffer, addr0)(ACR_JNISTDARGS,
+ jobject bb)
{
UNREFERENCED_O;
return P2J((*_E)->GetDirectBufferAddress(_E, bb));
}
-ACR_JNI_EXPORT_DECLARE(jlong, DirectByteBuffer, size)(ACR_JNISTDARGS,
- jobject bb)
+ACR_JNI_EXPORT_DECLARE(jlong, NioByteBuffer, size)(ACR_JNISTDARGS,
+ jobject bb)
{
UNREFERENCED_O;
return (*_E)->GetDirectBufferCapacity(_E, bb);
}
-ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, set)(ACR_JNISTDARGS,
- jobject bb,
- jint c,
- jint count)
+ACR_JNI_EXPORT_DECLARE(void, NioByteBuffer, set)(ACR_JNISTDARGS,
+ jobject bb,
+ jint c,
+ jint count)
{
void *m;
jlong sz;
@@ -475,12 +475,12 @@
}
}
-ACR_JNI_EXPORT_DECLARE(void, DirectByteBuffer, copy0)(ACR_JNISTDARGS,
- jobject srcb,
- jlong srco,
- jobject dstb,
- jlong dsto,
- jint count)
+ACR_JNI_EXPORT_DECLARE(void, NioByteBuffer, copy0)(ACR_JNISTDARGS,
+ jobject srcb,
+ jlong srco,
+ jobject dstb,
+ jlong dsto,
+ jint count)
{
void *d;
void *s;
@@ -529,3 +529,4 @@
ACR_EISNULL);
}
}
+
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=790602&r1=790601&r2=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Thu Jul 2 14:25:51 2009
@@ -40,7 +40,7 @@
suite.addTest(TestGroup.suite());
suite.addTest(TestStatus.suite());
suite.addTest(TestMemory.suite());
- suite.addTest(TestDirectByteBuffer.suite());
+ suite.addTest(TestNioByteBuffer.suite());
suite.addTest(TestPrivate.suite());
suite.addTest(TestFile.suite());
suite.addTest(TestStrings.suite());
Copied: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java (from r789654, commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java)
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java?p2=commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java&p1=commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java&r1=789654&r2=790602&rev=790602&view=diff==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestNioByteBuffer.java Thu Jul 2 14:25:51 2009
@@ -22,13 +22,13 @@
import junit.framework.*;
/**
- * DirectByteBuffer tests
+ * NioByteBuffer tests
*/
-public class TestDirectByteBuffer extends TestCase
+public class TestNioByteBuffer extends TestCase
{
public static Test suite() {
- TestSuite suite = new TestSuite(TestDirectByteBuffer.class);
+ TestSuite suite = new TestSuite(TestNioByteBuffer.class);
return suite;
}
@@ -42,19 +42,19 @@
public void testMalloc()
throws Exception
{
- ByteBuffer bb = DirectByteBuffer.allocate(1000);
+ ByteBuffer bb = NioByteBuffer.allocate(1000);
assertTrue("Direct", bb.isDirect());
assertEquals("Capacity", 1000, bb.capacity());
- DirectByteBuffer.free(bb);
+ NioByteBuffer.free(bb);
}
public void testCalloc()
throws Exception
{
- ByteBuffer bb = DirectByteBuffer.allocateAndClear(1000);
+ ByteBuffer bb = NioByteBuffer.allocateAndClear(1000);
assertTrue("Direct", bb.isDirect());
assertEquals("Capacity", 1000, bb.capacity());
- DirectByteBuffer.free(bb);
+ NioByteBuffer.free(bb);
}
@@ -63,7 +63,7 @@
{
// ptr, bb1 and bb2 share the same memory
Pointer ptr = Memory.malloc(1000);
- ByteBuffer bb = DirectByteBuffer.allocate(ptr);
+ ByteBuffer bb = NioByteBuffer.allocate(ptr);
assertTrue("Direct", bb.isDirect());
assertEquals("Capacity", 1000, bb.capacity());
/*
@@ -72,7 +72,7 @@
* Byte buffer will probably crash the JVM after the
* memory is free'd
* bb.putInt(0xcafebabe); might write to something else
- * DirectByteBuffer.free(bb); will free already free'd memory
+ * NioByteBuffer.free(bb); will free already free'd memory
* causing core.
*/
}
@@ -82,7 +82,7 @@
{
// ptr, bb1 and bb2 share the same memory
Pointer ptr = Memory.malloc(1000);
- ByteBuffer bb = DirectByteBuffer.allocate(ptr);
+ ByteBuffer bb = NioByteBuffer.allocate(ptr);
assertTrue("Direct", bb.isDirect());
assertEquals("Capacity", 1000, bb.capacity());
try {
@@ -91,7 +91,7 @@
// This is double free. Don't do this!
// Exception handler won't help here.
if (test_me) {
- DirectByteBuffer.free(bb);
+ NioByteBuffer.free(bb);
}
} catch (Throwable t) {
assertSame("Wrong Exception class",
@@ -102,29 +102,29 @@
public void testMemset()
throws Exception
{
- ByteBuffer bb = DirectByteBuffer.allocate(1000);
+ ByteBuffer bb = NioByteBuffer.allocate(1000);
assertTrue("Direct", bb.isDirect());
bb.putInt(0xcafebabe);
bb.rewind();
assertEquals("Value put", 0xcafebabe, bb.getInt());
- DirectByteBuffer.set(bb, 0x55, 1000);
+ NioByteBuffer.set(bb, 0x55, 1000);
assertEquals("Value set", 0x55555555, bb.getInt());
- DirectByteBuffer.free(bb);
+ NioByteBuffer.free(bb);
}
public void testCopy()
throws Exception
{
- ByteBuffer sb = DirectByteBuffer.allocate(1000);
- ByteBuffer db = DirectByteBuffer.allocateAndClear(1000);
+ ByteBuffer sb = NioByteBuffer.allocate(1000);
+ ByteBuffer db = NioByteBuffer.allocateAndClear(1000);
assertTrue("Direct", sb.isDirect());
assertTrue("Direct", db.isDirect());
sb.putInt(0xcafebabe);
- DirectByteBuffer.copy(sb, 0, db, 4, 996);
+ NioByteBuffer.copy(sb, 0, db, 4, 996);
assertEquals("Zero", 0, db.getInt());
assertEquals("Value", 0xcafebabe, db.getInt());
- DirectByteBuffer.free(sb);
- DirectByteBuffer.free(db);
+ NioByteBuffer.free(sb);
+ NioByteBuffer.free(db);
}
public void testArrayCreate()
@@ -132,7 +132,7 @@
{
// Aligned size 104 16 104 1000
long [] sizes = { 100, 10, 100, 1000 };
- ByteBuffer[] a = DirectByteBuffer.allocate(sizes, 0, sizes.length);
+ ByteBuffer[] a = NioByteBuffer.allocate(sizes, 0, sizes.length);
assertNotNull("Array", a);
for (int i = 0; i < sizes.length; i++) {
@@ -142,7 +142,7 @@
/* WARNING: Free only the first array element
* because they all share the same memory
*/
- DirectByteBuffer.free(a[0]);
+ NioByteBuffer.free(a[0]);
}
@@ -151,7 +151,7 @@
{
// Aligned size 104 16 104 1000
long [] sizes = { 100, 10, 100, 1000 };
- ByteBuffer[] a = DirectByteBuffer.allocate(sizes, 2, 2);
+ ByteBuffer[] a = NioByteBuffer.allocate(sizes, 2, 2);
assertNotNull("Array", a);
for (int i = 0; i < 2; i++) {
@@ -161,7 +161,7 @@
/* WARNING: Free only the first array element
* because they all share the same memory
*/
- DirectByteBuffer.free(a[0]);
+ NioByteBuffer.free(a[0]);
}
@@ -170,7 +170,7 @@
{
// Aligned size 104 16 104 1000
long [] sizes = { 100, 10, 100 , 1000};
- ByteBuffer[] a = DirectByteBuffer.allocateAndClear(sizes, 0, sizes.length);
+ ByteBuffer[] a = NioByteBuffer.allocateAndClear(sizes, 0, sizes.length);
assertNotNull("Array", a);
for (int i = 0; i < sizes.length; i++) {
@@ -180,7 +180,7 @@
/* WARNING: Free only the first array element
* because they all share the same memory
*/
- DirectByteBuffer.free(a[0]);
+ NioByteBuffer.free(a[0]);
}
@@ -192,7 +192,7 @@
// Aligned size
// 104 + 1000 = 1104
Pointer mem = Memory.malloc(1104);
- ByteBuffer[] a = DirectByteBuffer.allocate(mem, sizes, 2, 2);
+ ByteBuffer[] a = NioByteBuffer.allocate(mem, sizes, 2, 2);
assertNotNull("Array", a);
for (int i = 0; i < 2; i++) {
@@ -212,7 +212,7 @@
// Aligned size 104 16 104 1000
long [] sizes = { 100, 10, 100, 1000 };
Pointer mem = Memory.malloc();
- ByteBuffer[] a = DirectByteBuffer.allocate(mem, sizes, 2, 2);
+ ByteBuffer[] a = NioByteBuffer.allocate(mem, sizes, 2, 2);
assertNotNull("Array", a);
for (int i = 0; i < 2; i++) {