diff --git a/src/builtin.cpp b/src/builtin.cpp index 396088dc56..dc1f1f652a 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -456,6 +456,11 @@ Java_java_lang_System_getVMProperty(Thread* t, jclass, jstring name, r = makeLocalReference(t, makeString(t, "%s", t->m->finder->path())); } else if (strcmp(n, "avian.version") == 0) { r = makeLocalReference(t, makeString(t, AVIAN_VERSION)); + } else { + const char* v = findProperty(t, n); + if (v) { + r = makeLocalReference(t, makeString(t, v)); + } } if (r) { diff --git a/src/compile.cpp b/src/compile.cpp index aea9eebd58..fe83e102d4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -27,7 +27,7 @@ vmCall(); namespace { -const bool Verbose = false; +const bool DebugCompile = true; const bool DebugNatives = false; const bool DebugCallTable = false; const bool DebugMethodTree = false; @@ -3389,12 +3389,26 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, } void -logCompile(const void* code, unsigned size, const char* class_, +logCompile(MyThread* t, const void* code, unsigned size, const char* class_, const char* name, const char* spec) { - fprintf(stderr, "%s.%s%s: %p %p\n", - class_, name, spec, code, - static_cast(code) + size); + static FILE* log = 0; + static bool open = false; + if (not open) { + open = true; + const char* path = findProperty(t, "avian.jit.log"); + if (name) { + log = fopen(path, "wb"); + } else { + log = stderr; + } + } + + if (log) { + fprintf(log, "%p %p %s.%s%s\n", + code, static_cast(code) + size, + class_, name, spec); + } } void @@ -3644,8 +3658,8 @@ finish(MyThread* t, Assembler* a, const char* name) a->writeTo(start); - if (Verbose) { - logCompile(start, a->length(), 0, name, 0); + if (DebugCompile) { + logCompile(t, start, a->length(), 0, name, 0); } return result; @@ -3740,9 +3754,9 @@ finish(MyThread* t, Context* context) set(t, result, SingletonBody + offset, p->value); } - if (Verbose) { + if (DebugCompile) { logCompile - (start, codeSize, + (t, start, codeSize, reinterpret_cast (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), reinterpret_cast @@ -4992,9 +5006,9 @@ compileThunks(MyThread* t, MyProcessor* p) uint8_t* start = reinterpret_cast (&singletonValue(t, p->thunkTable, 0)); - if (Verbose) { - logCompile(start, p->thunkSize * ThunkCount, 0, "thunkTable", 0); - fprintf(stderr, "thunk size: %d\n", p->thunkSize); + if (DebugCompile) { + logCompile(t, start, p->thunkSize * ThunkCount, 0, "thunkTable", 0); + //fprintf(stderr, "thunk size: %d\n", p->thunkSize); } tableContext.promise.resolved_ = true; diff --git a/src/finder.cpp b/src/finder.cpp index 973439b927..c4316b7550 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -20,7 +20,7 @@ void* allocate(System* s, unsigned size) { void* p = s->tryAllocate(size); - if (p == 0) abort(); + if (p == 0) s->abort(); return p; } diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 329e948687..ce7107dbbc 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -2072,6 +2072,8 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) const char* bootClasspath = ""; const char* bootClasspathAppend = ""; + unsigned propertyCount = 0; + for (int i = 0; i < a->nOptions; ++i) { if (strncmp(a->options[i].optionString, "-X", 2) == 0) { const char* p = a->options[i].optionString + 2; @@ -2106,7 +2108,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) classpath = p + sizeof(CLASSPATH_PROPERTY); } - // todo: add properties to VM + ++ propertyCount; } } @@ -2133,8 +2135,17 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) Finder* f = makeFinder(s, classpathBuffer, bootLibrary); Processor* p = makeProcessor(s, h); + const char** properties = static_cast + (h->allocate(sizeof(const char*) * propertyCount)); + const char** propertyPointer = properties; + for (int i = 0; i < a->nOptions; ++i) { + if (strncmp(a->options[i].optionString, "-D", 2) == 0) { + *(propertyPointer++) = a->options[i].optionString + 2; + } + } + *m = new (h->allocate(sizeof(Machine))) - Machine(s, h, f, p, bootLibrary, builtins); + Machine(s, h, f, p, bootLibrary, builtins, properties, propertyCount); *t = p->makeThread(*m, 0, 0); diff --git a/src/machine.cpp b/src/machine.cpp index 0b1840feb6..572270e2f0 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1633,7 +1633,8 @@ namespace vm { Machine::Machine(System* system, Heap* heap, Finder* finder, Processor* processor, const char* bootLibrary, - const char* builtins): + const char* builtins, const char** properties, + unsigned propertyCount): vtable(&javaVMVTable), system(system), heapClient(new (heap->allocate(sizeof(HeapClient))) @@ -1645,6 +1646,8 @@ Machine::Machine(System* system, Heap* heap, Finder* finder, exclusive(0), jniReferences(0), builtins(builtins), + properties(properties), + propertyCount(propertyCount), activeCount(0), liveCount(0), fixedFootprint(0), diff --git a/src/machine.h b/src/machine.h index 0c4d841f74..d2adce2e33 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1122,7 +1122,8 @@ class Machine { }; Machine(System* system, Heap* heap, Finder* finder, Processor* processor, - const char* bootLibrary, const char* builtins); + const char* bootLibrary, const char* builtins, + const char** properties, unsigned propertyCount); ~Machine() { dispose(); @@ -1144,6 +1145,8 @@ class Machine { Thread* exclusive; Reference* jniReferences; const char* builtins; + const char** properties; + unsigned propertyCount; unsigned activeCount; unsigned liveCount; unsigned fixedFootprint; @@ -1510,6 +1513,23 @@ setObjectClass(Thread*, object o, object value) | (reinterpret_cast(cast(o, 0)) & (~PointerMask))); } +inline const char* +findProperty(Thread* t, const char* name) +{ + for (unsigned i = 0; i < t->m->propertyCount; ++i) { + const char* p = t->m->properties[i]; + const char* n = name; + while (*p and *p != '=' and *n and *p == *n) { + ++ p; + ++ n; + } + if (*p == '=' and *n == 0) { + return p + 1; + } + } + return 0; +} + object& arrayBodyUnsafe(Thread*, object, unsigned);