jamvm

changeset 405:99039a39df1f

Support creating a DirectByteBuffer in OpenJDK from JNI.

2008-08-04 Andrew John Hughes <gnu_andrew@member.fsf.org>

* src/jni.c,
* src/symbol.h:
Support creating a DirectByteBuffer from JNI
under OpenJDK.
author andrew
date Tue Aug 05 06:24:55 2008 +0100 (2008-08-05)
parents f70700d622a8
children 2f855beaaf73
files ChangeLog src/jni.c src/symbol.h
line diff
     1.1 --- a/ChangeLog	Tue Aug 05 06:07:38 2008 +0100
     1.2 +++ b/ChangeLog	Tue Aug 05 06:24:55 2008 +0100
     1.3 @@ -5,6 +5,13 @@
     1.4  ==============
     1.5  2008-08-04  Andrew John Hughes  <gnu_andrew@member.fsf.org>
     1.6  
     1.7 +	* src/jni.c,
     1.8 +	* src/symbol.h:
     1.9 +	Support creating a DirectByteBuffer from JNI
    1.10 +	under OpenJDK.
    1.11 +
    1.12 +2008-08-04  Andrew John Hughes  <gnu_andrew@member.fsf.org>
    1.13 +
    1.14  	* src/natives.c:
    1.15  	Add support for OpenJDK loading of libjava.so.
    1.16  
     2.1 --- a/src/jni.c	Tue Aug 05 06:07:38 2008 +0100
     2.2 +++ b/src/jni.c	Tue Aug 05 06:24:55 2008 +0100
     2.3 @@ -65,6 +65,11 @@
     2.4      /* Cache class and method/fields for JNI 1.4 NIO support */
     2.5  
     2.6      buffer_class = findSystemClass0(SYMBOL(java_nio_Buffer));
     2.7 +    /* VMDIFF: GNU Classpath's direct buffer implementation is called
     2.8 +       DirectByteBufferImpl.ReadWrite whereas OpenJDK's is simply DirectByteBuffer.
     2.9 +       GNU Classpath requires that the pointer to the buffer is encapsulated
    2.10 +       in a gnu.classpath.Pointer */
    2.11 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    2.12      buffImpl_class = findSystemClass0(SYMBOL(java_nio_DirectByteBufferImpl_ReadWrite));
    2.13      rawdata_class = findSystemClass0(sizeof(uintptr_t) == 4 ? SYMBOL(gnu_classpath_Pointer32)
    2.14                                                              : SYMBOL(gnu_classpath_Pointer64));
    2.15 @@ -72,7 +77,6 @@
    2.16      if(buffer_class != NULL && buffImpl_class != NULL && rawdata_class != NULL) {
    2.17          buffImpl_init_mb = findMethod(buffImpl_class, SYMBOL(object_init),
    2.18                        SYMBOL(_java_lang_Object_gnu_classpath_Pointer_III__V));
    2.19 -
    2.20          buffCap_fb = findField(buffer_class, SYMBOL(cap), SYMBOL(I));
    2.21          rawdata_fb = findField(rawdata_class, SYMBOL(data), sizeof(uintptr_t) == 4 ? SYMBOL(I)
    2.22                                                                                     : SYMBOL(J));
    2.23 @@ -82,14 +86,32 @@
    2.24      if(buffImpl_init_mb == NULL || buffCap_fb == NULL ||
    2.25               rawdata_fb == NULL || buffAddr_fb == NULL) {
    2.26          return;
    2.27 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    2.28 +    buffImpl_class = findSystemClass0(SYMBOL(java_nio_DirectByteBuffer));
    2.29 +
    2.30 +    if(buffer_class != NULL && buffImpl_class != NULL) {
    2.31 +        buffImpl_init_mb = findMethod(buffImpl_class, SYMBOL(object_init),
    2.32 +                      SYMBOL(_LI__V));
    2.33 +        buffCap_fb = findField(buffer_class, SYMBOL(capacity), SYMBOL(I));
    2.34 +        buffAddr_fb = findField(buffer_class, SYMBOL(address), SYMBOL(J));
    2.35 +    }
    2.36 +
    2.37 +    if(buffImpl_init_mb == NULL || buffCap_fb == NULL ||
    2.38 +             buffAddr_fb == NULL) {
    2.39 +        return;
    2.40 +#endif
    2.41      }
    2.42  
    2.43      registerStaticClassRef(&buffImpl_class);
    2.44 -    registerStaticClassRef(&rawdata_class);
    2.45  
    2.46      buffCap_offset = buffCap_fb->offset;
    2.47      buffAddr_offset = buffAddr_fb->offset;
    2.48 +
    2.49 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    2.50 +    registerStaticClassRef(&rawdata_class);
    2.51      rawdata_offset = rawdata_fb->offset;
    2.52 +#endif
    2.53 +
    2.54      nio_init_OK = TRUE;
    2.55  }
    2.56  
    2.57 @@ -280,6 +302,10 @@
    2.58      if(!nio_init_OK)
    2.59          return NULL;
    2.60  
    2.61 +    /* VMDIFF: GNU Classpath encapsulates the pointer in a Pointer object
    2.62 +       referenced by the rawdata variable.  It also requires more arguments
    2.63 +       which are simply defaulted on OpenJDK. */
    2.64 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    2.65      if((buff = allocObject(buffImpl_class)) != NULL &&
    2.66              (rawdata = allocObject(rawdata_class)) != NULL) {
    2.67  
    2.68 @@ -287,6 +313,10 @@
    2.69          executeMethod(buff, buffImpl_init_mb, NULL, rawdata, (int)capacity,
    2.70                        (int)capacity, 0);
    2.71      }
    2.72 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    2.73 +    if((buff = allocObject(buffImpl_class)) != NULL) 
    2.74 +      executeMethod(buff, buffImpl_init_mb, (jlong) addr, (jint)capacity);
    2.75 +#endif
    2.76  
    2.77      return (jobject) addJNILref(buff);
    2.78  }
    2.79 @@ -298,9 +328,16 @@
    2.80          return NULL;
    2.81  
    2.82      if(buff != NULL) {
    2.83 +      /* VMDIFF: GNU Classpath uses a gnu.classpath.Pointer object to
    2.84 +	 store the address whereas it can be found in the buffer itself
    2.85 +	 in OpenJDK. */
    2.86 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    2.87          Object *rawdata = (Object *)INST_DATA(buff)[buffAddr_offset];
    2.88          if(rawdata != NULL)
    2.89              return (void*)INST_DATA(rawdata)[rawdata_offset];
    2.90 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    2.91 +            return (void*)INST_DATA(buff)[buffAddr_offset];
    2.92 +#endif
    2.93      }
    2.94  
    2.95      return NULL;
     3.1 --- a/src/symbol.h	Tue Aug 05 06:07:38 2008 +0100
     3.2 +++ b/src/symbol.h	Tue Aug 05 06:24:55 2008 +0100
     3.3 @@ -29,7 +29,11 @@
     3.4      action(Z, "Z"), \
     3.5      action(pd, "pd"), \
     3.6      action(put, "put"), \
     3.7 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
     3.8      action(cap, "cap"), \
     3.9 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    3.10 +    action(capacity, "capacity"), \
    3.11 +#endif
    3.12      action(run, "run"), \
    3.13      action(main, "main"), \
    3.14      action(data, "data"), \
    3.15 @@ -138,7 +142,11 @@
    3.16      action(java_lang_reflect_Constructor, "java/lang/reflect/Constructor"), \
    3.17      action(java_lang_ref_PhantomReference, "java/lang/ref/PhantomReference"), \
    3.18      action(jamvm_java_lang_VMClassLoaderData, "jamvm/java/lang/VMClassLoaderData"), \
    3.19 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    3.20      action(java_nio_DirectByteBufferImpl_ReadWrite, "java/nio/DirectByteBufferImpl$ReadWrite"), \
    3.21 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    3.22 +    action(java_nio_DirectByteBuffer, "java/nio/DirectByteBuffer"), \
    3.23 +#endif
    3.24      \
    3.25      /* Exception class names */\
    3.26      action(java_lang_Error, "java/lang/Error"), \
    3.27 @@ -203,8 +211,12 @@
    3.28             "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"), \
    3.29      action(_java_lang_Throwable__java_lang_Throwable, \
    3.30             "(Ljava/lang/Throwable;)Ljava/lang/Throwable;"), \
    3.31 +#ifdef WITH_JAVA_RUNTIME_LIBRARY_CLASSPATH
    3.32      action(_java_lang_Object_gnu_classpath_Pointer_III__V, \
    3.33             "(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"), \
    3.34 +#elif WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
    3.35 +    action(_LI__V, "(LI)V"), \
    3.36 +#endif
    3.37      action(_java_lang_String__V, "(Ljava/lang/String;)V"), \
    3.38      action(_array_java_lang_String__V, "([Ljava/lang/String;)V"), \
    3.39      action(_java_lang_Throwable__V, "(Ljava/lang/Throwable;)V"), \