From 97ce7d2b4ea8e3ebdf564b6e8e6e0c064db62d99 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 16:40:57 -0600 Subject: [PATCH] pass CallEvent arguments in Slice as well --- include/avian/codegen/compiler.h | 5 +- src/codegen/compiler.cpp | 9 ++- src/codegen/compiler/event.cpp | 85 +++++++++++++-------- src/codegen/compiler/event.h | 15 ++-- src/compile.cpp | 125 ++++++++++++++++++------------- 5 files changed, 147 insertions(+), 92 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index 31d0535082..18b7b6164e 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -12,6 +12,7 @@ #define AVIAN_CODEGEN_COMPILER_H #include +#include #include "avian/zone.h" #include "assembler.h" #include "ir.h" @@ -91,8 +92,8 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint /*, - util::Slice arguments*/) = 0; + unsigned argumentFootprint, + util::Slice arguments) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_() = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index f631c72f6d..e81b626b6b 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2497,7 +2497,8 @@ class MyCompiler: public Compiler { resultType.size(), argumentStack, index, - 0); + 0, + util::Slice(0, 0)); return result; } @@ -2506,7 +2507,8 @@ class MyCompiler: public Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint) + unsigned argumentFootprint, + Slice arguments) { Value* result = value(&c, resultType); appendCall(&c, @@ -2517,7 +2519,8 @@ class MyCompiler: public Compiler { resultType.size(), c.stack, 0, - argumentFootprint); + argumentFootprint, + arguments); return result; } diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index ab6e8d2563..2b8bbc9a38 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -187,21 +187,27 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* success class CallEvent: public Event { public: - CallEvent(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint): - Event(c), - address(address), - traceHandler(traceHandler), - result(result), - returnAddressSurrogate(0), - framePointerSurrogate(0), - popIndex(0), - stackArgumentIndex(0), - flags(flags), - resultSize(resultSize), - stackArgumentFootprint(stackArgumentFootprint) + CallEvent(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments UNUSED) + : Event(c), + address(address), + traceHandler(traceHandler), + result(result), + returnAddressSurrogate(0), + framePointerSurrogate(0), + popIndex(0), + stackArgumentIndex(0), + flags(flags), + resultSize(resultSize), + stackArgumentFootprint(stackArgumentFootprint) { uint32_t registerMask = c->regFile->generalRegisters.mask; @@ -280,10 +286,12 @@ class CallEvent: public Event { Stack* stack = stackBefore; if (stackArgumentFootprint) { - RUNTIME_ARRAY(Value*, arguments, stackArgumentFootprint); + RUNTIME_ARRAY(Value*, argsArr, stackArgumentFootprint); for (int i = stackArgumentFootprint - 1; i >= 0; --i) { Value* v = stack->value; + ir::Value* v2 UNUSED = arguments[i]; stack = stack->next; + assert(c, v == v2); if ((vm::TargetBytesPerWord == 8 and (v == 0 or (i >= 1 and stack->value == 0))) @@ -291,10 +299,10 @@ class CallEvent: public Event { { assert(c, vm::TargetBytesPerWord == 8 or v->nextWord == stack->value); - RUNTIME_ARRAY_BODY(arguments)[i--] = stack->value; + RUNTIME_ARRAY_BODY(argsArr)[i--] = stack->value; stack = stack->next; } - RUNTIME_ARRAY_BODY(arguments)[i] = v; + RUNTIME_ARRAY_BODY(argsArr)[i] = v; } int returnAddressIndex; @@ -321,7 +329,7 @@ class CallEvent: public Event { } for (unsigned i = 0; i < stackArgumentFootprint; ++i) { - Value* v = RUNTIME_ARRAY_BODY(arguments)[i]; + Value* v = RUNTIME_ARRAY_BODY(argsArr)[i]; if (v) { int frameIndex = i + frameOffset; @@ -493,16 +501,28 @@ class CallEvent: public Event { unsigned stackArgumentFootprint; }; -void -appendCall(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint) +void appendCall(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments) { - append(c, new(c->zone) - CallEvent(c, address, flags, traceHandler, result, - resultSize, argumentStack, argumentCount, - stackArgumentFootprint)); + append(c, + new (c->zone) CallEvent(c, + address, + flags, + traceHandler, + result, + resultSize, + argumentStack, + argumentCount, + stackArgumentFootprint, + arguments)); } @@ -944,7 +964,8 @@ appendCombine(Context* c, lir::TernaryOperation type, resultSize, argumentStack, stackSize, - 0); + 0, + util::Slice(0, 0)); } else { append (c, new(c->zone) @@ -1067,7 +1088,8 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, resultSize, argumentStack, ceilingDivide(firstSize, vm::TargetBytesPerWord), - 0); + 0, + util::Slice(0, 0)); } else { append(c, new(c->zone) TranslateEvent @@ -1432,7 +1454,8 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first 4, argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, - 0); + 0, + util::Slice(0, 0)); appendBranch(c, thunkBranch(c, type), diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 02eba8135f..b14c54a593 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -113,11 +113,16 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor, Link* nextSuccessor, ForkState* forkState); -void -appendCall(Context* c, Value* address, unsigned flags, - TraceHandler* traceHandler, Value* result, unsigned resultSize, - Stack* argumentStack, unsigned argumentCount, - unsigned stackArgumentFootprint); +void appendCall(Context* c, + Value* address, + unsigned flags, + TraceHandler* traceHandler, + Value* result, + unsigned resultSize, + Stack* argumentStack, + unsigned argumentCount, + unsigned stackArgumentFootprint, + util::Slice arguments); void appendReturn(Context* c, unsigned size, Value* value); diff --git a/src/compile.cpp b/src/compile.cpp index e1a9ac3436..0d2706d550 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1221,56 +1221,60 @@ class Context { MyThread* t; }; - Context(MyThread* t, BootContext* bootContext, object method): - thread(t), - zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(t->arch->makeAssembler(t->m->heap, &zone)), - client(t), - compiler(makeCompiler(t->m->system, assembler, &zone, &client)), - method(method), - bootContext(bootContext), - objectPool(0), - subroutines(0), - traceLog(0), - visitTable(makeVisitTable(t, &zone, method)), - rootTable(makeRootTable(t, &zone, method)), - subroutineTable(0), - executableAllocator(0), - executableStart(0), - executableSize(0), - objectPoolCount(0), - traceLogCount(0), - dirtyRoots(false), - leaf(true), - eventLog(t->m->system, t->m->heap, 1024), - protector(this), - resource(this) + Context(MyThread* t, BootContext* bootContext, object method) + : thread(t), + zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), + client(t), + compiler(makeCompiler(t->m->system, assembler, &zone, &client)), + method(method), + bootContext(bootContext), + objectPool(0), + subroutines(0), + traceLog(0), + visitTable(makeVisitTable(t, &zone, method)), + rootTable(makeRootTable(t, &zone, method)), + subroutineTable(0), + executableAllocator(0), + executableStart(0), + executableSize(0), + objectPoolCount(0), + traceLogCount(0), + dirtyRoots(false), + leaf(true), + eventLog(t->m->system, t->m->heap, 1024), + protector(this), + resource(this), + argumentBuffer( + (ir::Value**)t->m->heap->allocate(256 * sizeof(ir::Value*)), + 256) // below the maximal allowed parameter count for Java { } - Context(MyThread* t): - thread(t), - zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), - assembler(t->arch->makeAssembler(t->m->heap, &zone)), - client(t), - compiler(0), - method(0), - bootContext(0), - objectPool(0), - subroutines(0), - traceLog(0), - visitTable(0), - rootTable(0), - subroutineTable(0), - executableAllocator(0), - executableStart(0), - executableSize(0), - objectPoolCount(0), - traceLogCount(0), - dirtyRoots(false), - leaf(true), - eventLog(t->m->system, t->m->heap, 0), - protector(this), - resource(this) + Context(MyThread* t) + : thread(t), + zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), + assembler(t->arch->makeAssembler(t->m->heap, &zone)), + client(t), + compiler(0), + method(0), + bootContext(0), + objectPool(0), + subroutines(0), + traceLog(0), + visitTable(0), + rootTable(0), + subroutineTable(0), + executableAllocator(0), + executableStart(0), + executableSize(0), + objectPoolCount(0), + traceLogCount(0), + dirtyRoots(false), + leaf(true), + eventLog(t->m->system, t->m->heap, 0), + protector(this), + resource(this), + argumentBuffer(0, 0) { } ~Context() { @@ -1291,6 +1295,10 @@ class Context { eventLog.dispose(); zone.dispose(); + + if (argumentBuffer.begin()) { + thread->m->heap->free(argumentBuffer.begin(), 256 * sizeof(ir::Value*)); + } } MyThread* thread; @@ -1316,6 +1324,7 @@ class Context { Vector eventLog; MyProtector protector; MyResource resource; + Slice argumentBuffer; }; unsigned @@ -2024,6 +2033,17 @@ class Frame { } } + Slice peekMethodArguments(unsigned footprint UNUSED) + { + ir::Value** ptr = context->argumentBuffer.items; + + for (unsigned i = 0; i < footprint; i++) { + *(ptr++) = c->peek(1, footprint - i - 1); + } + + return Slice(context->argumentBuffer.items, footprint); + } + void stackCall(ir::Value* methodValue, object methodObject, unsigned flags, @@ -2035,7 +2055,8 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint); + footprint, + peekMethodArguments(footprint)); pop(footprint); @@ -2057,7 +2078,8 @@ class Frame { flags, trace, operandTypeForFieldCode(t, returnCode), - footprint); + footprint, + peekMethodArguments(footprint)); pop(footprint); @@ -5087,7 +5109,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0), operandTypeForFieldCode(t, returnCode), - parameterFootprint); + parameterFootprint, + frame->peekMethodArguments(parameterFootprint)); frame->pop(parameterFootprint);