Attached is a patch that fixes the warnings in the NIO files I
changed, and fixes the problem on Darwin (adding the 'volatile'
keyword to the MappedByteBufferImpl instance we create and return
appears to fix this). A bug in GCC 4.0 on that platform, perhaps?
I can't test this properly because Jamvm has started dying with this
error on Classpath HEAD:
Cannot create system class loader
Exception occured while printing exception (java/lang/
RuntimeException)...
Original exception was java/lang/NoSuchFieldError
Has something changed in the VM interface recently?
Feel free to commit this if I can't get a decent environment to test
this up again soon.
Thanks,
Index: native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
===================================================================
RCS file:
/cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c,v
retrieving revision 1.22
diff -u -b -B -r1.22 gnu_java_nio_channels_FileChannelImpl.c
--- native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 26 Jul 2005
12:35:05 -0000 1.22
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 27 Jul 2005
06:11:53 -0000
@@ -513,10 +513,10 @@
#ifdef HAVE_MMAP
jclass MappedByteBufferImpl_class;
jclass RawData_class;
- jmethodID MappedByteBufferImpl_init;
- jmethodID RawData_init;
+ jmethodID MappedByteBufferImpl_init = NULL;
+ jmethodID RawData_init = NULL;
jobject RawData_instance;
- jobject buffer;
+ volatile jobject buffer;
long pagesize;
int prot, flags;
int fd;
@@ -559,6 +559,12 @@
{
return NULL;
}
+ if (RawData_init == NULL)
+ {
+ JCL_ThrowException (env, "java/lang/InternalError",
+ "could not get RawData constructor");
+ return NULL;
+ }
prot = PROT_READ;
if (mode == '+')
@@ -575,7 +581,7 @@
/* Unalign the mapped value back up, since we aligned offset
down to a multiple of the page size. */
- address = p + (position % pagesize);
+ address = (void *) ((char *) p + (position % pagesize));
#if (SIZEOF_VOID_P == 4)
RawData_instance = (*env)->NewObject (env, RawData_class,
@@ -596,6 +602,13 @@
if ((*env)->ExceptionOccurred (env))
{
+ munmap (p, ALIGN_UP (size, pagesize));
+ return NULL;
+ }
+ if (MappedByteBufferImpl_init == NULL)
+ {
+ JCL_ThrowException (env, "java/lang/InternalError",
+ "could not get MappedByteBufferImpl constructor");
munmap (p, ALIGN_UP (size, pagesize));
return NULL;
}
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.5
diff -u -b -B -r1.5 java_nio_MappedByteBufferImpl.c
--- native/jni/java-nio/java_nio_MappedByteBufferImpl.c 24 Jul 2005 03:35:58
-0000 1.5
+++ native/jni/java-nio/java_nio_MappedByteBufferImpl.c 27 Jul 2005 06:11:54
-0000
@@ -45,6 +45,7 @@
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
@@ -97,7 +98,7 @@
jfieldID MappedByteBufferImpl_address;
jfieldID MappedByteBufferImpl_size;
jfieldID RawData_data;
- jobject MappedByteBufferImpl_address_value;
+ jobject MappedByteBufferImpl_address_value = NULL;
*address = NULL;
/* 'address' is declared in java.nio.Buffer */
@@ -115,6 +116,12 @@
}
if ((*env)->ExceptionOccurred (env))
return;
+ if (MappedByteBufferImpl_address_value == NULL)
+ {
+ JCL_ThrowException (env, "java/lang/NullPointerException",
+ "mapped address is NULL");
+ return;
+ }
#if (SIZEOF_VOID_P == 4)
RawData_data =
@@ -166,9 +173,8 @@
#ifdef HAVE_MINCORE
void *address;
size_t size;
- unsigned char *vec;
- size_t count;
- int i;
+ char *vec;
+ size_t count, i;
const long pagesize = get_pagesize ();
/*
@@ -179,7 +185,7 @@
if (address == NULL)
return JNI_FALSE;
count = (size_t) ((size + pagesize - 1) / pagesize);
- vec = (unsigned char *) malloc (count * sizeof (unsigned char));
+ vec = (char *) malloc (count * sizeof (unsigned char));
if (mincore (address, size, vec) != 0)
{
free (vec);
@@ -206,6 +212,8 @@
size_t size;
get_raw_values (env, this, &address, &size);
+ if (address == NULL)
+ return;
madvise (address, size, MADV_WILLNEED);
#else
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.7
diff -u -b -B -r1.7 java_nio_VMDirectByteBuffer.c
--- native/jni/java-nio/java_nio_VMDirectByteBuffer.c 24 Jul 2005 03:35:58
-0000 1.7
+++ native/jni/java-nio/java_nio_VMDirectByteBuffer.c 27 Jul 2005 06:11:57
-0000
@@ -204,7 +204,7 @@
jobject address, jint index, jbyteArray src, jint src_offset, jint src_len)
{
jbyte *_src = (*env)->GetByteArrayElements (env, src, NULL) + src_offset;
- jbyte *dst = NIOGetPointer (env, address) + index;
+ jbyte *dst = (jbyte *) NIOGetPointer (env, address) + index;
(*env)->ReleaseByteArrayElements (env, src, _src, 0);
memcpy (dst, _src, src_len);
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches