From 000aeb25c1d2da88fa9a7c48e65621a64a675913 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 8 Nov 2008 16:21:30 -0700 Subject: [PATCH] handle case where first instruction is the target of a branch properly --- src/compile.cpp | 33 +++++++-------------------------- src/compiler.cpp | 28 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index c81cdb61fb..91ac141cb9 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1839,32 +1839,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->startLogicalIp(ip); - if (ip == 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 - (&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) { + if (exceptionHandlerStart >= 0) { c->initLocalsFromLogicalIp(exceptionHandlerStart); exceptionHandlerStart = -1; @@ -3894,8 +3869,11 @@ compile(MyThread* t, Context* context) uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))]; Frame frame(context, stackMap); + handleEntrance(t, &frame); + unsigned index = 0; if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { + c->initLocal(1, index); frame.set(index++, Frame::Object); } @@ -3907,16 +3885,19 @@ compile(MyThread* t, Context* context) switch (*it.next()) { case 'L': case '[': + c->initLocal(1, index); frame.set(index++, Frame::Object); break; case 'J': case 'D': + c->initLocal(2, index); frame.set(index++, Frame::Long); frame.set(index++, Frame::Long); break; default: + c->initLocal(1, index); frame.set(index++, Frame::Integer); break; } diff --git a/src/compiler.cpp b/src/compiler.cpp index 17f2f63243..99a8036d30 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -15,13 +15,13 @@ using namespace vm; namespace { -const bool DebugAppend = false; -const bool DebugCompile = false; +const bool DebugAppend = true; +const bool DebugCompile = true; const bool DebugStack = false; const bool DebugRegisters = false; const bool DebugFrameIndexes = false; const bool DebugFrame = false; -const bool DebugControl = false; +const bool DebugControl = true; const bool DebugReads = false; const int AnyFrameIndex = -2; @@ -3322,8 +3322,6 @@ appendDummy(Context* c) void append(Context* c, Event* e) { - assert(c, c->logicalIp >= 0); - LogicalInstruction* i = c->logicalCode[c->logicalIp]; if (c->stack != i->stack or c->locals != i->locals) { appendDummy(c); @@ -3700,7 +3698,7 @@ block(Context* c, Event* head) unsigned compile(Context* c) { - if (c->logicalIp >= 0 and c->logicalCode[c->logicalIp]->lastEvent == 0) { + if (c->logicalCode[c->logicalIp]->lastEvent == 0) { appendDummy(c); } @@ -3910,7 +3908,7 @@ saveState(Context* c) void 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); } @@ -4006,20 +4004,28 @@ class MyCompiler: public Compiler { memset(c.frameResources, 0, frameResourceSize); + // leave room for logical instruction -1 + unsigned codeSize = sizeof(LogicalInstruction*) + * (logicalCodeLength + 1); c.logicalCode = static_cast - (c.zone->allocate(sizeof(LogicalInstruction*) * logicalCodeLength)); - memset(c.logicalCode, 0, sizeof(LogicalInstruction*) * logicalCodeLength); + (c.zone->allocate(codeSize)); + memset(c.logicalCode, 0, codeSize); + c.logicalCode++; c.locals = static_cast (c.zone->allocate(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) { 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); } @@ -4051,7 +4057,7 @@ class MyCompiler: public Compiler { assert(&c, logicalIp < c.logicalCodeLength); 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); }