Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: native.c 7912 2007-05-18 13:12:09Z twisti $
+ $Id: native.c 8132 2007-06-22 11:15:47Z twisti $
*/
# include <ltdl.h>
#endif
+#include <stdint.h>
+
#include "vm/types.h"
#include "mm/memory.h"
tree_native_methods = avl_create(&native_tree_native_methods_comparator);
- /* register the intern native functions */
-
- nativevm_init();
-
/* everything's ok */
return true;
*******************************************************************************/
-void native_method_register(utf *classname, JNINativeMethod *methods, s4 count)
+void native_method_register(utf *classname, const JNINativeMethod *methods,
+ int32_t count)
{
native_methods_node_t *nmn;
utf *name;
utf *descriptor;
- s4 i;
+ int32_t i;
/* insert all methods passed */
{
lt_dlhandle handle;
+ if (opt_verbosejni) {
+ printf("[Loading native library ");
+ utf_display_printable_ascii(filename);
+ printf(" ... ");
+ }
+
/* try to open the library */
handle = lt_dlopen(filename->text);
/* no function was found, throw exception */
- *exceptionptr =
- new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
- mname);
+ exceptions_throw_unsatisfiedlinkerror(mname);
return NULL;
}
functionptr native_resolve_function(methodinfo *m)
{
+ java_objectheader *cl;
utf *name;
utf *newname;
functionptr f;
hashtable_library_name_entry *ne;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
+#if defined(WITH_CLASSPATH_SUN)
+ methodinfo *method_findNative;
+ java_objectheader *s;
+#endif
+
+ cl = m->class->classloader;
/* verbose output */
/* normally addresses are aligned to 4, 8 or 16 bytes */
- key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
+ key = ((u4) (ptrint) cl) >> 4; /* align to 16-byte */
slot = key & (hashtable_library->size - 1);
le = hashtable_library->ptr[slot];
le = le->hashlink;
}
+#if defined(WITH_CLASSPATH_SUN)
+ if (f == NULL) {
+ /* We can resolve the function directly from
+ java.lang.ClassLoader as it's a static function. */
+ /* XXX should be done in native_init */
+
+ method_findNative =
+ class_resolveclassmethod(class_java_lang_ClassLoader,
+ utf_findNative,
+ utf_java_lang_ClassLoader_java_lang_String__J,
+ class_java_lang_ClassLoader,
+ true);
+
+ if (method_findNative == NULL)
+ return NULL;
+
+ /* try the normal name */
+
+ s = javastring_new(name);
+
+ f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
+ NULL, cl, s);
+
+ /* if not found, try the mangled name */
+
+ if (f == NULL) {
+ s = javastring_new(newname);
+
+ f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
+ NULL, cl, s);
+ }
+ }
+#endif
+
if (f != NULL)
if (opt_verbosejni)
printf("JNI ]\n");
/* find initializer */
- m = class_resolveclassmethod(c,
- utf_init,
- utf_java_lang_String__void,
- NULL,
- true);
+ m = class_findmethod(c, utf_init, utf_java_lang_String__void);
/* initializer not found */
}
-java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
-{
- methodinfo *m;
- java_objectheader *o;
-
- if (c == NULL)
- vm_abort("native_new_and_init_int: c == NULL");
-
- /* create object */
-
- o = builtin_new(c);
-
- if (o == NULL)
- return NULL;
-
- /* find initializer */
-
- m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
-
- /* initializer not found */
-
- if (m == NULL)
- return NULL;
-
- /* call initializer */
-
- (void) vm_call_method(m, o, i);
-
- return o;
-}
-
-
-java_objectheader *native_new_and_init_throwable(classinfo *c, java_objectheader *t)
-{
- java_objectheader *o;
- methodinfo *m;
-
- if (c == NULL)
- vm_abort("native_new_and_init_throwable: c == NULL");
-
- /* create object */
-
- o = builtin_new(c);
-
- if (o == NULL)
- return NULL;
-
- /* find initializer */
-
- m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
-
- /* initializer not found */
-
- if (m == NULL)
- return NULL;
-
- /* call initializer */
-
- (void) vm_call_method(m, o, t);
-
- return o;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where