Hi,
this makes the java-nio code make use of the target native layer.
Sorry for introducing more 'ugly' macro calls. I will rectify that when
switching to the posix layer. Then we can use shorter macro names or
even better function calls like cp_mem_alloc() or something similar. You
should consider this as a work in progress...
2006-01-18 Roman Kennke <[EMAIL PROTECTED]>
* native/jni/java-nio/gnu_java_nio_VMPipe.c:
Removed unnecessary include.
* native/jni/java-nio/gnu_java_nio_VMSelector.c:
Reorganized includes to only include sys/* headers when available.
* native/jni/java-nio/java_nio_MappedByteBufferImpl.c:
(get_pagesize): Return 0 when nothing else works.
(Java_java_nio_MappedByteBufferImpl_unmapImpl):
Replaced munmap() and strerror() with corresponding target macros.
(Java_java_nio_MappedByteBufferImpl_isLoadedImpl):
Replaced strerror() with corresponding target macro.
(Java_java_nio_MappedByteBufferImpl_forceImpl):
Replaced strerror() with corresponding target macro.
* native/jni/java-nio/java_nio_VMDirectByteBuffer.c:
(Java_java_nio_VMDirectByteBuffer_allocate):
Replaced malloc() with the corresponding target macro.
(Java_java_nio_VMDirectByteBuffer_free):
Replaced free() with the corresponding target macro.
(Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_Pointer_2IB):
Add index to pointer when assigning the value.
(Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_Pointer_2I_3BII):
Replaced memcpy with corresponding target macro. Add index when
doing the memcpy, not when fetching the pointer.
(Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_Pointer_2I_3BII):
Replaced memcpy with corresponding target macro.
(Java_java_nio_VMDirectByteBuffer_shiftDown):
Replaced memmove with the corresponding target macro.
/Roman
Index: native/jni/java-nio/gnu_java_nio_VMPipe.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_VMPipe.c,v
retrieving revision 1.4
diff -u -r1.4 gnu_java_nio_VMPipe.c
--- native/jni/java-nio/gnu_java_nio_VMPipe.c 2 Jul 2005 20:32:55 -0000 1.4
+++ native/jni/java-nio/gnu_java_nio_VMPipe.c 18 Jan 2006 09:56:59 -0000
@@ -36,7 +36,6 @@
exception statement from your version. */
#include <config.h>
-#include <errno.h>
#include <jni.h>
#include <jcl.h>
Index: native/jni/java-nio/gnu_java_nio_VMSelector.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_VMSelector.c,v
retrieving revision 1.9
diff -u -r1.9 gnu_java_nio_VMSelector.c
--- native/jni/java-nio/gnu_java_nio_VMSelector.c 2 Jul 2005 20:32:55 -0000 1.9
+++ native/jni/java-nio/gnu_java_nio_VMSelector.c 18 Jan 2006 09:56:59 -0000
@@ -38,12 +38,15 @@
#include "config.h"
/* <sys/types.h> needs to be included on OSX before <sys/select.h> */
-#if defined(HAVE_SYS_TYPES_H)
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+ #include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+ #include <sys/time.h>
#endif
-
-#include <sys/select.h>
-#include <sys/time.h>
#include <string.h>
Index: native/jni/java-nio/java_nio_MappedByteBufferImpl.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/java_nio_MappedByteBufferImpl.c,v
retrieving revision 1.10
diff -u -r1.10 java_nio_MappedByteBufferImpl.c
--- native/jni/java-nio/java_nio_MappedByteBufferImpl.c 3 Aug 2005 13:12:59 -0000 1.10
+++ native/jni/java-nio/java_nio_MappedByteBufferImpl.c 18 Jan 2006 09:56:59 -0000
@@ -36,22 +36,19 @@
exception statement from your version. */
#include <config.h>
-#include <errno.h>
#include <jni.h>
#include <jcl.h>
-#include "java_nio_MappedByteBufferImpl.h"
-
-#include <errno.h>
#include <string.h>
-#include <stdlib.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+ #include <unistd.h>
#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif /* HAVE_SYS_MMAN_H */
+
+#include "target_native.h"
+#include "target_native_memory.h"
+
+#include "java_nio_MappedByteBufferImpl.h"
#define IO_EXCEPTION "java/io/IOException"
@@ -73,6 +70,8 @@
return getpagesize ();
#elif defined (HAVE_SYSCONF)
return sysconf (_SC_PAGESIZE);
+#else
+ return 0;
#endif /* HAVE_GETPAGESIZE / HAVE_SYSCONF */
}
@@ -135,15 +134,17 @@
#ifdef HAVE_MUNMAP
void *address;
size_t size;
+ int result;
get_raw_values (env, this, &address, &size);
if (address == NULL)
return;
- if (munmap (address, size) != 0)
+ TARGET_NATIVE_MEMORY_UNMAP(address,size,result);
+ if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ JCL_ThrowException (env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING ());
return;
}
#else
@@ -185,7 +186,7 @@
#endif /* __cplusplus */
{
free (vec);
- JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ JCL_ThrowException (env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING ());
return JNI_FALSE;
}
@@ -233,7 +234,7 @@
/* FIXME: is using MS_SYNC ok? Should we use MS_INVALIDATE? */
if (msync (address, size, MS_SYNC) != 0)
{
- JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ JCL_ThrowException (env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING ());
}
#else
JCL_ThrowException (env, IO_EXCEPTION,
Index: native/jni/java-nio/java_nio_VMDirectByteBuffer.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c,v
retrieving revision 1.12
diff -u -r1.12 java_nio_VMDirectByteBuffer.c
--- native/jni/java-nio/java_nio_VMDirectByteBuffer.c 10 Jan 2006 14:20:48 -0000 1.12
+++ native/jni/java-nio/java_nio_VMDirectByteBuffer.c 18 Jan 2006 09:56:59 -0000
@@ -36,13 +36,15 @@
exception statement from your version. */
#include <config.h>
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <jni.h>
#include <jcl.h>
+#include "target_native.h"
+#include "target_native_memory.h"
+
#include "java_nio_VMDirectByteBuffer.h"
JNIEXPORT jobject JNICALL
@@ -51,8 +53,7 @@
{
void *buffer;
- buffer = malloc (capacity);
-
+ TARGET_NATIVE_MEMORY_ALLOC(buffer,void*,capacity);
if (buffer == NULL)
{
JCL_ThrowException (env, "java/lang/OutOfMemoryError",
@@ -67,7 +68,7 @@
Java_java_nio_VMDirectByteBuffer_free
(JNIEnv * env, jclass clazz __attribute__ ((__unused__)), jobject address)
{
- free (JCL_GetRawData (env, address));
+ TARGET_NATIVE_MEMORY_FREE(JCL_GetRawData (env, address));
}
JNIEXPORT jbyte JNICALL
@@ -83,8 +84,8 @@
(JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
jobject address, jint index, jbyte value)
{
- jbyte *pointer = (jbyte *) JCL_GetRawData (env, address) + index;
- *pointer = value;
+ jbyte *pointer = (jbyte *) JCL_GetRawData (env, address);
+ *(pointer + index) = value;
}
JNIEXPORT void JNICALL
@@ -92,9 +93,9 @@
(JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
jobject address, jint index, jbyteArray dst, jint dst_offset, jint dst_len)
{
- jbyte *src = (jbyte *) JCL_GetRawData (env, address) + index;
+ jbyte *src = (jbyte *) JCL_GetRawData (env, address);
jbyte *_dst = (*env)->GetByteArrayElements (env, dst, NULL);
- memcpy (_dst + dst_offset, src, dst_len);
+ TARGET_NATIVE_MEMORY_FAST_COPY(src + index,_dst + dst_offset,dst_len);
(*env)->ReleaseByteArrayElements (env, dst, _dst, 0);
}
@@ -105,7 +106,7 @@
{
jbyte *_src = (*env)->GetByteArrayElements (env, src, NULL);
jbyte *dst = (jbyte *)JCL_GetRawData (env, address);
- memcpy (dst + index, _src + src_offset, src_len);
+ TARGET_NATIVE_MEMORY_FAST_COPY(_src + src_offset,dst + index,src_len);
(*env)->ReleaseByteArrayElements (env, src, _src, 0);
}
@@ -114,9 +115,9 @@
(JNIEnv * env, jclass clazz __attribute__ ((__unused__)),
jobject address, jint dst_offset, jint src_offset, jint count)
{
- jbyte *dst = (jbyte *) JCL_GetRawData (env, address) + dst_offset;
- jbyte *src = (jbyte *) JCL_GetRawData (env, address) + src_offset;
- memmove (dst, src, count);
+ jbyte *dst = (jbyte *) JCL_GetRawData (env, address);
+ jbyte *src = (jbyte *) JCL_GetRawData (env, address);
+ TARGET_NATIVE_MEMORY_COPY(src + src_offset,dst + dst_offset,count);
}
JNIEXPORT jobject JNICALL
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches