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 | #ifndef jit_shared_BaselineCompiler_shared_h |
michael@0 | 8 | #define jit_shared_BaselineCompiler_shared_h |
michael@0 | 9 | |
michael@0 | 10 | #include "jit/BaselineFrameInfo.h" |
michael@0 | 11 | #include "jit/BaselineIC.h" |
michael@0 | 12 | #include "jit/BytecodeAnalysis.h" |
michael@0 | 13 | #include "jit/IonMacroAssembler.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace js { |
michael@0 | 16 | namespace jit { |
michael@0 | 17 | |
michael@0 | 18 | class BaselineCompilerShared |
michael@0 | 19 | { |
michael@0 | 20 | protected: |
michael@0 | 21 | JSContext *cx; |
michael@0 | 22 | JSScript *script; |
michael@0 | 23 | jsbytecode *pc; |
michael@0 | 24 | MacroAssembler masm; |
michael@0 | 25 | bool ionCompileable_; |
michael@0 | 26 | bool ionOSRCompileable_; |
michael@0 | 27 | bool debugMode_; |
michael@0 | 28 | |
michael@0 | 29 | TempAllocator &alloc_; |
michael@0 | 30 | BytecodeAnalysis analysis_; |
michael@0 | 31 | FrameInfo frame; |
michael@0 | 32 | |
michael@0 | 33 | FallbackICStubSpace stubSpace_; |
michael@0 | 34 | js::Vector<ICEntry, 16, SystemAllocPolicy> icEntries_; |
michael@0 | 35 | |
michael@0 | 36 | // Stores the native code offset for a bytecode pc. |
michael@0 | 37 | struct PCMappingEntry |
michael@0 | 38 | { |
michael@0 | 39 | uint32_t pcOffset; |
michael@0 | 40 | uint32_t nativeOffset; |
michael@0 | 41 | PCMappingSlotInfo slotInfo; |
michael@0 | 42 | |
michael@0 | 43 | // If set, insert a PCMappingIndexEntry before encoding the |
michael@0 | 44 | // current entry. |
michael@0 | 45 | bool addIndexEntry; |
michael@0 | 46 | |
michael@0 | 47 | void fixupNativeOffset(MacroAssembler &masm) { |
michael@0 | 48 | CodeOffsetLabel offset(nativeOffset); |
michael@0 | 49 | offset.fixup(&masm); |
michael@0 | 50 | JS_ASSERT(offset.offset() <= UINT32_MAX); |
michael@0 | 51 | nativeOffset = (uint32_t) offset.offset(); |
michael@0 | 52 | } |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | js::Vector<PCMappingEntry, 16, SystemAllocPolicy> pcMappingEntries_; |
michael@0 | 56 | |
michael@0 | 57 | // Labels for the 'movWithPatch' for loading IC entry pointers in |
michael@0 | 58 | // the generated IC-calling code in the main jitcode. These need |
michael@0 | 59 | // to be patched with the actual icEntry offsets after the BaselineScript |
michael@0 | 60 | // has been allocated. |
michael@0 | 61 | struct ICLoadLabel { |
michael@0 | 62 | size_t icEntry; |
michael@0 | 63 | CodeOffsetLabel label; |
michael@0 | 64 | }; |
michael@0 | 65 | js::Vector<ICLoadLabel, 16, SystemAllocPolicy> icLoadLabels_; |
michael@0 | 66 | |
michael@0 | 67 | uint32_t pushedBeforeCall_; |
michael@0 | 68 | mozilla::DebugOnly<bool> inCall_; |
michael@0 | 69 | |
michael@0 | 70 | CodeOffsetLabel spsPushToggleOffset_; |
michael@0 | 71 | |
michael@0 | 72 | BaselineCompilerShared(JSContext *cx, TempAllocator &alloc, JSScript *script); |
michael@0 | 73 | |
michael@0 | 74 | ICEntry *allocateICEntry(ICStub *stub, ICEntry::Kind kind) { |
michael@0 | 75 | if (!stub) |
michael@0 | 76 | return nullptr; |
michael@0 | 77 | |
michael@0 | 78 | // Create the entry and add it to the vector. |
michael@0 | 79 | if (!icEntries_.append(ICEntry(script->pcToOffset(pc), kind))) |
michael@0 | 80 | return nullptr; |
michael@0 | 81 | ICEntry &vecEntry = icEntries_.back(); |
michael@0 | 82 | |
michael@0 | 83 | // Set the first stub for the IC entry to the fallback stub |
michael@0 | 84 | vecEntry.setFirstStub(stub); |
michael@0 | 85 | |
michael@0 | 86 | // Return pointer to the IC entry |
michael@0 | 87 | return &vecEntry; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | bool addICLoadLabel(CodeOffsetLabel label) { |
michael@0 | 91 | JS_ASSERT(!icEntries_.empty()); |
michael@0 | 92 | ICLoadLabel loadLabel; |
michael@0 | 93 | loadLabel.label = label; |
michael@0 | 94 | loadLabel.icEntry = icEntries_.length() - 1; |
michael@0 | 95 | return icLoadLabels_.append(loadLabel); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | JSFunction *function() const { |
michael@0 | 99 | // Not delazifying here is ok as the function is guaranteed to have |
michael@0 | 100 | // been delazified before compilation started. |
michael@0 | 101 | return script->functionNonDelazifying(); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | PCMappingSlotInfo getStackTopSlotInfo() { |
michael@0 | 105 | JS_ASSERT(frame.numUnsyncedSlots() <= 2); |
michael@0 | 106 | switch (frame.numUnsyncedSlots()) { |
michael@0 | 107 | case 0: |
michael@0 | 108 | return PCMappingSlotInfo::MakeSlotInfo(); |
michael@0 | 109 | case 1: |
michael@0 | 110 | return PCMappingSlotInfo::MakeSlotInfo(PCMappingSlotInfo::ToSlotLocation(frame.peek(-1))); |
michael@0 | 111 | case 2: |
michael@0 | 112 | default: |
michael@0 | 113 | return PCMappingSlotInfo::MakeSlotInfo(PCMappingSlotInfo::ToSlotLocation(frame.peek(-1)), |
michael@0 | 114 | PCMappingSlotInfo::ToSlotLocation(frame.peek(-2))); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | template <typename T> |
michael@0 | 119 | void pushArg(const T& t) { |
michael@0 | 120 | masm.Push(t); |
michael@0 | 121 | } |
michael@0 | 122 | void prepareVMCall() { |
michael@0 | 123 | pushedBeforeCall_ = masm.framePushed(); |
michael@0 | 124 | inCall_ = true; |
michael@0 | 125 | |
michael@0 | 126 | // Ensure everything is synced. |
michael@0 | 127 | frame.syncStack(0); |
michael@0 | 128 | |
michael@0 | 129 | // Save the frame pointer. |
michael@0 | 130 | masm.Push(BaselineFrameReg); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | enum CallVMPhase { |
michael@0 | 134 | POST_INITIALIZE, |
michael@0 | 135 | PRE_INITIALIZE, |
michael@0 | 136 | CHECK_OVER_RECURSED |
michael@0 | 137 | }; |
michael@0 | 138 | bool callVM(const VMFunction &fun, CallVMPhase phase=POST_INITIALIZE); |
michael@0 | 139 | |
michael@0 | 140 | public: |
michael@0 | 141 | BytecodeAnalysis &analysis() { |
michael@0 | 142 | return analysis_; |
michael@0 | 143 | } |
michael@0 | 144 | }; |
michael@0 | 145 | |
michael@0 | 146 | } // namespace jit |
michael@0 | 147 | } // namespace js |
michael@0 | 148 | |
michael@0 | 149 | #endif /* jit_shared_BaselineCompiler_shared_h */ |