invoke static initializers more lazily

This commit is contained in:
Joel Dice 2008-01-08 12:36:34 -07:00
parent 551addc638
commit cfc959a3d2

View File

@ -1135,6 +1135,13 @@ unwind(MyThread* t)
vmJump(ip, base, stack, t); vmJump(ip, base, stack, t);
} }
void FORCE_ALIGN
tryInitClass(MyThread* t, object class_)
{
initClass(t, class_);
if (UNLIKELY(t->exception)) unwind(t);
}
void* FORCE_ALIGN void* FORCE_ALIGN
findInterfaceMethodFromInstance(MyThread* t, object method, object instance) findInterfaceMethodFromInstance(MyThread* t, object method, object instance)
{ {
@ -2223,10 +2230,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
Operand* table; Operand* table;
if (instruction == getstatic) { if (instruction == getstatic) {
PROTECT(t, field); c->indirectCall
(c->constant(reinterpret_cast<intptr_t>(tryInitClass)),
initClass(t, fieldClass(t, field)); frame->trace(0, false),
if (UNLIKELY(t->exception)) return; 2, c->thread(), frame->append(fieldClass(t, field)));
table = frame->append(classStaticTable(t, fieldClass(t, field))); table = frame->append(classStaticTable(t, fieldClass(t, field)));
} else { } else {
@ -2606,9 +2613,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
object class_ = methodClass(t, target); object class_ = methodClass(t, target);
if (isSpecialMethod(t, target, class_)) { if (isSpecialMethod(t, target, class_)) {
initClass(t, classSuper(t, class_));
if (UNLIKELY(t->exception)) return;
target = findMethod(t, target, classSuper(t, class_)); target = findMethod(t, target, classSuper(t, class_));
} }
@ -2620,10 +2624,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
object target = resolveMethod(t, codePool(t, code), index - 1); object target = resolveMethod(t, codePool(t, code), index - 1);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
PROTECT(t, target);
initClass(t, methodClass(t, target));
if (UNLIKELY(t->exception)) return;
compileDirectInvoke(t, frame, target); compileDirectInvoke(t, frame, target);
} break; } break;
@ -3062,10 +3062,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
object class_ = resolveClassInPool(t, codePool(t, code), index - 1); object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
PROTECT(t, class_);
initClass(t, class_);
if (UNLIKELY(t->exception)) return;
if (classVmFlags(t, class_) & WeakReferenceFlag) { if (classVmFlags(t, class_) & WeakReferenceFlag) {
c->indirectCall c->indirectCall
@ -3172,10 +3168,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip)
object staticTable = 0; object staticTable = 0;
if (instruction == putstatic) { if (instruction == putstatic) {
PROTECT(t, field); c->indirectCall
(c->constant(reinterpret_cast<intptr_t>(tryInitClass)),
initClass(t, fieldClass(t, field)); frame->trace(0, false),
if (UNLIKELY(t->exception)) return; 2, c->thread(), frame->append(fieldClass(t, field)));
staticTable = classStaticTable(t, fieldClass(t, field)); staticTable = classStaticTable(t, fieldClass(t, field));
} }
@ -3853,6 +3849,9 @@ invokeNative2(MyThread* t, object method)
{ {
PROTECT(t, method); PROTECT(t, method);
initClass(t, methodClass(t, method));
if (UNLIKELY(t->exception)) return 0;
if (objectClass(t, methodCode(t, method)) if (objectClass(t, methodCode(t, method))
== arrayBody(t, t->m->types, Machine::ByteArrayType)) == arrayBody(t, t->m->types, Machine::ByteArrayType))
{ {
@ -4643,6 +4642,9 @@ compile(MyThread* t, object method)
ACQUIRE(t, t->m->classLock); ACQUIRE(t, t->m->classLock);
if (methodCompiled(t, method) == p->getDefaultCompiled(t)) { if (methodCompiled(t, method) == p->getDefaultCompiled(t)) {
initClass(t, methodClass(t, method));
if (UNLIKELY(t->exception)) return;
Context context(t, method, p->indirectCaller); Context context(t, method, p->indirectCaller);
object compiled = compile(t, &context); object compiled = compile(t, &context);