implement helper methods for invokespecial; add thread type

This commit is contained in:
Joel Dice 2007-06-13 08:03:08 -06:00
parent 8cc54280d9
commit 5e225c94a3
3 changed files with 46 additions and 6 deletions

View File

@ -200,4 +200,10 @@ enum TypeCode {
T_LONG = 11 T_LONG = 11
}; };
const unsigned ACC_PUBLIC = 1 << 0;
const unsigned ACC_FINAL = 1 << 4;
const unsigned ACC_SUPER = 1 << 5;
const unsigned ACC_INTERFACE = 1 << 9;
const unsigned ACC_ABSTRACT = 1 << 10;
#endif//CONSTANTS_H #endif//CONSTANTS_H

View File

@ -3,6 +3,7 @@
(uint16_t fixedSize) (uint16_t fixedSize)
(uint16_t arrayElementSize) (uint16_t arrayElementSize)
(object objectMask) (object objectMask)
(uint16_t flags)
(object name) (object name)
(object super) (object super)
(object interfaceTable) (object interfaceTable)
@ -75,6 +76,10 @@
(uint32_t ip) (uint32_t ip)
(object next)) (object next))
(type thread
(object localMap)
(object exceptionHandler))
(type string (type string
(object bytes) (object bytes)
(int32_t offset) (int32_t offset)

View File

@ -39,7 +39,6 @@ class Machine {
unsigned liveCount; unsigned liveCount;
System::Monitor* stateLock; System::Monitor* stateLock;
System::Monitor* heapLock; System::Monitor* heapLock;
object jstringClass;
}; };
class Thread { class Thread {
@ -75,6 +74,7 @@ class Thread {
Thread* next; Thread* next;
Thread* child; Thread* child;
State state; State state;
object thread;
object frame; object frame;
object code; object code;
object exception; object exception;
@ -133,6 +133,7 @@ iterate(Thread* t, Heap::Visitor* v)
{ {
t->heapIndex = 0; t->heapIndex = 0;
v->visit(&(t->thread));
v->visit(&(t->frame)); v->visit(&(t->frame));
v->visit(&(t->code)); v->visit(&(t->code));
v->visit(&(t->exception)); v->visit(&(t->exception));
@ -492,11 +493,38 @@ findInterfaceMethod(Thread* t, object method, object o)
abort(t); abort(t);
} }
inline object
findMethod(Thread* t, object method, object class_)
{
return rawArrayBody(t, classMethodTable(t, class_))
[methodOffset(t, method)];
}
inline object inline object
findVirtualMethod(Thread* t, object method, object o) findVirtualMethod(Thread* t, object method, object o)
{ {
return rawArrayBody(t, classMethodTable(t, objectClass(o))) return findMethod(t, method, objectClass(o));
[methodOffset(t, method)]; }
bool
isSuperclass(Thread* t, object class_, object base)
{
Type id = classId(t, class_);
for (object oc = classSuper(t, base); oc; oc = classSuper(t, oc)) {
if (classId(t, oc) == id) {
return true;
}
}
return false;
}
inline bool
isSpecialMethod(Thread* t, object method, object class_)
{
return (classFlags(t, class_) & ACC_SUPER)
and strcmp("<init>", reinterpret_cast<char*>
(byteArrayBody(t, methodName(t, method)))) != 0
and isSuperclass(t, methodClass(t, method), class_);
} }
object object
@ -1317,8 +1345,9 @@ run(Thread* t)
parameterCount = methodParameterCount(t, method); parameterCount = methodParameterCount(t, method);
if (LIKELY(stack[sp - parameterCount])) { if (LIKELY(stack[sp - parameterCount])) {
if (isSpecialMethod(method, stack[sp - parameterCount])) { object class_ = methodClass(t, frameMethod(t, t->frame));
code = findSpecialMethod(t, method, stack[sp - parameterCount]); if (isSpecialMethod(t, method, class_)) {
code = findMethod(t, method, classSuper(t, class_));
if (UNLIKELY(exception)) goto throw_; if (UNLIKELY(exception)) goto throw_;
} else { } else {
code = method; code = method;
@ -1905,7 +1934,7 @@ run(Thread* t)
} }
} }
object method = defaultExceptionHandler(t); object method = threadExceptionHandler(t, t->thread);
code = methodCode(t, method); code = methodCode(t, method);
frame = makeFrame(t, method, 0, 0, 0, codeMaxLocals(t, code)); frame = makeFrame(t, method, 0, 0, 0, codeMaxLocals(t, code));
sp = 0; sp = 0;