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/BaselineFrameInfo.h" |
michael@0 | 8 | |
michael@0 | 9 | #ifdef DEBUG |
michael@0 | 10 | # include "jit/BytecodeAnalysis.h" |
michael@0 | 11 | #endif |
michael@0 | 12 | |
michael@0 | 13 | using namespace js; |
michael@0 | 14 | using namespace js::jit; |
michael@0 | 15 | |
michael@0 | 16 | bool |
michael@0 | 17 | FrameInfo::init(TempAllocator &alloc) |
michael@0 | 18 | { |
michael@0 | 19 | // One slot is always needed for this/arguments type checks. |
michael@0 | 20 | size_t nstack = Max(script->nslots() - script->nfixed(), size_t(1)); |
michael@0 | 21 | if (!stack.init(alloc, nstack)) |
michael@0 | 22 | return false; |
michael@0 | 23 | |
michael@0 | 24 | return true; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void |
michael@0 | 28 | FrameInfo::sync(StackValue *val) |
michael@0 | 29 | { |
michael@0 | 30 | switch (val->kind()) { |
michael@0 | 31 | case StackValue::Stack: |
michael@0 | 32 | break; |
michael@0 | 33 | case StackValue::LocalSlot: |
michael@0 | 34 | masm.pushValue(addressOfLocal(val->localSlot())); |
michael@0 | 35 | break; |
michael@0 | 36 | case StackValue::ArgSlot: |
michael@0 | 37 | masm.pushValue(addressOfArg(val->argSlot())); |
michael@0 | 38 | break; |
michael@0 | 39 | case StackValue::ThisSlot: |
michael@0 | 40 | masm.pushValue(addressOfThis()); |
michael@0 | 41 | break; |
michael@0 | 42 | case StackValue::Register: |
michael@0 | 43 | masm.pushValue(val->reg()); |
michael@0 | 44 | break; |
michael@0 | 45 | case StackValue::Constant: |
michael@0 | 46 | masm.pushValue(val->constant()); |
michael@0 | 47 | break; |
michael@0 | 48 | default: |
michael@0 | 49 | MOZ_ASSUME_UNREACHABLE("Invalid kind"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | val->setStack(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void |
michael@0 | 56 | FrameInfo::syncStack(uint32_t uses) |
michael@0 | 57 | { |
michael@0 | 58 | JS_ASSERT(uses <= stackDepth()); |
michael@0 | 59 | |
michael@0 | 60 | uint32_t depth = stackDepth() - uses; |
michael@0 | 61 | |
michael@0 | 62 | for (uint32_t i = 0; i < depth; i++) { |
michael@0 | 63 | StackValue *current = &stack[i]; |
michael@0 | 64 | sync(current); |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | uint32_t |
michael@0 | 69 | FrameInfo::numUnsyncedSlots() |
michael@0 | 70 | { |
michael@0 | 71 | // Start at the bottom, find the first value that's not synced. |
michael@0 | 72 | uint32_t i = 0; |
michael@0 | 73 | for (; i < stackDepth(); i++) { |
michael@0 | 74 | if (peek(-int32_t(i + 1))->kind() == StackValue::Stack) |
michael@0 | 75 | break; |
michael@0 | 76 | } |
michael@0 | 77 | return i; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void |
michael@0 | 81 | FrameInfo::popValue(ValueOperand dest) |
michael@0 | 82 | { |
michael@0 | 83 | StackValue *val = peek(-1); |
michael@0 | 84 | |
michael@0 | 85 | switch (val->kind()) { |
michael@0 | 86 | case StackValue::Constant: |
michael@0 | 87 | masm.moveValue(val->constant(), dest); |
michael@0 | 88 | break; |
michael@0 | 89 | case StackValue::LocalSlot: |
michael@0 | 90 | masm.loadValue(addressOfLocal(val->localSlot()), dest); |
michael@0 | 91 | break; |
michael@0 | 92 | case StackValue::ArgSlot: |
michael@0 | 93 | masm.loadValue(addressOfArg(val->argSlot()), dest); |
michael@0 | 94 | break; |
michael@0 | 95 | case StackValue::ThisSlot: |
michael@0 | 96 | masm.loadValue(addressOfThis(), dest); |
michael@0 | 97 | break; |
michael@0 | 98 | case StackValue::Stack: |
michael@0 | 99 | masm.popValue(dest); |
michael@0 | 100 | break; |
michael@0 | 101 | case StackValue::Register: |
michael@0 | 102 | masm.moveValue(val->reg(), dest); |
michael@0 | 103 | break; |
michael@0 | 104 | default: |
michael@0 | 105 | MOZ_ASSUME_UNREACHABLE("Invalid kind"); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // masm.popValue already adjusted the stack pointer, don't do it twice. |
michael@0 | 109 | pop(DontAdjustStack); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void |
michael@0 | 113 | FrameInfo::popRegsAndSync(uint32_t uses) |
michael@0 | 114 | { |
michael@0 | 115 | // x86 has only 3 Value registers. Only support 2 regs here for now, |
michael@0 | 116 | // so that there's always a scratch Value register for reg -> reg |
michael@0 | 117 | // moves. |
michael@0 | 118 | JS_ASSERT(uses > 0); |
michael@0 | 119 | JS_ASSERT(uses <= 2); |
michael@0 | 120 | JS_ASSERT(uses <= stackDepth()); |
michael@0 | 121 | |
michael@0 | 122 | syncStack(uses); |
michael@0 | 123 | |
michael@0 | 124 | switch (uses) { |
michael@0 | 125 | case 1: |
michael@0 | 126 | popValue(R0); |
michael@0 | 127 | break; |
michael@0 | 128 | case 2: { |
michael@0 | 129 | // If the second value is in R1, move it to R2 so that it's not |
michael@0 | 130 | // clobbered by the first popValue. |
michael@0 | 131 | StackValue *val = peek(-2); |
michael@0 | 132 | if (val->kind() == StackValue::Register && val->reg() == R1) { |
michael@0 | 133 | masm.moveValue(R1, R2); |
michael@0 | 134 | val->setRegister(R2); |
michael@0 | 135 | } |
michael@0 | 136 | popValue(R1); |
michael@0 | 137 | popValue(R0); |
michael@0 | 138 | break; |
michael@0 | 139 | } |
michael@0 | 140 | default: |
michael@0 | 141 | MOZ_ASSUME_UNREACHABLE("Invalid uses"); |
michael@0 | 142 | } |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | #ifdef DEBUG |
michael@0 | 146 | void |
michael@0 | 147 | FrameInfo::assertValidState(const BytecodeInfo &info) |
michael@0 | 148 | { |
michael@0 | 149 | // Check stack depth. |
michael@0 | 150 | JS_ASSERT(stackDepth() == info.stackDepth); |
michael@0 | 151 | |
michael@0 | 152 | // Start at the bottom, find the first value that's not synced. |
michael@0 | 153 | uint32_t i = 0; |
michael@0 | 154 | for (; i < stackDepth(); i++) { |
michael@0 | 155 | if (stack[i].kind() != StackValue::Stack) |
michael@0 | 156 | break; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | // Assert all values on top of it are also not synced. |
michael@0 | 160 | for (; i < stackDepth(); i++) |
michael@0 | 161 | JS_ASSERT(stack[i].kind() != StackValue::Stack); |
michael@0 | 162 | |
michael@0 | 163 | // Assert every Value register is used by at most one StackValue. |
michael@0 | 164 | // R2 is used as scratch register by the compiler and FrameInfo, |
michael@0 | 165 | // so it shouldn't be used for StackValues. |
michael@0 | 166 | bool usedR0 = false, usedR1 = false; |
michael@0 | 167 | |
michael@0 | 168 | for (i = 0; i < stackDepth(); i++) { |
michael@0 | 169 | if (stack[i].kind() == StackValue::Register) { |
michael@0 | 170 | ValueOperand reg = stack[i].reg(); |
michael@0 | 171 | if (reg == R0) { |
michael@0 | 172 | JS_ASSERT(!usedR0); |
michael@0 | 173 | usedR0 = true; |
michael@0 | 174 | } else if (reg == R1) { |
michael@0 | 175 | JS_ASSERT(!usedR1); |
michael@0 | 176 | usedR1 = true; |
michael@0 | 177 | } else { |
michael@0 | 178 | MOZ_ASSUME_UNREACHABLE("Invalid register"); |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | } |
michael@0 | 182 | } |
michael@0 | 183 | #endif |