touch up type safety in types.def

This commit is contained in:
Joshua Warner 2014-06-26 18:17:16 -06:00 committed by Joshua Warner
parent c796bdbde4
commit a1583f1ecc
9 changed files with 84 additions and 105 deletions

View File

@ -58,20 +58,20 @@ Java_java_net_Socket_closeInput(JNIEnv* e, jclass, SOCKET sock) {
extern "C" JNIEXPORT void JNICALL extern "C" JNIEXPORT void JNICALL
Avian_java_net_Socket_send(vm::Thread* t, vm::object, uintptr_t* arguments) { /* SOCKET s, object buffer_obj, int start_pos, int count */ Avian_java_net_Socket_send(vm::Thread* t, vm::object, uintptr_t* arguments) { /* SOCKET s, object buffer_obj, int start_pos, int count */
SOCKET& s = *(reinterpret_cast<SOCKET*>(&arguments[0])); SOCKET& s = *(reinterpret_cast<SOCKET*>(&arguments[0]));
vm::object buffer_obj = reinterpret_cast<vm::object>(arguments[2]); vm::GcByteArray* buffer_obj = vm::cast<vm::GcByteArray>(t, reinterpret_cast<vm::object>(arguments[2]));
int32_t& start_pos = *(reinterpret_cast<int32_t*>(&arguments[3])); int32_t& start_pos = *(reinterpret_cast<int32_t*>(&arguments[3]));
int32_t& count = *(reinterpret_cast<int32_t*>(&arguments[4])); int32_t& count = *(reinterpret_cast<int32_t*>(&arguments[4]));
char* buffer = reinterpret_cast<char*>(&vm::byteArrayBody(t, buffer_obj, start_pos)); char* buffer = reinterpret_cast<char*>(&buffer_obj->body()[start_pos]);
avian::classpath::sockets::send((JNIEnv*)t, s, buffer, count); avian::classpath::sockets::send((JNIEnv*)t, s, buffer, count);
} }
extern "C" JNIEXPORT int64_t JNICALL extern "C" JNIEXPORT int64_t JNICALL
Avian_java_net_Socket_recv(vm::Thread* t, vm::object, uintptr_t* arguments) { /* SOCKET s, object buffer_obj, int start_pos, int count */ Avian_java_net_Socket_recv(vm::Thread* t, vm::object, uintptr_t* arguments) { /* SOCKET s, object buffer_obj, int start_pos, int count */
SOCKET& s = *(reinterpret_cast<SOCKET*>(&arguments[0])); SOCKET& s = *(reinterpret_cast<SOCKET*>(&arguments[0]));
vm::object buffer_obj = reinterpret_cast<vm::object>(arguments[2]); vm::GcByteArray* buffer_obj = vm::cast<vm::GcByteArray>(t, reinterpret_cast<vm::object>(arguments[2]));
int32_t& start_pos = *(reinterpret_cast<int32_t*>(&arguments[3])); int32_t& start_pos = *(reinterpret_cast<int32_t*>(&arguments[3]));
int32_t& count = *(reinterpret_cast<int32_t*>(&arguments[4])); int32_t& count = *(reinterpret_cast<int32_t*>(&arguments[4]));
char* buffer = reinterpret_cast<char*>(&vm::byteArrayBody(t, buffer_obj, start_pos)); char* buffer = reinterpret_cast<char*>(&buffer_obj->body()[start_pos]);
return avian::classpath::sockets::recv((JNIEnv*)t, s, buffer, count); return avian::classpath::sockets::recv((JNIEnv*)t, s, buffer, count);
} }

View File

@ -497,7 +497,7 @@ resolveExceptionJTypes(Thread* t, GcClassLoader* loader, GcMethodAddendum* adden
o = reinterpret_cast<object>(getJClass(t, cast<GcClass>(t, o))); o = reinterpret_cast<object>(getJClass(t, cast<GcClass>(t, o)));
set(t, array, ArrayBody + (i * BytesPerWord), o); set(t, reinterpret_cast<object>(array), ArrayBody + (i * BytesPerWord), o);
} }
return array; return array;

View File

