handle case where first instruction is the target of a branch properly

This commit is contained in:
Joel Dice 2008-11-08 16:21:30 -07:00
parent decd24965a
commit 000aeb25c1
2 changed files with 24 additions and 37 deletions

View File

@ -1839,32 +1839,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
frame->startLogicalIp(ip); frame->startLogicalIp(ip);
if (ip == 0) { if (exceptionHandlerStart >= 0) {
handleEntrance(t, frame);
int index = 0;
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
c->initLocal(1, index++);
}
for (MethodSpecIterator it
(t, reinterpret_cast<const char*>
(&byteArrayBody(t, methodSpec(t, context->method), 0)));
it.hasNext();)
{
switch (*it.next()) {
case 'J':
case 'D':
c->initLocal(2, index);
index += 2;
break;
default:
c->initLocal(1, index++);
break;
}
}
} else if (exceptionHandlerStart >= 0) {
c->initLocalsFromLogicalIp(exceptionHandlerStart); c->initLocalsFromLogicalIp(exceptionHandlerStart);
exceptionHandlerStart = -1; exceptionHandlerStart = -1;
@ -3894,8 +3869,11 @@ compile(MyThread* t, Context* context)
uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))]; uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))];
Frame frame(context, stackMap); Frame frame(context, stackMap);
handleEntrance(t, &frame);
unsigned index = 0; unsigned index = 0;
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
c->initLocal(1, index);
frame.set(index++, Frame::Object); frame.set(index++, Frame::Object);
} }
@ -3907,16 +3885,19 @@ compile(MyThread* t, Context* context)
switch (*it.next()) { switch (*it.next()) {
case 'L': case 'L':
case '[': case '[':
c->initLocal(1, index);
frame.set(index++, Frame::Object); frame.set(index++, Frame::Object);
break; break;
case 'J': case 'J':
case 'D': case 'D':
c->initLocal(2, index);
frame.set(index++, Frame::Long); frame.set(index++, Frame::Long);
frame.set(index++, Frame::Long); frame.set(index++, Frame::Long);
break; break;
default: default:
c->initLocal(1, index);
frame.set(index++, Frame::Integer); frame.set(index++, Frame::Integer);
break; break;
} }

View File

@ -15,13 +15,13 @@ using namespace vm;
namespace { namespace {
const bool DebugAppend = false; const bool DebugAppend = true;
const bool DebugCompile = false; const bool DebugCompile = true;
const bool DebugStack = false; const bool DebugStack = false;
const bool DebugRegisters = false; const bool DebugRegisters = false;
const bool DebugFrameIndexes = false; const bool DebugFrameIndexes = false;
const bool DebugFrame = false; const bool DebugFrame = false;
const bool DebugControl = false; const bool DebugControl = true;
const bool DebugReads = false; const bool DebugReads = false;
const int AnyFrameIndex = -2; const int AnyFrameIndex = -2;
@ -3322,8 +3322,6 @@ appendDummy(Context* c)
void void
append(Context* c, Event* e) append(Context* c, Event* e)
{ {
assert(c, c->logicalIp >= 0);
LogicalInstruction* i = c->logicalCode[c->logicalIp]; LogicalInstruction* i = c->logicalCode[c->logicalIp];
if (c->stack != i->stack or c->locals != i->locals) { if (c->stack != i->stack or c->locals != i->locals) {
appendDummy(c); appendDummy(c);
@ -3700,7 +3698,7 @@ block(Context* c, Event* head)
unsigned unsigned
compile(Context* c) compile(Context* c)
{ {
if (c->logicalIp >= 0 and c->logicalCode[c->logicalIp]->lastEvent == 0) { if (c->logicalCode[c->logicalIp]->lastEvent == 0) {
appendDummy(c); appendDummy(c);
} }
@ -3910,7 +3908,7 @@ saveState(Context* c)
void void
restoreState(Context* c, ForkState* s) restoreState(Context* c, ForkState* s)
{ {
if (c->logicalIp >= 0 and c->logicalCode[c->logicalIp]->lastEvent == 0) { if (c->logicalCode[c->logicalIp]->lastEvent == 0) {
appendDummy(c); appendDummy(c);
} }
@ -4006,20 +4004,28 @@ class MyCompiler: public Compiler {
memset(c.frameResources, 0, frameResourceSize); memset(c.frameResources, 0, frameResourceSize);
// leave room for logical instruction -1
unsigned codeSize = sizeof(LogicalInstruction*)
* (logicalCodeLength + 1);
c.logicalCode = static_cast<LogicalInstruction**> c.logicalCode = static_cast<LogicalInstruction**>
(c.zone->allocate(sizeof(LogicalInstruction*) * logicalCodeLength)); (c.zone->allocate(codeSize));
memset(c.logicalCode, 0, sizeof(LogicalInstruction*) * logicalCodeLength); memset(c.logicalCode, 0, codeSize);
c.logicalCode++;
c.locals = static_cast<Local*> c.locals = static_cast<Local*>
(c.zone->allocate(sizeof(Local) * localFootprint)); (c.zone->allocate(sizeof(Local) * localFootprint));
memset(c.locals, 0, sizeof(Local) * localFootprint); memset(c.locals, 0, sizeof(Local) * localFootprint);
c.logicalCode[-1] = new
(c.zone->allocate(sizeof(LogicalInstruction)))
LogicalInstruction(-1, c.stack, c.locals);
} }
virtual void visitLogicalIp(unsigned logicalIp) { virtual void visitLogicalIp(unsigned logicalIp) {
assert(&c, logicalIp < c.logicalCodeLength); assert(&c, logicalIp < c.logicalCodeLength);
if (c.logicalIp >= 0 and c.logicalCode[c.logicalIp]->lastEvent == 0) { if (c.logicalCode[c.logicalIp]->lastEvent == 0) {
appendDummy(&c); appendDummy(&c);
} }
@ -4051,7 +4057,7 @@ class MyCompiler: public Compiler {
assert(&c, logicalIp < c.logicalCodeLength); assert(&c, logicalIp < c.logicalCodeLength);
assert(&c, c.logicalCode[logicalIp] == 0); assert(&c, c.logicalCode[logicalIp] == 0);
if (c.logicalIp >= 0 and c.logicalCode[c.logicalIp]->lastEvent == 0) { if (c.logicalCode[c.logicalIp]->lastEvent == 0) {
appendDummy(&c); appendDummy(&c);
} }