From 9f0327bb9eb412e5cbc932e76638bfeb3cb3408d Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 28 Jun 2014 23:37:24 -0600 Subject: [PATCH] add process and classpath-avian changes --- src/classpath-avian.cpp | 48 ++++++++++++++--------------- src/process.cpp | 67 ++++++++++++++++++++--------------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 8a38c384e5..b34ff2cc78 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -61,18 +61,18 @@ class MyClasspath : public Classpath { { PROTECT(t, vmMethod); - object jmethod = reinterpret_cast(makeJmethod(t, vmMethod, false)); + GcJmethod* jmethod = makeJmethod(t, vmMethod, false); return vmMethod->name()->body()[0] == '<' - ? reinterpret_cast(makeJconstructor(t, cast(t, jmethod))) : jmethod; + ? reinterpret_cast(makeJconstructor(t, jmethod)) : reinterpret_cast(jmethod); } virtual GcMethod* getVMMethod(Thread* t, object jmethod) { return objectClass(t, jmethod) == type(t, GcJmethod::Type) - ? cast(t, jmethodVmMethod(t, jmethod)) - : cast(t, jmethodVmMethod(t, jconstructorMethod(t, jmethod))); + ? cast(t, jmethod)->vmMethod() + : cast(t, jmethod)->method()->vmMethod(); } virtual object @@ -84,7 +84,7 @@ class MyClasspath : public Classpath { virtual GcField* getVMField(Thread* t, object jfield) { - return cast(t, jfieldVmField(t, jfield)); + return cast(t, jfield)->vmField(); } virtual void @@ -492,11 +492,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_reflect_Array_makeObjectArray (Thread* t, object, uintptr_t* arguments) { - object elementType = reinterpret_cast(arguments[0]); + GcJclass* elementType = cast(t, reinterpret_cast(arguments[0])); int length = arguments[1]; return reinterpret_cast - (makeObjectArray(t, cast(t, jclassVmClass(t, elementType)), length)); + (makeObjectArray(t, elementType->vmClass(), length)); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -587,7 +587,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT void JNICALL Avian_java_lang_ClassLoader_load(Thread* t, object, uintptr_t* arguments) { - object name = reinterpret_cast(arguments[0]); + GcString* name = cast(t, reinterpret_cast(arguments[0])); Thread::LibraryLoadStack stack( t, @@ -595,9 +595,9 @@ extern "C" AVIAN_EXPORT void JNICALL bool mapName = arguments[2]; - unsigned length = stringLength(t, name); + unsigned length = name->length(t); THREAD_RUNTIME_ARRAY(t, char, n, length + 1); - stringChars(t, cast(t, name), RUNTIME_ARRAY_BODY(n)); + stringChars(t, name, RUNTIME_ARRAY_BODY(n)); loadLibrary(t, "", RUNTIME_ARRAY_BODY(n), mapName, true); } @@ -708,13 +708,13 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_java_lang_Thread_enumerate (Thread* t, object, uintptr_t* arguments) { - object array = reinterpret_cast(*arguments); + GcArray* array = cast(t, reinterpret_cast(*arguments)); ACQUIRE_RAW(t, t->m->stateLock); - unsigned count = min(t->m->liveCount, objectArrayLength(t, array)); + unsigned count = min(t->m->liveCount, objectArrayLength(t, reinterpret_cast(array))); unsigned index = 0; - local::enumerateThreads(t, t->m->rootThread, array, &index, count); + local::enumerateThreads(t, t->m->rootThread, reinterpret_cast(array), &index, count); return count; } @@ -729,16 +729,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_avian_Atomic_getOffset (Thread* t, object, uintptr_t* arguments) { - return fieldOffset - (t, jfieldVmField(t, reinterpret_cast(arguments[0]))); + return cast(t, reinterpret_cast(arguments[0]))->vmField()->offset(); } extern "C" AVIAN_EXPORT int64_t JNICALL Avian_sun_misc_Unsafe_objectFieldOffset (Thread* t, object, uintptr_t* arguments) { - return fieldOffset - (t, jfieldVmField(t, reinterpret_cast(arguments[1]))); + return cast(t, reinterpret_cast(arguments[1]))->vmField()->offset(); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -786,10 +784,12 @@ extern "C" AVIAN_EXPORT int64_t JNICALL Avian_avian_Classes_makeMethod (Thread* t, object, uintptr_t* arguments) { - object method = arrayBody - (t, classMethodTable - (t, jclassVmClass(t, reinterpret_cast(arguments[0]))), - arguments[1]); + GcMethod* method = cast( + t, + cast(t, + cast(t, reinterpret_cast(arguments[0])) + ->vmClass() + ->methodTable())->body()[arguments[1]]); PROTECT(t, method); GcClass* c = resolveClass @@ -803,8 +803,8 @@ Avian_avian_Classes_makeMethod t->m->processor->invoke(t, constructor, instance, method); - if (byteArrayBody(t, methodName(t, method), 0) == '<') { - method = instance; + if (method->name()->body()[0] == '<') { + object oldInstance = instance; c = resolveClass (t, cast(t, root(t, Machine::BootLoader)), "java/lang/reflect/Constructor"); @@ -814,7 +814,7 @@ Avian_avian_Classes_makeMethod GcMethod* constructor = resolveMethod (t, c, "", "(Ljava/lang/Method;)V"); - t->m->processor->invoke(t, constructor, instance, method); + t->m->processor->invoke(t, constructor, instance, oldInstance); } return reinterpret_cast(instance); diff --git a/src/process.cpp b/src/process.cpp index a065c4f90d..704953e883 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -61,36 +61,36 @@ mangle(int8_t c, char* dst) return 6; default: - dst[0] = c; + dst[0] = c; return 1; } } unsigned -jniNameLength(Thread* t, GcMethod* method, bool decorate) +jniNameLength(Thread* t UNUSED, GcMethod* method, bool decorate) { unsigned size = 0; - object className = reinterpret_cast(method->class_()->name()); - for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { - size += mangledSize(byteArrayBody(t, className, i)); + GcByteArray* className = method->class_()->name(); + for (unsigned i = 0; i < className->length() - 1; ++i) { + size += mangledSize(className->body()[i]); } ++ size; - object methodName = reinterpret_cast(method->name()); - for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { - size += mangledSize(byteArrayBody(t, methodName, i)); + GcByteArray* methodName = method->name(); + for (unsigned i = 0; i < methodName->length() - 1; ++i) { + size += mangledSize(methodName->body()[i]); } if (decorate) { size += 2; - object methodSpec = reinterpret_cast(method->spec()); - for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 - and byteArrayBody(t, methodSpec, i) != ')'; ++i) + GcByteArray* methodSpec = method->spec(); + for (unsigned i = 1; i < methodSpec->length() - 1 + and methodSpec->body()[i] != ')'; ++i) { - size += mangledSize(byteArrayBody(t, methodSpec, i)); + size += mangledSize(methodSpec->body()[i]); } } @@ -98,33 +98,33 @@ jniNameLength(Thread* t, GcMethod* method, bool decorate) } void -makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, +makeJNIName(Thread* t UNUSED, const char* prefix, unsigned prefixLength, char* name, GcMethod* method, bool decorate) { memcpy(name, prefix, prefixLength); name += prefixLength; - object className = reinterpret_cast(method->class_()->name()); - for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { - name += mangle(byteArrayBody(t, className, i), name); + GcByteArray* className = method->class_()->name(); + for (unsigned i = 0; i < className->length() - 1; ++i) { + name += mangle(className->body()[i], name); } *(name++) = '_'; - object methodName = reinterpret_cast(method->name()); - for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { - name += mangle(byteArrayBody(t, methodName, i), name); + GcByteArray* methodName = method->name(); + for (unsigned i = 0; i < methodName->length() - 1; ++i) { + name += mangle(methodName->body()[i], name); } if (decorate) { *(name++) = '_'; *(name++) = '_'; - object methodSpec = reinterpret_cast(method->spec()); - for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 - and byteArrayBody(t, methodSpec, i) != ')'; ++i) + GcByteArray* methodSpec = method->spec(); + for (unsigned i = 1; i < methodSpec->length() - 1 + and methodSpec->body()[i] != ')'; ++i) { - name += mangle(byteArrayBody(t, methodSpec, i), name); + name += mangle(methodSpec->body()[i], name); } } @@ -245,18 +245,18 @@ resolveNative(Thread* t, GcMethod* method) PROTECT(t, native); - object runtimeData = reinterpret_cast(getMethodRuntimeData(t, method)); + GcMethodRuntimeData* runtimeData = getMethodRuntimeData(t, method); // ensure other threads only see the methodRuntimeDataNative field // populated once the object it points to has been populated: storeStoreMemoryBarrier(); - set(t, runtimeData, MethodRuntimeDataNative, native); + set(t, reinterpret_cast(runtimeData), MethodRuntimeDataNative, native); } } int -findLineNumber(Thread* t, GcMethod* method, unsigned ip) +findLineNumber(Thread* t UNUSED, GcMethod* method, unsigned ip) { if (method->flags() & ACC_NATIVE) { return NativeLine; @@ -266,18 +266,17 @@ findLineNumber(Thread* t, GcMethod* method, unsigned ip) // about, so we back up first: -- ip; - object code = reinterpret_cast(method->code()); - object lnt = reinterpret_cast(codeLineNumberTable(t, code)); + GcLineNumberTable* lnt = method->code()->lineNumberTable(); if (lnt) { unsigned bottom = 0; - unsigned top = lineNumberTableLength(t, lnt); + unsigned top = lnt->length(); for (unsigned span = top - bottom; span; span = top - bottom) { unsigned middle = bottom + (span / 2); - uint64_t ln = lineNumberTableBody(t, lnt, middle); + uint64_t ln = lnt->body()[middle]; if (ip >= lineNumberIp(ln) - and (middle + 1 == lineNumberTableLength(t, lnt) - or ip < lineNumberIp(lineNumberTableBody(t, lnt, middle + 1)))) + and (middle + 1 == lnt->length() + or ip < lineNumberIp(lnt->body()[middle + 1]))) { return lineNumberLine(ln); } else if (ip < lineNumberIp(ln)) { @@ -287,8 +286,8 @@ findLineNumber(Thread* t, GcMethod* method, unsigned ip) } } - if (top < lineNumberTableLength(t, lnt)) { - return lineNumberLine(lineNumberTableBody(t, lnt, top)); + if (top < lnt->length()) { + return lineNumberLine(lnt->body()[top]); } else { return UnknownLine; }