From 61c708d7b2914cc4730087fd7d039ff0406994e9 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 28 Sep 2008 13:00:52 -0600 Subject: [PATCH] reserve stack space for arguments to native calls --- src/compile.cpp | 8 ++++++-- src/compiler.cpp | 23 +++++++---------------- src/compiler.h | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 0dc5c0026c..a0a9ad536c 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -35,6 +35,8 @@ const bool DebugFrameMaps = false; const bool CheckArrayBounds = true; +const unsigned MaxNativeCallFootprint = 4; + class MyThread: public Thread { public: class CallTrace { @@ -338,7 +340,9 @@ alignedFrameSize(MyThread* t, object method) return t->arch->alignFrameSize (localSize(t, method) - methodParameterFootprint(t, method) - + codeMaxStack(t, methodCode(t, method))); + + codeMaxStack(t, methodCode(t, method)) + + MaxNativeCallFootprint + - t->arch->argumentRegisterCount()); } unsigned @@ -3898,7 +3902,7 @@ compile(MyThread* t, Context* context) unsigned footprint = methodParameterFootprint(t, context->method); unsigned locals = localSize(t, context->method); c->init(codeLength(t, methodCode(t, context->method)), footprint, locals, - codeMaxStack(t, methodCode(t, context->method))); + alignedFrameSize(t, context->method)); uint8_t stackMap[codeMaxStack(t, methodCode(t, context->method))]; Frame frame(context, stackMap); diff --git a/src/compiler.cpp b/src/compiler.cpp index 4c3b7b9bed..d136e5f0ca 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -267,9 +267,9 @@ class Context { logicalCodeLength(0), parameterFootprint(0), localFootprint(0), - maxStackFootprint(0), stackPadding(0), machineCodeSize(0), + alignedFrameSize(0), availableRegisterCount(arch->registerCount()), constantCompare(CompareNone), pass(ScanPass) @@ -304,9 +304,9 @@ class Context { unsigned logicalCodeLength; unsigned parameterFootprint; unsigned localFootprint; - unsigned maxStackFootprint; unsigned stackPadding; unsigned machineCodeSize; + unsigned alignedFrameSize; unsigned availableRegisterCount; ConstantCompare constantCompare; Pass pass; @@ -507,20 +507,11 @@ class Event { unsigned readCount; }; -unsigned -alignedFrameSize(Context* c) -{ - return c->arch->alignFrameSize - (c->localFootprint - - c->parameterFootprint - + c->maxStackFootprint); -} - int localOffset(Context* c, int v) { int parameterFootprint = c->parameterFootprint; - int frameSize = alignedFrameSize(c); + int frameSize = c->alignedFrameSize; int offset = ((v < parameterFootprint) ? (frameSize @@ -1669,7 +1660,7 @@ class CallEvent: public Event { uint32_t mask = ~0; Stack* s = argumentStack; unsigned index = 0; - unsigned frameIndex = alignedFrameSize(c) + c->parameterFootprint; + unsigned frameIndex = c->alignedFrameSize + c->parameterFootprint; for (unsigned i = 0; i < argumentCount; ++i) { Read* target; if (index < c->arch->argumentRegisterCount()) { @@ -2806,7 +2797,7 @@ compile(Context* c) Block* firstBlock = block(c, c->firstEvent); Block* block = firstBlock; - a->allocateFrame(alignedFrameSize(c)); + a->allocateFrame(c->alignedFrameSize); for (Event* e = c->firstEvent; e; e = e->next) { e->block = block; @@ -3020,12 +3011,12 @@ class MyCompiler: public Compiler { } virtual void init(unsigned logicalCodeLength, unsigned parameterFootprint, - unsigned localFootprint, unsigned maxStackFootprint) + unsigned localFootprint, unsigned alignedFrameSize) { c.logicalCodeLength = logicalCodeLength; c.parameterFootprint = parameterFootprint; c.localFootprint = localFootprint; - c.maxStackFootprint = maxStackFootprint; + c.alignedFrameSize = alignedFrameSize; c.logicalCode = static_cast (c.zone->allocate(sizeof(LogicalInstruction*) * logicalCodeLength)); diff --git a/src/compiler.h b/src/compiler.h index 50a1c0a00b..def40b5ac0 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -40,7 +40,7 @@ class Compiler { virtual void restoreState(State* state) = 0; virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint, - unsigned localFootprint, unsigned maxStackFootprint) = 0; + unsigned localFootprint, unsigned alignedFrameSize) = 0; virtual void visitLogicalIp(unsigned logicalIp) = 0; virtual void startLogicalIp(unsigned logicalIp) = 0;