ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "debug.h" |
| 35 | #include "runtime.h" |
| 36 | #include "serialize.h" |
| 37 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 38 | namespace v8 { |
| 39 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 41 | // ------------------------------------------------------------------------- |
| 42 | // MacroAssembler implementation. |
| 43 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 44 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 45 | : Assembler(arg_isolate, buffer, size), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 46 | generating_stub_(false), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 47 | allow_stub_calls_(true) { |
| 48 | if (isolate() != NULL) { |
| 49 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 50 | isolate()); |
| 51 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 55 | void MacroAssembler::RecordWriteHelper(Register object, |
| 56 | Register addr, |
| 57 | Register scratch) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 58 | if (emit_debug_code()) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 59 | // Check that the object is not in new space. |
| 60 | Label not_in_new_space; |
| 61 | InNewSpace(object, scratch, not_equal, ¬_in_new_space); |
| 62 | Abort("new-space object passed to RecordWriteHelper"); |
| 63 | bind(¬_in_new_space); |
| 64 | } |
| 65 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 66 | // Compute the page start address from the heap object pointer, and reuse |
| 67 | // the 'object' register for it. |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 68 | and_(object, ~Page::kPageAlignmentMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 70 | // Compute number of region covering addr. See Page::GetRegionNumberForAddress |
| 71 | // method for more details. |
| 72 | and_(addr, Page::kPageAlignmentMask); |
| 73 | shr(addr, Page::kRegionSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 74 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 75 | // Set dirty mark for region. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 76 | // Bit tests with a memory operand should be avoided on Intel processors, |
| 77 | // as they usually have long latency and multiple uops. We load the bit base |
| 78 | // operand to a register at first and store it back after bit set. |
| 79 | mov(scratch, Operand(object, Page::kDirtyFlagOffset)); |
| 80 | bts(Operand(scratch), addr); |
| 81 | mov(Operand(object, Page::kDirtyFlagOffset), scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 85 | void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, |
| 86 | XMMRegister scratch_reg, |
| 87 | Register result_reg) { |
| 88 | Label done; |
| 89 | ExternalReference zero_ref = ExternalReference::address_of_zero(); |
| 90 | movdbl(scratch_reg, Operand::StaticVariable(zero_ref)); |
| 91 | Set(result_reg, Immediate(0)); |
| 92 | ucomisd(input_reg, scratch_reg); |
| 93 | j(below, &done, Label::kNear); |
| 94 | ExternalReference half_ref = ExternalReference::address_of_one_half(); |
| 95 | movdbl(scratch_reg, Operand::StaticVariable(half_ref)); |
| 96 | addsd(scratch_reg, input_reg); |
| 97 | cvttsd2si(result_reg, Operand(scratch_reg)); |
| 98 | test(result_reg, Immediate(0xFFFFFF00)); |
| 99 | j(zero, &done, Label::kNear); |
| 100 | Set(result_reg, Immediate(255)); |
| 101 | bind(&done); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void MacroAssembler::ClampUint8(Register reg) { |
| 106 | Label done; |
| 107 | test(reg, Immediate(0xFFFFFF00)); |
| 108 | j(zero, &done, Label::kNear); |
| 109 | setcc(negative, reg); // 1 if negative, 0 if positive. |
| 110 | dec_b(reg); // 0 if negative, 255 if positive. |
| 111 | bind(&done); |
| 112 | } |
| 113 | |
| 114 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 115 | void MacroAssembler::InNewSpace(Register object, |
| 116 | Register scratch, |
| 117 | Condition cc, |
| 118 | Label* branch, |
| 119 | Label::Distance branch_near) { |
| 120 | ASSERT(cc == equal || cc == not_equal); |
| 121 | if (Serializer::enabled()) { |
| 122 | // Can't do arithmetic on external references if it might get serialized. |
| 123 | mov(scratch, Operand(object)); |
| 124 | // The mask isn't really an address. We load it as an external reference in |
| 125 | // case the size of the new space is different between the snapshot maker |
| 126 | // and the running system. |
| 127 | and_(Operand(scratch), |
| 128 | Immediate(ExternalReference::new_space_mask(isolate()))); |
| 129 | cmp(Operand(scratch), |
| 130 | Immediate(ExternalReference::new_space_start(isolate()))); |
| 131 | j(cc, branch, branch_near); |
| 132 | } else { |
| 133 | int32_t new_space_start = reinterpret_cast<int32_t>( |
| 134 | ExternalReference::new_space_start(isolate()).address()); |
| 135 | lea(scratch, Operand(object, -new_space_start)); |
| 136 | and_(scratch, isolate()->heap()->NewSpaceMask()); |
| 137 | j(cc, branch, branch_near); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 142 | void MacroAssembler::RecordWrite(Register object, |
| 143 | int offset, |
| 144 | Register value, |
| 145 | Register scratch) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 146 | // First, check if a write barrier is even needed. The tests below |
| 147 | // catch stores of Smis and stores into young gen. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 148 | Label done; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 150 | // Skip barrier if writing a smi. |
| 151 | ASSERT_EQ(0, kSmiTag); |
| 152 | test(value, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 153 | j(zero, &done, Label::kNear); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 154 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 155 | InNewSpace(object, value, equal, &done, Label::kNear); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | |
whesse@chromium.org | e88a9ed | 2010-04-15 15:07:46 +0000 | [diff] [blame] | 157 | // The offset is relative to a tagged or untagged HeapObject pointer, |
| 158 | // so either offset or offset + kHeapObjectTag must be a |
| 159 | // multiple of kPointerSize. |
| 160 | ASSERT(IsAligned(offset, kPointerSize) || |
| 161 | IsAligned(offset + kHeapObjectTag, kPointerSize)); |
| 162 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 163 | Register dst = scratch; |
| 164 | if (offset != 0) { |
| 165 | lea(dst, Operand(object, offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 167 | // Array access: calculate the destination address in the same manner as |
| 168 | // KeyedStoreIC::GenerateGeneric. Multiply a smi by 2 to get an offset |
| 169 | // into an array of words. |
| 170 | ASSERT_EQ(1, kSmiTagSize); |
| 171 | ASSERT_EQ(0, kSmiTag); |
| 172 | lea(dst, Operand(object, dst, times_half_pointer_size, |
| 173 | FixedArray::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 174 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 175 | RecordWriteHelper(object, dst, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | |
| 177 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 178 | |
| 179 | // Clobber all input registers when running with the debug-code flag |
| 180 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 181 | if (emit_debug_code()) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 182 | mov(object, Immediate(BitCast<int32_t>(kZapValue))); |
| 183 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 184 | mov(scratch, Immediate(BitCast<int32_t>(kZapValue))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 185 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 189 | void MacroAssembler::RecordWrite(Register object, |
| 190 | Register address, |
| 191 | Register value) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 192 | // First, check if a write barrier is even needed. The tests below |
| 193 | // catch stores of Smis and stores into young gen. |
| 194 | Label done; |
| 195 | |
| 196 | // Skip barrier if writing a smi. |
| 197 | ASSERT_EQ(0, kSmiTag); |
| 198 | test(value, Immediate(kSmiTagMask)); |
| 199 | j(zero, &done); |
| 200 | |
| 201 | InNewSpace(object, value, equal, &done); |
| 202 | |
| 203 | RecordWriteHelper(object, address, value); |
| 204 | |
| 205 | bind(&done); |
| 206 | |
| 207 | // Clobber all input registers when running with the debug-code flag |
| 208 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 209 | if (emit_debug_code()) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 210 | mov(object, Immediate(BitCast<int32_t>(kZapValue))); |
| 211 | mov(address, Immediate(BitCast<int32_t>(kZapValue))); |
| 212 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 217 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 218 | void MacroAssembler::DebugBreak() { |
| 219 | Set(eax, Immediate(0)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 220 | mov(ebx, Immediate(ExternalReference(Runtime::kDebugBreak, isolate()))); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 221 | CEntryStub ces(1); |
| 222 | call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 223 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 224 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 226 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | void MacroAssembler::Set(Register dst, const Immediate& x) { |
| 228 | if (x.is_zero()) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 229 | xor_(dst, Operand(dst)); // Shorter than mov. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 231 | mov(dst, x); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | |
| 236 | void MacroAssembler::Set(const Operand& dst, const Immediate& x) { |
| 237 | mov(dst, x); |
| 238 | } |
| 239 | |
| 240 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 241 | bool MacroAssembler::IsUnsafeImmediate(const Immediate& x) { |
| 242 | static const int kMaxImmediateBits = 17; |
| 243 | if (x.rmode_ != RelocInfo::NONE) return false; |
| 244 | return !is_intn(x.x_, kMaxImmediateBits); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | void MacroAssembler::SafeSet(Register dst, const Immediate& x) { |
| 249 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
| 250 | Set(dst, Immediate(x.x_ ^ jit_cookie())); |
| 251 | xor_(dst, jit_cookie()); |
| 252 | } else { |
| 253 | Set(dst, x); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | void MacroAssembler::SafePush(const Immediate& x) { |
| 259 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
| 260 | push(Immediate(x.x_ ^ jit_cookie())); |
| 261 | xor_(Operand(esp, 0), Immediate(jit_cookie())); |
| 262 | } else { |
| 263 | push(x); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 268 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 269 | InstanceType type, |
| 270 | Register map) { |
| 271 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 272 | CmpInstanceType(map, type); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 277 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 278 | static_cast<int8_t>(type)); |
| 279 | } |
| 280 | |
| 281 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 282 | void MacroAssembler::CheckFastElements(Register map, |
| 283 | Label* fail, |
| 284 | Label::Distance distance) { |
| 285 | STATIC_ASSERT(JSObject::FAST_ELEMENTS == 0); |
| 286 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 287 | Map::kMaximumBitField2FastElementValue); |
| 288 | j(above, fail, distance); |
| 289 | } |
| 290 | |
| 291 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 292 | void MacroAssembler::CheckMap(Register obj, |
| 293 | Handle<Map> map, |
| 294 | Label* fail, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 295 | SmiCheckType smi_check_type) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 296 | if (smi_check_type == DO_SMI_CHECK) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 297 | JumpIfSmi(obj, fail); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 298 | } |
| 299 | cmp(FieldOperand(obj, HeapObject::kMapOffset), Immediate(map)); |
| 300 | j(not_equal, fail); |
| 301 | } |
| 302 | |
| 303 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 304 | void MacroAssembler::DispatchMap(Register obj, |
| 305 | Handle<Map> map, |
| 306 | Handle<Code> success, |
| 307 | SmiCheckType smi_check_type) { |
| 308 | Label fail; |
ager@chromium.org | 560b07b | 2011-05-23 16:33:44 +0000 | [diff] [blame] | 309 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 310 | JumpIfSmi(obj, &fail); |
| 311 | } |
| 312 | cmp(FieldOperand(obj, HeapObject::kMapOffset), Immediate(map)); |
| 313 | j(equal, success); |
| 314 | |
| 315 | bind(&fail); |
| 316 | } |
| 317 | |
| 318 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 319 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 320 | Register map, |
| 321 | Register instance_type) { |
| 322 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 323 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 324 | ASSERT(kNotStringTag != 0); |
| 325 | test(instance_type, Immediate(kIsNotStringMask)); |
| 326 | return zero; |
| 327 | } |
| 328 | |
| 329 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 330 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 331 | Register map, |
| 332 | Register scratch, |
| 333 | Label* fail) { |
| 334 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 335 | IsInstanceJSObjectType(map, scratch, fail); |
| 336 | } |
| 337 | |
| 338 | |
| 339 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 340 | Register scratch, |
| 341 | Label* fail) { |
| 342 | movzx_b(scratch, FieldOperand(map, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 343 | sub(Operand(scratch), Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
| 344 | cmp(scratch, |
| 345 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE - FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 346 | j(above, fail); |
| 347 | } |
| 348 | |
| 349 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | void MacroAssembler::FCmp() { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 351 | if (CpuFeatures::IsSupported(CMOV)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 352 | fucomip(); |
| 353 | ffree(0); |
| 354 | fincstp(); |
| 355 | } else { |
| 356 | fucompp(); |
| 357 | push(eax); |
| 358 | fnstsw_ax(); |
| 359 | sahf(); |
| 360 | pop(eax); |
| 361 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 365 | void MacroAssembler::AbortIfNotNumber(Register object) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 366 | Label ok; |
| 367 | test(object, Immediate(kSmiTagMask)); |
| 368 | j(zero, &ok); |
| 369 | cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 370 | isolate()->factory()->heap_number_map()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 371 | Assert(equal, "Operand not a number"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 372 | bind(&ok); |
| 373 | } |
| 374 | |
| 375 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 376 | void MacroAssembler::AbortIfNotSmi(Register object) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 377 | test(object, Immediate(kSmiTagMask)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 378 | Assert(equal, "Operand is not a smi"); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 382 | void MacroAssembler::AbortIfNotString(Register object) { |
| 383 | test(object, Immediate(kSmiTagMask)); |
| 384 | Assert(not_equal, "Operand is not a string"); |
| 385 | push(object); |
| 386 | mov(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 387 | CmpInstanceType(object, FIRST_NONSTRING_TYPE); |
| 388 | pop(object); |
| 389 | Assert(below, "Operand is not a string"); |
| 390 | } |
| 391 | |
| 392 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 393 | void MacroAssembler::AbortIfSmi(Register object) { |
| 394 | test(object, Immediate(kSmiTagMask)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 395 | Assert(not_equal, "Operand is a smi"); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 399 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | push(ebp); |
| 401 | mov(ebp, Operand(esp)); |
| 402 | push(esi); |
| 403 | push(Immediate(Smi::FromInt(type))); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 404 | push(Immediate(CodeObject())); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 405 | if (emit_debug_code()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 406 | cmp(Operand(esp, 0), Immediate(isolate()->factory()->undefined_value())); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 407 | Check(not_equal, "code object not properly patched"); |
| 408 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 412 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 413 | if (emit_debug_code()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | cmp(Operand(ebp, StandardFrameConstants::kMarkerOffset), |
| 415 | Immediate(Smi::FromInt(type))); |
| 416 | Check(equal, "stack frame types must match"); |
| 417 | } |
| 418 | leave(); |
| 419 | } |
| 420 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 421 | |
| 422 | void MacroAssembler::EnterExitFramePrologue() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 423 | // Setup the frame structure on the stack. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 424 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 425 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 426 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 427 | push(ebp); |
| 428 | mov(ebp, Operand(esp)); |
| 429 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 430 | // Reserve room for entry stack pointer and push the code object. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 431 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 432 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 433 | push(Immediate(CodeObject())); // Accessed from ExitFrame::code_slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 434 | |
| 435 | // Save the frame pointer and the context in top. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 436 | ExternalReference c_entry_fp_address(Isolate::k_c_entry_fp_address, |
| 437 | isolate()); |
| 438 | ExternalReference context_address(Isolate::k_context_address, |
| 439 | isolate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 440 | mov(Operand::StaticVariable(c_entry_fp_address), ebp); |
| 441 | mov(Operand::StaticVariable(context_address), esi); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 442 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 443 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 444 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 445 | void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) { |
| 446 | // Optionally save all XMM registers. |
| 447 | if (save_doubles) { |
| 448 | CpuFeatures::Scope scope(SSE2); |
| 449 | int space = XMMRegister::kNumRegisters * kDoubleSize + argc * kPointerSize; |
| 450 | sub(Operand(esp), Immediate(space)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 451 | const int offset = -2 * kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 452 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 453 | XMMRegister reg = XMMRegister::from_code(i); |
| 454 | movdbl(Operand(ebp, offset - ((i + 1) * kDoubleSize)), reg); |
| 455 | } |
| 456 | } else { |
| 457 | sub(Operand(esp), Immediate(argc * kPointerSize)); |
| 458 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 459 | |
| 460 | // Get the required frame alignment for the OS. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 461 | const int kFrameAlignment = OS::ActivationFrameAlignment(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 462 | if (kFrameAlignment > 0) { |
| 463 | ASSERT(IsPowerOf2(kFrameAlignment)); |
| 464 | and_(esp, -kFrameAlignment); |
| 465 | } |
| 466 | |
| 467 | // Patch the saved entry sp. |
| 468 | mov(Operand(ebp, ExitFrameConstants::kSPOffset), esp); |
| 469 | } |
| 470 | |
| 471 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 472 | void MacroAssembler::EnterExitFrame(bool save_doubles) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 473 | EnterExitFramePrologue(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 474 | |
| 475 | // Setup argc and argv in callee-saved registers. |
| 476 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 477 | mov(edi, Operand(eax)); |
| 478 | lea(esi, Operand(ebp, eax, times_4, offset)); |
| 479 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 480 | // Reserve space for argc, argv and isolate. |
| 481 | EnterExitFrameEpilogue(3, save_doubles); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 485 | void MacroAssembler::EnterApiExitFrame(int argc) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 486 | EnterExitFramePrologue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 487 | EnterExitFrameEpilogue(argc, false); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 491 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
| 492 | // Optionally restore all XMM registers. |
| 493 | if (save_doubles) { |
| 494 | CpuFeatures::Scope scope(SSE2); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 495 | const int offset = -2 * kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 496 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 497 | XMMRegister reg = XMMRegister::from_code(i); |
| 498 | movdbl(reg, Operand(ebp, offset - ((i + 1) * kDoubleSize))); |
| 499 | } |
| 500 | } |
| 501 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 502 | // Get the return address from the stack and restore the frame pointer. |
| 503 | mov(ecx, Operand(ebp, 1 * kPointerSize)); |
| 504 | mov(ebp, Operand(ebp, 0 * kPointerSize)); |
| 505 | |
| 506 | // Pop the arguments and the receiver from the caller stack. |
| 507 | lea(esp, Operand(esi, 1 * kPointerSize)); |
| 508 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 509 | // Push the return address to get ready to return. |
| 510 | push(ecx); |
| 511 | |
| 512 | LeaveExitFrameEpilogue(); |
| 513 | } |
| 514 | |
| 515 | void MacroAssembler::LeaveExitFrameEpilogue() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 516 | // Restore current context from top and clear it in debug mode. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 517 | ExternalReference context_address(Isolate::k_context_address, isolate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 518 | mov(esi, Operand::StaticVariable(context_address)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 519 | #ifdef DEBUG |
| 520 | mov(Operand::StaticVariable(context_address), Immediate(0)); |
| 521 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 522 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 523 | // Clear the top frame. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 524 | ExternalReference c_entry_fp_address(Isolate::k_c_entry_fp_address, |
| 525 | isolate()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 526 | mov(Operand::StaticVariable(c_entry_fp_address), Immediate(0)); |
| 527 | } |
| 528 | |
| 529 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 530 | void MacroAssembler::LeaveApiExitFrame() { |
| 531 | mov(esp, Operand(ebp)); |
| 532 | pop(ebp); |
| 533 | |
| 534 | LeaveExitFrameEpilogue(); |
| 535 | } |
| 536 | |
| 537 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 539 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 540 | // Adjust this code if not the case. |
| 541 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 542 | // The pc (return address) is already on TOS. |
| 543 | if (try_location == IN_JAVASCRIPT) { |
| 544 | if (type == TRY_CATCH_HANDLER) { |
| 545 | push(Immediate(StackHandler::TRY_CATCH)); |
| 546 | } else { |
| 547 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 548 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | push(ebp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | } else { |
| 551 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 552 | // The frame pointer does not point to a JS frame so we save NULL |
| 553 | // for ebp. We expect the code throwing an exception to check ebp |
| 554 | // before dereferencing it to restore the context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | push(Immediate(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 556 | push(Immediate(0)); // NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 558 | // Save the current handler as the next handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 559 | push(Operand::StaticVariable(ExternalReference(Isolate::k_handler_address, |
| 560 | isolate()))); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 561 | // Link this handler as the new current one. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 562 | mov(Operand::StaticVariable(ExternalReference(Isolate::k_handler_address, |
| 563 | isolate())), |
| 564 | esp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 568 | void MacroAssembler::PopTryHandler() { |
| 569 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 570 | pop(Operand::StaticVariable(ExternalReference(Isolate::k_handler_address, |
| 571 | isolate()))); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 572 | add(Operand(esp), Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 573 | } |
| 574 | |
| 575 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 576 | void MacroAssembler::Throw(Register value) { |
| 577 | // Adjust this code if not the case. |
| 578 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 579 | |
| 580 | // eax must hold the exception. |
| 581 | if (!value.is(eax)) { |
| 582 | mov(eax, value); |
| 583 | } |
| 584 | |
| 585 | // Drop the sp to the top of the handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 586 | ExternalReference handler_address(Isolate::k_handler_address, |
| 587 | isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 588 | mov(esp, Operand::StaticVariable(handler_address)); |
| 589 | |
| 590 | // Restore next handler and frame pointer, discard handler state. |
| 591 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 592 | pop(Operand::StaticVariable(handler_address)); |
| 593 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 1 * kPointerSize); |
| 594 | pop(ebp); |
| 595 | pop(edx); // Remove state. |
| 596 | |
| 597 | // Before returning we restore the context from the frame pointer if |
| 598 | // not NULL. The frame pointer is NULL in the exception handler of |
| 599 | // a JS entry frame. |
| 600 | Set(esi, Immediate(0)); // Tentatively set context pointer to NULL. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 601 | Label skip; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 602 | cmp(ebp, 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 603 | j(equal, &skip, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 604 | mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 605 | bind(&skip); |
| 606 | |
| 607 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 608 | ret(0); |
| 609 | } |
| 610 | |
| 611 | |
| 612 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 613 | Register value) { |
| 614 | // Adjust this code if not the case. |
| 615 | STATIC_ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 616 | |
| 617 | // eax must hold the exception. |
| 618 | if (!value.is(eax)) { |
| 619 | mov(eax, value); |
| 620 | } |
| 621 | |
| 622 | // Drop sp to the top stack handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 623 | ExternalReference handler_address(Isolate::k_handler_address, |
| 624 | isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 625 | mov(esp, Operand::StaticVariable(handler_address)); |
| 626 | |
| 627 | // Unwind the handlers until the ENTRY handler is found. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 628 | Label loop, done; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 629 | bind(&loop); |
| 630 | // Load the type of the current stack handler. |
| 631 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 632 | cmp(Operand(esp, kStateOffset), Immediate(StackHandler::ENTRY)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 633 | j(equal, &done, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 634 | // Fetch the next handler in the list. |
| 635 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 636 | mov(esp, Operand(esp, kNextOffset)); |
| 637 | jmp(&loop); |
| 638 | bind(&done); |
| 639 | |
| 640 | // Set the top handler address to next handler past the current ENTRY handler. |
| 641 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 642 | pop(Operand::StaticVariable(handler_address)); |
| 643 | |
| 644 | if (type == OUT_OF_MEMORY) { |
| 645 | // Set external caught exception to false. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 646 | ExternalReference external_caught( |
| 647 | Isolate::k_external_caught_exception_address, |
| 648 | isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 649 | mov(eax, false); |
| 650 | mov(Operand::StaticVariable(external_caught), eax); |
| 651 | |
| 652 | // Set pending exception and eax to out of memory exception. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 653 | ExternalReference pending_exception(Isolate::k_pending_exception_address, |
| 654 | isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 655 | mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 656 | mov(Operand::StaticVariable(pending_exception), eax); |
| 657 | } |
| 658 | |
| 659 | // Clear the context pointer. |
| 660 | Set(esi, Immediate(0)); |
| 661 | |
| 662 | // Restore fp from handler and discard handler state. |
| 663 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 1 * kPointerSize); |
| 664 | pop(ebp); |
| 665 | pop(edx); // State. |
| 666 | |
| 667 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 668 | ret(0); |
| 669 | } |
| 670 | |
| 671 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 672 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 673 | Register scratch, |
| 674 | Label* miss) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 675 | Label same_contexts; |
| 676 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | ASSERT(!holder_reg.is(scratch)); |
| 678 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 679 | // Load current lexical context from the stack frame. |
| 680 | mov(scratch, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 681 | |
| 682 | // When generating debug code, make sure the lexical context is set. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 683 | if (emit_debug_code()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | cmp(Operand(scratch), Immediate(0)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 685 | Check(not_equal, "we should not have an empty lexical context"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 687 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 688 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 689 | mov(scratch, FieldOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 690 | mov(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 691 | |
| 692 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 693 | if (emit_debug_code()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 694 | push(scratch); |
| 695 | // Read the first word and compare to global_context_map. |
| 696 | mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 697 | cmp(scratch, isolate()->factory()->global_context_map()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 698 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 699 | pop(scratch); |
| 700 | } |
| 701 | |
| 702 | // Check if both contexts are the same. |
| 703 | cmp(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 704 | j(equal, &same_contexts); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 705 | |
| 706 | // Compare security tokens, save holder_reg on the stack so we can use it |
| 707 | // as a temporary register. |
| 708 | // |
| 709 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 710 | push(holder_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | // Check that the security token in the calling global object is |
| 712 | // compatible with the security token in the receiving global |
| 713 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 714 | mov(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 715 | |
| 716 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 717 | if (emit_debug_code()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 718 | cmp(holder_reg, isolate()->factory()->null_value()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 719 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 720 | |
| 721 | push(holder_reg); |
| 722 | // Read the first word and compare to global_context_map(), |
| 723 | mov(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 724 | cmp(holder_reg, isolate()->factory()->global_context_map()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 725 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 726 | pop(holder_reg); |
| 727 | } |
| 728 | |
| 729 | int token_offset = Context::kHeaderSize + |
| 730 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 731 | mov(scratch, FieldOperand(scratch, token_offset)); |
| 732 | cmp(scratch, FieldOperand(holder_reg, token_offset)); |
| 733 | pop(holder_reg); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 734 | j(not_equal, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 735 | |
| 736 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 740 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 741 | Register scratch, |
| 742 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 743 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 744 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 745 | |
| 746 | // Just return if allocation top is already known. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 747 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 748 | // No use of scratch if allocation top is provided. |
| 749 | ASSERT(scratch.is(no_reg)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 750 | #ifdef DEBUG |
| 751 | // Assert that result actually contains top on entry. |
| 752 | cmp(result, Operand::StaticVariable(new_space_allocation_top)); |
| 753 | Check(equal, "Unexpected allocation top"); |
| 754 | #endif |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | |
| 758 | // Move address of new object to result. Use scratch register if available. |
| 759 | if (scratch.is(no_reg)) { |
| 760 | mov(result, Operand::StaticVariable(new_space_allocation_top)); |
| 761 | } else { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 762 | mov(Operand(scratch), Immediate(new_space_allocation_top)); |
| 763 | mov(result, Operand(scratch, 0)); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | |
| 768 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 769 | Register scratch) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 770 | if (emit_debug_code()) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 771 | test(result_end, Immediate(kObjectAlignmentMask)); |
| 772 | Check(zero, "Unaligned allocation in new space"); |
| 773 | } |
| 774 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 775 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 776 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 777 | |
| 778 | // Update new top. Use scratch if available. |
| 779 | if (scratch.is(no_reg)) { |
| 780 | mov(Operand::StaticVariable(new_space_allocation_top), result_end); |
| 781 | } else { |
| 782 | mov(Operand(scratch, 0), result_end); |
| 783 | } |
| 784 | } |
| 785 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 786 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 787 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 788 | Register result, |
| 789 | Register result_end, |
| 790 | Register scratch, |
| 791 | Label* gc_required, |
| 792 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 793 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 794 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 795 | // Trash the registers to simulate an allocation failure. |
| 796 | mov(result, Immediate(0x7091)); |
| 797 | if (result_end.is_valid()) { |
| 798 | mov(result_end, Immediate(0x7191)); |
| 799 | } |
| 800 | if (scratch.is_valid()) { |
| 801 | mov(scratch, Immediate(0x7291)); |
| 802 | } |
| 803 | } |
| 804 | jmp(gc_required); |
| 805 | return; |
| 806 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 807 | ASSERT(!result.is(result_end)); |
| 808 | |
| 809 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 810 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 811 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 812 | Register top_reg = result_end.is_valid() ? result_end : result; |
| 813 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 814 | // Calculate new top and bail out if new space is exhausted. |
| 815 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 816 | ExternalReference::new_space_allocation_limit_address(isolate()); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 817 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 818 | if (!top_reg.is(result)) { |
| 819 | mov(top_reg, result); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 820 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 821 | add(Operand(top_reg), Immediate(object_size)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 822 | j(carry, gc_required); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 823 | cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 824 | j(above, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 825 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 826 | // Update allocation top. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 827 | UpdateAllocationTopHelper(top_reg, scratch); |
| 828 | |
| 829 | // Tag result if requested. |
| 830 | if (top_reg.is(result)) { |
| 831 | if ((flags & TAG_OBJECT) != 0) { |
| 832 | sub(Operand(result), Immediate(object_size - kHeapObjectTag)); |
| 833 | } else { |
| 834 | sub(Operand(result), Immediate(object_size)); |
| 835 | } |
| 836 | } else if ((flags & TAG_OBJECT) != 0) { |
| 837 | add(Operand(result), Immediate(kHeapObjectTag)); |
| 838 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 842 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 843 | ScaleFactor element_size, |
| 844 | Register element_count, |
| 845 | Register result, |
| 846 | Register result_end, |
| 847 | Register scratch, |
| 848 | Label* gc_required, |
| 849 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 850 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 851 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 852 | // Trash the registers to simulate an allocation failure. |
| 853 | mov(result, Immediate(0x7091)); |
| 854 | mov(result_end, Immediate(0x7191)); |
| 855 | if (scratch.is_valid()) { |
| 856 | mov(scratch, Immediate(0x7291)); |
| 857 | } |
| 858 | // Register element_count is not modified by the function. |
| 859 | } |
| 860 | jmp(gc_required); |
| 861 | return; |
| 862 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 863 | ASSERT(!result.is(result_end)); |
| 864 | |
| 865 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 866 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 867 | |
| 868 | // Calculate new top and bail out if new space is exhausted. |
| 869 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 870 | ExternalReference::new_space_allocation_limit_address(isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 871 | |
| 872 | // We assume that element_count*element_size + header_size does not |
| 873 | // overflow. |
| 874 | lea(result_end, Operand(element_count, element_size, header_size)); |
| 875 | add(result_end, Operand(result)); |
| 876 | j(carry, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 877 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 878 | j(above, gc_required); |
| 879 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 880 | // Tag result if requested. |
| 881 | if ((flags & TAG_OBJECT) != 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 882 | lea(result, Operand(result, kHeapObjectTag)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 883 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 884 | |
| 885 | // Update allocation top. |
| 886 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 890 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 891 | Register result, |
| 892 | Register result_end, |
| 893 | Register scratch, |
| 894 | Label* gc_required, |
| 895 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 896 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 897 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 898 | // Trash the registers to simulate an allocation failure. |
| 899 | mov(result, Immediate(0x7091)); |
| 900 | mov(result_end, Immediate(0x7191)); |
| 901 | if (scratch.is_valid()) { |
| 902 | mov(scratch, Immediate(0x7291)); |
| 903 | } |
| 904 | // object_size is left unchanged by this function. |
| 905 | } |
| 906 | jmp(gc_required); |
| 907 | return; |
| 908 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 909 | ASSERT(!result.is(result_end)); |
| 910 | |
| 911 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 912 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 913 | |
| 914 | // Calculate new top and bail out if new space is exhausted. |
| 915 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 916 | ExternalReference::new_space_allocation_limit_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 917 | if (!object_size.is(result_end)) { |
| 918 | mov(result_end, object_size); |
| 919 | } |
| 920 | add(result_end, Operand(result)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 921 | j(carry, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 922 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 923 | j(above, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 924 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 925 | // Tag result if requested. |
| 926 | if ((flags & TAG_OBJECT) != 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 927 | lea(result, Operand(result, kHeapObjectTag)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 928 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 929 | |
| 930 | // Update allocation top. |
| 931 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | |
| 935 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 936 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 937 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 938 | |
| 939 | // Make sure the object has no tag before resetting top. |
| 940 | and_(Operand(object), Immediate(~kHeapObjectTagMask)); |
| 941 | #ifdef DEBUG |
| 942 | cmp(object, Operand::StaticVariable(new_space_allocation_top)); |
| 943 | Check(below, "Undo allocation of non allocated memory"); |
| 944 | #endif |
| 945 | mov(Operand::StaticVariable(new_space_allocation_top), object); |
| 946 | } |
| 947 | |
| 948 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 949 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 950 | Register scratch1, |
| 951 | Register scratch2, |
| 952 | Label* gc_required) { |
| 953 | // Allocate heap number in new space. |
| 954 | AllocateInNewSpace(HeapNumber::kSize, |
| 955 | result, |
| 956 | scratch1, |
| 957 | scratch2, |
| 958 | gc_required, |
| 959 | TAG_OBJECT); |
| 960 | |
| 961 | // Set the map. |
| 962 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 963 | Immediate(isolate()->factory()->heap_number_map())); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 967 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 968 | Register length, |
| 969 | Register scratch1, |
| 970 | Register scratch2, |
| 971 | Register scratch3, |
| 972 | Label* gc_required) { |
| 973 | // Calculate the number of bytes needed for the characters in the string while |
| 974 | // observing object alignment. |
| 975 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 976 | ASSERT(kShortSize == 2); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 977 | // scratch1 = length * 2 + kObjectAlignmentMask. |
| 978 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 979 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 980 | |
| 981 | // Allocate two byte string in new space. |
| 982 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 983 | times_1, |
| 984 | scratch1, |
| 985 | result, |
| 986 | scratch2, |
| 987 | scratch3, |
| 988 | gc_required, |
| 989 | TAG_OBJECT); |
| 990 | |
| 991 | // Set the map, length and hash field. |
| 992 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 993 | Immediate(isolate()->factory()->string_map())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 994 | mov(scratch1, length); |
| 995 | SmiTag(scratch1); |
| 996 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 997 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 998 | Immediate(String::kEmptyHashField)); |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1003 | Register length, |
| 1004 | Register scratch1, |
| 1005 | Register scratch2, |
| 1006 | Register scratch3, |
| 1007 | Label* gc_required) { |
| 1008 | // Calculate the number of bytes needed for the characters in the string while |
| 1009 | // observing object alignment. |
| 1010 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1011 | mov(scratch1, length); |
| 1012 | ASSERT(kCharSize == 1); |
| 1013 | add(Operand(scratch1), Immediate(kObjectAlignmentMask)); |
| 1014 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 1015 | |
| 1016 | // Allocate ascii string in new space. |
| 1017 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 1018 | times_1, |
| 1019 | scratch1, |
| 1020 | result, |
| 1021 | scratch2, |
| 1022 | scratch3, |
| 1023 | gc_required, |
| 1024 | TAG_OBJECT); |
| 1025 | |
| 1026 | // Set the map, length and hash field. |
| 1027 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1028 | Immediate(isolate()->factory()->ascii_string_map())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1029 | mov(scratch1, length); |
| 1030 | SmiTag(scratch1); |
| 1031 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1032 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1033 | Immediate(String::kEmptyHashField)); |
| 1034 | } |
| 1035 | |
| 1036 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1037 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1038 | int length, |
| 1039 | Register scratch1, |
| 1040 | Register scratch2, |
| 1041 | Label* gc_required) { |
| 1042 | ASSERT(length > 0); |
| 1043 | |
| 1044 | // Allocate ascii string in new space. |
| 1045 | AllocateInNewSpace(SeqAsciiString::SizeFor(length), |
| 1046 | result, |
| 1047 | scratch1, |
| 1048 | scratch2, |
| 1049 | gc_required, |
| 1050 | TAG_OBJECT); |
| 1051 | |
| 1052 | // Set the map, length and hash field. |
| 1053 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1054 | Immediate(isolate()->factory()->ascii_string_map())); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 1055 | mov(FieldOperand(result, String::kLengthOffset), |
| 1056 | Immediate(Smi::FromInt(length))); |
| 1057 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1058 | Immediate(String::kEmptyHashField)); |
| 1059 | } |
| 1060 | |
| 1061 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1062 | void MacroAssembler::AllocateConsString(Register result, |
| 1063 | Register scratch1, |
| 1064 | Register scratch2, |
| 1065 | Label* gc_required) { |
| 1066 | // Allocate heap number in new space. |
| 1067 | AllocateInNewSpace(ConsString::kSize, |
| 1068 | result, |
| 1069 | scratch1, |
| 1070 | scratch2, |
| 1071 | gc_required, |
| 1072 | TAG_OBJECT); |
| 1073 | |
| 1074 | // Set the map. The other fields are left uninitialized. |
| 1075 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1076 | Immediate(isolate()->factory()->cons_string_map())); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1081 | Register scratch1, |
| 1082 | Register scratch2, |
| 1083 | Label* gc_required) { |
| 1084 | // Allocate heap number in new space. |
| 1085 | AllocateInNewSpace(ConsString::kSize, |
| 1086 | result, |
| 1087 | scratch1, |
| 1088 | scratch2, |
| 1089 | gc_required, |
| 1090 | TAG_OBJECT); |
| 1091 | |
| 1092 | // Set the map. The other fields are left uninitialized. |
| 1093 | mov(FieldOperand(result, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1094 | Immediate(isolate()->factory()->cons_ascii_string_map())); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1097 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1098 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 1099 | // long or aligned copies. The contents of scratch and length are destroyed. |
| 1100 | // Source and destination are incremented by length. |
| 1101 | // Many variants of movsb, loop unrolling, word moves, and indexed operands |
| 1102 | // have been tried here already, and this is fastest. |
| 1103 | // A simpler loop is faster on small copies, but 30% slower on large ones. |
| 1104 | // The cld() instruction must have been emitted, to set the direction flag(), |
| 1105 | // before calling this function. |
| 1106 | void MacroAssembler::CopyBytes(Register source, |
| 1107 | Register destination, |
| 1108 | Register length, |
| 1109 | Register scratch) { |
| 1110 | Label loop, done, short_string, short_loop; |
| 1111 | // Experimentation shows that the short string loop is faster if length < 10. |
| 1112 | cmp(Operand(length), Immediate(10)); |
| 1113 | j(less_equal, &short_string); |
| 1114 | |
| 1115 | ASSERT(source.is(esi)); |
| 1116 | ASSERT(destination.is(edi)); |
| 1117 | ASSERT(length.is(ecx)); |
| 1118 | |
| 1119 | // Because source is 4-byte aligned in our uses of this function, |
| 1120 | // we keep source aligned for the rep_movs call by copying the odd bytes |
| 1121 | // at the end of the ranges. |
| 1122 | mov(scratch, Operand(source, length, times_1, -4)); |
| 1123 | mov(Operand(destination, length, times_1, -4), scratch); |
| 1124 | mov(scratch, ecx); |
| 1125 | shr(ecx, 2); |
| 1126 | rep_movs(); |
| 1127 | and_(Operand(scratch), Immediate(0x3)); |
| 1128 | add(destination, Operand(scratch)); |
| 1129 | jmp(&done); |
| 1130 | |
| 1131 | bind(&short_string); |
| 1132 | test(length, Operand(length)); |
| 1133 | j(zero, &done); |
| 1134 | |
| 1135 | bind(&short_loop); |
| 1136 | mov_b(scratch, Operand(source, 0)); |
| 1137 | mov_b(Operand(destination, 0), scratch); |
| 1138 | inc(source); |
| 1139 | inc(destination); |
| 1140 | dec(length); |
| 1141 | j(not_zero, &short_loop); |
| 1142 | |
| 1143 | bind(&done); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1146 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1147 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1148 | Register op, |
| 1149 | Label* then_label) { |
| 1150 | Label ok; |
| 1151 | test(result, Operand(result)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1152 | j(not_zero, &ok); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1153 | test(op, Operand(op)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1154 | j(sign, then_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1155 | bind(&ok); |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1160 | Register op1, |
| 1161 | Register op2, |
| 1162 | Register scratch, |
| 1163 | Label* then_label) { |
| 1164 | Label ok; |
| 1165 | test(result, Operand(result)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1166 | j(not_zero, &ok); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1167 | mov(scratch, Operand(op1)); |
| 1168 | or_(scratch, Operand(op2)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1169 | j(sign, then_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1170 | bind(&ok); |
| 1171 | } |
| 1172 | |
| 1173 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1174 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1175 | Register result, |
| 1176 | Register scratch, |
| 1177 | Label* miss) { |
| 1178 | // Check that the receiver isn't a smi. |
| 1179 | test(function, Immediate(kSmiTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1180 | j(zero, miss); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1181 | |
| 1182 | // Check that the function really is a function. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1183 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1184 | j(not_equal, miss); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1185 | |
| 1186 | // Make sure that the function has an instance prototype. |
| 1187 | Label non_instance; |
| 1188 | movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
| 1189 | test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1190 | j(not_zero, &non_instance); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1191 | |
| 1192 | // Get the prototype or initial map from the function. |
| 1193 | mov(result, |
| 1194 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1195 | |
| 1196 | // If the prototype or initial map is the hole, don't return it and |
| 1197 | // simply miss the cache instead. This will allow us to allocate a |
| 1198 | // prototype object on-demand in the runtime system. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1199 | cmp(Operand(result), Immediate(isolate()->factory()->the_hole_value())); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1200 | j(equal, miss); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1201 | |
| 1202 | // If the function does not have an initial map, we're done. |
| 1203 | Label done; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1204 | CmpObjectType(result, MAP_TYPE, scratch); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1205 | j(not_equal, &done); |
| 1206 | |
| 1207 | // Get the prototype from the initial map. |
| 1208 | mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 1209 | jmp(&done); |
| 1210 | |
| 1211 | // Non-instance prototype: Fetch prototype from constructor field |
| 1212 | // in initial map. |
| 1213 | bind(&non_instance); |
| 1214 | mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1215 | |
| 1216 | // All done. |
| 1217 | bind(&done); |
| 1218 | } |
| 1219 | |
| 1220 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1221 | void MacroAssembler::CallStub(CodeStub* stub, unsigned ast_id) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1222 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1223 | call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1227 | MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1228 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1229 | Object* result; |
| 1230 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1231 | if (!maybe_result->ToObject(&result)) return maybe_result; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1232 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1233 | call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1234 | return result; |
| 1235 | } |
| 1236 | |
| 1237 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1238 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1239 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1240 | jmp(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 1241 | } |
| 1242 | |
| 1243 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1244 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1245 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1246 | Object* result; |
| 1247 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1248 | if (!maybe_result->ToObject(&result)) return maybe_result; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1249 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1250 | jmp(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1251 | return result; |
| 1252 | } |
| 1253 | |
| 1254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1255 | void MacroAssembler::StubReturn(int argc) { |
| 1256 | ASSERT(argc >= 1 && generating_stub()); |
| 1257 | ret((argc - 1) * kPointerSize); |
| 1258 | } |
| 1259 | |
| 1260 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1261 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1262 | if (num_arguments > 0) { |
| 1263 | add(Operand(esp), Immediate(num_arguments * kPointerSize)); |
| 1264 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1265 | mov(eax, Immediate(isolate()->factory()->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1269 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1270 | // The assert checks that the constants for the maximum number of digits |
| 1271 | // for an array index cached in the hash field and the number of bits |
| 1272 | // reserved for it does not conflict. |
| 1273 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1274 | (1 << String::kArrayIndexValueBits)); |
| 1275 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1276 | // the low kHashShift bits. |
| 1277 | and_(hash, String::kArrayIndexValueMask); |
| 1278 | STATIC_ASSERT(String::kHashShift >= kSmiTagSize && kSmiTag == 0); |
| 1279 | if (String::kHashShift > kSmiTagSize) { |
| 1280 | shr(hash, String::kHashShift - kSmiTagSize); |
| 1281 | } |
| 1282 | if (!index.is(hash)) { |
| 1283 | mov(index, hash); |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1288 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 1289 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1290 | } |
| 1291 | |
| 1292 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1294 | const Runtime::Function* function = Runtime::FunctionForId(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1295 | Set(eax, Immediate(function->nargs)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1296 | mov(ebx, Immediate(ExternalReference(function, isolate()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1297 | CEntryStub ces(1); |
| 1298 | ces.SaveDoubles(); |
| 1299 | CallStub(&ces); |
| 1300 | } |
| 1301 | |
| 1302 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1303 | MaybeObject* MacroAssembler::TryCallRuntime(Runtime::FunctionId id, |
| 1304 | int num_arguments) { |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1305 | return TryCallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1306 | } |
| 1307 | |
| 1308 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1309 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 1310 | int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1311 | // If the expected number of arguments of the runtime function is |
| 1312 | // constant, we check that the actual number of arguments match the |
| 1313 | // expectation. |
| 1314 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1315 | IllegalOperation(num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | return; |
| 1317 | } |
| 1318 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1319 | // TODO(1236192): Most runtime routines don't need the number of |
| 1320 | // arguments passed in because it is constant. At some point we |
| 1321 | // should remove this need and make the runtime routine entry code |
| 1322 | // smarter. |
| 1323 | Set(eax, Immediate(num_arguments)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1324 | mov(ebx, Immediate(ExternalReference(f, isolate()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1325 | CEntryStub ces(1); |
| 1326 | CallStub(&ces); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1330 | MaybeObject* MacroAssembler::TryCallRuntime(const Runtime::Function* f, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1331 | int num_arguments) { |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1332 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1333 | IllegalOperation(num_arguments); |
| 1334 | // Since we did not call the stub, there was no allocation failure. |
| 1335 | // Return some non-failure object. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1336 | return isolate()->heap()->undefined_value(); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1339 | // TODO(1236192): Most runtime routines don't need the number of |
| 1340 | // arguments passed in because it is constant. At some point we |
| 1341 | // should remove this need and make the runtime routine entry code |
| 1342 | // smarter. |
| 1343 | Set(eax, Immediate(num_arguments)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1344 | mov(ebx, Immediate(ExternalReference(f, isolate()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1345 | CEntryStub ces(1); |
| 1346 | return TryCallStub(&ces); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1350 | void MacroAssembler::CallExternalReference(ExternalReference ref, |
| 1351 | int num_arguments) { |
| 1352 | mov(eax, Immediate(num_arguments)); |
| 1353 | mov(ebx, Immediate(ref)); |
| 1354 | |
| 1355 | CEntryStub stub(1); |
| 1356 | CallStub(&stub); |
| 1357 | } |
| 1358 | |
| 1359 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1360 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1361 | int num_arguments, |
| 1362 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1363 | // TODO(1236192): Most runtime routines don't need the number of |
| 1364 | // arguments passed in because it is constant. At some point we |
| 1365 | // should remove this need and make the runtime routine entry code |
| 1366 | // smarter. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1367 | Set(eax, Immediate(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1368 | JumpToExternalReference(ext); |
| 1369 | } |
| 1370 | |
| 1371 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1372 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 1373 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 1374 | // TODO(1236192): Most runtime routines don't need the number of |
| 1375 | // arguments passed in because it is constant. At some point we |
| 1376 | // should remove this need and make the runtime routine entry code |
| 1377 | // smarter. |
| 1378 | Set(eax, Immediate(num_arguments)); |
| 1379 | return TryJumpToExternalReference(ext); |
| 1380 | } |
| 1381 | |
| 1382 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1383 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1384 | int num_arguments, |
| 1385 | int result_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1386 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 1387 | num_arguments, |
| 1388 | result_size); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1392 | MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid, |
| 1393 | int num_arguments, |
| 1394 | int result_size) { |
| 1395 | return TryTailCallExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1396 | ExternalReference(fid, isolate()), num_arguments, result_size); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1400 | // If true, a Handle<T> returned by value from a function with cdecl calling |
| 1401 | // convention will be returned directly as a value of location_ field in a |
| 1402 | // register eax. |
| 1403 | // If false, it is returned as a pointer to a preallocated by caller memory |
| 1404 | // region. Pointer to this region should be passed to a function as an |
| 1405 | // implicit first argument. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1406 | #if defined(USING_BSD_ABI) || defined(__MINGW32__) || defined(__CYGWIN__) |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1407 | static const bool kReturnHandlesDirectly = true; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1408 | #else |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1409 | static const bool kReturnHandlesDirectly = false; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1410 | #endif |
| 1411 | |
| 1412 | |
| 1413 | Operand ApiParameterOperand(int index) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1414 | return Operand( |
| 1415 | esp, (index + (kReturnHandlesDirectly ? 0 : 1)) * kPointerSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1419 | void MacroAssembler::PrepareCallApiFunction(int argc, Register scratch) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1420 | if (kReturnHandlesDirectly) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1421 | EnterApiExitFrame(argc); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1422 | // When handles are returned directly we don't have to allocate extra |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1423 | // space for and pass an out parameter. |
| 1424 | } else { |
| 1425 | // We allocate two additional slots: return value and pointer to it. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1426 | EnterApiExitFrame(argc + 2); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1427 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1428 | // The argument slots are filled as follows: |
| 1429 | // |
| 1430 | // n + 1: output cell |
| 1431 | // n: arg n |
| 1432 | // ... |
| 1433 | // 1: arg1 |
| 1434 | // 0: pointer to the output cell |
| 1435 | // |
| 1436 | // Note that this is one more "argument" than the function expects |
| 1437 | // so the out cell will have to be popped explicitly after returning |
| 1438 | // from the function. The out cell contains Handle. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1439 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1440 | // pointer to out cell. |
| 1441 | lea(scratch, Operand(esp, (argc + 1) * kPointerSize)); |
| 1442 | mov(Operand(esp, 0 * kPointerSize), scratch); // output. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1443 | if (emit_debug_code()) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1444 | mov(Operand(esp, (argc + 1) * kPointerSize), Immediate(0)); // out cell. |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(ApiFunction* function, |
| 1451 | int stack_space) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1452 | ExternalReference next_address = |
| 1453 | ExternalReference::handle_scope_next_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1454 | ExternalReference limit_address = |
| 1455 | ExternalReference::handle_scope_limit_address(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1456 | ExternalReference level_address = |
| 1457 | ExternalReference::handle_scope_level_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1458 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1459 | // Allocate HandleScope in callee-save registers. |
| 1460 | mov(ebx, Operand::StaticVariable(next_address)); |
| 1461 | mov(edi, Operand::StaticVariable(limit_address)); |
| 1462 | add(Operand::StaticVariable(level_address), Immediate(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1463 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1464 | // Call the api function! |
| 1465 | call(function->address(), RelocInfo::RUNTIME_ENTRY); |
| 1466 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1467 | if (!kReturnHandlesDirectly) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1468 | // The returned value is a pointer to the handle holding the result. |
| 1469 | // Dereference this to get to the location. |
| 1470 | mov(eax, Operand(eax, 0)); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1471 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1472 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1473 | Label empty_handle; |
| 1474 | Label prologue; |
| 1475 | Label promote_scheduled_exception; |
| 1476 | Label delete_allocated_handles; |
| 1477 | Label leave_exit_frame; |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1478 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1479 | // Check if the result handle holds 0. |
| 1480 | test(eax, Operand(eax)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1481 | j(zero, &empty_handle); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1482 | // It was non-zero. Dereference to get the result value. |
| 1483 | mov(eax, Operand(eax, 0)); |
| 1484 | bind(&prologue); |
| 1485 | // No more valid handles (the result handle was the last one). Restore |
| 1486 | // previous handle scope. |
| 1487 | mov(Operand::StaticVariable(next_address), ebx); |
| 1488 | sub(Operand::StaticVariable(level_address), Immediate(1)); |
| 1489 | Assert(above_equal, "Invalid HandleScope level"); |
| 1490 | cmp(edi, Operand::StaticVariable(limit_address)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1491 | j(not_equal, &delete_allocated_handles); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1492 | bind(&leave_exit_frame); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1493 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1494 | // Check if the function scheduled an exception. |
| 1495 | ExternalReference scheduled_exception_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1496 | ExternalReference::scheduled_exception_address(isolate()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1497 | cmp(Operand::StaticVariable(scheduled_exception_address), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1498 | Immediate(isolate()->factory()->the_hole_value())); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1499 | j(not_equal, &promote_scheduled_exception); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1500 | LeaveApiExitFrame(); |
| 1501 | ret(stack_space * kPointerSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1502 | bind(&promote_scheduled_exception); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1503 | MaybeObject* result = |
| 1504 | TryTailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); |
| 1505 | if (result->IsFailure()) { |
| 1506 | return result; |
| 1507 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1508 | bind(&empty_handle); |
| 1509 | // It was zero; the result is undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1510 | mov(eax, isolate()->factory()->undefined_value()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1511 | jmp(&prologue); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame] | 1512 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1513 | // HandleScope limit has changed. Delete allocated extensions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1514 | ExternalReference delete_extensions = |
| 1515 | ExternalReference::delete_handle_scope_extensions(isolate()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1516 | bind(&delete_allocated_handles); |
| 1517 | mov(Operand::StaticVariable(limit_address), edi); |
| 1518 | mov(edi, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1519 | mov(Operand(esp, 0), Immediate(ExternalReference::isolate_address())); |
| 1520 | mov(eax, Immediate(delete_extensions)); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1521 | call(Operand(eax)); |
| 1522 | mov(eax, edi); |
| 1523 | jmp(&leave_exit_frame); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1524 | |
| 1525 | return result; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1529 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1530 | // Set the entry point and jump to the C entry runtime stub. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1531 | mov(ebx, Immediate(ext)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1532 | CEntryStub ces(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1533 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1537 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 1538 | const ExternalReference& ext) { |
| 1539 | // Set the entry point and jump to the C entry runtime stub. |
| 1540 | mov(ebx, Immediate(ext)); |
| 1541 | CEntryStub ces(1); |
| 1542 | return TryTailCallStub(&ces); |
| 1543 | } |
| 1544 | |
| 1545 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1546 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 1547 | // This macro takes the dst register to make the code more readable |
| 1548 | // at the call sites. However, the dst register has to be ecx to |
| 1549 | // follow the calling convention which requires the call type to be |
| 1550 | // in ecx. |
| 1551 | ASSERT(dst.is(ecx)); |
| 1552 | if (call_kind == CALL_AS_FUNCTION) { |
| 1553 | // Set to some non-zero smi by updating the least significant |
| 1554 | // byte. |
| 1555 | mov_b(Operand(dst), 1 << kSmiTagSize); |
| 1556 | } else { |
| 1557 | // Set to smi zero by clearing the register. |
| 1558 | xor_(dst, Operand(dst)); |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1563 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1564 | const ParameterCount& actual, |
| 1565 | Handle<Code> code_constant, |
| 1566 | const Operand& code_operand, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1567 | Label* done, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1568 | InvokeFlag flag, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1569 | Label::Distance done_near, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1570 | const CallWrapper& call_wrapper, |
| 1571 | CallKind call_kind) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1572 | bool definitely_matches = false; |
| 1573 | Label invoke; |
| 1574 | if (expected.is_immediate()) { |
| 1575 | ASSERT(actual.is_immediate()); |
| 1576 | if (expected.immediate() == actual.immediate()) { |
| 1577 | definitely_matches = true; |
| 1578 | } else { |
| 1579 | mov(eax, actual.immediate()); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1580 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1581 | if (expected.immediate() == sentinel) { |
| 1582 | // Don't worry about adapting arguments for builtins that |
| 1583 | // don't want that done. Skip adaption code by making it look |
| 1584 | // like we have a match between expected and actual number of |
| 1585 | // arguments. |
| 1586 | definitely_matches = true; |
| 1587 | } else { |
| 1588 | mov(ebx, expected.immediate()); |
| 1589 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1590 | } |
| 1591 | } else { |
| 1592 | if (actual.is_immediate()) { |
| 1593 | // Expected is in register, actual is immediate. This is the |
| 1594 | // case when we invoke function values without going through the |
| 1595 | // IC mechanism. |
| 1596 | cmp(expected.reg(), actual.immediate()); |
| 1597 | j(equal, &invoke); |
| 1598 | ASSERT(expected.reg().is(ebx)); |
| 1599 | mov(eax, actual.immediate()); |
| 1600 | } else if (!expected.reg().is(actual.reg())) { |
| 1601 | // Both expected and actual are in (different) registers. This |
| 1602 | // is the case when we invoke functions using call and apply. |
| 1603 | cmp(expected.reg(), Operand(actual.reg())); |
| 1604 | j(equal, &invoke); |
| 1605 | ASSERT(actual.reg().is(eax)); |
| 1606 | ASSERT(expected.reg().is(ebx)); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | if (!definitely_matches) { |
| 1611 | Handle<Code> adaptor = |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1612 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1613 | if (!code_constant.is_null()) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1614 | mov(edx, Immediate(code_constant)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1615 | add(Operand(edx), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1616 | } else if (!code_operand.is_reg(edx)) { |
| 1617 | mov(edx, code_operand); |
| 1618 | } |
| 1619 | |
| 1620 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1621 | call_wrapper.BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1622 | SetCallKind(ecx, call_kind); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1623 | call(adaptor, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1624 | call_wrapper.AfterCall(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1625 | jmp(done, done_near); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1626 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1627 | SetCallKind(ecx, call_kind); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1628 | jmp(adaptor, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1629 | } |
| 1630 | bind(&invoke); |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | |
| 1635 | void MacroAssembler::InvokeCode(const Operand& code, |
| 1636 | const ParameterCount& expected, |
| 1637 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1638 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1639 | const CallWrapper& call_wrapper, |
| 1640 | CallKind call_kind) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1641 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1642 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1643 | &done, flag, Label::kNear, call_wrapper, |
| 1644 | call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1646 | call_wrapper.BeforeCall(CallSize(code)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1647 | SetCallKind(ecx, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1648 | call(code); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1649 | call_wrapper.AfterCall(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1650 | } else { |
| 1651 | ASSERT(flag == JUMP_FUNCTION); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1652 | SetCallKind(ecx, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1653 | jmp(code); |
| 1654 | } |
| 1655 | bind(&done); |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 1660 | const ParameterCount& expected, |
| 1661 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1662 | RelocInfo::Mode rmode, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1663 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1664 | const CallWrapper& call_wrapper, |
| 1665 | CallKind call_kind) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1666 | Label done; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1667 | Operand dummy(eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1668 | InvokePrologue(expected, actual, code, dummy, &done, flag, Label::kNear, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1669 | call_wrapper, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1670 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1671 | call_wrapper.BeforeCall(CallSize(code, rmode)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1672 | SetCallKind(ecx, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1673 | call(code, rmode); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1674 | call_wrapper.AfterCall(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1675 | } else { |
| 1676 | ASSERT(flag == JUMP_FUNCTION); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1677 | SetCallKind(ecx, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1678 | jmp(code, rmode); |
| 1679 | } |
| 1680 | bind(&done); |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | void MacroAssembler::InvokeFunction(Register fun, |
| 1685 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1686 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1687 | const CallWrapper& call_wrapper, |
| 1688 | CallKind call_kind) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1689 | ASSERT(fun.is(edi)); |
| 1690 | mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1691 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1692 | mov(ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1693 | SmiUntag(ebx); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1694 | |
| 1695 | ParameterCount expected(ebx); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1696 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1697 | expected, actual, flag, call_wrapper, call_kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1701 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 1702 | const ParameterCount& actual, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1703 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1704 | const CallWrapper& call_wrapper, |
| 1705 | CallKind call_kind) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1706 | ASSERT(function->is_compiled()); |
| 1707 | // Get the function and setup the context. |
| 1708 | mov(edi, Immediate(Handle<JSFunction>(function))); |
| 1709 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1710 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1711 | ParameterCount expected(function->shared()->formal_parameter_count()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | if (V8::UseCrankshaft()) { |
| 1713 | // TODO(kasperl): For now, we always call indirectly through the |
| 1714 | // code field in the function to allow recompilation to take effect |
| 1715 | // without changing any of the call sites. |
| 1716 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1717 | expected, actual, flag, call_wrapper, call_kind); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1718 | } else { |
| 1719 | Handle<Code> code(function->code()); |
| 1720 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1721 | flag, call_wrapper, call_kind); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1722 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1726 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1727 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 1728 | const CallWrapper& call_wrapper) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1729 | // Calls are not allowed in some stubs. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1730 | ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | |
| 1732 | // Rely on the assertion to check that the number of provided |
| 1733 | // arguments match the expected number of arguments. Fake a |
| 1734 | // parameter count to avoid emitting code to do the check. |
| 1735 | ParameterCount expected(0); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1736 | GetBuiltinFunction(edi, id); |
| 1737 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1738 | expected, expected, flag, call_wrapper, CALL_AS_METHOD); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1741 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 1742 | Builtins::JavaScript id) { |
| 1743 | // Load the JavaScript builtin function from the builtins object. |
| 1744 | mov(target, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1745 | mov(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
| 1746 | mov(target, FieldOperand(target, |
| 1747 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 1748 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1749 | |
| 1750 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1751 | ASSERT(!target.is(edi)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1752 | // Load the JavaScript builtin function from the builtins object. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1753 | GetBuiltinFunction(edi, id); |
| 1754 | // Load the code entry point from the function into the target register. |
| 1755 | mov(target, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1759 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 1760 | if (context_chain_length > 0) { |
| 1761 | // Move up the chain of contexts to the context containing the slot. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1762 | mov(dst, Operand(esi, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1763 | for (int i = 1; i < context_chain_length; i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1764 | mov(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1765 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1766 | } else { |
| 1767 | // Slot is in the current function context. Move it into the |
| 1768 | // destination register in case we store into it (the write barrier |
| 1769 | // cannot be allowed to destroy the context in esi). |
| 1770 | mov(dst, esi); |
| 1771 | } |
| 1772 | |
| 1773 | // We should not have found a 'with' context by walking the context chain |
| 1774 | // (i.e., the static scope chain and runtime context chain do not agree). |
| 1775 | // A variable occurring in such a scope should have slot type LOOKUP and |
| 1776 | // not CONTEXT. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1777 | if (emit_debug_code()) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1778 | cmp(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1779 | Check(equal, "Yo dawg, I heard you liked function contexts " |
| 1780 | "so I put function contexts in all your contexts"); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1785 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 1786 | // Load the global or builtins object from the current context. |
| 1787 | mov(function, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1788 | // Load the global context from the global or builtins object. |
| 1789 | mov(function, FieldOperand(function, GlobalObject::kGlobalContextOffset)); |
| 1790 | // Load the function from the global context. |
| 1791 | mov(function, Operand(function, Context::SlotOffset(index))); |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 1796 | Register map) { |
| 1797 | // Load the initial map. The global functions all have initial maps. |
| 1798 | mov(map, FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1799 | if (emit_debug_code()) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1800 | Label ok, fail; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1801 | CheckMap(map, isolate()->factory()->meta_map(), &fail, DO_SMI_CHECK); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1802 | jmp(&ok); |
| 1803 | bind(&fail); |
| 1804 | Abort("Global functions must have initial map"); |
| 1805 | bind(&ok); |
| 1806 | } |
| 1807 | } |
| 1808 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1809 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1810 | // Store the value in register src in the safepoint register stack |
| 1811 | // slot for register dst. |
| 1812 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Register src) { |
| 1813 | mov(SafepointRegisterSlot(dst), src); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Immediate src) { |
| 1818 | mov(SafepointRegisterSlot(dst), src); |
| 1819 | } |
| 1820 | |
| 1821 | |
| 1822 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 1823 | mov(dst, SafepointRegisterSlot(src)); |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | Operand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 1828 | return Operand(esp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 1829 | } |
| 1830 | |
| 1831 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1832 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 1833 | // The registers are pushed starting with the lowest encoding, |
| 1834 | // which means that lowest encodings are furthest away from |
| 1835 | // the stack pointer. |
| 1836 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 1837 | return kNumSafepointRegisters - reg_code - 1; |
| 1838 | } |
| 1839 | |
| 1840 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1841 | void MacroAssembler::Ret() { |
| 1842 | ret(0); |
| 1843 | } |
| 1844 | |
| 1845 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1846 | void MacroAssembler::Ret(int bytes_dropped, Register scratch) { |
| 1847 | if (is_uint16(bytes_dropped)) { |
| 1848 | ret(bytes_dropped); |
| 1849 | } else { |
| 1850 | pop(scratch); |
| 1851 | add(Operand(esp), Immediate(bytes_dropped)); |
| 1852 | push(scratch); |
| 1853 | ret(0); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1860 | void MacroAssembler::Drop(int stack_elements) { |
| 1861 | if (stack_elements > 0) { |
| 1862 | add(Operand(esp), Immediate(stack_elements * kPointerSize)); |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1867 | void MacroAssembler::Move(Register dst, Register src) { |
| 1868 | if (!dst.is(src)) { |
| 1869 | mov(dst, src); |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1874 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 1875 | mov(dst, value); |
| 1876 | } |
| 1877 | |
| 1878 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1879 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 1880 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1881 | mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 1887 | ASSERT(value > 0); |
| 1888 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1889 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1890 | if (value == 1) { |
| 1891 | inc(operand); |
| 1892 | } else { |
| 1893 | add(operand, Immediate(value)); |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | |
| 1899 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 1900 | ASSERT(value > 0); |
| 1901 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1902 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1903 | if (value == 1) { |
| 1904 | dec(operand); |
| 1905 | } else { |
| 1906 | sub(operand, Immediate(value)); |
| 1907 | } |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1912 | void MacroAssembler::IncrementCounter(Condition cc, |
| 1913 | StatsCounter* counter, |
| 1914 | int value) { |
| 1915 | ASSERT(value > 0); |
| 1916 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1917 | Label skip; |
| 1918 | j(NegateCondition(cc), &skip); |
| 1919 | pushfd(); |
| 1920 | IncrementCounter(counter, value); |
| 1921 | popfd(); |
| 1922 | bind(&skip); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | void MacroAssembler::DecrementCounter(Condition cc, |
| 1928 | StatsCounter* counter, |
| 1929 | int value) { |
| 1930 | ASSERT(value > 0); |
| 1931 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1932 | Label skip; |
| 1933 | j(NegateCondition(cc), &skip); |
| 1934 | pushfd(); |
| 1935 | DecrementCounter(counter, value); |
| 1936 | popfd(); |
| 1937 | bind(&skip); |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1942 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1943 | if (emit_debug_code()) Check(cc, msg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1947 | void MacroAssembler::AssertFastElements(Register elements) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1948 | if (emit_debug_code()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1949 | Factory* factory = isolate()->factory(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1950 | Label ok; |
| 1951 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1952 | Immediate(factory->fixed_array_map())); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1953 | j(equal, &ok); |
| 1954 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1955 | Immediate(factory->fixed_cow_array_map())); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1956 | j(equal, &ok); |
| 1957 | Abort("JSObject with fast elements map has slow elements"); |
| 1958 | bind(&ok); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1963 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 1964 | Label L; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1965 | j(cc, &L); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1966 | Abort(msg); |
| 1967 | // will not return here |
| 1968 | bind(&L); |
| 1969 | } |
| 1970 | |
| 1971 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1972 | void MacroAssembler::CheckStackAlignment() { |
| 1973 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 1974 | int frame_alignment_mask = frame_alignment - 1; |
| 1975 | if (frame_alignment > kPointerSize) { |
| 1976 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1977 | Label alignment_as_expected; |
| 1978 | test(esp, Immediate(frame_alignment_mask)); |
| 1979 | j(zero, &alignment_as_expected); |
| 1980 | // Abort if stack is not aligned. |
| 1981 | int3(); |
| 1982 | bind(&alignment_as_expected); |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1987 | void MacroAssembler::Abort(const char* msg) { |
| 1988 | // We want to pass the msg string like a smi to avoid GC |
| 1989 | // problems, however msg is not guaranteed to be aligned |
| 1990 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1991 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1992 | // from the real pointer as a smi. |
| 1993 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 1994 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 1995 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 1996 | #ifdef DEBUG |
| 1997 | if (msg != NULL) { |
| 1998 | RecordComment("Abort message: "); |
| 1999 | RecordComment(msg); |
| 2000 | } |
| 2001 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2002 | // Disable stub call restrictions to always allow calls to abort. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2003 | AllowStubCallsScope allow_scope(this, true); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2004 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2005 | push(eax); |
| 2006 | push(Immediate(p0)); |
| 2007 | push(Immediate(reinterpret_cast<intptr_t>(Smi::FromInt(p1 - p0)))); |
| 2008 | CallRuntime(Runtime::kAbort, 2); |
| 2009 | // will not return here |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2010 | int3(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2014 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 2015 | Register descriptors) { |
| 2016 | mov(descriptors, |
| 2017 | FieldOperand(map, Map::kInstanceDescriptorsOrBitField3Offset)); |
| 2018 | Label not_smi; |
| 2019 | JumpIfNotSmi(descriptors, ¬_smi); |
| 2020 | mov(descriptors, isolate()->factory()->empty_descriptor_array()); |
| 2021 | bind(¬_smi); |
| 2022 | } |
| 2023 | |
| 2024 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2025 | void MacroAssembler::LoadPowerOf2(XMMRegister dst, |
| 2026 | Register scratch, |
| 2027 | int power) { |
| 2028 | ASSERT(is_uintn(power + HeapNumber::kExponentBias, |
| 2029 | HeapNumber::kExponentBits)); |
| 2030 | mov(scratch, Immediate(power + HeapNumber::kExponentBias)); |
| 2031 | movd(dst, Operand(scratch)); |
| 2032 | psllq(dst, HeapNumber::kMantissaBits); |
| 2033 | } |
| 2034 | |
| 2035 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2036 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( |
| 2037 | Register instance_type, |
| 2038 | Register scratch, |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 2039 | Label* failure) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2040 | if (!scratch.is(instance_type)) { |
| 2041 | mov(scratch, instance_type); |
| 2042 | } |
| 2043 | and_(scratch, |
| 2044 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask); |
| 2045 | cmp(scratch, kStringTag | kSeqStringTag | kAsciiStringTag); |
| 2046 | j(not_equal, failure); |
| 2047 | } |
| 2048 | |
| 2049 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2050 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 2051 | Register object2, |
| 2052 | Register scratch1, |
| 2053 | Register scratch2, |
| 2054 | Label* failure) { |
| 2055 | // Check that both objects are not smis. |
| 2056 | ASSERT_EQ(0, kSmiTag); |
| 2057 | mov(scratch1, Operand(object1)); |
| 2058 | and_(scratch1, Operand(object2)); |
| 2059 | test(scratch1, Immediate(kSmiTagMask)); |
| 2060 | j(zero, failure); |
| 2061 | |
| 2062 | // Load instance type for both strings. |
| 2063 | mov(scratch1, FieldOperand(object1, HeapObject::kMapOffset)); |
| 2064 | mov(scratch2, FieldOperand(object2, HeapObject::kMapOffset)); |
| 2065 | movzx_b(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2066 | movzx_b(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 2067 | |
| 2068 | // Check that both are flat ascii strings. |
| 2069 | const int kFlatAsciiStringMask = |
| 2070 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 2071 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2072 | // Interleave bits from both instance types and compare them in one check. |
| 2073 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 2074 | and_(scratch1, kFlatAsciiStringMask); |
| 2075 | and_(scratch2, kFlatAsciiStringMask); |
| 2076 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 2077 | cmp(scratch1, kFlatAsciiStringTag | (kFlatAsciiStringTag << 3)); |
| 2078 | j(not_equal, failure); |
| 2079 | } |
| 2080 | |
| 2081 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2082 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2083 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2084 | if (frame_alignment != 0) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2085 | // Make stack end at alignment and make room for num_arguments words |
| 2086 | // and the original value of esp. |
| 2087 | mov(scratch, esp); |
| 2088 | sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2089 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2090 | and_(esp, -frame_alignment); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2091 | mov(Operand(esp, num_arguments * kPointerSize), scratch); |
| 2092 | } else { |
| 2093 | sub(Operand(esp), Immediate(num_arguments * kPointerSize)); |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2099 | int num_arguments) { |
| 2100 | // Trashing eax is ok as it will be the return value. |
| 2101 | mov(Operand(eax), Immediate(function)); |
| 2102 | CallCFunction(eax, num_arguments); |
| 2103 | } |
| 2104 | |
| 2105 | |
| 2106 | void MacroAssembler::CallCFunction(Register function, |
| 2107 | int num_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2108 | // Check stack alignment. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2109 | if (emit_debug_code()) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2110 | CheckStackAlignment(); |
| 2111 | } |
| 2112 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2113 | call(Operand(function)); |
| 2114 | if (OS::ActivationFrameAlignment() != 0) { |
| 2115 | mov(esp, Operand(esp, num_arguments * kPointerSize)); |
| 2116 | } else { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2117 | add(Operand(esp), Immediate(num_arguments * kPointerSize)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2122 | CodePatcher::CodePatcher(byte* address, int size) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2123 | : address_(address), |
| 2124 | size_(size), |
| 2125 | masm_(Isolate::Current(), address, size + Assembler::kGap) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2126 | // Create a new macro assembler pointing to the address of the code to patch. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2127 | // The size is adjusted with kGap on order for the assembler to generate size |
| 2128 | // bytes of instructions without failing with buffer size constraints. |
| 2129 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | CodePatcher::~CodePatcher() { |
| 2134 | // Indicate that code has changed. |
| 2135 | CPU::FlushICache(address_, size_); |
| 2136 | |
| 2137 | // Check that the code was patched as expected. |
| 2138 | ASSERT(masm_.pc_ == address_ + size_); |
| 2139 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2140 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2141 | |
| 2142 | |
| 2143 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2144 | |
| 2145 | #endif // V8_TARGET_ARCH_IA32 |