remove old function-based accessors

This commit is contained in:
Joshua Warner 2014-06-26 18:17:46 -06:00 committed by Joshua Warner
parent a1583f1ecc
commit 75f2dd013c
6 changed files with 283 additions and 336 deletions

View File

@ -1317,9 +1317,6 @@ class Machine {
void void
printTrace(Thread* t, GcThrowable* exception); printTrace(Thread* t, GcThrowable* exception);
uint8_t&
threadInterrupted(Thread* t, object thread);
void void
enterActiveState(Thread* t); enterActiveState(Thread* t);
@ -1579,6 +1576,8 @@ class Thread {
unsigned flags; unsigned flags;
}; };
class GcJfield;
class Classpath { class Classpath {
public: public:
virtual object virtual object
@ -1600,7 +1599,7 @@ class Classpath {
makeJField(Thread* t, GcField* vmField) = 0; makeJField(Thread* t, GcField* vmField) = 0;
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) = 0; getVMField(Thread* t, GcJfield* jfield) = 0;
virtual void virtual void
clearInterrupted(Thread* t) = 0; clearInterrupted(Thread* t) = 0;
@ -2321,19 +2320,20 @@ makeString(Thread* t, object data, int32_t hash, int32_t)
# endif // not HAVE_StringHash32 # endif // not HAVE_StringHash32
inline GcString* inline GcString*
makeString(Thread* t, object data, unsigned offset, unsigned length, unsigned) makeString(Thread* t, object odata, unsigned offset, unsigned length, unsigned)
{ {
if (offset == 0 and length == charArrayLength(t, data)) { GcCharArray* data = cast<GcCharArray>(t, odata);
return makeString(t, data, 0, 0); if (offset == 0 and length == data->length()) {
return makeString(t, reinterpret_cast<object>(data), 0, 0);
} else { } else {
PROTECT(t, data); PROTECT(t, data);
object array = reinterpret_cast<object>(makeCharArray(t, length)); GcCharArray* array = makeCharArray(t, length);
memcpy(&charArrayBody(t, array, 0), &charArrayBody(t, data, offset), memcpy(array->body().begin(), &data->body()[offset],
length * 2); length * 2);
return makeString(t, array, 0, 0); return makeString(t, reinterpret_cast<object>(array), 0, 0);
} }
} }
@ -3843,11 +3843,11 @@ resolveMethod(Thread* t, GcMethod* method, unsigned index, bool throw_ = true)
GcVector* GcVector*
vectorAppend(Thread*, GcVector*, object); vectorAppend(Thread*, GcVector*, object);
inline object inline GcClassRuntimeData*
getClassRuntimeDataIfExists(Thread* t, GcClass* c) getClassRuntimeDataIfExists(Thread* t, GcClass* c)
{ {
if (c->runtimeDataIndex()) { if (c->runtimeDataIndex()) {
return cast<GcVector>(t, root(t, Machine::ClassRuntimeDataTable))->body()[c->runtimeDataIndex() - 1]; return cast<GcClassRuntimeData>(t, cast<GcVector>(t, root(t, Machine::ClassRuntimeDataTable))->body()[c->runtimeDataIndex() - 1]);
} else { } else {
return 0; return 0;
} }

View File

@ -111,8 +111,7 @@ makeMethodOrConstructor(Thread* t, GcJclass* c, unsigned index)
{ {
PROTECT(t, c); PROTECT(t, c);
GcMethod* method = cast<GcMethod>(t, arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>(t, c->vmClass()->methodTable())->body()[index]);
(t, c->vmClass()->methodTable(), index));
PROTECT(t, method); PROTECT(t, method);
unsigned parameterCount; unsigned parameterCount;
@ -152,8 +151,8 @@ makeField(Thread* t, GcJclass* c, unsigned index)
{ {
PROTECT(t, c); PROTECT(t, c);
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, c->vmClass()->fieldTable(), index)); (t, c->vmClass()->fieldTable())->body()[index]);
PROTECT(t, field); PROTECT(t, field);
@ -249,16 +248,18 @@ class MyClasspath : public Classpath {
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object array, int32_t offset, int32_t length)
{ {
if (objectClass(t, array) == type(t, GcByteArray::Type)) { if (objectClass(t, array) == type(t, GcByteArray::Type)) {
GcByteArray* byteArray = cast<GcByteArray>(t, array);
PROTECT(t, array); PROTECT(t, array);
PROTECT(t, byteArray);
object charArray = reinterpret_cast<object>(makeCharArray(t, length)); GcCharArray* charArray = makeCharArray(t, length);
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
expect(t, (byteArrayBody(t, array, offset + i) & 0x80) == 0); expect(t, (byteArray->body()[offset + i] & 0x80) == 0);
charArrayBody(t, charArray, i) = byteArrayBody(t, array, offset + i); charArray->body()[i] = byteArray->body()[offset + i];
} }
array = charArray; array = reinterpret_cast<object>(charArray);
} else { } else {
expect(t, objectClass(t, array) == type(t, GcCharArray::Type)); expect(t, objectClass(t, array) == type(t, GcCharArray::Type));
} }
@ -312,9 +313,9 @@ class MyClasspath : public Classpath {
virtual object virtual object
makeJMethod(Thread* t, GcMethod* vmMethod) makeJMethod(Thread* t, GcMethod* vmMethod)
{ {
object table = vmMethod->class_()->methodTable(); GcArray* table = cast<GcArray>(t, vmMethod->class_()->methodTable());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
if (reinterpret_cast<object>(vmMethod) == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmMethod) == table->body()[i]) {
return makeMethodOrConstructor return makeMethodOrConstructor
(t, getJClass(t, vmMethod->class_()), i); (t, getJClass(t, vmMethod->class_()), i);
} }
@ -326,20 +327,20 @@ class MyClasspath : public Classpath {
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type)
? arrayBody ? cast<GcArray>
(t, jmethodDeclaringClass(t, jmethod)->vmClass()->methodTable(), (t, cast<GcJmethod>(t, jmethod)->declaringClass()->vmClass()->methodTable())
jmethodSlot(t, jmethod)) ->body()[cast<GcJmethod>(t, jmethod)->slot()]
: arrayBody : cast<GcArray>
(t, jconstructorDeclaringClass(t, jmethod)->vmClass()->methodTable(), (t, cast<GcJconstructor>(t, jmethod)->declaringClass()->vmClass()->methodTable())
jconstructorSlot(t, jmethod))); ->body()[cast<GcJconstructor>(t, jmethod)->slot()]);
} }
virtual object virtual object
makeJField(Thread* t, GcField* vmField) makeJField(Thread* t, GcField* vmField)
{ {
object table = vmField->class_()->fieldTable(); GcArray* table = cast<GcArray>(t, vmField->class_()->fieldTable());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
if (reinterpret_cast<object>(vmField) == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmField) == table->body()[i]) {
return makeField(t, getJClass(t, vmField->class_()), i); return makeField(t, getJClass(t, vmField->class_()), i);
} }
} }
@ -347,11 +348,11 @@ class MyClasspath : public Classpath {
} }
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, GcJfield* jfield)
{ {
return cast<GcField>(t, arrayBody return cast<GcField>(t, cast<GcArray>
(t, jfieldDeclaringClass(t, jfield)->vmClass()->fieldTable(), (t, jfield->declaringClass()->vmClass()->fieldTable())->body()
jfieldSlot(t, jfield))); [jfield->slot()]);
} }
virtual void virtual void
@ -790,35 +791,35 @@ setField(Thread* t, GcField* field, object instance, object value)
unsigned offset = field->offset(); unsigned offset = field->offset();
switch (field->code()) { switch (field->code()) {
case ByteField: case ByteField:
fieldAtOffset<int8_t>(target, offset) = byteValue(t, value); fieldAtOffset<int8_t>(target, offset) = cast<GcByte>(t, value)->value();
break; break;
case BooleanField: case BooleanField:
fieldAtOffset<int8_t>(target, offset) = booleanValue(t, value); fieldAtOffset<int8_t>(target, offset) = cast<GcBoolean>(t, value)->value();
break; break;
case CharField: case CharField:
fieldAtOffset<int16_t>(target, offset) = charValue(t, value); fieldAtOffset<int16_t>(target, offset) = cast<GcChar>(t, value)->value();
break; break;
case ShortField: case ShortField:
fieldAtOffset<int16_t>(target, offset) = shortValue(t, value); fieldAtOffset<int16_t>(target, offset) = cast<GcShort>(t, value)->value();
break; break;
case IntField: case IntField:
fieldAtOffset<int32_t>(target, offset) = intValue(t, value); fieldAtOffset<int32_t>(target, offset) = cast<GcInt>(t, value)->value();
break; break;
case LongField: case LongField:
fieldAtOffset<int64_t>(target, offset) = longValue(t, value); fieldAtOffset<int64_t>(target, offset) = cast<GcLong>(t, value)->value();
break; break;
case FloatField: case FloatField:
fieldAtOffset<int32_t>(target, offset) = floatValue(t, value); fieldAtOffset<int32_t>(target, offset) = cast<GcFloat>(t, value)->value();
break; break;
case DoubleField: case DoubleField:
fieldAtOffset<int64_t>(target, offset) = doubleValue(t, value); fieldAtOffset<int64_t>(target, offset) = cast<GcDouble>(t, value)->value();
break; break;
case ObjectField: case ObjectField:
@ -1028,14 +1029,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_String_isEmpty Avian_java_lang_String_isEmpty
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return stringLength(t, reinterpret_cast<object>(arguments[0])) == 0; return cast<GcString>(t, reinterpret_cast<object>(arguments[0]))->length(t) == 0;
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_String_length Avian_java_lang_String_length
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return stringLength(t, reinterpret_cast<object>(arguments[0])); return cast<GcString>(t, reinterpret_cast<object>(arguments[0]))->length(t);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1087,15 +1088,15 @@ Avian_java_lang_Class_getInterfaces
GcClassAddendum* addendum = c->vmClass()->addendum(); GcClassAddendum* addendum = c->vmClass()->addendum();
if (addendum) { if (addendum) {
object table = addendum->interfaceTable(); GcArray* table = cast<GcArray>(t, addendum->interfaceTable());
if (table) { if (table) {
PROTECT(t, table); PROTECT(t, table);
object array = makeObjectArray(t, arrayLength(t, table)); object array = makeObjectArray(t, table->length());
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
GcJclass* c = getJClass(t, cast<GcClass>(t, arrayBody(t, table, i))); GcJclass* c = getJClass(t, cast<GcClass>(t, table->body()[i]));
set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast<object>(c)); set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast<object>(c));
} }
@ -1113,7 +1114,7 @@ Avian_java_lang_Class_getDeclaredClasses
{ {
return reinterpret_cast<intptr_t> return reinterpret_cast<intptr_t>
(getDeclaredClasses (getDeclaredClasses
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass(),
arguments[1])); arguments[1]));
} }
@ -1123,14 +1124,14 @@ Avian_java_lang_Class_getDeclaringClass
{ {
return reinterpret_cast<intptr_t> return reinterpret_cast<intptr_t>
(getDeclaringClass (getDeclaringClass
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])))); (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_getEnclosingMethod Avian_java_lang_Class_getEnclosingMethod
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcClass* c = jclassVmClass(t, reinterpret_cast<object>(arguments[0])); GcClass* c = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass();
PROTECT(t, c); PROTECT(t, c);
GcClassAddendum* addendum = c->addendum(); GcClassAddendum* addendum = c->addendum();
@ -1174,7 +1175,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_newInstanceImpl Avian_java_lang_Class_newInstanceImpl
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcClass* c = jclassVmClass(t, reinterpret_cast<object>(arguments[0])); GcClass* c = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass();
GcMethod* method = resolveMethod(t, c, "<init>", "()V"); GcMethod* method = resolveMethod(t, c, "<init>", "()V");
PROTECT(t, method); PROTECT(t, method);
@ -1240,9 +1241,9 @@ Avian_java_lang_Class_getDeclaredField
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes", "findField", (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes", "findField",
"(Lavian/VMClass;Ljava/lang/String;)I"); "(Lavian/VMClass;Ljava/lang/String;)I");
int index = intValue int index = cast<GcInt>
(t, t->m->processor->invoke (t, t->m->processor->invoke
(t, method, 0, c->vmClass(), name)); (t, method, 0, c->vmClass(), name))->value();
if (index >= 0) { if (index >= 0) {
return reinterpret_cast<uintptr_t>(local::makeField(t, c, index)); return reinterpret_cast<uintptr_t>(local::makeField(t, c, index));
@ -1268,9 +1269,9 @@ Avian_java_lang_Class_getDeclaredConstructorOrMethod
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes", "findMethod", (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes", "findMethod",
"(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I"); "(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I");
int index = intValue int index = cast<GcInt>
(t, t->m->processor->invoke (t, t->m->processor->invoke
(t, method, 0, c->vmClass(), name, parameterTypes)); (t, method, 0, c->vmClass(), name, parameterTypes))->value();
if (index >= 0) { if (index >= 0) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
@ -1399,11 +1400,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_objectFieldOffset Avian_sun_misc_Unsafe_objectFieldOffset
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object jfield = reinterpret_cast<object>(arguments[1]); GcJfield* jfield = cast<GcJfield>(t, reinterpret_cast<object>(arguments[1]));
return fieldOffset return cast<GcField>
(t, arrayBody (t, cast<GcArray>
(t, jfieldDeclaringClass(t, jfield)->vmClass()->fieldTable(), (t, jfield->declaringClass()->vmClass()->fieldTable())
jfieldSlot(t, jfield))); ->body()[jfield->slot()])->offset();
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
@ -1418,7 +1419,7 @@ Avian_java_lang_VMThread_interrupt
interrupt interrupt
(t, reinterpret_cast<Thread*> (t, reinterpret_cast<Thread*>
(threadPeer(t, fieldAtOffset<object>(vmThread, field->offset())))); (cast<GcThread>(t, fieldAtOffset<object>(vmThread, field->offset()))->peer()));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1438,8 +1439,7 @@ Avian_java_lang_VMThread_isInterrupted
GcField* field = resolveField GcField* field = resolveField
(t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;"); (t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;");
return threadInterrupted return cast<GcThread>(t, fieldAtOffset<object>(vmThread, field->offset()))->interrupted();
(t, fieldAtOffset<object>(vmThread, field->offset()));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1491,7 +1491,7 @@ Avian_dalvik_system_VMStack_getThreadStackTrace
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
Thread* p = reinterpret_cast<Thread*> Thread* p = reinterpret_cast<Thread*>
(threadPeer(t, reinterpret_cast<object>(arguments[0]))); (cast<GcThread>(t, reinterpret_cast<object>(arguments[0]))->peer());
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(local::translateStackTrace (local::translateStackTrace
@ -1707,14 +1707,14 @@ Avian_java_lang_Class_getModifiers
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return classModifiers return classModifiers
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))); (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass());
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_getSuperclass Avian_java_lang_Class_getSuperclass
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcClass* c = jclassVmClass(t, reinterpret_cast<object>(arguments[0])); GcClass* c = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass();
if (c->flags() & ACC_INTERFACE) { if (c->flags() & ACC_INTERFACE) {
return 0; return 0;
} else { } else {
@ -1734,7 +1734,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_getNameNative Avian_java_lang_Class_getNameNative
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcByteArray* name = jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->name(); GcByteArray* name = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->name();
THREAD_RUNTIME_ARRAY(t, char, s, name->length()); THREAD_RUNTIME_ARRAY(t, char, s, name->length());
replace('/', '.', RUNTIME_ARRAY_BODY(s), replace('/', '.', RUNTIME_ARRAY_BODY(s),
@ -1748,7 +1748,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_isInterface Avian_java_lang_Class_isInterface
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return (jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->flags() return (cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->flags()
& ACC_INTERFACE) != 0; & ACC_INTERFACE) != 0;
} }
@ -1756,7 +1756,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_isPrimitive Avian_java_lang_Class_isPrimitive
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return (jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->vmFlags() return (cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->vmFlags()
& PrimitiveFlag) != 0; & PrimitiveFlag) != 0;
} }
@ -1764,7 +1764,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_isAnonymousClass Avian_java_lang_Class_isAnonymousClass
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcByteArray* name = jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->name(); GcByteArray* name = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->name();
for (unsigned i = 0; i < name->length() - 1; ++i) { for (unsigned i = 0; i < name->length() - 1; ++i) {
int c = name->body()[i]; int c = name->body()[i];
@ -1781,19 +1781,19 @@ Avian_java_lang_Class_getClassLoader
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->loader()); (cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->loader());
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_isAssignableFrom Avian_java_lang_Class_isAssignableFrom
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); GcJclass* this_ = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]));
object that = reinterpret_cast<object>(arguments[1]); GcJclass* that = cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]));
if (LIKELY(that)) { if (LIKELY(that)) {
return isAssignableFrom return isAssignableFrom
(t, jclassVmClass(t, this_), jclassVmClass(t, that)); (t, this_->vmClass(), that->vmClass());
} else { } else {
throwNew(t, GcNullPointerException::Type); throwNew(t, GcNullPointerException::Type);
} }
@ -1803,11 +1803,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_isInstance Avian_java_lang_Class_isInstance
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); GcJclass* this_ = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]));
object o = reinterpret_cast<object>(arguments[1]); object o = reinterpret_cast<object>(arguments[1]);
if (o) { if (o) {
return instanceOf(t, jclassVmClass(t, this_), o); return instanceOf(t, this_->vmClass(), o);
} else { } else {
return 0; return 0;
} }
@ -1853,9 +1853,9 @@ Avian_java_lang_reflect_Method_invokeNative
{ {
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
object args = reinterpret_cast<object>(arguments[2]); object args = reinterpret_cast<object>(arguments[2]);
GcMethod* method = cast<GcMethod>(t, arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[3]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[3]))->vmClass()->methodTable())
arguments[6])); ->body()[arguments[6]]);
return reinterpret_cast<uintptr_t>(invoke(t, method, instance, args)); return reinterpret_cast<uintptr_t>(invoke(t, method, instance, args));
} }
@ -1864,21 +1864,21 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_getMethodModifiers Avian_java_lang_reflect_Method_getMethodModifiers
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return methodFlags return cast<GcMethod>
(t, arrayBody (t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->methodTable())
arguments[1])); ->body()[arguments[1]])->flags();
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_isAnnotationPresent Avian_java_lang_reflect_Method_isAnnotationPresent
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->methodTable())
arguments[1]); ->body()[arguments[1]]);
GcMethodAddendum* addendum = methodAddendum(t, method); GcMethodAddendum* addendum = method->addendum();
if (addendum) { if (addendum) {
object table = addendum->annotationTable(); object table = addendum->annotationTable();
if (table) { if (table) {
@ -1899,11 +1899,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_getAnnotation Avian_java_lang_reflect_Method_getAnnotation
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->methodTable())
arguments[1]); ->body()[arguments[1]]);
GcMethodAddendum* addendum = methodAddendum(t, method); GcMethodAddendum* addendum = method->addendum();
if (addendum) { if (addendum) {
object table = addendum->annotationTable(); object table = addendum->annotationTable();
if (table) { if (table) {
@ -1921,7 +1921,7 @@ Avian_java_lang_reflect_Method_getAnnotation
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(t->m->processor->invoke (t->m->processor->invoke
(t, get, 0, methodClass(t, method)->loader(), (t, get, 0, method->class_()->loader(),
objectArrayBody(t, table, i))); objectArrayBody(t, table, i)));
} }
} }
@ -1935,11 +1935,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_getDeclaredAnnotations Avian_java_lang_reflect_Method_getDeclaredAnnotations
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->methodTable())
arguments[1]); ->body()[arguments[1]]);
GcMethodAddendum* addendum = methodAddendum(t, method); GcMethodAddendum* addendum = method->addendum();
if (addendum) { if (addendum) {
object table = addendum->annotationTable(); object table = addendum->annotationTable();
if (table) { if (table) {
@ -1960,7 +1960,7 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
object a = t->m->processor->invoke object a = t->m->processor->invoke
(t, get, 0, methodClass(t, method)->loader(), (t, get, 0, method->class_()->loader(),
objectArrayBody(t, table, i)); objectArrayBody(t, table, i));
set(t, array, ArrayBody + (i * BytesPerWord), a); set(t, array, ArrayBody + (i * BytesPerWord), a);
@ -1982,10 +1982,10 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
object, object,
uintptr_t* arguments) uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody( GcField* field = cast<GcField>(t, cast<GcArray>(
t, t,
jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(), cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->fieldTable())
arguments[1])); ->body()[arguments[1]]);
GcFieldAddendum* addendum = field->addendum(); GcFieldAddendum* addendum = field->addendum();
if (addendum) { if (addendum) {
@ -2015,7 +2015,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
= t->m->processor->invoke(t, = t->m->processor->invoke(t,
get, get,
0, 0,
classLoader(t, reinterpret_cast<object>(arguments[0])), cast<GcClass>(t, reinterpret_cast<object>(arguments[0]))->loader(),
objectArrayBody(t, table, i)); objectArrayBody(t, table, i));
set(t, array, ArrayBody + (i * BytesPerWord), a); set(t, array, ArrayBody + (i * BytesPerWord), a);
@ -2036,11 +2036,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_getDefaultValue Avian_java_lang_reflect_Method_getDefaultValue
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))->methodTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass()->methodTable())
arguments[2]); ->body()[arguments[2]]);
GcMethodAddendum* addendum = methodAddendum(t, method); GcMethodAddendum* addendum = method->addendum();
if (addendum) { if (addendum) {
GcMethod* get = resolveMethod GcMethod* get = resolveMethod
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes", (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "avian/Classes",
@ -2050,7 +2050,7 @@ Avian_java_lang_reflect_Method_getDefaultValue
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(t->m->processor->invoke (t->m->processor->invoke
(t, get, 0, methodClass(t, method)->loader(), addendum)); (t, get, 0, method->class_()->loader(), addendum));
} }
return 0; return 0;
@ -2063,12 +2063,12 @@ Avian_java_lang_reflect_Constructor_constructNative
object args = reinterpret_cast<object>(arguments[1]); object args = reinterpret_cast<object>(arguments[1]);
PROTECT(t, args); PROTECT(t, args);
GcClass* c = jclassVmClass(t, reinterpret_cast<object>(arguments[2])); GcClass* c = cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass();
PROTECT(t, c); PROTECT(t, c);
initClass(t, c); initClass(t, c);
GcMethod* method = cast<GcMethod>(t, arrayBody(t, c->methodTable(), arguments[4])); GcMethod* method = cast<GcMethod>(t, cast<GcArray>(t, c->methodTable())->body()[arguments[4]]);
PROTECT(t, method); PROTECT(t, method);
object instance = makeNew(t, c); object instance = makeNew(t, c);
@ -2083,9 +2083,9 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getField Avian_java_lang_reflect_Field_getField
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass()->fieldTable())
arguments[4])); ->body()[arguments[4]]);
PROTECT(t, field); PROTECT(t, field);
@ -2099,41 +2099,41 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getIField Avian_java_lang_reflect_Field_getIField
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass()->fieldTable())
arguments[4])); ->body()[arguments[4]]);
PROTECT(t, field); PROTECT(t, field);
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
PROTECT(t, instance); PROTECT(t, instance);
return intValue(t, local::getField(t, field, instance)); return cast<GcInt>(t, local::getField(t, field, instance))->value();
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getJField Avian_java_lang_reflect_Field_getJField
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass()->fieldTable())
arguments[4])); ->body()[arguments[4]]);
PROTECT(t, field); PROTECT(t, field);
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
PROTECT(t, instance); PROTECT(t, instance);
return longValue(t, local::getField(t, field, instance)); return cast<GcLong>(t, local::getField(t, field, instance))->value();
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
Avian_java_lang_reflect_Field_setField Avian_java_lang_reflect_Field_setField
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass()->fieldTable())
arguments[4])); ->body()[arguments[4]]);
PROTECT(t, field); PROTECT(t, field);
@ -2150,9 +2150,9 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_java_lang_reflect_Field_setIField Avian_java_lang_reflect_Field_setIField
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[2]))->vmClass()->fieldTable())
arguments[4])); ->body()[arguments[4]]);
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
PROTECT(t, instance); PROTECT(t, instance);
@ -2166,19 +2166,19 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getFieldModifiers Avian_java_lang_reflect_Field_getFieldModifiers
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return fieldFlags return cast<GcField>
(t, arrayBody (t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass()->fieldTable())
arguments[2])); ->body()[arguments[2]])->flags();
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getAnnotation Avian_java_lang_reflect_Field_getAnnotation
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass()->fieldTable())
arguments[1])); ->body()[arguments[1]]);
GcFieldAddendum* addendum = field->addendum(); GcFieldAddendum* addendum = field->addendum();
if (addendum) { if (addendum) {
@ -2212,19 +2212,19 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Field_getSignatureAnnotation Avian_java_lang_reflect_Field_getSignatureAnnotation
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcField* field = cast<GcField>(t, arrayBody GcField* field = cast<GcField>(t, cast<GcArray>
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))->fieldTable(), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass()->fieldTable())
arguments[2])); ->body()[arguments[2]]);
object addendum = reinterpret_cast<object>(field->addendum()); GcFieldAddendum* addendum = field->addendum();
if (addendum) { if (addendum) {
object signature = addendumSignature(t, addendum); GcByteArray* signature = cast<GcByteArray>(t, addendum->signature());
if (signature) { if (signature) {
object array = makeObjectArray(t, 1); object array = makeObjectArray(t, 1);
PROTECT(t, array); PROTECT(t, array);
GcString* string = t->m->classpath->makeString GcString* string = t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1); (t, reinterpret_cast<object>(signature), 0, signature->length() - 1);
set(t, array, ArrayBody, reinterpret_cast<object>(string)); set(t, array, ArrayBody, reinterpret_cast<object>(string));
@ -2274,7 +2274,7 @@ Avian_java_lang_reflect_Array_createObjectArray
{ {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeObjectArray (makeObjectArray
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])), (t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass(),
arguments[1])); arguments[1]));
} }
@ -2289,15 +2289,15 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_dalvik_system_VMRuntime_newNonMovableArray Avian_dalvik_system_VMRuntime_newNonMovableArray
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
if (jclassVmClass(t, reinterpret_cast<object>(arguments[1])) if (cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass()
== type(t, GcJbyte::Type)) == type(t, GcJbyte::Type))
{ {
object array = allocate3 GcByteArray* array = reinterpret_cast<GcByteArray*>(allocate3
(t, t->m->heap, Machine::FixedAllocation, (t, t->m->heap, Machine::FixedAllocation,
ArrayBody + arguments[2], false); ArrayBody + arguments[2], false));
setObjectClass(t, array, type(t, GcByteArray::Type)); setObjectClass(t, reinterpret_cast<object>(array), type(t, GcByteArray::Type));
byteArrayLength(t, array) = arguments[2]; array->length() = arguments[2];
return reinterpret_cast<intptr_t>(array); return reinterpret_cast<intptr_t>(array);
} else { } else {
@ -2427,7 +2427,7 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_libcore_io_OsConstants_initConstants Avian_libcore_io_OsConstants_initConstants
(Thread* t, object method, uintptr_t*) (Thread* t, object method, uintptr_t*)
{ {
object c = methodClass(t, method); object c = method->class_();
PROTECT(t, c); PROTECT(t, c);
object table = classStaticTable(t, c); object table = classStaticTable(t, c);

View File

@ -82,9 +82,9 @@ class MyClasspath : public Classpath {
} }
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t UNUSED, GcJfield* jfield)
{ {
return cast<GcJfield>(t, jfield)->vmField(); return jfield->vmField();
} }
virtual void virtual void

View File

@ -316,7 +316,7 @@ primitiveName(Thread* t, GcClass* c)
} }
} }
object GcByteArray*
getClassName(Thread* t, GcClass* c) getClassName(Thread* t, GcClass* c)
{ {
if (c->name() == 0) { if (c->name() == 0) {
@ -331,15 +331,15 @@ getClassName(Thread* t, GcClass* c)
} }
} }
return reinterpret_cast<object>(c->name()); return c->name();
} }
GcString* GcString*
makeClassNameString(Thread* t, object name) makeClassNameString(Thread* t, GcByteArray* name)
{ {
THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, name)); THREAD_RUNTIME_ARRAY(t, char, s, name->length());
replace('/', '.', RUNTIME_ARRAY_BODY(s), replace('/', '.', RUNTIME_ARRAY_BODY(s),
reinterpret_cast<char*>(&byteArrayBody(t, name, 0))); reinterpret_cast<char*>(name->body().begin()));
return makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); return makeString(t, "%s", RUNTIME_ARRAY_BODY(s));
} }
@ -498,14 +498,15 @@ class MyClasspath : public Classpath {
} }
virtual GcString* virtual GcString*
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object oarray, int32_t offset, int32_t length)
{ {
if (objectClass(t, array) == type(t, GcByteArray::Type)) { if (objectClass(t, oarray) == type(t, GcByteArray::Type)) {
GcByteArray* array = cast<GcByteArray>(t, oarray);
PROTECT(t, array); PROTECT(t, array);
GcCharArray* charArray = makeCharArray(t, length); GcCharArray* charArray = makeCharArray(t, length);
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
if (byteArrayBody(t, array, offset + i) & 0x80) { if (array->body()[offset + i] & 0x80) {
GcMethod* constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, type(t, GcString::Type), "<init>", (t, type(t, GcString::Type), "<init>",
"([BIILjava/lang/String;)V"); "([BIILjava/lang/String;)V");
@ -523,15 +524,15 @@ class MyClasspath : public Classpath {
return cast<GcString>(t, s); return cast<GcString>(t, s);
} }
charArrayBody(t, reinterpret_cast<object>(charArray), i) = byteArrayBody(t, array, offset + i); charArray->body()[i] = array->body()[offset + i];
} }
array = reinterpret_cast<object>(charArray); oarray = reinterpret_cast<object>(charArray);
} else { } else {
expect(t, objectClass(t, array) == type(t, GcCharArray::Type)); expect(t, objectClass(t, oarray) == type(t, GcCharArray::Type));
} }
return vm::makeString(t, array, offset, length, 0); return vm::makeString(t, oarray, offset, length, 0);
} }
virtual GcThread* virtual GcThread*
@ -591,13 +592,21 @@ class MyClasspath : public Classpath {
virtual GcMethod* virtual GcMethod*
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(
? arrayBody t,
(t, jmethodClazz(t, jmethod)->vmClass()->methodTable(), objectClass(t, jmethod) == type(t, GcJmethod::Type)
jmethodSlot(t, jmethod)) ? cast<GcArray>(t,
: arrayBody cast<GcJmethod>(t, jmethod)
(t, jconstructorClazz(t, jmethod)->vmClass()->methodTable(), ->clazz()
jconstructorSlot(t, jmethod))); ->vmClass()
->methodTable())
->body()[cast<GcJmethod>(t, jmethod)->slot()]
: cast<GcArray>(t,
cast<GcJconstructor>(t, jmethod)
->clazz()
->vmClass()
->methodTable())
->body()[cast<GcJconstructor>(t, jmethod)->slot()]);
} }
virtual object virtual object
@ -607,10 +616,12 @@ class MyClasspath : public Classpath {
} }
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, GcJfield* jfield)
{ {
return cast<GcField>(t, arrayBody return cast
(t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield))); <GcField>(t,
cast<GcArray>(t, jfield->clazz()->vmClass()->fieldTable())
->body()[jfield->slot()]);
} }
virtual void virtual void
@ -2109,17 +2120,17 @@ classDeclaredMethodCount(Thread* t, GcClass* c)
return count; return count;
} }
} }
object table = c->methodTable(); GcArray* table = cast<GcArray>(t, c->methodTable());
return table == 0 ? 0 : arrayLength(t, table); return table == 0 ? 0 : table->length();
} }
unsigned unsigned
countMethods(Thread* t, GcClass* c, bool publicOnly) countMethods(Thread* t, GcClass* c, bool publicOnly)
{ {
object table = c->methodTable(); GcArray* table = cast<GcArray>(t, c->methodTable());
unsigned count = 0; unsigned count = 0;
for (unsigned i = 0, j = classDeclaredMethodCount(t, c); i < j; ++i) { for (unsigned i = 0, j = classDeclaredMethodCount(t, c); i < j; ++i) {
GcMethod* vmMethod = cast<GcMethod>(t, arrayBody(t, table, i)); GcMethod* vmMethod = cast<GcMethod>(t, table->body()[i]);
if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC)) if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC))
and vmMethod->name()->body()[0] != '<') and vmMethod->name()->body()[0] != '<')
{ {
@ -2132,28 +2143,28 @@ countMethods(Thread* t, GcClass* c, bool publicOnly)
unsigned unsigned
countFields(Thread* t, GcClass* c, bool publicOnly) countFields(Thread* t, GcClass* c, bool publicOnly)
{ {
object table = c->fieldTable(); GcArray* table = cast<GcArray>(t, c->fieldTable());
if (publicOnly) { if (publicOnly) {
unsigned count = 0; unsigned count = 0;
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
GcField* vmField = cast<GcField>(t, arrayBody(t, table, i)); GcField* vmField = cast<GcField>(t, table->body()[i]);
if (vmField->flags() & ACC_PUBLIC) { if (vmField->flags() & ACC_PUBLIC) {
++ count; ++ count;
} }
} }
return count; return count;
} else { } else {
return objectArrayLength(t, table); return objectArrayLength(t, reinterpret_cast<object>(table));
} }
} }
unsigned unsigned
countConstructors(Thread* t, GcClass* c, bool publicOnly) countConstructors(Thread* t, GcClass* c, bool publicOnly)
{ {
object table = c->methodTable(); GcArray* table = cast<GcArray>(t, c->methodTable());
unsigned count = 0; unsigned count = 0;
for (unsigned i = 0, j = classDeclaredMethodCount(t, c); i < j; ++i) { for (unsigned i = 0, j = classDeclaredMethodCount(t, c); i < j; ++i) {
GcMethod* vmMethod = cast<GcMethod>(t, arrayBody(t, table, i)); GcMethod* vmMethod = cast<GcMethod>(t, table->body()[i]);
if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC)) if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC))
and strcmp(reinterpret_cast<char*> and strcmp(reinterpret_cast<char*>
(vmMethod->name()->body().begin()), (vmMethod->name()->body().begin()),
@ -2249,22 +2260,21 @@ makeJmethod(Thread* t, GcMethod* vmMethod, int index)
object annotationTable; object annotationTable;
object parameterAnnotationTable; object parameterAnnotationTable;
object annotationDefault; object annotationDefault;
object addendum = reinterpret_cast<object>(vmMethod->addendum()); GcMethodAddendum* addendum = vmMethod->addendum();
if (addendum) { if (addendum) {
signature = addendumSignature(t, addendum); signature = addendum->signature();
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
signature = reinterpret_cast<object>(t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1)); (t, signature, 0, cast<GcByteArray>(t, signature)->length() - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendum->annotationTable();
parameterAnnotationTable = methodAddendumParameterAnnotationTable parameterAnnotationTable = addendum->parameterAnnotationTable();
(t, addendum);
annotationDefault = methodAddendumAnnotationDefault(t, addendum); annotationDefault = addendum->annotationDefault();
} else { } else {
signature = 0; signature = 0;
annotationTable = 0; annotationTable = 0;
@ -2285,9 +2295,9 @@ makeJmethod(Thread* t, GcMethod* vmMethod, int index)
} }
if (index == -1) { if (index == -1) {
object table = vmMethod->class_()->methodTable(); GcArray* table = cast<GcArray>(t, vmMethod->class_()->methodTable());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
if (reinterpret_cast<object>(vmMethod) == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmMethod) == table->body()[i]) {
index = i; index = i;
break; break;
} }
@ -2324,19 +2334,18 @@ makeJconstructor(Thread* t, GcMethod* vmMethod, int index)
object signature; object signature;
object annotationTable; object annotationTable;
object parameterAnnotationTable; object parameterAnnotationTable;
object addendum = reinterpret_cast<object>(vmMethod->addendum()); GcMethodAddendum* addendum = vmMethod->addendum();
if (addendum) { if (addendum) {
signature = addendumSignature(t, addendum); signature = addendum->signature();
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
signature = reinterpret_cast<object>(t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1)); (t, signature, 0, cast<GcByteArray>(t, signature)->length() - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendum->annotationTable();
parameterAnnotationTable = methodAddendumParameterAnnotationTable parameterAnnotationTable = addendum->parameterAnnotationTable();
(t, addendum);
} else { } else {
signature = 0; signature = 0;
annotationTable = 0; annotationTable = 0;
@ -2355,9 +2364,9 @@ makeJconstructor(Thread* t, GcMethod* vmMethod, int index)
} }
if (index == -1) { if (index == -1) {
object table = vmMethod->class_()->methodTable(); GcArray* table = cast<GcArray>(t, vmMethod->class_()->methodTable());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
if (reinterpret_cast<object>(vmMethod) == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmMethod) == table->body()[i]) {
index = i; index = i;
break; break;
} }
@ -2414,7 +2423,7 @@ makeJfield(Thread* t, GcField* vmField, int index)
PROTECT(t, addendum); PROTECT(t, addendum);
signature = reinterpret_cast<object>(t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1)); (t, signature, 0, cast<GcByteArray>(t, signature)->length() - 1));
} }
annotationTable = addendum->annotationTable(); annotationTable = addendum->annotationTable();
@ -2434,9 +2443,9 @@ makeJfield(Thread* t, GcField* vmField, int index)
} }
if (index == -1) { if (index == -1) {
object table = vmField->class_()->fieldTable(); GcArray* table = cast<GcArray>(t, vmField->class_()->fieldTable());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
if (reinterpret_cast<object>(vmField) == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmField) == table->body()[i]) {
index = i; index = i;
break; break;
} }
@ -2511,7 +2520,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_getSuperclass Avian_java_lang_Class_getSuperclass
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcClass* class_ = jclassVmClass(t, reinterpret_cast<object>(arguments[0])); GcClass* class_ = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass();
if (class_->flags() & ACC_INTERFACE) { if (class_->flags() & ACC_INTERFACE) {
return 0; return 0;
} else { } else {
@ -2557,7 +2566,7 @@ Avian_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoade
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
//object name = reinterpret_cast<object>(arguments[1]); //object name = reinterpret_cast<object>(arguments[1]);
object data = reinterpret_cast<object>(arguments[2]); GcByteArray* data = cast<GcByteArray>(t, reinterpret_cast<object>(arguments[2]));
int32_t offset = arguments[3]; int32_t offset = arguments[3];
int32_t length = arguments[4]; int32_t length = arguments[4];
GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[5])); GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[5]));
@ -2568,7 +2577,7 @@ Avian_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoade
THREAD_RESOURCE2(t, uint8_t*, buffer, int, length, THREAD_RESOURCE2(t, uint8_t*, buffer, int, length,
t->m->heap->free(buffer, length)); t->m->heap->free(buffer, length));
memcpy(buffer, &byteArrayBody(t, data, offset), length); memcpy(buffer, &data->body()[offset], length);
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(getJClass(t, cast<GcClass>(t, defineClass(t, loader, buffer, length)))); (getJClass(t, cast<GcClass>(t, defineClass(t, loader, buffer, length))));
@ -2578,7 +2587,7 @@ extern "C" AVIAN_EXPORT int64_t
Avian_sun_misc_Unsafe_allocateInstance Avian_sun_misc_Unsafe_allocateInstance
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
GcClass* c = jclassVmClass(t, reinterpret_cast<object>(arguments[1])); GcClass* c = cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass();
PROTECT(t, c); PROTECT(t, c);
initClass(t, c); initClass(t, c);
@ -2590,10 +2599,10 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_staticFieldOffset Avian_sun_misc_Unsafe_staticFieldOffset
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object jfield = reinterpret_cast<object>(arguments[1]); GcJfield* jfield = cast<GcJfield>(t, reinterpret_cast<object>(arguments[1]));
return fieldOffset return cast<GcField>
(t, arrayBody (t, cast<GcArray>
(t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield))); (t, jfield->clazz()->vmClass()->fieldTable())->body()[jfield->slot()])->offset();
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -2601,17 +2610,17 @@ Avian_sun_misc_Unsafe_staticFieldBase
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(jfieldClazz(t, reinterpret_cast<object>(arguments[1]))->vmClass()->staticTable()); (cast<GcJfield>(t, reinterpret_cast<object>(arguments[1]))->clazz()->vmClass()->staticTable());
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_objectFieldOffset Avian_sun_misc_Unsafe_objectFieldOffset
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object jfield = reinterpret_cast<object>(arguments[1]); GcJfield* jfield = cast<GcJfield>(t, reinterpret_cast<object>(arguments[1]));
return fieldOffset return cast<GcField>
(t, arrayBody (t, cast<GcArray>
(t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield))); (t, jfield->clazz()->vmClass()->fieldTable())->body()[jfield->slot()])->offset();
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -2778,7 +2787,7 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_ensureClassInitialized Avian_sun_misc_Unsafe_ensureClassInitialized
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
initClass(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))); initClass(t, cast<GcJclass>(t, reinterpret_cast<object>(arguments[1]))->vmClass());
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
@ -3212,7 +3221,7 @@ EXPORT(JVM_GetStackTraceDepth)(Thread* t, jobject throwable)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
return objectArrayLength(t, throwableTrace(t, *throwable)); return objectArrayLength(t, cast<GcThrowable>(t, *throwable)->trace());
} }
uint64_t uint64_t
@ -3224,7 +3233,7 @@ jvmGetStackTraceElement(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference (makeLocalReference
(t, reinterpret_cast<object>(makeStackTraceElement (t, reinterpret_cast<object>(makeStackTraceElement
(t, cast<GcTraceElement>(t, objectArrayBody(t, throwableTrace(t, *throwable), index)))))); (t, cast<GcTraceElement>(t, objectArrayBody(t, cast<GcThrowable>(t, *throwable)->trace(), index))))));
} }
extern "C" AVIAN_EXPORT jobject JNICALL extern "C" AVIAN_EXPORT jobject JNICALL
@ -3293,7 +3302,7 @@ EXPORT(JVM_IsThreadAlive)(Thread* t, jobject thread)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
Thread* p = reinterpret_cast<Thread*>(threadPeer(t, *thread)); Thread* p = reinterpret_cast<Thread*>(cast<GcThread>(t, *thread)->peer());
return p and (p->flags & Thread::ActiveFlag) != 0; return p and (p->flags & Thread::ActiveFlag) != 0;
} }
@ -3484,8 +3493,7 @@ jvmGetClassContext(Thread* t, uintptr_t*)
for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) { for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) {
object c = reinterpret_cast<object>(getJClass( object c = reinterpret_cast<object>(getJClass(
t, t,
methodClass(t, cast<GcMethod>(t, cast<GcTraceElement>(t, objectArrayBody(t, trace, i))->method())->class_()));
traceElementMethod(t, objectArrayBody(t, trace, i)))));
set(t, context, ArrayBody + (i * BytesPerWord), c); set(t, context, ArrayBody + (i * BytesPerWord), c);
} }
@ -3517,14 +3525,14 @@ jvmGetSystemPackage(Thread* t, uintptr_t* arguments)
object key = reinterpret_cast<object>(makeByteArray(t, RUNTIME_ARRAY_BODY(chars))); object key = reinterpret_cast<object>(makeByteArray(t, RUNTIME_ARRAY_BODY(chars)));
object array = hashMapFind GcByteArray* array = cast<GcByteArray>(t, hashMapFind
(t, cast<GcHashMap>(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); (t, cast<GcHashMap>(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual));
if (array) { if (array) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, reinterpret_cast<object>(t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, array, 0, byteArrayLength(t, array))))); (t, reinterpret_cast<object>(array), 0, array->length()))));
} else { } else {
return 0; return 0;
} }
@ -3681,28 +3689,28 @@ EXPORT(JVM_SetArrayElement)(Thread* t, jobject array, jint index,
switch (objectClass(t, *array)->name()->body()[1]) { switch (objectClass(t, *array)->name()->body()[1]) {
case 'Z': case 'Z':
fieldAtOffset<int8_t>(*array, ArrayBody + index) = booleanValue(t, *value); fieldAtOffset<int8_t>(*array, ArrayBody + index) = cast<GcBoolean>(t, *value)->value();
break; break;
case 'B': case 'B':
fieldAtOffset<int8_t>(*array, ArrayBody + index) = byteValue(t, *value); fieldAtOffset<int8_t>(*array, ArrayBody + index) = cast<GcByte>(t, *value)->value();
break; break;
case 'C': case 'C':
fieldAtOffset<int16_t>(*array, ArrayBody + (index * 2)) = charValue(t, *value); fieldAtOffset<int16_t>(*array, ArrayBody + (index * 2)) = cast<GcChar>(t, *value)->value();
break; break;
case 'S': case 'S':
fieldAtOffset<int16_t>(*array, ArrayBody + (index * 2)) = shortValue(t, *value); fieldAtOffset<int16_t>(*array, ArrayBody + (index * 2)) = cast<GcShort>(t, *value)->value();
break; break;
case 'I': case 'I':
fieldAtOffset<int32_t>(*array, ArrayBody + (index * 4)) = intValue(t, *value); fieldAtOffset<int32_t>(*array, ArrayBody + (index * 4)) = cast<GcInt>(t, *value)->value();
break; break;
case 'F': case 'F':
fieldAtOffset<int32_t>(*array, ArrayBody + (index * 4)) = floatValue(t, *value); fieldAtOffset<int32_t>(*array, ArrayBody + (index * 4)) = cast<GcFloat>(t, *value)->value();
break; break;
case 'J': case 'J':
fieldAtOffset<int64_t>(*array, ArrayBody + (index * 8)) = longValue(t, *value); fieldAtOffset<int64_t>(*array, ArrayBody + (index * 8)) = cast<GcLong>(t, *value)->value();
break; break;
case 'D': case 'D':
fieldAtOffset<int64_t>(*array, ArrayBody + (index * 8)) = doubleValue(t, *value); fieldAtOffset<int64_t>(*array, ArrayBody + (index * 8)) = cast<GcDouble>(t, *value)->value();
break; break;
case 'L': case 'L':
case '[': case '[':
@ -3718,11 +3726,11 @@ EXPORT(JVM_SetPrimitiveArrayElement)(Thread*, jobject, jint, jvalue,
unsigned char) { abort(); } unsigned char) { abort(); }
object object
makeNewArray(Thread* t, object c, unsigned length) makeNewArray(Thread* t, GcClass* c, unsigned length)
{ {
if (classVmFlags(t, c) & PrimitiveFlag) { if (c->vmFlags() & PrimitiveFlag) {
const char* name = reinterpret_cast<char*> const char* name = reinterpret_cast<char*>
(&byteArrayBody(t, local::getClassName(t, cast<GcClass>(t, c)), 0)); (local::getClassName(t, c)->body().begin());
switch (*name) { switch (*name) {
case 'b': case 'b':
@ -3740,7 +3748,7 @@ makeNewArray(Thread* t, object c, unsigned length)
default: abort(t); default: abort(t);
} }
} else { } else {
return reinterpret_cast<object>(makeObjectArray(t, cast<GcClass>(t, c), length)); return reinterpret_cast<object>(makeObjectArray(t, c, length));
} }
} }
@ -3752,7 +3760,7 @@ jvmNewArray(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference (makeLocalReference
(t, makeNewArray(t, reinterpret_cast<object>((*elementClass)->vmClass()), length))); (t, makeNewArray(t, (*elementClass)->vmClass(), length)));
} }
extern "C" AVIAN_EXPORT jobject JNICALL extern "C" AVIAN_EXPORT jobject JNICALL
@ -3781,7 +3789,7 @@ jvmNewMultiArray(Thread* t, uintptr_t* arguments)
} }
object array = makeNewArray object array = makeNewArray
(t, reinterpret_cast<object>((*elementClass)->vmClass()), RUNTIME_ARRAY_BODY(counts)[0]); (t, (*elementClass)->vmClass(), RUNTIME_ARRAY_BODY(counts)[0]);
PROTECT(t, array); PROTECT(t, array);
populateMultiArray(t, array, RUNTIME_ARRAY_BODY(counts), 0, populateMultiArray(t, array, RUNTIME_ARRAY_BODY(counts), 0,
@ -4001,16 +4009,16 @@ jvmGetClassInterfaces(Thread* t, uintptr_t* arguments)
GcClassAddendum* addendum = (*c)->vmClass()->addendum(); GcClassAddendum* addendum = (*c)->vmClass()->addendum();
if (addendum) { if (addendum) {
object table = addendum->interfaceTable(); GcArray* table = cast<GcArray>(t, addendum->interfaceTable());
if (table) { if (table) {
PROTECT(t, table); PROTECT(t, table);
object array = makeObjectArray object array = makeObjectArray
(t, type(t, GcJclass::Type), arrayLength(t, table)); (t, type(t, GcJclass::Type), table->length());
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
object c = reinterpret_cast<object>(getJClass(t, cast<GcClass>(t, arrayBody(t, table, i)))); object c = reinterpret_cast<object>(getJClass(t, cast<GcClass>(t, table->body()[i])));
set(t, array, ArrayBody + (i * BytesPerWord), c); set(t, array, ArrayBody + (i * BytesPerWord), c);
} }
@ -4070,10 +4078,10 @@ EXPORT(JVM_GetClassSigners)(Thread* t, jclass c)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object runtimeData = getClassRuntimeDataIfExists(t, (*c)->vmClass()); GcClassRuntimeData* runtimeData = getClassRuntimeDataIfExists(t, (*c)->vmClass());
return runtimeData ? reinterpret_cast<jobjectArray>(makeLocalReference return runtimeData ? reinterpret_cast<jobjectArray>(makeLocalReference
(t, classRuntimeDataSigners(t, runtimeData))) : 0; (t, runtimeData->signers())) : 0;
} }
extern "C" AVIAN_EXPORT jbyteArray JNICALL extern "C" AVIAN_EXPORT jbyteArray JNICALL
@ -4177,7 +4185,7 @@ uint64_t
jvmGetClassModifiers(Thread* t, uintptr_t* arguments) jvmGetClassModifiers(Thread* t, uintptr_t* arguments)
{ {
return classModifiers return classModifiers
(t, jclassVmClass(t, *reinterpret_cast<jobject>(arguments[0]))); (t, cast<GcJclass>(t, *reinterpret_cast<jobject>(arguments[0]))->vmClass());
} }
extern "C" AVIAN_EXPORT jint JNICALL extern "C" AVIAN_EXPORT jint JNICALL
@ -4194,7 +4202,7 @@ jvmGetDeclaredClasses(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, getDeclaredClasses (t, getDeclaredClasses
(t, jclassVmClass(t, *reinterpret_cast<jobject>(arguments[0])), false))); (t, cast<GcJclass>(t, *reinterpret_cast<jobject>(arguments[0]))->vmClass(), false)));
} }
extern "C" AVIAN_EXPORT jobjectArray JNICALL extern "C" AVIAN_EXPORT jobjectArray JNICALL
@ -4211,7 +4219,7 @@ jvmGetDeclaringClass(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, reinterpret_cast<object>(getDeclaringClass (t, reinterpret_cast<object>(getDeclaringClass
(t, jclassVmClass(t, *reinterpret_cast<jobject>(arguments[0])))))); (t, cast<GcJclass>(t, *reinterpret_cast<jobject>(arguments[0]))->vmClass()))));
} }
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
@ -4229,12 +4237,12 @@ jvmGetClassSignature(Thread* t, uintptr_t* arguments)
GcClassAddendum* addendum = (*c)->vmClass()->addendum(); GcClassAddendum* addendum = (*c)->vmClass()->addendum();
if (addendum) { if (addendum) {
object signature = addendum->signature(); GcByteArray* signature = cast<GcByteArray>(t, addendum->signature());
if (signature) { if (signature) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, reinterpret_cast<object>(t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1)))); (t, reinterpret_cast<object>(signature), 0, signature->length() - 1))));
} }
} }
return 0; return 0;
@ -4264,7 +4272,7 @@ jvmGetClassDeclaredMethods(Thread* t, uintptr_t* arguments)
jclass c = reinterpret_cast<jclass>(arguments[0]); jclass c = reinterpret_cast<jclass>(arguments[0]);
jboolean publicOnly = arguments[1]; jboolean publicOnly = arguments[1];
object table = (*c)->vmClass()->methodTable(); GcArray* table = cast<GcArray>(t, (*c)->vmClass()->methodTable());
if (table) { if (table) {
PROTECT(t, table); PROTECT(t, table);
@ -4277,7 +4285,7 @@ jvmGetClassDeclaredMethods(Thread* t, uintptr_t* arguments)
for (unsigned i = 0, j = classDeclaredMethodCount(t, (*c)->vmClass()); for (unsigned i = 0, j = classDeclaredMethodCount(t, (*c)->vmClass());
i < j; ++i) i < j; ++i)
{ {
GcMethod* vmMethod = cast<GcMethod>(t, arrayBody(t, table, i)); GcMethod* vmMethod = cast<GcMethod>(t, table->body()[i]);
PROTECT(t, vmMethod); PROTECT(t, vmMethod);
if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC)) if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC))
@ -4313,7 +4321,7 @@ jvmGetClassDeclaredFields(Thread* t, uintptr_t* arguments)
{ {
jclass c = reinterpret_cast<jclass>(arguments[0]); jclass c = reinterpret_cast<jclass>(arguments[0]);
jboolean publicOnly = arguments[1]; jboolean publicOnly = arguments[1];
object table = (*c)->vmClass()->fieldTable(); GcArray* table = cast<GcArray>(t, (*c)->vmClass()->fieldTable());
if (table) { if (table) {
PROTECT(t, table); PROTECT(t, table);
@ -4323,8 +4331,8 @@ jvmGetClassDeclaredFields(Thread* t, uintptr_t* arguments)
PROTECT(t, array); PROTECT(t, array);
unsigned ai = 0; unsigned ai = 0;
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < table->length(); ++i) {
GcField* vmField = cast<GcField>(t, arrayBody(t, table, i)); GcField* vmField = cast<GcField>(t, table->body()[i]);
PROTECT(t, vmField); PROTECT(t, vmField);
if ((not publicOnly) or (vmField->flags() & ACC_PUBLIC)) { if ((not publicOnly) or (vmField->flags() & ACC_PUBLIC)) {
@ -4360,7 +4368,7 @@ jvmGetClassDeclaredConstructors(Thread* t, uintptr_t* arguments)
jclass c = reinterpret_cast<jclass>(arguments[0]); jclass c = reinterpret_cast<jclass>(arguments[0]);
jboolean publicOnly = arguments[1]; jboolean publicOnly = arguments[1];
object table = (*c)->vmClass()->methodTable(); GcArray* table = cast<GcArray>(t, (*c)->vmClass()->methodTable());
if (table) { if (table) {
PROTECT(t, table); PROTECT(t, table);
@ -4373,7 +4381,7 @@ jvmGetClassDeclaredConstructors(Thread* t, uintptr_t* arguments)
for (unsigned i = 0, j = classDeclaredMethodCount(t, (*c)->vmClass()); for (unsigned i = 0, j = classDeclaredMethodCount(t, (*c)->vmClass());
i < j; ++i) i < j; ++i)
{ {
GcMethod* vmMethod = cast<GcMethod>(t, arrayBody(t, table, i)); GcMethod* vmMethod = cast<GcMethod>(t, table->body()[i]);
PROTECT(t, vmMethod); PROTECT(t, vmMethod);
if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC)) if (((not publicOnly) or (vmMethod->flags() & ACC_PUBLIC))
@ -4422,9 +4430,9 @@ jvmInvokeMethod(Thread* t, uintptr_t* arguments)
jobject instance = reinterpret_cast<jobject>(arguments[1]); jobject instance = reinterpret_cast<jobject>(arguments[1]);
jobjectArray args = reinterpret_cast<jobjectArray>(arguments[2]); jobjectArray args = reinterpret_cast<jobjectArray>(arguments[2]);
GcMethod* vmMethod = cast<GcMethod>(t, arrayBody GcMethod* vmMethod = cast<GcMethod>(t, cast<GcArray>
(t, jmethodClazz(t, *method)->vmClass()->methodTable(), (t, cast<GcJmethod>(t, *method)->clazz()->vmClass()->methodTable())->body()[
jmethodSlot(t, *method))); cast<GcJmethod>(t, *method)->slot()]);
if (vmMethod->flags() & ACC_STATIC) { if (vmMethod->flags() & ACC_STATIC) {
instance = 0; instance = 0;
@ -4458,12 +4466,12 @@ jvmNewInstanceFromConstructor(Thread* t, uintptr_t* arguments)
jobjectArray args = reinterpret_cast<jobjectArray>(arguments[1]); jobjectArray args = reinterpret_cast<jobjectArray>(arguments[1]);
object instance = make object instance = make
(t, jconstructorClazz(t, *constructor)->vmClass()); (t, cast<GcJconstructor>(t, *constructor)->clazz()->vmClass());
PROTECT(t, instance); PROTECT(t, instance);
GcMethod* method = cast<GcMethod>(t, arrayBody GcMethod* method = cast<GcMethod>(t, cast<GcArray>
(t, jconstructorClazz(t, *constructor)->vmClass()->methodTable(), (t, cast<GcJconstructor>(t, *constructor)->clazz()->vmClass()->methodTable())->body()[
jconstructorSlot(t, *constructor))); cast<GcJconstructor>(t, *constructor)->slot()]);
invoke(t, method, reinterpret_cast<object>(instance), args ? reinterpret_cast<object>(*args) : 0); invoke(t, method, reinterpret_cast<object>(instance), args ? reinterpret_cast<object>(*args) : 0);
@ -5265,20 +5273,20 @@ getEnclosingMethodInfo(Thread* t, uintptr_t* arguments)
set(t, array, ArrayBody, enclosingClass); set(t, array, ArrayBody, enclosingClass);
object enclosingMethod = addendum->enclosingMethod(); GcPair* enclosingMethod = cast<GcPair>(t, addendum->enclosingMethod());
if (enclosingMethod) { if (enclosingMethod) {
PROTECT(t, enclosingMethod); PROTECT(t, enclosingMethod);
GcString* name = t->m->classpath->makeString GcString* name = t->m->classpath->makeString
(t, pairFirst(t, enclosingMethod), 0, (t, enclosingMethod->first(), 0,
byteArrayLength(t, pairFirst(t, enclosingMethod)) - 1); cast<GcByteArray>(t, enclosingMethod->first())->length() - 1);
set(t, array, ArrayBody + BytesPerWord, reinterpret_cast<object>(name)); set(t, array, ArrayBody + BytesPerWord, reinterpret_cast<object>(name));
GcString* spec = t->m->classpath->makeString GcString* spec = t->m->classpath->makeString
(t, pairSecond(t, enclosingMethod), 0, (t, enclosingMethod->second(), 0,
byteArrayLength(t, pairSecond(t, enclosingMethod)) - 1); cast<GcByteArray>(t, enclosingMethod->second())->length() - 1);
set(t, array, ArrayBody + (2 * BytesPerWord), reinterpret_cast<object>(spec)); set(t, array, ArrayBody + (2 * BytesPerWord), reinterpret_cast<object>(spec));
} }

View File

@ -3241,7 +3241,7 @@ fromReflectedField(Thread* t, uintptr_t* arguments)
{ {
jobject f = reinterpret_cast<jobject>(arguments[0]); jobject f = reinterpret_cast<jobject>(arguments[0]);
return fieldID(t, t->m->classpath->getVMField(t, *f)); return fieldID(t, t->m->classpath->getVMField(t, cast<GcJfield>(t, *f)));
} }
jfieldID JNICALL jfieldID JNICALL

View File

@ -875,14 +875,8 @@ std::string cppFieldType(Module& module, Field& f) {
} }
} }
void writeAccessorName(Output* out, Class* cl, Field& field)
{
out->write(cl->name);
out->write(capitalize(field.name));
}
void void
writeAccessor(Output* out, Module& module, Class* cl, Field& field, bool isArray) writeAccessor(Output* out, Class* cl, Field& field)
{ {
std::string typeName = field.typeName; std::string typeName = field.typeName;
@ -897,61 +891,6 @@ writeAccessor(Output* out, Module& module, Class* cl, Field& field, bool isArray
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
out->write(capitalize(field.name)); out->write(capitalize(field.name));
out->write(" 1\n\n"); out->write(" 1\n\n");
out->write("inline ");
// if (endsWith("[0]", typeName)) {
// out->write(take(strlen(typeName) - 3, typeName));
// out->write("*");
// } else {
out->write(cppFieldType(module, field));
out->write("&");
// }
out->write("\n");
writeAccessorName(out, cl, field);
out->write("(Thread* t UNUSED, object");
out->write(" o");
if (isArray) {
out->write(", unsigned i");
}
out->write(") {\n");
out->write(" assertT(t, t->m->unsafe or ");
out->write("instanceOf(t, reinterpret_cast<GcClass*>(arrayBodyUnsafe");
out->write("(t, t->m->types, Gc::");
out->write(capitalize(cl->name));
out->write("Type))");
out->write(", o));\n");
if (isArray) {
out->write(" assertT(t, i < ");
out->write(cl->name);
out->write("Length(t, o));\n");
}
out->write(" return *reinterpret_cast<");
// if (endsWith("[0]", typeName)) {
// out->write(take(strlen(typeName) - 3, typeName));
// out->write("*");
// } else {
out->write(cppFieldType(module, field));
out->write("*");
// }
out->write(">(reinterpret_cast<uint8_t*>(o) + ");
out->write(capitalize(cl->name));
out->write(capitalize(field.name));
if (isArray) {
out->write(" + (i * ");
unsigned elementSize = sizeOf(module, field.typeName);
out->write(elementSize);
out->write(")");
}
out->write(");\n}\n\n");
} }
void void
@ -963,11 +902,11 @@ writeAccessors(Output* out, Module& module)
Field& f = **it; Field& f = **it;
if(!f.polyfill) { if(!f.polyfill) {
writeAccessor(out, module, cl, f, false); writeAccessor(out, cl, f);
} }
} }
if(cl->arrayField) { if(cl->arrayField) {
writeAccessor(out, module, cl, *cl->arrayField, true); writeAccessor(out, cl, *cl->arrayField);
} }
} }
} }