/* src/native/native.c - table of native functions
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
bool native_init(void)
{
+ TRACESUBSYSTEMINITIALIZATION("native_init");
+
#if defined(ENABLE_LTDL)
/* initialize libltdl */
char *utf_ptr;
u2 c;
s4 i;
- s4 dumpsize;
utf *u;
+ int32_t dumpmarker;
/* mark memory */
- dumpsize = dump_size();
+ DMARKER;
utf_ptr = descriptor->text;
namelen = strlen(name->text) + strlen("__") + strlen("0");
/* release memory */
- dump_release(dumpsize);
+ DRELEASE;
return u;
}
char *utf_endptr;
u2 c;
u4 pos;
- s4 dumpsize;
utf *u;
+ int32_t dumpmarker;
/* mark memory */
- dumpsize = dump_size();
+ DMARKER;
/* Calculate length of native function name. We multiply the
class and method name length by 6 as this is the maxium
/* release memory */
- dump_release(dumpsize);
+ DRELEASE;
return u;
}
/* fill the temporary structure used for searching the tree */
- tmpnmn.classname = m->class->name;
+ tmpnmn.classname = m->clazz->name;
tmpnmn.name = m->name;
tmpnmn.descriptor = m->descriptor;
utf *newname;
functionptr f;
#if defined(ENABLE_LTDL)
- classloader *cl;
+ classloader_t *cl;
hashtable_library_loader_entry *le;
hashtable_library_name_entry *ne;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
#endif
-#if defined(WITH_CLASSPATH_SUN)
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
methodinfo *method_findNative;
java_handle_t *s;
#endif
if (opt_verbosejni) {
printf("[Dynamic-linking native method ");
- utf_display_printable_ascii_classname(m->class->name);
+ utf_display_printable_ascii_classname(m->clazz->name);
printf(".");
utf_display_printable_ascii(m->name);
printf(" ... ");
/* generate method symbol string */
- name = native_method_symbol(m->class->name, m->name);
+ name = native_method_symbol(m->clazz->name, m->name);
/* generate overloaded function (having the types in it's name) */
#if defined(ENABLE_LTDL)
/* Get the classloader. */
- cl = class_get_classloader(m->class);
+ cl = class_get_classloader(m->clazz);
/* normally addresses are aligned to 4, 8 or 16 bytes */
le = le->hashlink;
}
-# if defined(WITH_CLASSPATH_SUN)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
if (f == NULL) {
/* We can resolve the function directly from
java.lang.ClassLoader as it's a static function. */
*******************************************************************************/
#if defined(ENABLE_LTDL)
-void native_library_add(utf *filename, classloader *loader, lt_dlhandle handle)
+void native_library_add(utf *filename, classloader_t *loader, lt_dlhandle handle)
{
hashtable_library_loader_entry *le;
hashtable_library_name_entry *ne; /* library name */
#if defined(ENABLE_LTDL)
hashtable_library_name_entry *native_library_find(utf *filename,
- classloader *loader)
+ classloader_t *loader)
{
hashtable_library_loader_entry *le;
hashtable_library_name_entry *ne; /* library name */
#endif
+/* native_library_load *********************************************************
+
+ Load a native library and initialize it, if possible.
+
+ IN:
+ name ... name of the library
+ cl ..... classloader which loads this library
+
+ RETURN:
+ 1 ... library loaded successfully
+ 0 ... error
+
+*******************************************************************************/
+
+int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
+{
+#if defined(ENABLE_LTDL)
+ lt_dlhandle handle;
+# if defined(ENABLE_JNI)
+ lt_ptr onload;
+ int32_t version;
+# endif
+
+ if (name == NULL) {
+ exceptions_throw_nullpointerexception();
+ return 0;
+ }
+
+ /* Is the library already loaded? */
+
+ if (native_library_find(name, cl) != NULL)
+ return 1;
+
+ /* Open the library. */
+
+ handle = native_library_open(name);
+
+ if (handle == NULL)
+ return 0;
+
+# if defined(ENABLE_JNI)
+ /* Resolve JNI_OnLoad function. */
+
+ onload = lt_dlsym(handle, "JNI_OnLoad");
+
+ if (onload != NULL) {
+ JNIEXPORT int32_t (JNICALL *JNI_OnLoad) (JavaVM *, void *);
+ JavaVM *vm;
+
+ JNI_OnLoad = (JNIEXPORT int32_t (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
+
+ (*env)->GetJavaVM(env, &vm);
+
+ version = JNI_OnLoad(vm, NULL);
+
+ /* If the version is not 1.2 and not 1.4 the library cannot be
+ loaded. */
+
+ if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
+ lt_dlclose(handle);
+ return 0;
+ }
+ }
+# endif
+
+ /* Insert the library name into the library hash. */
+
+ native_library_add(name, cl, handle);
+
+ return 1;
+#else
+ vm_abort("native_library_load: not available");
+
+ /* Keep compiler happy. */
+
+ return 0;
+#endif
+}
+
+
/* native_new_and_init *********************************************************
Creates a new object on the heap and calls the initializer.