add process and classpath-avian changes

This commit is contained in:
Joshua Warner 2014-06-28 23:37:24 -06:00 committed by Joshua Warner
parent 86d9249f29
commit 9f0327bb9e
2 changed files with 57 additions and 58 deletions

View File

@ -61,18 +61,18 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, vmMethod); PROTECT(t, vmMethod);
object jmethod = reinterpret_cast<object>(makeJmethod(t, vmMethod, false)); GcJmethod* jmethod = makeJmethod(t, vmMethod, false);
return vmMethod->name()->body()[0] == '<' return vmMethod->name()->body()[0] == '<'
? reinterpret_cast<object>(makeJconstructor(t, cast<GcJmethod>(t, jmethod))) : jmethod; ? reinterpret_cast<object>(makeJconstructor(t, jmethod)) : reinterpret_cast<object>(jmethod);
} }
virtual GcMethod* virtual GcMethod*
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, GcJmethod::Type) return objectClass(t, jmethod) == type(t, GcJmethod::Type)
? cast<GcMethod>(t, jmethodVmMethod(t, jmethod)) ? cast<GcJmethod>(t, jmethod)->vmMethod()
: cast<GcMethod>(t, jmethodVmMethod(t, jconstructorMethod(t, jmethod))); : cast<GcJconstructor>(t, jmethod)->method()->vmMethod();
} }
virtual object virtual object
@ -84,7 +84,7 @@ class MyClasspath : public Classpath {
virtual GcField* virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return cast<GcField>(t, jfieldVmField(t, jfield)); return cast<GcJfield>(t, jfield)->vmField();
} }
virtual void virtual void
@ -492,11 +492,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Array_makeObjectArray Avian_java_lang_reflect_Array_makeObjectArray
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object elementType = reinterpret_cast<object>(arguments[0]); GcJclass* elementType = cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]));
int length = arguments[1]; int length = arguments[1];
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(makeObjectArray(t, cast<GcClass>(t, jclassVmClass(t, elementType)), length)); (makeObjectArray(t, elementType->vmClass(), length));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -587,7 +587,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
Avian_java_lang_ClassLoader_load(Thread* t, object, uintptr_t* arguments) Avian_java_lang_ClassLoader_load(Thread* t, object, uintptr_t* arguments)
{ {
object name = reinterpret_cast<object>(arguments[0]); GcString* name = cast<GcString>(t, reinterpret_cast<object>(arguments[0]));
Thread::LibraryLoadStack stack( Thread::LibraryLoadStack stack(
t, t,
@ -595,9 +595,9 @@ extern "C" AVIAN_EXPORT void JNICALL
bool mapName = arguments[2]; bool mapName = arguments[2];
unsigned length = stringLength(t, name); unsigned length = name->length(t);
THREAD_RUNTIME_ARRAY(t, char, n, length + 1); THREAD_RUNTIME_ARRAY(t, char, n, length + 1);
stringChars(t, cast<GcString>(t, name), RUNTIME_ARRAY_BODY(n)); stringChars(t, name, RUNTIME_ARRAY_BODY(n));
loadLibrary(t, "", RUNTIME_ARRAY_BODY(n), mapName, true); loadLibrary(t, "", RUNTIME_ARRAY_BODY(n), mapName, true);
} }
@ -708,13 +708,13 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Thread_enumerate Avian_java_lang_Thread_enumerate
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object array = reinterpret_cast<object>(*arguments); GcArray* array = cast<GcArray>(t, reinterpret_cast<object>(*arguments));
ACQUIRE_RAW(t, t->m->stateLock); ACQUIRE_RAW(t, t->m->stateLock);
unsigned count = min(t->m->liveCount, objectArrayLength(t, array)); unsigned count = min(t->m->liveCount, objectArrayLength(t, reinterpret_cast<object>(array)));
unsigned index = 0; unsigned index = 0;
local::enumerateThreads(t, t->m->rootThread, array, &index, count); local::enumerateThreads(t, t->m->rootThread, reinterpret_cast<object>(array), &index, count);
return count; return count;
} }
@ -729,16 +729,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_avian_Atomic_getOffset Avian_avian_Atomic_getOffset
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return fieldOffset return cast<GcJfield>(t, reinterpret_cast<object>(arguments[0]))->vmField()->offset();
(t, jfieldVmField(t, reinterpret_cast<object>(arguments[0])));
} }
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)
{ {
return fieldOffset return cast<GcJfield>(t, reinterpret_cast<object>(arguments[1]))->vmField()->offset();
(t, jfieldVmField(t, reinterpret_cast<object>(arguments[1])));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -786,10 +784,12 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_avian_Classes_makeMethod Avian_avian_Classes_makeMethod
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = arrayBody GcMethod* method = cast<GcMethod>(
(t, classMethodTable t,
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))), cast<GcArray>(t,
arguments[1]); cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))
->vmClass()
->methodTable())->body()[arguments[1]]);
PROTECT(t, method); PROTECT(t, method);
GcClass* c = resolveClass GcClass* c = resolveClass
@ -803,8 +803,8 @@ Avian_avian_Classes_makeMethod
t->m->processor->invoke(t, constructor, instance, method); t->m->processor->invoke(t, constructor, instance, method);
if (byteArrayBody(t, methodName(t, method), 0) == '<') { if (method->name()->body()[0] == '<') {
method = instance; object oldInstance = instance;
c = resolveClass c = resolveClass
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/reflect/Constructor"); (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/reflect/Constructor");
@ -814,7 +814,7 @@ Avian_avian_Classes_makeMethod
GcMethod* constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, c, "<init>", "(Ljava/lang/Method;)V"); (t, c, "<init>", "(Ljava/lang/Method;)V");
t->m->processor->invoke(t, constructor, instance, method); t->m->processor->invoke(t, constructor, instance, oldInstance);
} }
return reinterpret_cast<uintptr_t>(instance); return reinterpret_cast<uintptr_t>(instance);

