Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "jit/shared/BaselineCompiler-shared.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "jit/BaselineIC.h" |
michael@0 | 10 | #include "jit/VMFunctions.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace js; |
michael@0 | 13 | using namespace js::jit; |
michael@0 | 14 | |
michael@0 | 15 | BaselineCompilerShared::BaselineCompilerShared(JSContext *cx, TempAllocator &alloc, JSScript *script) |
michael@0 | 16 | : cx(cx), |
michael@0 | 17 | script(script), |
michael@0 | 18 | pc(script->code()), |
michael@0 | 19 | ionCompileable_(jit::IsIonEnabled(cx) && CanIonCompileScript(cx, script, false)), |
michael@0 | 20 | ionOSRCompileable_(jit::IsIonEnabled(cx) && CanIonCompileScript(cx, script, true)), |
michael@0 | 21 | debugMode_(cx->compartment()->debugMode()), |
michael@0 | 22 | alloc_(alloc), |
michael@0 | 23 | analysis_(alloc, script), |
michael@0 | 24 | frame(script, masm), |
michael@0 | 25 | stubSpace_(), |
michael@0 | 26 | icEntries_(), |
michael@0 | 27 | pcMappingEntries_(), |
michael@0 | 28 | icLoadLabels_(), |
michael@0 | 29 | pushedBeforeCall_(0), |
michael@0 | 30 | inCall_(false), |
michael@0 | 31 | spsPushToggleOffset_() |
michael@0 | 32 | { } |
michael@0 | 33 | |
michael@0 | 34 | bool |
michael@0 | 35 | BaselineCompilerShared::callVM(const VMFunction &fun, CallVMPhase phase) |
michael@0 | 36 | { |
michael@0 | 37 | JitCode *code = cx->runtime()->jitRuntime()->getVMWrapper(fun); |
michael@0 | 38 | if (!code) |
michael@0 | 39 | return false; |
michael@0 | 40 | |
michael@0 | 41 | #ifdef DEBUG |
michael@0 | 42 | // Assert prepareVMCall() has been called. |
michael@0 | 43 | JS_ASSERT(inCall_); |
michael@0 | 44 | inCall_ = false; |
michael@0 | 45 | #endif |
michael@0 | 46 | |
michael@0 | 47 | // Compute argument size. Note that this include the size of the frame pointer |
michael@0 | 48 | // pushed by prepareVMCall. |
michael@0 | 49 | uint32_t argSize = fun.explicitStackSlots() * sizeof(void *) + sizeof(void *); |
michael@0 | 50 | |
michael@0 | 51 | // Assert all arguments were pushed. |
michael@0 | 52 | JS_ASSERT(masm.framePushed() - pushedBeforeCall_ == argSize); |
michael@0 | 53 | |
michael@0 | 54 | Address frameSizeAddress(BaselineFrameReg, BaselineFrame::reverseOffsetOfFrameSize()); |
michael@0 | 55 | uint32_t frameVals = frame.nlocals() + frame.stackDepth(); |
michael@0 | 56 | uint32_t frameBaseSize = BaselineFrame::FramePointerOffset + BaselineFrame::Size(); |
michael@0 | 57 | uint32_t frameFullSize = frameBaseSize + (frameVals * sizeof(Value)); |
michael@0 | 58 | if (phase == POST_INITIALIZE) { |
michael@0 | 59 | masm.store32(Imm32(frameFullSize), frameSizeAddress); |
michael@0 | 60 | uint32_t descriptor = MakeFrameDescriptor(frameFullSize + argSize, JitFrame_BaselineJS); |
michael@0 | 61 | masm.push(Imm32(descriptor)); |
michael@0 | 62 | |
michael@0 | 63 | } else if (phase == PRE_INITIALIZE) { |
michael@0 | 64 | masm.store32(Imm32(frameBaseSize), frameSizeAddress); |
michael@0 | 65 | uint32_t descriptor = MakeFrameDescriptor(frameBaseSize + argSize, JitFrame_BaselineJS); |
michael@0 | 66 | masm.push(Imm32(descriptor)); |
michael@0 | 67 | |
michael@0 | 68 | } else { |
michael@0 | 69 | JS_ASSERT(phase == CHECK_OVER_RECURSED); |
michael@0 | 70 | Label afterWrite; |
michael@0 | 71 | Label writePostInitialize; |
michael@0 | 72 | |
michael@0 | 73 | // If OVER_RECURSED is set, then frame locals haven't been pushed yet. |
michael@0 | 74 | masm.branchTest32(Assembler::Zero, |
michael@0 | 75 | frame.addressOfFlags(), |
michael@0 | 76 | Imm32(BaselineFrame::OVER_RECURSED), |
michael@0 | 77 | &writePostInitialize); |
michael@0 | 78 | |
michael@0 | 79 | masm.move32(Imm32(frameBaseSize), BaselineTailCallReg); |
michael@0 | 80 | masm.jump(&afterWrite); |
michael@0 | 81 | |
michael@0 | 82 | masm.bind(&writePostInitialize); |
michael@0 | 83 | masm.move32(Imm32(frameFullSize), BaselineTailCallReg); |
michael@0 | 84 | |
michael@0 | 85 | masm.bind(&afterWrite); |
michael@0 | 86 | masm.store32(BaselineTailCallReg, frameSizeAddress); |
michael@0 | 87 | masm.add32(Imm32(argSize), BaselineTailCallReg); |
michael@0 | 88 | masm.makeFrameDescriptor(BaselineTailCallReg, JitFrame_BaselineJS); |
michael@0 | 89 | masm.push(BaselineTailCallReg); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // Perform the call. |
michael@0 | 93 | masm.call(code); |
michael@0 | 94 | uint32_t callOffset = masm.currentOffset(); |
michael@0 | 95 | masm.pop(BaselineFrameReg); |
michael@0 | 96 | |
michael@0 | 97 | // Add a fake ICEntry (without stubs), so that the return offset to |
michael@0 | 98 | // pc mapping works. |
michael@0 | 99 | ICEntry entry(script->pcToOffset(pc), ICEntry::Kind_CallVM); |
michael@0 | 100 | entry.setReturnOffset(callOffset); |
michael@0 | 101 | |
michael@0 | 102 | return icEntries_.append(entry); |
michael@0 | 103 | } |