This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.nio direct buffers


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I would like to commit the attached patch which adds real direct 
buffer support to libgcj. Please review and comment.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+7x9hWSOgCCdjSDsRAs2zAKCOz+LiPJOCtAUxXpfqAknrCcI08ACfbqYh
dP6tJsiGbbnVd0CjD8PCUFA=
=QwC8
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1951
diff -u -b -B -r1.1951 ChangeLog
--- ChangeLog	17 Jun 2003 13:01:19 -0000	1.1951
+++ ChangeLog	17 Jun 2003 13:57:21 -0000
@@ -1,5 +1,20 @@
 2003-06-17  Michael Koch  <konqueror@gmx.de>
 
+	* java/nio/DirectByteBufferImpl.java
+	(address): Made package private.
+	(DirectByteBufferImpl): New constructor.
+	* java/nio/natDirectByteBufferImpl.cc
+	(allocateImpl): Moved to java.nio namespace, implemented.
+	(freeImpl): Likewise.
+	(getImpl): Likewise.
+	(putImpl): Likewise.
+	* jni.cc
+	(_Jv_JNI_NewDirectByteBuffer): Implemented.
+	(_Jv_JNI_GetDirectBufferAddress): Implemented.
+	(_Jv_JNI_GetDirectBufferCapacity): Implemented.
+
+2003-06-17  Michael Koch  <konqueror@gmx.de>
+
 	* java/util/prefs/AbstractPreferences.java,
 	java/util/prefs/PreferencesFactory.java:
 	Reworked imports, removed unused imports.
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.71
diff -u -b -B -r1.71 jni.cc
--- jni.cc	12 Jun 2003 15:39:17 -0000	1.71
+++ jni.cc	17 Jun 2003 13:57:22 -0000
@@ -35,11 +35,13 @@
 #include <java/lang/reflect/Method.h>
 #include <java/lang/reflect/Modifier.h>
 #include <java/lang/OutOfMemoryError.h>
-#include <java/util/IdentityHashMap.h>
 #include <java/lang/Integer.h>
 #include <java/lang/ThreadGroup.h>
 #include <java/lang/Thread.h>
 #include <java/lang/IllegalAccessError.h>
+#include <java/nio/DirectByteBufferImpl.h>
+#include <java/util/IdentityHashMap.h>
+#include <gnu/gcj/RawData.h>
 
 #include <gcj/method.h>
 #include <gcj/field.h>
@@ -1720,24 +1722,28 @@
 // Direct byte buffers.
 
 static jobject
-(JNICALL _Jv_JNI_NewDirectByteBuffer) (JNIEnv *, void *, jlong)
+(JNICALL _Jv_JNI_NewDirectByteBuffer) (JNIEnv *, void *address, jlong length)
 {
-  // For now we don't support this.
-  return NULL;
+  using namespace gnu::gcj;
+  using namespace java::nio;
+  return new DirectByteBufferImpl (reinterpret_cast<RawData *> (address),
+				   length);
 }
 
 static void *
-(JNICALL _Jv_JNI_GetDirectBufferAddress) (JNIEnv *, jobject)
+(JNICALL _Jv_JNI_GetDirectBufferAddress) (JNIEnv *, jobject buffer)
 {
-  // For now we don't support this.
-  return NULL;
+  using namespace java::nio;
+  DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
+  return reinterpret_cast<void *> (bb->address);
 }
 
 static jlong
-(JNICALL _Jv_JNI_GetDirectBufferCapacity) (JNIEnv *, jobject)
+(JNICALL _Jv_JNI_GetDirectBufferCapacity) (JNIEnv *, jobject buffer)
 {
-  // For now we don't support this.
-  return -1;
+  using namespace java::nio;
+  DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
+  return bb->capacity();
 }
 
 
Index: java/nio/DirectByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/DirectByteBufferImpl.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 DirectByteBufferImpl.java
--- java/nio/DirectByteBufferImpl.java	20 May 2003 08:58:31 -0000	1.1
+++ java/nio/DirectByteBufferImpl.java	17 Jun 2003 13:57:22 -0000
@@ -42,9 +42,14 @@
 
 public class DirectByteBufferImpl extends ByteBuffer
 {
-  private RawData address;
+  RawData address;
   private int offset;
   private boolean readOnly;
+
+  public DirectByteBufferImpl (RawData address, long len)
+  {
+    this (address, 0, (int) len, (int) len, 0, -1, false);
+  }
   
   public DirectByteBufferImpl (RawData address, int offset, int capacity,
                                int limit, int position, int mark,
Index: java/nio/natDirectByteBufferImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/natDirectByteBufferImpl.cc,v
retrieving revision 1.1
diff -u -b -B -r1.1 natDirectByteBufferImpl.cc
--- java/nio/natDirectByteBufferImpl.cc	20 May 2003 08:58:31 -0000	1.1
+++ java/nio/natDirectByteBufferImpl.cc	17 Jun 2003 13:57:22 -0000
@@ -13,33 +13,33 @@
 #include <gcj/cni.h>
 #include <jvm.h>
 
+#include <stdlib.h>
+
 #include <gnu/gcj/RawData.h>
 #include <java/nio/DirectByteBufferImpl.h>
 
 gnu::gcj::RawData*
-java::nio::DirectByteBufferImpl::allocateImpl (jint /*capacity*/)
+java::nio::DirectByteBufferImpl::allocateImpl (jint capacity)
 {
-  // FIXME: implement this
-  return 0;
+  return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
 }
 
 void
-java::nio::DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* /*address*/)
+java::nio::DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* address)
 {
-  // FIXME: implement this
+  ::free (reinterpret_cast<void*> (address));
 }
 
 jbyte
-java::nio::DirectByteBufferImpl::getImpl (jint /*index*/)
+java::nio::DirectByteBufferImpl::getImpl (jint index)
 {
-  // FIXME: implement this
-  // Dont forget: add offset to index
-  return 0;
+  jbyte* pointer = reinterpret_cast<jbyte*> (address) + offset + index;
+  return *pointer;
 }
 
 void
-java::nio::DirectByteBufferImpl::putImpl (jint /*index*/, jbyte /*value*/)
+java::nio::DirectByteBufferImpl::putImpl (jint index, jbyte value)
 {
-  // FIXME: implement this
-  // Dont forget: add offset to index
+  jbyte* pointer = reinterpret_cast<jbyte*> (address) + offset + index;
+  *pointer = value;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]