GNU header update.
[cacao.git] / src / native / vm / VMRuntime.c
index cd5226c5ce58bc53a2c905919a9bdb802a08d725..2e9c7083d4bc9e52d7808f0add0af4b54820298c 100644 (file)
@@ -1,9 +1,9 @@
-/* nat/Runtime.c - java/lang/Runtime
+/* native/vm/VMRuntime.c - java/lang/VMRuntime
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005 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
 
    This file is part of CACAO.
 
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: VMRuntime.c 1514 2004-11-17 11:52:46Z twisti $
+   $Id: VMRuntime.c 1735 2004-12-07 14:33:27Z twisti $
 
 */
 
 #include <unistd.h>
 #include <sys/utsname.h>
 
+#if !defined(STATIC_CLASSPATH)
+#include <dlfcn.h>
+#endif
+
 #include "config.h"
-#include "exceptions.h"
-#include "main.h"
-#include "jni.h"
-#include "builtin.h"
-#include "exceptions.h"
-#include "loader.h"
-#include "native.h"
-#include "tables.h"
-#include "asmpart.h"
+#include "cacao/cacao.h"
 #include "mm/boehm.h"
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_io_File.h"
+#include "native/include/java_lang_String.h"
+#include "native/include/java_lang_Process.h"
+#include "native/include/java_util_Properties.h"     /* java_lang_VMRuntime.h */
+#include "native/include/java_lang_VMRuntime.h"
 #include "toolbox/logging.h"
-#include "toolbox/memory.h"
-#include "nat/java_io_File.h"
-#include "nat/java_lang_String.h"
-#include "nat/java_lang_Process.h"
-#include "nat/java_util_Properties.h"    /* needed for java_lang_VMRuntime.h */
-#include "nat/java_lang_VMRuntime.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/loader.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
 
-#ifndef STATIC_CLASSPATH
-#include <dlfcn.h>
-#endif
 
 /* this should work on BSD */
 /*
@@ -303,8 +303,10 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass cla
 {
        int retVal=0;
 
+#ifdef JOWENN_DEBUG
        char *buffer;
        int buffer_len;
+#endif
        utf *data;
 
 #ifdef JOWENN_DEBUG
@@ -333,7 +335,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass cla
 #ifndef STATIC_CLASSPATH
        /*here it could be interesting to store the references in a list eg for nicely cleaning up or for certain platforms*/
         if (dlopen(data->text,RTLD_NOW | RTLD_GLOBAL)) {
-               log_text("LIBLOADED");
+               /*log_text("LIBLOADED");*/
                 retVal=1;
         }
 #else
@@ -403,9 +405,13 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_insertSystemProperties(JNIEnv *e
        char *user;
        char *home;
        struct utsname utsnamebuf;
+#if !defined(STATIC_CLASSPATH)
+       char *libpath;
+       s4    libpathlen;
+#endif
 
        if (!p) {
-               *exceptionptr = new_exception(string_java_lang_NullPointerException);
+               *exceptionptr = new_nullpointerexception();
                return;
        }
 
@@ -443,11 +449,37 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_insertSystemProperties(JNIEnv *e
        insert_property(m, p, "java.specification.name", "Java Platform API Specification");
        insert_property(m, p, "java.class.version", "48.0");
        insert_property(m, p, "java.class.path", classpath);
+
 #if defined(STATIC_CLASSPATH)
        insert_property(m, p, "java.library.path" , ".");
 #else
-       insert_property(m, p, "java.library.path" , getenv("LD_LIBRARY_PATH"));
+       libpathlen = strlen(INSTALL_PREFIX) + strlen(CACAO_LIBRARY_PATH) + 1;
+
+       if (getenv("CACAO_LIB_OVERRIDE"))
+               libpathlen += strlen(getenv("CACAO_LIB_OVERRIDE")) + 1;
+
+       if (getenv("LD_LIBRARY_PATH"))
+               libpathlen += strlen(getenv("LD_LIBRARY_PATH")) + 1;
+
+       libpath = MNEW(char, libpathlen);
+
+       if (getenv("CACAO_LIB_OVERRIDE")) {
+               strcat(libpath, getenv("CACAO_LIB_OVERRIDE"));
+               strcat(libpath, ":");
+       }
+
+       strcat(libpath, INSTALL_PREFIX);
+       strcat(libpath, CACAO_LIBRARY_PATH);
+
+       if (getenv("LD_LIBRARY_PATH")) {
+               strcat(libpath, ":");
+               strcat(libpath, getenv("LD_LIBRARY_PATH"));
+       }
+       insert_property(m, p, "java.library.path", libpath);
+
+       MFREE(libpath, char, libpathlen);
 #endif
+
        insert_property(m, p, "java.io.tmpdir", "/tmp");
        insert_property(m, p, "java.compiler", "cacao.jit");
        insert_property(m, p, "java.ext.dirs", "");
@@ -472,7 +504,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_insertSystemProperties(JNIEnv *e
        /* XXX do we need this one? */
        { "java.protocol.handler.pkgs", "gnu.java.net.protocol"}
 #endif
-       insert_property(m,p,"java.protocol.handler.pkgs","gnu.java.net.protocol");
+       insert_property(m, p, "java.protocol.handler.pkgs", "gnu.java.net.protocol");
 
        /* insert properties defined on commandline */