diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2012-12-11 10:03:40 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2012-12-11 23:16:32 +0100 |
commit | 5e39d56c0974faa28c5060a12064e1ad7f611ea0 (patch) | |
tree | a2f900ab936799f002e769e9a48d191af773d3d8 /qv4isel_masm.cpp | |
parent | bcdddfda8ca81752b249540b0abaefb46eb5f766 (diff) |
Remove IR::Function from the runtime.
This fixes potential leaks of IR::Functions, lowers the memory usage
of the functions that the VM needs (because the IR fields are not
present in the VM::Function), and makes both managed by the module
respectively the ExecutionEngine.
Change-Id: I6748ad98b062f994eae9dd14f1919aec5aa7c0b0
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'qv4isel_masm.cpp')
-rw-r--r-- | qv4isel_masm.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/qv4isel_masm.cpp b/qv4isel_masm.cpp index bcd7585c64..d107a6be0c 100644 --- a/qv4isel_masm.cpp +++ b/qv4isel_masm.cpp @@ -313,7 +313,7 @@ static void printDisassembledOutputWithCalls(const char* output, const QHash<voi } #endif -void Assembler::link() +void Assembler::link(VM::Function *vmFunc) { QHashIterator<IR::BasicBlock *, QVector<Jump> > it(_patches); while (it.hasNext()) { @@ -343,7 +343,7 @@ void Assembler::link() #endif QByteArray name = _function->name->toUtf8(); - _function->codeRef = linkBuffer.finalizeCodeWithDisassembly("%s", name.data()); + vmFunc->codeRef = linkBuffer.finalizeCodeWithDisassembly("%s", name.data()); WTF::setDataFile(stderr); #if OS(LINUX) @@ -354,14 +354,14 @@ void Assembler::link() free(disasmOutput); #endif } else { - _function->codeRef = linkBuffer.finalizeCodeWithoutDisassembly(); + vmFunc->codeRef = linkBuffer.finalizeCodeWithoutDisassembly(); } - _function->code = (Value (*)(VM::ExecutionContext *, const uchar *)) _function->codeRef.code().executableAddress(); + vmFunc->code = (Value (*)(VM::ExecutionContext *, const uchar *)) vmFunc->codeRef.code().executableAddress(); } -InstructionSelection::InstructionSelection(VM::ExecutionEngine *engine) - : _engine(engine) +InstructionSelection::InstructionSelection(VM::ExecutionEngine *engine, IR::Module *module) + : EvalInstructionSelection(engine, module) , _block(0) , _function(0) , _asm(0) @@ -373,7 +373,7 @@ InstructionSelection::~InstructionSelection() delete _asm; } -void InstructionSelection::operator()(IR::Function *function) +VM::Function *InstructionSelection::run(IR::Function *function) { qSwap(_function, function); Assembler* oldAssembler = _asm; @@ -417,16 +417,19 @@ void InstructionSelection::operator()(IR::Function *function) #endif _asm->ret(); - _asm->link(); + VM::Function *vmFunc = vmFunction(_function); + _asm->link(vmFunc); qSwap(_function, function); delete _asm; _asm = oldAssembler; + + return vmFunc; } String *InstructionSelection::identifier(const QString &s) { - return _engine->identifier(s); + return engine()->identifier(s); } void InstructionSelection::callActivationProperty(IR::Call *call, IR::Temp *result) @@ -662,16 +665,18 @@ void InstructionSelection::visitMove(IR::Move *s) return; } else if (IR::String *str = s->source->asString()) { Address dest = _asm->loadTempAddress(Assembler::ScratchRegister, t); - Value v = Value::fromString(_engine->newString(*str->value)); + Value v = Value::fromString(engine()->newString(*str->value)); _asm->storeValue(v, dest); return; } else if (IR::RegExp *re = s->source->asRegExp()) { Address dest = _asm->loadTempAddress(Assembler::ScratchRegister, t); - Value v = Value::fromObject(_engine->newRegExpObject(*re->value, re->flags)); + Value v = Value::fromObject(engine()->newRegExpObject(*re->value, re->flags)); _asm->storeValue(v, dest); return; } else if (IR::Closure *clos = s->source->asClosure()) { - generateFunctionCall(t, __qmljs_init_closure, Assembler::TrustedImmPtr(clos->value), Assembler::ContextRegister); + VM::Function *vmFunc = vmFunction(clos->value); + assert(vmFunc); + generateFunctionCall(t, __qmljs_init_closure, Assembler::TrustedImmPtr(vmFunc), Assembler::ContextRegister); return; } else if (IR::New *ctor = s->source->asNew()) { if (ctor->base->asName()) { |