* Removed all Id tags.
[cacao.git] / src / native / vm / java_lang_Runtime.c
index 8ef1d3c5ebe050ec809154b49c6123448f27fafe..d167ec35373028b5abf5229b35a4370c769918bd 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $
-
 */
 
 
 #include "config.h"
+
+#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
+# include <ltdl.h>
+#endif
+
 #include "vm/types.h"
 
 #include "mm/gc-common.h"
 
+#include "native/jni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_String.h"
+
+#include "toolbox/logging.h"
+
+#include "vm/exceptions.h"
+#include "vm/stringlocal.h"
 #include "vm/vm.h"
 
+#include "vmcore/options.h"
+
 
 /* should we run all finalizers on exit? */
 static bool finalizeOnExit = false;
 
 
 /*
- * Class:     java/lang/VMRuntime
+ * Class:     java/lang/Runtime
  * Method:    exitInternal
  * Signature: (I)V
  */
@@ -54,7 +68,7 @@ void _Jv_java_lang_Runtime_exit(s4 status)
 
 
 /*
- * Class:     java/lang/VMRuntime
+ * Class:     java/lang/Runtime
  * Method:    freeMemory
  * Signature: ()J
  */
@@ -65,7 +79,7 @@ s8 _Jv_java_lang_Runtime_freeMemory(void)
 
 
 /*
- * Class:     java/lang/VMRuntime
+ * Class:     java/lang/Runtime
  * Method:    totalMemory
  * Signature: ()J
  */
@@ -86,6 +100,101 @@ void _Jv_java_lang_Runtime_gc(void)
 }
 
 
+/*
+ * Class:     java/lang/Runtime
+ * Method:    loadLibrary
+ * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)I
+ */
+#if defined(ENABLE_JNI)
+s4 _Jv_java_lang_Runtime_loadLibrary(JNIEnv *env, java_lang_String *libname, classloader *cl)
+#else
+s4 _Jv_java_lang_Runtime_loadLibrary(java_lang_String *libname, classloader *cl)
+#endif
+{
+#if defined(ENABLE_LTDL)
+       utf               *name;
+       lt_dlhandle        handle;
+# if defined(ENABLE_JNI)
+       lt_ptr             onload;
+       s4                 version;
+# endif
+
+       if (libname == NULL) {
+               exceptions_throw_nullpointerexception();
+               return 0;
+       }
+
+       name = javastring_toutf((java_handle_t *) libname, false);
+
+       /* 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 s4 (JNICALL *JNI_OnLoad) (JavaVM *, void *);
+               JavaVM *vm;
+
+               JNI_OnLoad = (JNIEXPORT s4 (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("_Jv_java_lang_Runtime_loadLibrary: not available");
+
+       /* keep compiler happy */
+
+       return 0;
+#endif
+}
+
+
+#if defined(ENABLE_JAVASE)
+
+/*
+ * Class:     java/lang/Runtime
+ * Method:    runFinalizersOnExit
+ * Signature: (Z)V
+ */
+void _Jv_java_lang_Runtime_runFinalizersOnExit(s4 value)
+{
+       /* XXX threading */
+
+       finalizeOnExit = value;
+}
+
+#endif
+
+
 /*
  * 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