@ -1356,7 +1356,6 @@ vmRun_returnAddress();
class GcThread; class GcThread;
class GcThrowable; class GcThrowable;
class GcString; class GcString;
class GcField;
class Thread { class Thread {
public: public:

View File

@ -327,10 +327,10 @@ class MyClasspath : public Classpath {
{ {
return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type)
? arrayBody ? arrayBody
(t, jclassVmClass(t, jmethodDeclaringClass(t, jmethod))->methodTable(), (t, jmethodDeclaringClass(t, jmethod)->vmClass()->methodTable(),
jmethodSlot(t, jmethod)) jmethodSlot(t, jmethod))
: arrayBody : arrayBody
(t,jclassVmClass(t, jconstructorDeclaringClass(t, jmethod))->methodTable(), (t, jconstructorDeclaringClass(t, jmethod)->vmClass()->methodTable(),
jconstructorSlot(t, jmethod))); jconstructorSlot(t, jmethod)));
} }
@ -350,7 +350,7 @@ class MyClasspath : public Classpath {
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return cast<GcField>(t, arrayBody return cast<GcField>(t, arrayBody
(t, jclassVmClass(t, jfieldDeclaringClass(t, jfield))->fieldTable(), (t, jfieldDeclaringClass(t, jfield)->vmClass()->fieldTable(),
jfieldSlot(t, jfield))); jfieldSlot(t, jfield)));
} }
@ -1402,7 +1402,7 @@ Avian_sun_misc_Unsafe_objectFieldOffset
object jfield = reinterpret_cast<object>(arguments[1]); object jfield = reinterpret_cast<object>(arguments[1]);
return fieldOffset return fieldOffset
(t, arrayBody (t, arrayBody
(t, jclassVmClass(t, jfieldDeclaringClass(t, jfield))->fieldTable(), (t, jfieldDeclaringClass(t, jfield)->vmClass()->fieldTable(),
jfieldSlot(t, jfield))); jfieldSlot(t, jfield)));
} }
@ -1878,9 +1878,9 @@ Avian_java_lang_reflect_Method_isAnnotationPresent
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(),
arguments[1]); arguments[1]);
object addendum = methodAddendum(t, method); GcMethodAddendum* addendum = methodAddendum(t, method);
if (addendum) { if (addendum) {
object table = addendumAnnotationTable(t, addendum); object table = addendum->annotationTable();
if (table) { if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
if (objectArrayBody(t, objectArrayBody(t, table, i), 1) if (objectArrayBody(t, objectArrayBody(t, table, i), 1)
@ -1903,9 +1903,9 @@ Avian_java_lang_reflect_Method_getAnnotation
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(),
arguments[1]); arguments[1]);
object addendum = methodAddendum(t, method); GcMethodAddendum* addendum = methodAddendum(t, method);
if (addendum) { if (addendum) {
object table = addendumAnnotationTable(t, addendum); object table = addendum->annotationTable();
if (table) { if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
if (objectArrayBody(t, objectArrayBody(t, table, i), 1) if (objectArrayBody(t, objectArrayBody(t, table, i), 1)
@ -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, classLoader(t, methodClass(t, method)), (t, get, 0, methodClass(t, method)->loader(),
objectArrayBody(t, table, i))); objectArrayBody(t, table, i)));
} }
} }
@ -1939,9 +1939,9 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->methodTable(),
arguments[1]); arguments[1]);
object addendum = methodAddendum(t, method); GcMethodAddendum* addendum = methodAddendum(t, method);
if (addendum) { if (addendum) {
object table = addendumAnnotationTable(t, addendum); object table = addendum->annotationTable();
if (table) { if (table) {
PROTECT(t, method); PROTECT(t, method);
PROTECT(t, table); PROTECT(t, 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, classLoader(t, methodClass(t, method)), (t, get, 0, methodClass(t, method)->loader(),
objectArrayBody(t, table, i)); objectArrayBody(t, table, i));
set(t, array, ArrayBody + (i * BytesPerWord), a); set(t, array, ArrayBody + (i * BytesPerWord), a);
@ -1987,9 +1987,9 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(), jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(),
arguments[1])); arguments[1]));
object addendum = reinterpret_cast<object>(field->addendum()); GcFieldAddendum* addendum = field->addendum();
if (addendum) { if (addendum) {
object table = addendumAnnotationTable(t, addendum); object table = addendum->annotationTable();
if (table) { if (table) {
PROTECT(t, field); PROTECT(t, field);
PROTECT(t, table); PROTECT(t, table);
@ -2040,7 +2040,7 @@ Avian_java_lang_reflect_Method_getDefaultValue
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))->methodTable(), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[1]))->methodTable(),
arguments[2]); arguments[2]);
object addendum = methodAddendum(t, method); GcMethodAddendum* addendum = methodAddendum(t, method);
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, classLoader(t, methodClass(t, method)), addendum)); (t, get, 0, methodClass(t, method)->loader(), addendum));
} }
return 0; return 0;
@ -2180,9 +2180,9 @@ Avian_java_lang_reflect_Field_getAnnotation
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))->fieldTable(),
arguments[1])); arguments[1]));
object addendum = reinterpret_cast<object>(field->addendum()); GcFieldAddendum* addendum = field->addendum();
if (addendum) { if (addendum) {
object table = addendumAnnotationTable(t, addendum); object table = addendum->annotationTable();
if (table) { if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
if (objectArrayBody(t, objectArrayBody(t, table, i), 1) if (objectArrayBody(t, objectArrayBody(t, table, i), 1)

View File

@ -351,7 +351,7 @@ object
makeJconstructor(Thread* t, GcMethod* vmMethod, int index = -1); makeJconstructor(Thread* t, GcMethod* vmMethod, int index = -1);
object object
makeJfield(Thread* t, object vmField, int index = -1); makeJfield(Thread* t, GcField* vmField, int index = -1);
#ifdef AVIAN_OPENJDK_SRC #ifdef AVIAN_OPENJDK_SRC
void void
@ -593,24 +593,24 @@ class MyClasspath : public Classpath {
{ {
return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type)
? arrayBody ? arrayBody
(t, jclassVmClass(t, jmethodClazz(t, jmethod))->methodTable(), (t, jmethodClazz(t, jmethod)->vmClass()->methodTable(),
jmethodSlot(t, jmethod)) jmethodSlot(t, jmethod))
: arrayBody : arrayBody
(t, jclassVmClass(t, jconstructorClazz(t, jmethod))->methodTable(), (t, jconstructorClazz(t, jmethod)->vmClass()->methodTable(),
jconstructorSlot(t, jmethod))); jconstructorSlot(t, jmethod)));
} }
virtual object virtual object
makeJField(Thread* t, GcField* vmField) makeJField(Thread* t, GcField* vmField)
{ {
return reinterpret_cast<object>(makeJfield(t, reinterpret_cast<object>(vmField))); return reinterpret_cast<object>(makeJfield(t, vmField));
} }
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return cast<GcField>(t, arrayBody return cast<GcField>(t, arrayBody
(t, jclassVmClass(t, jfieldClazz(t, jfield))->fieldTable(), jfieldSlot(t, jfield))); (t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield)));
} }
virtual void virtual void
@ -2136,8 +2136,8 @@ countFields(Thread* t, GcClass* c, bool publicOnly)
if (publicOnly) { if (publicOnly) {
unsigned count = 0; unsigned count = 0;
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
object vmField = arrayBody(t, table, i); GcField* vmField = cast<GcField>(t, arrayBody(t, table, i));
if (fieldFlags(t, vmField) & ACC_PUBLIC) { if (vmField->flags() & ACC_PUBLIC) {
++ count; ++ count;
} }
} }
@ -2387,30 +2387,29 @@ makeJconstructor(Thread* t, GcMethod* vmMethod, int index)
} }
object object
makeJfield(Thread* t, object vmField, int index) makeJfield(Thread* t, GcField* vmField, int index)
{ {
PROTECT(t, vmField); PROTECT(t, vmField);
object name = intern object name = intern
(t, reinterpret_cast<object>(t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, fieldName(t, vmField), 0, byteArrayLength (t, reinterpret_cast<object>(vmField->name()), 0, vmField->name()->length() - 1)));
(t, fieldName(t, vmField)) - 1)));
PROTECT(t, name); PROTECT(t, name);
GcClass* type = resolveClassBySpec GcClass* type = resolveClassBySpec
(t, cast<GcClassLoader>(t, classLoader(t, fieldClass(t, vmField))), (t, vmField->class_()->loader(),
reinterpret_cast<char*> reinterpret_cast<char*>
(&byteArrayBody(t, fieldSpec(t, vmField), 0)), (vmField->spec()->body().begin()),
byteArrayLength(t, fieldSpec(t, vmField)) - 1); vmField->spec()->length() - 1);
PROTECT(t, type); PROTECT(t, type);
GcJclass* jtype = getJClass(t, type); GcJclass* jtype = getJClass(t, type);
object signature; object signature;
object annotationTable; object annotationTable;
object addendum = fieldAddendum(t, vmField); GcFieldAddendum* addendum = vmField->addendum();
if (addendum) { if (addendum) {
signature = addendumSignature(t, addendum); signature = addendum->signature();
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
@ -2418,7 +2417,7 @@ makeJfield(Thread* t, object vmField, int index)
(t, signature, 0, byteArrayLength(t, signature) - 1)); (t, signature, 0, byteArrayLength(t, signature) - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendum->annotationTable();
} else { } else {
signature = 0; signature = 0;
annotationTable = 0; annotationTable = 0;
@ -2428,16 +2427,16 @@ makeJfield(Thread* t, object vmField, int index)
PROTECT(t, annotationTable); PROTECT(t, annotationTable);
if (annotationTable) { if (annotationTable) {
GcClassRuntimeData* runtimeData = getClassRuntimeData(t, cast<GcClass>(t, fieldClass(t, vmField))); GcClassRuntimeData* runtimeData = getClassRuntimeData(t, vmField->class_());
set(t, reinterpret_cast<object>(runtimeData), ClassRuntimeDataPool, set(t, runtimeData, ClassRuntimeDataPool,
addendumPool(t, fieldAddendum(t, vmField))); vmField->addendum()->pool());
} }
if (index == -1) { if (index == -1) {
object table = classFieldTable(t, fieldClass(t, vmField)); object table = vmField->class_()->fieldTable();
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
if (vmField == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmField) == arrayBody(t, table, i)) {
index = i; index = i;
break; break;
} }
@ -2446,11 +2445,10 @@ makeJfield(Thread* t, object vmField, int index)
expect(t, index != -1); expect(t, index != -1);
GcJclass* jclass = getJClass(t, cast<GcClass>(t, fieldClass(t, vmField))); GcJclass* jclass = getJClass(t, vmField->class_());
return reinterpret_cast<object>(makeJfield return reinterpret_cast<object>(makeJfield
(t, true, 0, jclass, index, cast<GcString>(t, name), jtype, fieldFlags (t, true, 0, jclass, index, cast<GcString>(t, name), jtype, vmField->flags(), cast<GcString>(t, signature), 0, cast<GcByteArray>(t, annotationTable), 0, 0, 0, 0));
(t, vmField), cast<GcString>(t, signature), 0, cast<GcByteArray>(t, annotationTable), 0, 0, 0, 0));
} }
void void
@ -2595,7 +2593,7 @@ Avian_sun_misc_Unsafe_staticFieldOffset
object jfield = reinterpret_cast<object>(arguments[1]); object jfield = reinterpret_cast<object>(arguments[1]);
return fieldOffset return fieldOffset
(t, arrayBody (t, arrayBody
(t, jclassVmClass(t, jfieldClazz(t, jfield))->fieldTable(), jfieldSlot(t, jfield))); (t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield)));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -2603,8 +2601,7 @@ 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>
(jclassVmClass (jfieldClazz(t, reinterpret_cast<object>(arguments[1]))->vmClass()->staticTable());
(t, jfieldClazz(t, reinterpret_cast<object>(arguments[1])))->staticTable());
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -2614,7 +2611,7 @@ Avian_sun_misc_Unsafe_objectFieldOffset
object jfield = reinterpret_cast<object>(arguments[1]); object jfield = reinterpret_cast<object>(arguments[1]);
return fieldOffset return fieldOffset
(t, arrayBody (t, arrayBody
(t, jclassVmClass(t, jfieldClazz(t, jfield))->fieldTable(), jfieldSlot(t, jfield))); (t, jfieldClazz(t, jfield)->vmClass()->fieldTable(), jfieldSlot(t, jfield)));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -3487,10 +3484,8 @@ 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,
cast<GcClass>( methodClass(t,
t, traceElementMethod(t, objectArrayBody(t, trace, i)))));
methodClass(t,
traceElementMethod(t, objectArrayBody(t, trace, i))))));
set(t, context, ArrayBody + (i * BytesPerWord), c); set(t, context, ArrayBody + (i * BytesPerWord), c);
} }
@ -3902,7 +3897,7 @@ jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments)
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
EXPORT(JVM_FindClassFromClassLoader)(Thread* t, const char* name, EXPORT(JVM_FindClassFromClassLoader)(Thread* t, const char* name,
jboolean init, jobject* loader, jboolean init, jobject loader,
jboolean throwError) jboolean throwError)
{ {
uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(name), uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(name),
@ -3944,7 +3939,7 @@ jvmFindLoadedClass(Thread* t, uintptr_t* arguments)
} }
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
EXPORT(JVM_FindLoadedClass)(Thread* t, jobject* loader, jstring name) EXPORT(JVM_FindLoadedClass)(Thread* t, jobject loader, jstring name)
{ {
uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(loader), uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(loader),
reinterpret_cast<uintptr_t>(name) }; reinterpret_cast<uintptr_t>(name) };
@ -3965,7 +3960,7 @@ jvmDefineClass(Thread* t, uintptr_t* arguments)
} }
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
EXPORT(JVM_DefineClass)(Thread* t, const char*, jobject* loader, EXPORT(JVM_DefineClass)(Thread* t, const char*, jobject loader,
const uint8_t* data, jsize length, jobject) const uint8_t* data, jsize length, jobject)
{ {
uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(loader), uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(loader),
@ -3976,7 +3971,7 @@ EXPORT(JVM_DefineClass)(Thread* t, const char*, jobject* loader,
} }
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
EXPORT(JVM_DefineClassWithSource)(Thread* t, const char*, jobject* loader, EXPORT(JVM_DefineClassWithSource)(Thread* t, const char*, jobject loader,
const uint8_t* data, jsize length, jobject, const uint8_t* data, jsize length, jobject,
const char*) const char*)
{ {
@ -3984,7 +3979,7 @@ EXPORT(JVM_DefineClassWithSource)(Thread* t, const char*, jobject* loader,
} }
extern "C" AVIAN_EXPORT jclass JNICALL extern "C" AVIAN_EXPORT jclass JNICALL
EXPORT(JVM_DefineClassWithSourceCond)(Thread* t, const char*, jobject* loader, EXPORT(JVM_DefineClassWithSourceCond)(Thread* t, const char*, jobject loader,
const uint8_t* data, jsize length, const uint8_t* data, jsize length,
jobject, const char*, jboolean) jobject, const char*, jboolean)
{ {
@ -4329,10 +4324,10 @@ jvmGetClassDeclaredFields(Thread* t, uintptr_t* arguments)
unsigned ai = 0; unsigned ai = 0;
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
object vmField = arrayBody(t, table, i); GcField* vmField = cast<GcField>(t, arrayBody(t, table, i));
PROTECT(t, vmField); PROTECT(t, vmField);
if ((not publicOnly) or (fieldFlags(t, vmField) & ACC_PUBLIC)) { if ((not publicOnly) or (vmField->flags() & ACC_PUBLIC)) {
object field = makeJfield(t, vmField, i); object field = makeJfield(t, vmField, i);
assertT(t, ai < objectArrayLength(t, array)); assertT(t, ai < objectArrayLength(t, array));
@ -4428,7 +4423,7 @@ jvmInvokeMethod(Thread* t, uintptr_t* arguments)
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, arrayBody
(t, jclassVmClass(t, jmethodClazz(t, *method))->methodTable(), (t, jmethodClazz(t, *method)->vmClass()->methodTable(),
jmethodSlot(t, *method))); jmethodSlot(t, *method)));
if (vmMethod->flags() & ACC_STATIC) { if (vmMethod->flags() & ACC_STATIC) {
@ -4463,11 +4458,11 @@ 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, jclassVmClass(t, jconstructorClazz(t, *constructor))); (t, jconstructorClazz(t, *constructor)->vmClass());
PROTECT(t, instance); PROTECT(t, instance);
GcMethod* method = cast<GcMethod>(t, arrayBody GcMethod* method = cast<GcMethod>(t, arrayBody
(t, jclassVmClass(t, jconstructorClazz(t, *constructor))->methodTable(), (t, jconstructorClazz(t, *constructor)->vmClass()->methodTable(),
jconstructorSlot(t, *constructor))); jconstructorSlot(t, *constructor)));
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);

View File

@ -7519,7 +7519,7 @@ walkContinuationBody(MyThread* t, Heap::Walker* w, GcContinuation* c, int start)
{ {
const int BodyOffset = ContinuationBody / BytesPerWord; const int BodyOffset = ContinuationBody / BytesPerWord;
GcMethod* method = cast<GcMethod>(t, reinterpret_cast<object>(t->m->heap->follow(c->method()))); GcMethod* method = t->m->heap->follow(c->method());
int count = frameMapSizeInBits(t, method); int count = frameMapSizeInBits(t, method);
if (count) { if (count) {

View File

@ -122,13 +122,13 @@ int printInstruction(uint8_t* code, unsigned& ip, const char* prefix)
return fprintf(stderr, "drem"); return fprintf(stderr, "drem");
case dsub: case dsub:
return fprintf(stderr, "dsub"); return fprintf(stderr, "dsub");
case dup: case vm::dup:
return fprintf(stderr, "dup"); return fprintf(stderr, "dup");
case dup_x1: case dup_x1:
return fprintf(stderr, "dup_x1"); return fprintf(stderr, "dup_x1");
case dup_x2: case dup_x2:
return fprintf(stderr, "dup_x2"); return fprintf(stderr, "dup_x2");
case dup2: case vm::dup2:
return fprintf(stderr, "dup2"); return fprintf(stderr, "dup2");
case dup2_x1: case dup2_x1:
return fprintf(stderr, "dup2_x1"); return fprintf(stderr, "dup2_x1");

View File

@ -12,7 +12,6 @@
#include <avian/util/string.h> #include <avian/util/string.h>
#include <avian/util/runtime-array.h> #include <avian/util/runtime-array.h>
#include <avian/util/list.h> #include <avian/util/list.h>
#include <avian/util/slice.h>
#include <avian/util/hash.h> #include <avian/util/hash.h>
#include "avian/zlib-custom.h" #include "avian/zlib-custom.h"
@ -285,7 +284,7 @@ class JarIndex {
while (p < end) { while (p < end) {
if (signature(p) == EntrySignature) { if (signature(p) == EntrySignature) {
index = index->add(Entry(hash(avian::util::Slice<const uint8_t>(reinterpret_cast<const uint8_t*>(fileName(p)), fileNameLength(p))), p)); index = index->add(Entry(hash(Slice<const uint8_t>(fileName(p), fileNameLength(p))), p));
p = endOfEntry(p); p = endOfEntry(p);
} else { } else {

View File

@ -843,56 +843,42 @@ writeOffset(Output* out, Class* cl)
} }
} }
void std::string cppClassName(Class* cl) {
writeAccessorName(Output* out, Class* cl, Field& field) if(cl->name == "jobject") {
{ return "object";
out->write(cl->name); } else {
out->write(capitalize(field.name)); return "Gc" + capitalize(cl->name) + "*";
}
} }
void writeFieldType(Output* out, Module& module, Field& f) { std::string cppFieldType(Module& module, Field& f) {
if(f.javaSpec.size() != 0) { if(f.javaSpec.size() != 0) {
if(f.javaSpec[0] == 'L') { if(f.javaSpec[0] == 'L') {
std::string className = f.javaSpec.substr(1, f.javaSpec.size() - 2); std::string className = f.javaSpec.substr(1, f.javaSpec.size() - 2);
std::map<std::string, Class*>::iterator it = module.javaClasses.find(className); std::map<std::string, Class*>::iterator it = module.javaClasses.find(className);
if(it != module.javaClasses.end()) { if(it != module.javaClasses.end()) {
if(it->second->name == "jobject") { return cppClassName(it->second);
// TEMPORARY HACK!
out->write("object");
} else {
out->write("Gc");
out->write(capitalize(it->second->name));
out->write("*");
}
return;
} }
} else if(f.javaSpec[0] == '[') { } else if(f.javaSpec[0] == '[') {
std::map<std::string, Class*>::iterator it = module.javaClasses.find(f.javaSpec); std::map<std::string, Class*>::iterator it = module.javaClasses.find(f.javaSpec);
if(it != module.javaClasses.end()) { if(it != module.javaClasses.end()) {
out->write("Gc"); return cppClassName(it->second);
out->write(capitalize(it->second->name));
out->write("*");
return;
} }
} }
} }
std::map<std::string, Class*>::iterator it = module.classes.find(f.typeName); std::map<std::string, Class*>::iterator it = module.classes.find(f.typeName);
assert(f.typeName.size() > 0); assert(f.typeName.size() > 0);
if(it != module.classes.end()) { if(it != module.classes.end()) {
out->write("Gc"); return cppClassName(it->second);
out->write(capitalize(it->second->name));
out->write("*");
} else { } else {
out->write(f.typeName); return f.typeName;
} }
} }
void writeSimpleFieldType(Output* out, Module& module, Field& f) { void writeAccessorName(Output* out, Class* cl, Field& field)
if(f.javaSpec.size() != 0 && (f.javaSpec[0] == 'L' || f.javaSpec[0] == '[')) { {
out->write("object"); out->write(cl->name);
} else { out->write(capitalize(field.name));
writeFieldType(out, module, f);
}
} }
void void
@ -918,7 +904,7 @@ writeAccessor(Output* out, Module& module, Class* cl, Field& field, bool isArray
// out->write(take(strlen(typeName) - 3, typeName)); // out->write(take(strlen(typeName) - 3, typeName));
// out->write("*"); // out->write("*");
// } else { // } else {
writeSimpleFieldType(out, module, field); out->write(cppFieldType(module, field));
out->write("&"); out->write("&");
// } // }
@ -950,7 +936,7 @@ writeAccessor(Output* out, Module& module, Class* cl, Field& field, bool isArray
// out->write(take(strlen(typeName) - 3, typeName)); // out->write(take(strlen(typeName) - 3, typeName));
// out->write("*"); // out->write("*");
// } else { // } else {
writeSimpleFieldType(out, module, field); out->write(cppFieldType(module, field));
out->write("*"); out->write("*");
// } // }
@ -1026,7 +1012,7 @@ writeConstructorParameters(Output* out, Module& module, Class* cl)
Field& f = **it; Field& f = **it;
if(!f.polyfill) { if(!f.polyfill) {
out->write(", "); out->write(", ");
writeFieldType(out, module, f); out->write(cppFieldType(module, f));
out->write(" "); out->write(" ");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
} }
@ -1082,7 +1068,7 @@ void writeClassAccessors(Output* out, Module& module, Class* cl)
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) {
Field& f = **it; Field& f = **it;
out->write(" "); out->write(" ");
writeFieldType(out, module, f); out->write(cppFieldType(module, f));
if(!f.polyfill) { if(!f.polyfill) {
out->write("&"); out->write("&");
} }
@ -1097,7 +1083,7 @@ void writeClassAccessors(Output* out, Module& module, Class* cl)
out->write("); // polyfill, assumed to be implemented elsewhere\n"); out->write("); // polyfill, assumed to be implemented elsewhere\n");
} else { } else {
out->write(") { return field_at<"); out->write(") { return field_at<");
writeFieldType(out, module, f); out->write(cppFieldType(module, f));
out->write(">("); out->write(">(");
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
out->write(capitalize(f.name)); out->write(capitalize(f.name));