diff --git a/src/compile.cpp b/src/compile.cpp index cfe268f15f..4c25fb2d86 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -138,6 +138,19 @@ resolveThisPointer(MyThread* t, void* stack) [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 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) { return findInterfaceMethod(t, method, class_); } 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); 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); @@ -6333,6 +6346,8 @@ class SegFaultHandler: public System::SignalHandler { t->exception = makeNullPointerException(t); t->tracing = false; +// printTrace(t, t->exception); + findUnwindTarget(t, ip, base, stack); t->ip = oldIp; @@ -6543,6 +6558,8 @@ class MyProcessor: public Processor { assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0)); + method = findMethod(t, method, this_); + const char* spec = reinterpret_cast (&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)); + method = findMethod(t, method, this_); + const char* spec = reinterpret_cast (&byteArrayBody(t, methodSpec(t, method), 0)); diff --git a/src/machine.cpp b/src/machine.cpp index 11290bf0bf..9905f63ddf 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1326,7 +1326,8 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) hashMapInsert(t, virtualMap, method, method, methodHash); } - if (UNLIKELY(strcmp + if (UNLIKELY((classFlags(t, class_) & ACC_INTERFACE) == 0 + and strcmp (reinterpret_cast("finalize"), &byteArrayBody(t, methodName(t, method), 0)) == 0 and strcmp @@ -1775,6 +1776,8 @@ boot(Thread* t) |= ReferenceFlag; classVmFlags(t, arrayBody(t, m->types, Machine::WeakReferenceType)) |= ReferenceFlag | WeakReferenceFlag; + classVmFlags(t, arrayBody(t, m->types, Machine::SoftReferenceType)) + |= ReferenceFlag | WeakReferenceFlag; classVmFlags(t, arrayBody(t, m->types, Machine::PhantomReferenceType)) |= ReferenceFlag | WeakReferenceFlag; @@ -2428,16 +2431,18 @@ makeString(Thread* t, const char* format, ...) void stringChars(Thread* t, object string, char* chars) { - object data = stringData(t, string); - if (objectClass(t, data) - == arrayBody(t, t->m->types, Machine::ByteArrayType)) - { - memcpy(chars, - &byteArrayBody(t, data, stringOffset(t, string)), - stringLength(t, string)); - } else { - for (unsigned i = 0; i < stringLength(t, string); ++i) { - chars[i] = charArrayBody(t, data, stringOffset(t, string) + i); + if (stringLength(t, string)) { + object data = stringData(t, string); + if (objectClass(t, data) + == arrayBody(t, t->m->types, Machine::ByteArrayType)) + { + memcpy(chars, + &byteArrayBody(t, data, stringOffset(t, string)), + stringLength(t, string)); + } else { + for (unsigned i = 0; i < stringLength(t, string); ++i) { + chars[i] = charArrayBody(t, data, stringOffset(t, string) + i); + } } } chars[stringLength(t, string)] = 0; @@ -2446,17 +2451,19 @@ stringChars(Thread* t, object string, char* chars) void stringChars(Thread* t, object string, uint16_t* chars) { - object data = stringData(t, string); - 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); + if (stringLength(t, string)) { + object data = stringData(t, string); + 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); + } + } 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; } @@ -2821,7 +2828,7 @@ resolveClass(Thread* t, object loader, object spec) } if (LIKELY(t->exception == 0)) { - object method = findMethod + object method = findVirtualMethod (t, t->m->loadClassMethod, objectClass(t, loader)); if (LIKELY(t->exception == 0)) { diff --git a/src/machine.h b/src/machine.h index a5e686238c..38063626e0 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2185,7 +2185,7 @@ findMethod(Thread* t, object class_, object name, object spec) } inline object -findMethod(Thread* t, object method, object class_) +findVirtualMethod(Thread* t, object method, object class_) { return arrayBody(t, classVirtualTable(t, class_), methodOffset(t, method)); diff --git a/src/types.def b/src/types.def index 5afa48a8e8..1bf786e8f3 100644 --- a/src/types.def +++ b/src/types.def @@ -210,6 +210,8 @@ (type weakReference java/lang/ref/WeakReference) +(type softReference java/lang/ref/SoftReference) + (type phantomReference java/lang/ref/PhantomReference) (type byteArray [B