From b12b779c7f34dc5531695c492329d62206bbb782 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 25 Oct 2007 12:33:43 -0600 Subject: [PATCH] add support for passing properties to the VM via JNI; use vm.builtins property to specify builtin libraries --- classpath/java/io/File.java | 6 +++--- classpath/java/io/FileInputStream.java | 6 +++--- classpath/java/io/FileOutputStream.java | 6 +++--- classpath/java/lang/System.java | 6 +++--- classpath/java/util/zip/Inflater.java | 6 +++--- makefile | 2 +- src/builtin.cpp | 6 ++---- src/jnienv.cpp | 12 ++++++++++++ src/machine.cpp | 1 + src/machine.h | 1 + src/main.cpp | 13 +++++++++++++ 11 files changed, 45 insertions(+), 20 deletions(-) diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index 957ad9a8a5..8dd379c205 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -4,9 +4,9 @@ public class File { private static final String FileSeparator = System.getProperty("file.separator"); - static { - System.loadLibrary("natives"); - } +// static { +// System.loadLibrary("natives"); +// } private final String path; diff --git a/classpath/java/io/FileInputStream.java b/classpath/java/io/FileInputStream.java index 23a4b278aa..59d2420f5a 100644 --- a/classpath/java/io/FileInputStream.java +++ b/classpath/java/io/FileInputStream.java @@ -1,9 +1,9 @@ package java.io; public class FileInputStream extends InputStream { - static { - System.loadLibrary("natives"); - } +// static { +// System.loadLibrary("natives"); +// } private int fd; diff --git a/classpath/java/io/FileOutputStream.java b/classpath/java/io/FileOutputStream.java index fd9f577f14..0b2407730f 100644 --- a/classpath/java/io/FileOutputStream.java +++ b/classpath/java/io/FileOutputStream.java @@ -1,9 +1,9 @@ package java.io; public class FileOutputStream extends OutputStream { - static { - System.loadLibrary("natives"); - } +// static { +// System.loadLibrary("natives"); +// } private int fd; diff --git a/classpath/java/lang/System.java b/classpath/java/lang/System.java index 185524b0e7..95b8f6f0c7 100644 --- a/classpath/java/lang/System.java +++ b/classpath/java/lang/System.java @@ -19,9 +19,9 @@ public abstract class System { private static Property properties; - static { - loadLibrary("natives"); - } +// static { +// loadLibrary("natives"); +// } public static final PrintStream out = new PrintStream (new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true); diff --git a/classpath/java/util/zip/Inflater.java b/classpath/java/util/zip/Inflater.java index ecb32b6320..39b3187689 100644 --- a/classpath/java/util/zip/Inflater.java +++ b/classpath/java/util/zip/Inflater.java @@ -5,9 +5,9 @@ public class Inflater { private static final int Z_STREAM_END = 1; private static final int Z_NEED_DICT = 2; - static { - System.loadLibrary("natives"); - } +// static { +// System.loadLibrary("natives"); +// } private long peer; private byte[] input; diff --git a/makefile b/makefile index 03bc1efb19..01d78bb444 100644 --- a/makefile +++ b/makefile @@ -55,7 +55,7 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter \ common-cflags = $(warnings) -fno-rtti -fno-exceptions \ -I$(JAVA_HOME)/include -idirafter $(src) -I$(bld) -D__STDC_LIMIT_MACROS \ - -DBUILTIN_LIBRARIES=\"natives,tlscontext,scaler\" -D_JNI_IMPLEMENTATION_ + -D_JNI_IMPLEMENTATION_ system = posix asm = x86 diff --git a/src/builtin.cpp b/src/builtin.cpp index f8735fd81a..0c0947e581 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -496,9 +496,8 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) char n[length + 1]; stringChars(t, *name, n); -#ifdef BUILTIN_LIBRARIES - if (mapName) { - const char* s = BUILTIN_LIBRARIES; + if (mapName and t->m->builtins) { + const char* s = t->m->builtins; while (*s) { if (strncmp(s, n, length) == 0 and (s[length] == ',' or s[length] == 0)) @@ -511,7 +510,6 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) } } } -#endif // BUILTIN_LIBRARIES for (System::Library* lib = t->m->libraries; lib; lib = lib->next()) { if (lib->name() diff --git a/src/jnienv.cpp b/src/jnienv.cpp index ee9f36b42f..4084800e82 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -1837,9 +1837,12 @@ JNI_GetDefaultJavaVMInitArgs(void* args) JDK1_1InitArgs* a = static_cast(args); a->maxHeapSize = 128 * 1024 * 1024; a->classpath = "."; + a->properties = 0; return 0; } +#define BUILTINS_PROPERTY "vm.builtins" + extern "C" JNIEXPORT jint JNICALL JNI_CreateJavaVM(Machine** m, Thread** t, void* args) { @@ -1851,6 +1854,15 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) Processor* p = makeProcessor(s); *m = new (s->allocate(sizeof(Machine))) Machine(s, h, f, p); + + if (a->properties) { + for (const char** p = a->properties; *p; ++p) { + if (strncmp(*p, BUILTINS_PROPERTY, sizeof(BUILTINS_PROPERTY)) == 0) { + (*m)->builtins = (*p) + sizeof(BUILTINS_PROPERTY); + } + } + } + *t = p->makeThread(*m, 0, 0); return 0; diff --git a/src/machine.cpp b/src/machine.cpp index 25ed33c42f..1ea418623f 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1350,6 +1350,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder, rootThread(0), exclusive(0), jniReferences(0), + builtins(0), activeCount(0), liveCount(0), localThread(0), diff --git a/src/machine.h b/src/machine.h index 7cc5eed96d..21c2f16b9b 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1127,6 +1127,7 @@ class Machine { Thread* rootThread; Thread* exclusive; Reference* jniReferences; + const char* builtins; unsigned activeCount; unsigned liveCount; System::Local* localThread; diff --git a/src/main.cpp b/src/main.cpp index 86c911db23..fe78006bc2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,12 +28,15 @@ main(int ac, const char** av) const char* class_ = 0; int argc = 0; const char** argv = 0; + int propertyCount = 0; for (int i = 1; i < ac; ++i) { if (strcmp(av[i], "-cp") == 0) { vmArgs.classpath = const_cast(av[++i]); } else if (strncmp(av[i], "-Xmx", 4) == 0) { vmArgs.maxHeapSize = atoi(av[i] + 4); + } else if (strncmp(av[i], "-D", 2) == 0) { + ++ propertyCount; } else { class_ = av[i++]; if (i < ac) { @@ -44,6 +47,16 @@ main(int ac, const char** av) } } + const char* properties[propertyCount + 1]; + properties[propertyCount] = 0; + for (int i = 1; i < ac; ++i) { + if (strncmp(av[i], "-D", 2) == 0) { + properties[--propertyCount] = av[i] + 2; + } + } + + vmArgs.properties = const_cast(properties); + if (class_ == 0) { usageAndExit(av[0]); }