From 9c93c5989cc302e64f437bf5e349c2f3633e10cd Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 11 Jul 2014 08:38:56 -0600 Subject: [PATCH] apply classpath-common.h changes --- src/avian/classpath-common.h | 193 ++++++++++++++++++----------------- src/classpath-android.cpp | 10 +- src/classpath-avian.cpp | 4 +- src/classpath-openjdk.cpp | 14 +-- src/machine.cpp | 2 +- src/types.def | 10 +- 6 files changed, 119 insertions(+), 114 deletions(-) diff --git a/src/avian/classpath-common.h b/src/avian/classpath-common.h index 23027cd960..4b396d5672 100644 --- a/src/avian/classpath-common.h +++ b/src/avian/classpath-common.h @@ -54,19 +54,21 @@ getTrace(Thread* t, unsigned skipCount) t->m->processor->walkStack(t, &v); - if (v.trace == 0) v.trace = makeObjectArray(t, 0); + if (v.trace == 0) v.trace = reinterpret_cast(makeObjectArray(t, 0)); return v.trace; } bool -compatibleArrayTypes(Thread* t, object a, object b) +compatibleArrayTypes(Thread* t, object ao, object bo) { - return classArrayElementSize(t, a) - and classArrayElementSize(t, b) + GcClass* a = cast(t, ao); + GcClass* b = cast(t, bo); + return a->arrayElementSize() + and b->arrayElementSize() and (a == b - or (not ((classVmFlags(t, a) & PrimitiveFlag) - or (classVmFlags(t, b) & PrimitiveFlag)))); + or (not ((a->vmFlags() & PrimitiveFlag) + or (b->vmFlags() & PrimitiveFlag)))); } void @@ -266,10 +268,10 @@ clone(Thread* t, object o) reinterpret_cast(o) + 1, size - BytesPerWord); } else { - object classNameSlash = reinterpret_cast(objectClass(t, o)->name()); - THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash)); + GcByteArray* classNameSlash = objectClass(t, o)->name(); + THREAD_RUNTIME_ARRAY(t, char, classNameDot, classNameSlash->length()); replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot), - reinterpret_cast(&byteArrayBody(t, classNameSlash, 0))); + reinterpret_cast(classNameSlash->body().begin())); throwNew(t, GcCloneNotSupportedException::Type, "%s", RUNTIME_ARRAY_BODY(classNameDot)); } @@ -277,36 +279,38 @@ clone(Thread* t, object o) return clone; } -object -makeStackTraceElement(Thread* t, object e) +GcStackTraceElement* +makeStackTraceElement(Thread* t, GcTraceElement* e) { PROTECT(t, e); - GcMethod* method = cast(t, traceElementMethod(t, e)); + GcMethod* method = cast(t, e->method()); PROTECT(t, method); - object class_name = reinterpret_cast(method->class_()->name()); + GcByteArray* class_name = method->class_()->name(); PROTECT(t, class_name); - THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_name)); + THREAD_RUNTIME_ARRAY(t, char, s, class_name->length()); replace('/', '.', RUNTIME_ARRAY_BODY(s), - reinterpret_cast(&byteArrayBody(t, class_name, 0))); - class_name = reinterpret_cast(makeString(t, "%s", RUNTIME_ARRAY_BODY(s))); + reinterpret_cast(class_name->body().begin())); + GcString* class_name_string = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); + PROTECT(t, class_name_string); - object method_name = reinterpret_cast(method->name()); + GcByteArray* method_name = method->name(); PROTECT(t, method_name); - method_name = reinterpret_cast(t->m->classpath->makeString - (t, method_name, 0, byteArrayLength(t, method_name) - 1)); + GcString* method_name_string = t->m->classpath->makeString + (t, reinterpret_cast(method_name), 0, method_name->length() - 1); + PROTECT(t, method_name_string); unsigned line = t->m->processor->lineNumber - (t, method, traceElementIp(t, e)); + (t, method, e->ip()); - object file = reinterpret_cast(method->class_()->sourceFile()); - file = file ? reinterpret_cast(t->m->classpath->makeString - (t, file, 0, byteArrayLength(t, file) - 1)) : 0; + GcByteArray* file = method->class_()->sourceFile(); + GcString* file_string = file ? t->m->classpath->makeString + (t, reinterpret_cast(file), 0, file->length() - 1) : 0; - return reinterpret_cast(makeStackTraceElement(t, cast(t, class_name), cast(t, method_name), cast(t, file), line)); + return makeStackTraceElement(t, class_name_string, method_name_string, file_string, line); } object @@ -314,19 +318,19 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o) { switch (returnCode) { case ByteField: - return reinterpret_cast(makeByte(t, intValue(t, o))); + return reinterpret_cast(makeByte(t, cast(t, o)->value())); case BooleanField: - return reinterpret_cast(makeBoolean(t, intValue(t, o) != 0)); + return reinterpret_cast(makeBoolean(t, cast(t, o)->value() != 0)); case CharField: - return reinterpret_cast(makeChar(t, intValue(t, o))); + return reinterpret_cast(makeChar(t, cast(t, o)->value())); case ShortField: - return reinterpret_cast(makeShort(t, intValue(t, o))); + return reinterpret_cast(makeShort(t, cast(t, o)->value())); case FloatField: - return reinterpret_cast(makeFloat(t, intValue(t, o))); + return reinterpret_cast(makeFloat(t, cast(t, o)->value())); case IntField: case LongField: @@ -335,7 +339,7 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o) return o; case DoubleField: - return reinterpret_cast(makeDouble(t, longValue(t, o))); + return reinterpret_cast(makeDouble(t, cast(t, o)->value())); default: abort(t); @@ -372,14 +376,14 @@ resolveJType(Thread* t, GcClassLoader* loader, const char* spec, unsigned specLe return getJClass(t, resolveClassBySpec(t, loader, spec, specLength)); } -object +GcPair* resolveParameterTypes(Thread* t, GcClassLoader* loader, GcByteArray* spec, unsigned* parameterCount, unsigned* returnTypeSpec) { PROTECT(t, loader); PROTECT(t, spec); - object list = 0; + GcPair* list = 0; PROTECT(t, list); unsigned offset = 1; @@ -396,7 +400,7 @@ resolveParameterTypes(Thread* t, GcClassLoader* loader, GcByteArray* spec, (t, loader, reinterpret_cast(&spec->body()[start]), offset - start); - list = reinterpret_cast(makePair(t, reinterpret_cast(type), list)); + list = makePair(t, reinterpret_cast(type), reinterpret_cast(list)); ++ count; } break; @@ -420,13 +424,13 @@ resolveParameterTypes(Thread* t, GcClassLoader* loader, GcByteArray* spec, (t, loader, reinterpret_cast(&spec->body()[start]), offset - start); - list = reinterpret_cast(makePair(t, reinterpret_cast(type), list)); + list = makePair(t, reinterpret_cast(type), reinterpret_cast(list)); ++ count; } break; default: - list = reinterpret_cast(makePair - (t, reinterpret_cast(primitiveClass(t, spec->body()[offset])), list)); + list = makePair + (t, reinterpret_cast(primitiveClass(t, spec->body()[offset])), reinterpret_cast(list)); ++ offset; ++ count; break; @@ -442,7 +446,7 @@ object resolveParameterJTypes(Thread* t, GcClassLoader* loader, GcByteArray* spec, unsigned* parameterCount, unsigned* returnTypeSpec) { - object list = resolveParameterTypes + GcPair* list = resolveParameterTypes (t, loader, spec, parameterCount, returnTypeSpec); PROTECT(t, list); @@ -452,9 +456,9 @@ resolveParameterJTypes(Thread* t, GcClassLoader* loader, GcByteArray* spec, PROTECT(t, array); for (int i = *parameterCount - 1; i >= 0; --i) { - object c = reinterpret_cast(getJClass(t, cast(t, pairFirst(t, list)))); + object c = reinterpret_cast(getJClass(t, cast(t, list->first()))); set(t, array, ArrayBody + (i * BytesPerWord), c); - list = pairSecond(t, list); + list = cast(t, list->second()); } return array; @@ -470,21 +474,22 @@ resolveExceptionJTypes(Thread* t, GcClassLoader* loader, GcMethodAddendum* adden PROTECT(t, loader); PROTECT(t, addendum); + GcShortArray* exceptionTable = cast(t, addendum->exceptionTable()); + PROTECT(t, exceptionTable); + object array = makeObjectArray (t, type(t, GcJclass::Type), - shortArrayLength(t, addendum->exceptionTable())); + exceptionTable->length()); PROTECT(t, array); - for (unsigned i = 0; i < shortArrayLength - (t, addendum->exceptionTable()); ++i) + for (unsigned i = 0; i < exceptionTable->length(); ++i) { - uint16_t index = shortArrayBody - (t, addendum->exceptionTable(), i) - 1; + uint16_t index = exceptionTable->body()[i] - 1; - object o = singletonObject(t, addendum->pool(), index); + object o = singletonObject(t, addendum->pool()->as(t), index); if (objectClass(t, o) == type(t, GcReference::Type)) { - o = reinterpret_cast(resolveClass(t, loader, cast(t, referenceName(t, o)))); + o = reinterpret_cast(resolveClass(t, loader, cast(t, cast(t, o)->name()))); set(t, reinterpret_cast(addendum->pool()), SingletonBody + (index * BytesPerWord), o); @@ -612,11 +617,11 @@ intercept(Thread* t, GcClass* c, const char* name, const char* spec, // through the vtable. clone->flags() |= ACC_PRIVATE; - object native = reinterpret_cast(makeNativeIntercept(t, function, true, reinterpret_cast(clone))); + GcNativeIntercept* native = makeNativeIntercept(t, function, true, reinterpret_cast(clone)); PROTECT(t, native); - object runtimeData = reinterpret_cast(getMethodRuntimeData(t, m)); + GcMethodRuntimeData* runtimeData = getMethodRuntimeData(t, m); set(t, runtimeData, MethodRuntimeDataNative, native); } @@ -626,7 +631,7 @@ intercept(Thread* t, GcClass* c, const char* name, const char* spec, // be uncommented for debugging purposes. // fprintf(stderr, "unable to find %s%s in %s\n", - // name, spec, &byteArrayBody(t, className(t, c), 0)); + // name, spec, &byteArrayBody(t, c->name(), 0)); // abort(t); } @@ -637,23 +642,23 @@ getFinder(Thread* t, const char* name, unsigned nameLength) { ACQUIRE(t, t->m->referenceLock); - for (object p = root(t, Machine::VirtualFileFinders); - p; p = finderNext(t, p)) + for (GcFinder* p = cast(t, root(t, Machine::VirtualFileFinders)); + p; p = p->next()) { - if (byteArrayLength(t, finderName(t, p)) == nameLength + if (p->name()->length() == nameLength and strncmp(reinterpret_cast - (&byteArrayBody(t, finderName(t, p), 0)), + (p->name()->body().begin()), name, nameLength)) { - return static_cast(finderFinder(t, p)); + return static_cast(p->finder()); } } - object n = reinterpret_cast(makeByteArray(t, nameLength + 1)); - memcpy(&byteArrayBody(t, n, 0), name, nameLength); + GcByteArray* n = makeByteArray(t, nameLength + 1); + memcpy(n->body().begin(), name, nameLength); void* p = t->m->libraries->resolve - (reinterpret_cast(&byteArrayBody(t, n, 0))); + (reinterpret_cast(n->body().begin())); if (p) { uint8_t* (*function)(unsigned*); @@ -663,10 +668,10 @@ getFinder(Thread* t, const char* name, unsigned nameLength) uint8_t* data = function(&size); if (data) { Finder* f = makeFinder(t->m->system, t->m->heap, data, size); - object finder = reinterpret_cast(makeFinder - (t, f, n, root(t, Machine::VirtualFileFinders))); + GcFinder* finder = makeFinder + (t, f, n, cast(t, root(t, Machine::VirtualFileFinders))); - setRoot(t, Machine::VirtualFileFinders, finder); + setRoot(t, Machine::VirtualFileFinders, reinterpret_cast(finder)); return f; } @@ -676,21 +681,21 @@ getFinder(Thread* t, const char* name, unsigned nameLength) } object -getDeclaredClasses(Thread* t, object c, bool publicOnly) +getDeclaredClasses(Thread* t, GcClass* c, bool publicOnly) { - object addendum = classAddendum(t, c); + GcClassAddendum* addendum = c->addendum(); if (addendum) { - object table = classAddendumInnerClassTable(t, addendum); + GcArray* table = cast(t, addendum->innerClassTable()); if (table) { PROTECT(t, table); unsigned count = 0; - for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object reference = arrayBody(t, table, i); - object outer = innerClassReferenceOuter(t, reference); - if (outer and byteArrayEqual(t, outer, className(t, c)) + for (unsigned i = 0; i < table->length(); ++i) { + GcInnerClassReference* reference = cast(t, table->body()[i]); + GcByteArray* outer = reference->outer(); + if (outer and byteArrayEqual(t, reinterpret_cast(outer), reinterpret_cast(c->name())) and ((not publicOnly) - or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC))) + or (reference->flags() & ACC_PUBLIC))) { ++ count; } @@ -699,19 +704,19 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) object result = makeObjectArray(t, type(t, GcJclass::Type), count); PROTECT(t, result); - for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object reference = arrayBody(t, table, i); - object outer = innerClassReferenceOuter(t, reference); - if (outer and byteArrayEqual(t, outer, className(t, c)) + for (unsigned i = 0; i < table->length(); ++i) { + GcInnerClassReference* reference = cast(t, table->body()[i]); + GcByteArray* outer = reference->outer(); + if (outer and byteArrayEqual(t, reinterpret_cast(outer), reinterpret_cast(c->name())) and ((not publicOnly) - or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC))) + or (reference->flags() & ACC_PUBLIC))) { object inner = reinterpret_cast(getJClass( t, resolveClass( t, - cast(t, classLoader(t, c)), - cast(t, innerClassReferenceInner(t, arrayBody(t, table, i)))))); + c->loader(), + reference->inner()))); -- count; set(t, result, ArrayBody + (count * BytesPerWord), inner); @@ -726,23 +731,23 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly) } GcJclass* -getDeclaringClass(Thread* t, object c) +getDeclaringClass(Thread* t, GcClass* c) { - object addendum = classAddendum(t, c); + GcClassAddendum* addendum = c->addendum(); if (addendum) { - object table = classAddendumInnerClassTable(t, addendum); + GcArray* table = cast(t, addendum->innerClassTable()); if (table) { - for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object reference = arrayBody(t, table, i); - if (innerClassReferenceOuter(t, reference) and strcmp - (&byteArrayBody(t, innerClassReferenceInner(t, reference), 0), - &byteArrayBody(t, className(t, c), 0)) == 0) + for (unsigned i = 0; i < table->length(); ++i) { + GcInnerClassReference* reference = cast(t, table->body()[i]); + if (reference->outer() and strcmp + (reference->inner()->body().begin(), + c->name()->body().begin()) == 0) { return getJClass( t, resolveClass(t, - cast(t, classLoader(t, c)), - cast(t, innerClassReferenceOuter(t, reference)))); + c->loader(), + reference->outer())); } } } @@ -752,25 +757,25 @@ getDeclaringClass(Thread* t, object c) } unsigned -classModifiers(Thread* t, object c) +classModifiers(Thread* t, GcClass* c) { - object addendum = classAddendum(t, c); + GcClassAddendum* addendum = c->addendum(); if (addendum) { - object table = classAddendumInnerClassTable(t, addendum); + GcArray* table = cast(t, addendum->innerClassTable()); if (table) { - for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object reference = arrayBody(t, table, i); + for (unsigned i = 0; i < table->length(); ++i) { + GcInnerClassReference* reference = cast(t, table->body()[i]); if (0 == strcmp - (&byteArrayBody(t, className(t, c), 0), - &byteArrayBody(t, innerClassReferenceInner(t, reference), 0))) + (c->name()->body().begin(), + reference->inner()->body().begin())) { - return innerClassReferenceFlags(t, reference); + return reference->flags(); } } } } - return classFlags(t, c); + return c->flags(); } } // namespace vm diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index e3b7629e0b..5cb206ab71 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -219,9 +219,9 @@ translateStackTrace(Thread* t, object raw) PROTECT(t, array); for (unsigned i = 0; i < objectArrayLength(t, array); ++i) { - object e = makeStackTraceElement(t, objectArrayBody(t, raw, i)); + GcStackTraceElement* e = makeStackTraceElement(t, cast(t, objectArrayBody(t, raw, i))); - set(t, array, ArrayBody + (i * BytesPerWord), e); + set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast(e)); } return array; @@ -1116,7 +1116,7 @@ Avian_java_lang_Class_getDeclaredClasses { return reinterpret_cast (getDeclaredClasses - (t, jclassVmClass(t, reinterpret_cast(arguments[0])), + (t, cast(t, jclassVmClass(t, reinterpret_cast(arguments[0]))), arguments[1])); } @@ -1126,7 +1126,7 @@ Avian_java_lang_Class_getDeclaringClass { return reinterpret_cast (getDeclaringClass - (t, jclassVmClass(t, reinterpret_cast(arguments[0])))); + (t, cast(t, jclassVmClass(t, reinterpret_cast(arguments[0]))))); } extern "C" AVIAN_EXPORT int64_t JNICALL @@ -1711,7 +1711,7 @@ Avian_java_lang_Class_getModifiers (Thread* t, object, uintptr_t* arguments) { return classModifiers - (t, jclassVmClass(t, reinterpret_cast(arguments[0]))); + (t, cast(t, jclassVmClass(t, reinterpret_cast(arguments[0])))); } extern "C" AVIAN_EXPORT int64_t JNICALL diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index d431098538..8a38c384e5 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -642,8 +642,8 @@ Avian_java_lang_Throwable_resolveTrace PROTECT(t, array); for (unsigned i = 0; i < length; ++i) { - object ste = makeStackTraceElement(t, objectArrayBody(t, trace, i)); - set(t, array, ArrayBody + (i * BytesPerWord), ste); + GcStackTraceElement* ste = makeStackTraceElement(t, cast(t, objectArrayBody(t, trace, i))); + set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast(ste)); } return reinterpret_cast(array); diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index cd4b2ba7a3..ec35d50e41 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -3232,8 +3232,8 @@ jvmGetStackTraceElement(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference - (t, makeStackTraceElement - (t, objectArrayBody(t, throwableTrace(t, *throwable), index)))); + (t, reinterpret_cast(makeStackTraceElement + (t, cast(t, objectArrayBody(t, throwableTrace(t, *throwable), index)))))); } extern "C" AVIAN_EXPORT jobject JNICALL @@ -3448,8 +3448,8 @@ jvmDumpThreads(Thread* t, uintptr_t* arguments) PROTECT(t, array); for (unsigned traceIndex = 0; traceIndex < traceLength; ++ traceIndex) { - object ste = makeStackTraceElement - (t, objectArrayBody(t, trace, traceIndex)); + object ste = reinterpret_cast(makeStackTraceElement + (t, cast(t, objectArrayBody(t, trace, traceIndex)))); set(t, array, ArrayBody + (traceIndex * BytesPerWord), ste); } @@ -4188,7 +4188,7 @@ uint64_t jvmGetClassModifiers(Thread* t, uintptr_t* arguments) { return classModifiers - (t, jclassVmClass(t, *reinterpret_cast(arguments[0]))); + (t, cast(t, jclassVmClass(t, *reinterpret_cast(arguments[0])))); } extern "C" AVIAN_EXPORT jint JNICALL @@ -4205,7 +4205,7 @@ jvmGetDeclaredClasses(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference (t, getDeclaredClasses - (t, jclassVmClass(t, *reinterpret_cast(arguments[0])), false))); + (t, cast(t, jclassVmClass(t, *reinterpret_cast(arguments[0]))), false))); } extern "C" AVIAN_EXPORT jobjectArray JNICALL @@ -4222,7 +4222,7 @@ jvmGetDeclaringClass(Thread* t, uintptr_t* arguments) return reinterpret_cast (makeLocalReference (t, reinterpret_cast(getDeclaringClass - (t, jclassVmClass(t, *reinterpret_cast(arguments[0])))))); + (t, cast(t, jclassVmClass(t, *reinterpret_cast(arguments[0]))))))); } extern "C" AVIAN_EXPORT jclass JNICALL diff --git a/src/machine.cpp b/src/machine.cpp index 16f9a10b76..f9ab1dce19 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -227,7 +227,7 @@ turnOffTheLights(Thread* t) } for (object p = root(t, Machine::VirtualFileFinders); - p; p = finderNext(t, p)) + p; p = reinterpret_cast(cast(t, p)->next())) { static_cast(finderFinder(t, p))->dispose(); } diff --git a/src/types.def b/src/types.def index 6aba46ed97..d9b0a35546 100644 --- a/src/types.def +++ b/src/types.def @@ -63,11 +63,6 @@ (extends native) (object original)) -(type finder - (void* finder) - (object name) - (object next)) - (type region (void* region) (uint32_t position)) @@ -312,6 +307,11 @@ (extends jobject) (array int8_t body)) +(type finder + (void* finder) + (byteArray name) + (finder next)) + (type booleanArray [Z (extends jobject) (array uint8_t body))