View File

@ -61,36 +61,36 @@ mangle(int8_t c, char* dst)
return 6; return 6;
default: default:
dst[0] = c; dst[0] = c;
return 1; return 1;
} }
} }
unsigned unsigned
jniNameLength(Thread* t, GcMethod* method, bool decorate) jniNameLength(Thread* t UNUSED, GcMethod* method, bool decorate)
{ {
unsigned size = 0; unsigned size = 0;
object className = reinterpret_cast<object>(method->class_()->name()); GcByteArray* className = method->class_()->name();
for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { for (unsigned i = 0; i < className->length() - 1; ++i) {
size += mangledSize(byteArrayBody(t, className, i)); size += mangledSize(className->body()[i]);
} }
++ size; ++ size;
object methodName = reinterpret_cast<object>(method->name()); GcByteArray* methodName = method->name();
for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { for (unsigned i = 0; i < methodName->length() - 1; ++i) {
size += mangledSize(byteArrayBody(t, methodName, i)); size += mangledSize(methodName->body()[i]);
} }
if (decorate) { if (decorate) {
size += 2; size += 2;
object methodSpec = reinterpret_cast<object>(method->spec()); GcByteArray* methodSpec = method->spec();
for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 for (unsigned i = 1; i < methodSpec->length() - 1
and byteArrayBody(t, methodSpec, i) != ')'; ++i) and methodSpec->body()[i] != ')'; ++i)
{ {
size += mangledSize(byteArrayBody(t, methodSpec, i)); size += mangledSize(methodSpec->body()[i]);
} }
} }
@ -98,33 +98,33 @@ jniNameLength(Thread* t, GcMethod* method, bool decorate)
} }
void void
makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, makeJNIName(Thread* t UNUSED, const char* prefix, unsigned prefixLength, char* name,
GcMethod* method, bool decorate) GcMethod* method, bool decorate)
{ {
memcpy(name, prefix, prefixLength); memcpy(name, prefix, prefixLength);
name += prefixLength; name += prefixLength;
object className = reinterpret_cast<object>(method->class_()->name()); GcByteArray* className = method->class_()->name();
for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { for (unsigned i = 0; i < className->length() - 1; ++i) {
name += mangle(byteArrayBody(t, className, i), name); name += mangle(className->body()[i], name);
} }
*(name++) = '_'; *(name++) = '_';
object methodName = reinterpret_cast<object>(method->name()); GcByteArray* methodName = method->name();
for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { for (unsigned i = 0; i < methodName->length() - 1; ++i) {
name += mangle(byteArrayBody(t, methodName, i), name); name += mangle(methodName->body()[i], name);
} }
if (decorate) { if (decorate) {
*(name++) = '_'; *(name++) = '_';
*(name++) = '_'; *(name++) = '_';
object methodSpec = reinterpret_cast<object>(method->spec()); GcByteArray* methodSpec = method->spec();
for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 for (unsigned i = 1; i < methodSpec->length() - 1
and byteArrayBody(t, methodSpec, i) != ')'; ++i) and methodSpec->body()[i] != ')'; ++i)
{ {
name += mangle(byteArrayBody(t, methodSpec, i), name); name += mangle(methodSpec->body()[i], name);
} }
} }
@ -245,18 +245,18 @@ resolveNative(Thread* t, GcMethod* method)
PROTECT(t, native); PROTECT(t, native);
object runtimeData = reinterpret_cast<object>(getMethodRuntimeData(t, method)); GcMethodRuntimeData* runtimeData = getMethodRuntimeData(t, method);
// ensure other threads only see the methodRuntimeDataNative field // ensure other threads only see the methodRuntimeDataNative field
// populated once the object it points to has been populated: // populated once the object it points to has been populated:
storeStoreMemoryBarrier(); storeStoreMemoryBarrier();
set(t, runtimeData, MethodRuntimeDataNative, native); set(t, reinterpret_cast<object>(runtimeData), MethodRuntimeDataNative, native);
} }
} }
int int
findLineNumber(Thread* t, GcMethod* method, unsigned ip) findLineNumber(Thread* t UNUSED, GcMethod* method, unsigned ip)
{ {
if (method->flags() & ACC_NATIVE) { if (method->flags() & ACC_NATIVE) {
return NativeLine; return NativeLine;
@ -266,18 +266,17 @@ findLineNumber(Thread* t, GcMethod* method, unsigned ip)
// about, so we back up first: // about, so we back up first:
-- ip; -- ip;
object code = reinterpret_cast<object>(method->code()); GcLineNumberTable* lnt = method->code()->lineNumberTable();
object lnt = reinterpret_cast<object>(codeLineNumberTable(t, code));
if (lnt) { if (lnt) {
unsigned bottom = 0; unsigned bottom = 0;
unsigned top = lineNumberTableLength(t, lnt); unsigned top = lnt->length();
for (unsigned span = top - bottom; span; span = top - bottom) { for (unsigned span = top - bottom; span; span = top - bottom) {
unsigned middle = bottom + (span / 2); unsigned middle = bottom + (span / 2);
uint64_t ln = lineNumberTableBody(t, lnt, middle); uint64_t ln = lnt->body()[middle];
if (ip >= lineNumberIp(ln) if (ip >= lineNumberIp(ln)
and (middle + 1 == lineNumberTableLength(t, lnt) and (middle + 1 == lnt->length()
or ip < lineNumberIp(lineNumberTableBody(t, lnt, middle + 1)))) or ip < lineNumberIp(lnt->body()[middle + 1])))
{ {
return lineNumberLine(ln); return lineNumberLine(ln);
} else if (ip < lineNumberIp(ln)) { } else if (ip < lineNumberIp(ln)) {
@ -287,8 +286,8 @@ findLineNumber(Thread* t, GcMethod* method, unsigned ip)
} }
} }
if (top < lineNumberTableLength(t, lnt)) { if (top < lnt->length()) {
return lineNumberLine(lineNumberTableBody(t, lnt, top)); return lineNumberLine(lnt->body()[top]);
} else { } else {
return UnknownLine; return UnknownLine;
} }