Changes: Joseph Wenninger
Christian Thalinger
- $Id: VMRuntime.c 1173 2004-06-16 14:56:18Z jowenn $
+ $Id: VMRuntime.c 1494 2004-11-12 13:34:26Z twisti $
*/
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.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 "mm/boehm.h"
#include "toolbox/logging.h"
#include "toolbox/memory.h"
-#include "java_io_File.h"
-#include "java_lang_String.h"
-#include "java_lang_Process.h"
-#include "java_util_Properties.h" /* needed for java_lang_Runtime.h */
-#include "java_lang_VMRuntime.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 "config.h"
+#ifndef STATIC_CLASSPATH
+#include <dlfcn.h>
+#endif
+/* this should work on BSD */
+/*
+#if defined(__DARWIN__)
+#include <sys/sysctl.h>
+#endif
+*/
-#define JOWENN_DEBUG
+#undef JOWENN_DEBUG
/* should we run all finalizers on exit? */
-static s4 finalizeOnExit = false;
-
-#define MAXPROPS 100
-static bool shouldFinalizersBeRunOnExit=false;
-static int activeprops = 19;
-
-static char *proplist[MAXPROPS][2] = {
- { "java.class.path", NULL },
- { "java.home", NULL },
- { "user.home", NULL },
- { "user.name", NULL },
- { "user.dir", NULL },
-
- { "os.arch", NULL },
- { "os.name", NULL },
- { "os.version", NULL },
-
- { "java.class.version", "45.3" },
- { "java.version", PACKAGE":"VERSION },
- { "java.vendor", "CACAO Team" },
- { "java.vendor.url", "http://www.complang.tuwien.ac.at/java/cacao/" },
- { "java.vm.name", "CACAO"},
- { "java.tmpdir", "/tmp/"},
- { "java.io.tmpdir", "/tmp/"},
-
- { "path.separator", ":" },
- { "file.separator", "/" },
- { "line.separator", "\n" },
- { "java.protocol.handler.pkgs", "gnu.java.net.protocol"}
+static bool finalizeOnExit = false;
+
+/* temporary property structure */
+
+typedef struct property property;
+
+struct property {
+ char *key;
+ char *value;
+ property *next;
};
-void attach_property(char *name, char *value)
+static property *properties = NULL;
+
+
+/* create_property *************************************************************
+
+ Create a property entry for a command line property definition.
+
+*******************************************************************************/
+
+void create_property(char *key, char *value)
{
- if (activeprops >= MAXPROPS) panic("Too many properties defined");
- proplist[activeprops][0] = name;
- proplist[activeprops][1] = value;
- activeprops++;
+ property *p;
+
+ p = NEW(property);
+ p->key = key;
+ p->value = value;
+ p->next = properties;
+ properties = p;
}
+
+
+/* insert_property *************************************************************
+
+ Used for inserting a property into the system's properties table. Method m
+ (usually put) and the properties table must be given.
+
+*******************************************************************************/
+
+static void insert_property(methodinfo *m, java_util_Properties *p, char *key,
+ char *value)
+{
+ asm_calljavafunction(m,
+ p,
+ javastring_new_char(key),
+ javastring_new_char(value),
+ NULL);
+}
+
+
/*
* Class: java_lang_VMRuntime
* Method: execInternal
* Method: runFinalizersOnExit
* Signature: (Z)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, s4 par1)
+JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizersOnExit(JNIEnv *env, jclass clazz, s4 value)
{
+#ifdef __GNUC__
#warning threading
- shouldFinalizersBeRunOnExit=par1;
+#endif
+ finalizeOnExit = value;
}
+
/*
* Class: java/lang/Runtime
* Method: runFinalizationsForExit
*/
JNIEXPORT void JNICALL Java_java_lang_VMRuntime_runFinalizationForExit(JNIEnv *env, jclass clazz)
{
- if (shouldFinalizersBeRunOnExit) {
- gc_call();
- // gc_finalize_all();
- }
- log_text("Java_java_lang_VMRuntime_runFinalizationForExit called");
-
+/* if (finalizeOnExit) { */
+/* gc_call(); */
+ /* gc_finalize_all(); */
+/* } */
+/* log_text("Java_java_lang_VMRuntime_runFinalizationForExit called"); */
+ /*gc_finalize_all();*/
+ /*gc_invoke_finalizers();*/
+ /*gc_call();*/
}
#elif defined(_SC_NPROCESSORS_ONLN)
return (s4) sysconf(_SC_NPROCESSORS_ONLN);
+#elif defined(__DARWIN__)
+ /* this should work in BSD */
+ /*
+ int ncpu, mib[2], rc;
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_NCPU;
+ len = sizeof(ncpu);
+ rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+ return (s4) ncpu;
+ */
+
+ host_basic_info_data_t hinfo;
+ mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
+ kern_return_t rc;
+
+ rc = host_info(mach_host_self(), HOST_BASIC_INFO,
+ (host_info_t) &hinfo, &hinfo_count);
+
+ if (rc != KERN_SUCCESS) {
+ return -1;
+ }
+
+ return (s4) hinfo.avail_cpus;
+
#else
return 1;
#endif
*/
JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, java_lang_String *par1)
{
-#ifdef JOWENN_DEBUG
+ int retVal=0;
+
char *buffer;
int buffer_len;
utf *data;
-
+
+ log_text("Java_java_lang_VMRuntime_nativeLoad");
+
data = javastring_toutf(par1, 0);
if (!data) {
buffer = MNEW(char, buffer_len);
-
strcpy(buffer, "Java_java_lang_VMRuntime_nativeLoad:");
utf_sprint(buffer + strlen((char *) data), data);
log_text(buffer);
-
+
+
MFREE(buffer, char, buffer_len);
+
+
+#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");
+ retVal=1;
+ }
+#else
+ retVal=1;
#endif
- log_text("Java_java_lang_VMRuntime_nativeLoad");
- return 1;
+ return retVal;
}
return 0;;
}
- buffer_len = utf_strlen(data) + 6/*lib .so*/ +1 /*0*/;
+ buffer_len = utf_strlen(data) + 6 /*lib .so */ +1 /*0*/;
buffer = MNEW(char, buffer_len);
sprintf(buffer,"lib");
utf_sprint(buffer+3,data);
strcat(buffer,".so");
-
+#ifdef JOWENN_DEBUG
+ log_text("nativeGetLibName:");
log_text(buffer);
+#endif
resultString=javastring_new_char(buffer);
MFREE(buffer, char, buffer_len);
-
return resultString;
}
{
#define BUFFERSIZE 200
- u4 i;
methodinfo *m;
- char buffer[BUFFERSIZE];
+ char cwd[BUFFERSIZE];
+ char *java_home;
+ char *user;
+ char *home;
struct utsname utsnamebuf;
- proplist[0][1] = classpath;
- proplist[1][1] = getenv("JAVA_HOME");
- proplist[2][1] = getenv("HOME");
- proplist[3][1] = getenv("USER");
- proplist[4][1] = getcwd(buffer, BUFFERSIZE);
-
- /* get properties from system */
- uname(&utsnamebuf);
- proplist[5][1] = utsnamebuf.machine;
- proplist[6][1] = utsnamebuf.sysname;
- proplist[7][1] = utsnamebuf.release;
-
if (!p) {
*exceptionptr = new_exception(string_java_lang_NullPointerException);
return;
}
+ /* get properties from system */
+
+ (void) getcwd(cwd, BUFFERSIZE);
+ java_home = getenv("JAVA_HOME");
+ user = getenv("USER");
+ home = getenv("HOME");
+ uname(&utsnamebuf);
+
/* search for method to add properties */
- m = class_resolvemethod(p->header.vftbl->class,
- utf_new_char("put"),
- utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")
- );
-
- if (!m) {
- *exceptionptr = new_exception_message(string_java_lang_NoSuchMethodError,
- "java.lang.Properties.put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;)");
+
+ m = class_resolveclassmethod(p->header.vftbl->class,
+ utf_new_char("put"),
+ utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
+ clazz,
+ true);
+
+ if (!m)
return;
- }
- /* add the properties */
- for (i = 0; i < activeprops; i++) {
+ insert_property(m, p, "java.version", VERSION);
+ insert_property(m, p, "java.vendor", "CACAO Team");
+ insert_property(m, p, "java.vendor.url", "http://www.complang.tuwien.ac.at/java/cacao/");
+ insert_property(m, p, "java.home", java_home ? java_home : "null");
+ insert_property(m, p, "java.vm.specification.version", "1.0");
+ insert_property(m, p, "java.vm.specification.vendor", "Sun Microsystems Inc.");
+ insert_property(m, p, "java.vm.specification.name", "Java Virtual Machine Specification");
+ insert_property(m, p, "java.vm.version", VERSION);
+ insert_property(m, p, "java.vm.vendor", "CACAO Team");
+ insert_property(m, p, "java.vm.name", "CACAO");
+ insert_property(m, p, "java.specification.version", "1.4");
+ insert_property(m, p, "java.specification.vendor", "Sun Microsystems Inc.");
+ 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"));
+#endif
+ insert_property(m, p, "java.io.tmpdir", "/tmp");
+ insert_property(m, p, "java.compiler", "cacao.jit");
+ insert_property(m, p, "java.ext.dirs", "null");
+ insert_property(m, p, "os.name", utsnamebuf.sysname);
+ insert_property(m, p, "os.arch", utsnamebuf.machine);
+ insert_property(m, p, "os.version", utsnamebuf.release);
+ insert_property(m, p, "file.separator", "/");
+ /* insert_property(m, p, "file.encoding", "null"); -- this must be set properly */
+ insert_property(m, p, "path.separator", ":");
+ insert_property(m, p, "line.separator", "\n");
+ insert_property(m, p, "user.name", user ? user : "null");
+ insert_property(m, p, "user.home", home ? home : "null");
+ insert_property(m, p, "user.dir", cwd ? cwd : "null");
+
+#if 0
+ /* how do we get them? */
+ { "user.language", "en" },
+ { "user.region", "US" },
+ { "user.country", "US" },
+ { "user.timezone", "Europe/Vienna" },
+
+ /* XXX do we need this one? */
+ { "java.protocol.handler.pkgs", "gnu.java.net.protocol"}
+#endif
+
+ /* insert properties defined on commandline */
+
+ while (properties) {
+ property *tp;
- if (proplist[i][1] == NULL) proplist[i][1] = "";
+ insert_property(m, p, properties->key, properties->value);
- asm_calljavafunction(m,
- p,
- javastring_new_char(proplist[i][0]),
- javastring_new_char(proplist[i][1]),
- NULL
- );
+ tp = properties;
+ properties = properties->next;
+ FREE(tp, property);
}
return;