don't try to release monitor if we get OOME when trying to acquire it

We can't blindly try release the monitors for all synchronized methods
when unwinding the stack since we may not have finished acquiring the
most recent one when the exception was thrown.
This commit is contained in:
Joel Dice
2011-03-25 18:37:02 -06:00
parent 3e93d5d337
commit b9f8188544
3 changed files with 51 additions and 23 deletions

View File

@ -322,15 +322,29 @@ setLocalLong(Thread* t, unsigned index, uint64_t value)
void
pushFrame(Thread* t, object method)
{
if (t->frame >= 0) {
pokeInt(t, t->frame + FrameIpOffset, t->ip);
}
t->ip = 0;
PROTECT(t, method);
unsigned parameterFootprint = methodParameterFootprint(t, method);
unsigned base = t->sp - parameterFootprint;
unsigned locals = parameterFootprint;
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
// Try to acquire the monitor before doing anything else.
// Otherwise, if we were to push the frame first, we risk trying
// to release a monitor we never successfully acquired when we try
// to pop the frame back off.
if (methodFlags(t, method) & ACC_STATIC) {
acquire(t, methodClass(t, method));
} else {
acquire(t, peekObject(t, base));
}
}
if (t->frame >= 0) {
pokeInt(t, t->frame + FrameIpOffset, t->ip);
}
t->ip = 0;
if ((methodFlags(t, method) & ACC_NATIVE) == 0) {
t->code = methodCode(t, method);
@ -349,14 +363,6 @@ pushFrame(Thread* t, object method)
pokeInt(t, frame + FrameBaseOffset, base);
pokeObject(t, frame + FrameMethodOffset, method);
pokeInt(t, t->frame + FrameIpOffset, 0);
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
if (methodFlags(t, method) & ACC_STATIC) {
acquire(t, methodClass(t, method));
} else {
acquire(t, peekObject(t, base));
}
}
}
void