Re: [cp-patches] RFC: misc NIO fixes

2005-07-27 Thread Casey Marshall
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 -  1.22
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 27 Jul 2005 
06:11:53 -
@@ -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 
-  1.5
+++ native/jni/java-nio/java_nio_MappedByteBufferImpl.c 27 Jul 2005 06:11:54 
-
@@ -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 
-  1.7
+++ native/jni/java-nio/java_nio_VMDirectByteBuffer.c   27 Jul 2005 06:11:57 
-
@@ 

Re: [cp-patches] RFC: misc NIO fixes

2005-07-26 Thread Mark Wielaard
Hi,

On Sat, 2005-07-23 at 20:37 -0700, Casey Marshall wrote:
 Committed. I changed a few minor things, such as using Mark's  
 suggestion to use 'madvise' to load the file into core.
 
 I can't get this to work with Jamvm on Darwin; I get a bizarre  
 segfault when trying to create the new MappedByteBufferImpl, and  
 apparently 'mincore' does not work properly if the mapped region is  
 only one page in size. This appears to work fine on GNU/Linux,  
 however, so I'm putting it down to problems with Darwin.

I am seeing the following warnings (which break the build when
configured with --enable-Werror):

gnu_java_nio_channels_FileChannelImpl.c:565:
  warning: pointer of type 'void *' used in arithmetic
gnu_java_nio_channels_FileChannelImpl.c:504:
  warning: 'RawData_init' may be used uninitialized in this function
gnu_java_nio_channels_FileChannelImpl.c:503: warning:
  'MappedByteBufferImpl_init' may be used uninitialized in this function

I have not investigated them yet. But maybe they give a hint to why
things don't work on darwin?

Cheers,

Mark


signature.asc
Description: This is a digitally signed message part
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] RFC: misc NIO fixes

2005-07-23 Thread Casey Marshall
Committed. I changed a few minor things, such as using Mark's  
suggestion to use 'madvise' to load the file into core.


I can't get this to work with Jamvm on Darwin; I get a bizarre  
segfault when trying to create the new MappedByteBufferImpl, and  
apparently 'mincore' does not work properly if the mapped region is  
only one page in size. This appears to work fine on GNU/Linux,  
however, so I'm putting it down to problems with Darwin.


On Jul 18, 2005, at 11:58 PM, Casey Marshall wrote:


Hi,

Attached is a patch I'd like to get some comments on, before I  
check it in, especially if anyone can spot holes in my C. This patch


  - Implements FileChannel.map, and the native methods needed for  
MappedByteBufferImpl.
  - Adds a bulk put implementation to DirectByteBufferImpl using  
memcpy. This resulted in a 10x speedup of that method on jamvm (it  
is almost as good as the Blackdown JVM 1.4.2).
  - Fixes a memory leak in the native implementation of the bulk  
'get' method in VMDirectByteBuffer (it never called  
ReleaseByteArrayElements for the source array).


Ok? I might be too busy to get to this until next weekend.

(Apologies if the patch is 'application/octet-stream.' If anyone  
knows how to convince Mail.app that '.patch' is text/plain or text/ 
x-patch, I'd like to hear how.)


2005-07-18  Casey Marshall  [EMAIL PROTECTED]

* configure.ac (AC_CHECK_HEADERS): add sys/mman.h.
(AC_CHECK_FUNCS): add mmap and related functions.
* include/java_nio_VMDirectByteBuffer.h: regenerated.
* java/nio/DirectByteBufferImpl.java (put): new method.
* native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
(ALIGN_DOWN): new macro.
(ALIGN_UP): new macro.
(Java_gnu_java_nio_channels_FileChannelImpl_mapImpl): implemented.
* native/jni/java-nio/java_nio_MappedByteBufferImpl.c: updated
copyright years.
(ALIGN_DOWN): new macro.
(ALIGN_UP): new macro.
(get_pagesize): new function.
(get_raw_values): new function.
(Java_java_nio_MappedByteBufferImpl_unmapImpl): implemented.
(Java_java_nio_MappedByteBufferImpl_isLoadedImpl): implemented.
(Java_java_nio_MappedByteBufferImpl_loadImpl): implemented.
(Java_java_nio_MappedByteBufferImpl_forceImpl): implemented.
* native/jni/java-nio/java_nio_VMDirectByteBuffer.c
(Java_java_nio_VMDirectByteBuffer_put): renamed to
 
'Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_RawData_2IB.'
 
(Java_java_nio_VMDirectByteBuffer_get__Lgnu_classpath_RawData_2I_3BII) 
:

call 'ReleaseByteArrayElements' on the source byte array elements.
 
(Java_java_nio_VMDirectByteBuffer_put__Lgnu_classpath_RawData_2I_3BII) 
:

new method.
* vm/reference/java/nio/VMDirectByteBuffer.java
(put): new method.


nio.patch
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches





___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] RFC: misc NIO fixes

2005-07-21 Thread Mark Wielaard
Hi,

On Tue, 2005-07-19 at 09:12 -0500, Archie Cobbs wrote:
 Casey Marshall wrote:
  Attached is a patch I'd like to get some comments on, before I check  it 
  in, especially if anyone can spot holes in my C. This patch
 
 +  /* FIXME: I'd bet dollars for donuts the compiler optimizes this
 + away. How can we load memory into core??? */
 +  for (i = 0; i  size; i += pagesize)
 +{
 +  foo += ((int *) address)[i];
 +}
   }
 
 You can force the memory to be accessed e.g. like this:
 
for (i = 0; ... )
   *((volatile int *)address + i;

If the system has madvise you probably get the requested functionality
with madvise(address, size, MADV_WILLNEED).

Cheers,

Mark


signature.asc
Description: This is a digitally signed message part
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] RFC: misc NIO fixes

2005-07-21 Thread Casey Marshall

On Jul 21, 2005, at 3:04 PM, Mark Wielaard wrote:



Hi,

On Tue, 2005-07-19 at 09:12 -0500, Archie Cobbs wrote:



Casey Marshall wrote:


Attached is a patch I'd like to get some comments on, before I  
check  it

in, especially if anyone can spot holes in my C. This patch




+  /* FIXME: I'd bet dollars for donuts the compiler optimizes this
+ away. How can we load memory into core??? */
+  for (i = 0; i  size; i += pagesize)
+{
+  foo += ((int *) address)[i];
+}
  }

You can force the memory to be accessed e.g. like this:

   for (i = 0; ... )
  *((volatile int *)address + i;




If the system has madvise you probably get the requested functionality
with madvise(address, size, MADV_WILLNEED).




Aha! Yes, I had thought there was a function that did that. Thanks  
for the reminder, Mark.




___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] RFC: misc NIO fixes

2005-07-19 Thread Archie Cobbs

Casey Marshall wrote:
Attached is a patch I'd like to get some comments on, before I check  it 
in, especially if anyone can spot holes in my C. This patch


+  /* FIXME: I'd bet dollars for donuts the compiler optimizes this
+ away. How can we load memory into core??? */
+  for (i = 0; i  size; i += pagesize)
+{
+  foo += ((int *) address)[i];
+}
 }

You can force the memory to be accessed e.g. like this:

  for (i = 0; ... )
 *((volatile int *)address + i;

Otherwise looks good after a quick scan.

-Archie

__
Archie Cobbs  *CTO, Awarix*  http://www.awarix.com


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches