treat SoftReferences as WeakReferences; do vtable or interface table lookups as necessary in MyProcessor::invoke; various bugfixes

This commit is contained in:
Joel Dice 2009-08-13 09:17:05 -06:00
parent b3a5823536
commit 3facd3f735
4 changed files with 53 additions and 25 deletions

View File

@ -138,6 +138,19 @@ resolveThisPointer(MyThread* t, void* stack)
[t->arch->frameFooterSize() + t->arch->frameReturnAddressSize()]; [t->arch->frameFooterSize() + t->arch->frameReturnAddressSize()];
} }
object
findMethod(Thread* t, object method, object instance)
{
if ((methodFlags(t, method) & ACC_STATIC) == 0) {
if (methodVirtual(t, method)) {
return findVirtualMethod(t, method, objectClass(t, instance));
} else if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) {
return findInterfaceMethod(t, method, objectClass(t, instance));
}
}
return method;
}
object object
resolveTarget(MyThread* t, void* stack, object method) resolveTarget(MyThread* t, void* stack, object method)
{ {
@ -154,7 +167,7 @@ resolveTarget(MyThread* t, void* stack, object method)
if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) { if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) {
return findInterfaceMethod(t, method, class_); return findInterfaceMethod(t, method, class_);
} else { } else {
return findMethod(t, method, class_); return findVirtualMethod(t, method, class_);
} }
} }
@ -3513,7 +3526,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
object class_ = methodClass(t, context->method); object class_ = methodClass(t, context->method);
if (isSpecialMethod(t, target, class_)) { if (isSpecialMethod(t, target, class_)) {
target = findMethod(t, target, classSuper(t, class_)); target = findVirtualMethod(t, target, classSuper(t, class_));
} }
assert(t, (methodFlags(t, target) & ACC_STATIC) == 0); assert(t, (methodFlags(t, target) & ACC_STATIC) == 0);
@ -6333,6 +6346,8 @@ class SegFaultHandler: public System::SignalHandler {
t->exception = makeNullPointerException(t); t->exception = makeNullPointerException(t);
t->tracing = false; t->tracing = false;
// printTrace(t, t->exception);
findUnwindTarget(t, ip, base, stack); findUnwindTarget(t, ip, base, stack);
t->ip = oldIp; t->ip = oldIp;
@ -6543,6 +6558,8 @@ class MyProcessor: public Processor {
assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0));
method = findMethod(t, method, this_);
const char* spec = reinterpret_cast<char*> const char* spec = reinterpret_cast<char*>
(&byteArrayBody(t, methodSpec(t, method), 0)); (&byteArrayBody(t, methodSpec(t, method), 0));
@ -6574,6 +6591,8 @@ class MyProcessor: public Processor {
assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0));
method = findMethod(t, method, this_);
const char* spec = reinterpret_cast<char*> const char* spec = reinterpret_cast<char*>
(&byteArrayBody(t, methodSpec(t, method), 0)); (&byteArrayBody(t, methodSpec(t, method), 0));

View File

@ -1326,7 +1326,8 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool)
hashMapInsert(t, virtualMap, method, method, methodHash); hashMapInsert(t, virtualMap, method, method, methodHash);
} }
if (UNLIKELY(strcmp if (UNLIKELY((classFlags(t, class_) & ACC_INTERFACE) == 0
and strcmp
(reinterpret_cast<const int8_t*>("finalize"), (reinterpret_cast<const int8_t*>("finalize"),
&byteArrayBody(t, methodName(t, method), 0)) == 0 &byteArrayBody(t, methodName(t, method), 0)) == 0
and strcmp and strcmp
@ -1775,6 +1776,8 @@ boot(Thread* t)
|= ReferenceFlag; |= ReferenceFlag;
classVmFlags(t, arrayBody(t, m->types, Machine::WeakReferenceType)) classVmFlags(t, arrayBody(t, m->types, Machine::WeakReferenceType))
|= ReferenceFlag | WeakReferenceFlag; |= ReferenceFlag | WeakReferenceFlag;
classVmFlags(t, arrayBody(t, m->types, Machine::SoftReferenceType))
|= ReferenceFlag | WeakReferenceFlag;
classVmFlags(t, arrayBody(t, m->types, Machine::PhantomReferenceType)) classVmFlags(t, arrayBody(t, m->types, Machine::PhantomReferenceType))
|= ReferenceFlag | WeakReferenceFlag; |= ReferenceFlag | WeakReferenceFlag;
@ -2428,16 +2431,18 @@ makeString(Thread* t, const char* format, ...)
void void
stringChars(Thread* t, object string, char* chars) stringChars(Thread* t, object string, char* chars)
{ {
object data = stringData(t, string); if (stringLength(t, string)) {
if (objectClass(t, data) object data = stringData(t, string);
== arrayBody(t, t->m->types, Machine::ByteArrayType)) if (objectClass(t, data)
{ == arrayBody(t, t->m->types, Machine::ByteArrayType))
memcpy(chars, {
&byteArrayBody(t, data, stringOffset(t, string)), memcpy(chars,
stringLength(t, string)); &byteArrayBody(t, data, stringOffset(t, string)),
} else { stringLength(t, string));
for (unsigned i = 0; i < stringLength(t, string); ++i) { } else {
chars[i] = charArrayBody(t, data, stringOffset(t, string) + i); for (unsigned i = 0; i < stringLength(t, string); ++i) {
chars[i] = charArrayBody(t, data, stringOffset(t, string) + i);
}
} }
} }
chars[stringLength(t, string)] = 0; chars[stringLength(t, string)] = 0;
@ -2446,17 +2451,19 @@ stringChars(Thread* t, object string, char* chars)
void void
stringChars(Thread* t, object string, uint16_t* chars) stringChars(Thread* t, object string, uint16_t* chars)
{ {
object data = stringData(t, string); if (stringLength(t, string)) {
if (objectClass(t, data) object data = stringData(t, string);
== arrayBody(t, t->m->types, Machine::ByteArrayType)) if (objectClass(t, data)
{ == arrayBody(t, t->m->types, Machine::ByteArrayType))
for (unsigned i = 0; i < stringLength(t, string); ++i) { {
chars[i] = byteArrayBody(t, data, stringOffset(t, string) + i); for (unsigned i = 0; i < stringLength(t, string); ++i) {
chars[i] = byteArrayBody(t, data, stringOffset(t, string) + i);
}
} else {
memcpy(chars,
&charArrayBody(t, data, stringOffset(t, string)),
stringLength(t, string) * sizeof(uint16_t));
} }
} else {
memcpy(chars,
&charArrayBody(t, data, stringOffset(t, string)),
stringLength(t, string) * sizeof(uint16_t));
} }
chars[stringLength(t, string)] = 0; chars[stringLength(t, string)] = 0;
} }
@ -2821,7 +2828,7 @@ resolveClass(Thread* t, object loader, object spec)
} }
if (LIKELY(t->exception == 0)) { if (LIKELY(t->exception == 0)) {
object method = findMethod object method = findVirtualMethod
(t, t->m->loadClassMethod, objectClass(t, loader)); (t, t->m->loadClassMethod, objectClass(t, loader));
if (LIKELY(t->exception == 0)) { if (LIKELY(t->exception == 0)) {

View File

@ -2185,7 +2185,7 @@ findMethod(Thread* t, object class_, object name, object spec)
} }
inline object inline object
findMethod(Thread* t, object method, object class_) findVirtualMethod(Thread* t, object method, object class_)
{ {
return arrayBody(t, classVirtualTable(t, class_), return arrayBody(t, classVirtualTable(t, class_),
methodOffset(t, method)); methodOffset(t, method));

View File

@ -210,6 +210,8 @@
(type weakReference java/lang/ref/WeakReference) (type weakReference java/lang/ref/WeakReference)
(type softReference java/lang/ref/SoftReference)
(type phantomReference java/lang/ref/PhantomReference) (type phantomReference java/lang/ref/PhantomReference)
(type byteArray [B (type byteArray [B