Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 33 | #include "codegen.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | #include "debug.h" |
| 35 | #include "runtime.h" |
| 36 | #include "serialize.h" |
| 37 | |
| 38 | namespace v8 { |
| 39 | namespace internal { |
| 40 | |
| 41 | // ------------------------------------------------------------------------- |
| 42 | // MacroAssembler implementation. |
| 43 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 44 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 45 | : Assembler(arg_isolate, buffer, size), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | generating_stub_(false), |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 47 | allow_stub_calls_(true), |
| 48 | has_frame_(false) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 49 | if (isolate() != NULL) { |
| 50 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 51 | isolate()); |
| 52 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 56 | void MacroAssembler::InNewSpace( |
| 57 | Register object, |
| 58 | Register scratch, |
| 59 | Condition cc, |
| 60 | Label* condition_met, |
| 61 | Label::Distance condition_met_distance) { |
| 62 | ASSERT(cc == equal || cc == not_equal); |
| 63 | if (scratch.is(object)) { |
| 64 | and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 65 | } else { |
| 66 | mov(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 67 | and_(scratch, object); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 68 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 69 | // Check that we can use a test_b. |
| 70 | ASSERT(MemoryChunk::IN_FROM_SPACE < 8); |
| 71 | ASSERT(MemoryChunk::IN_TO_SPACE < 8); |
| 72 | int mask = (1 << MemoryChunk::IN_FROM_SPACE) |
| 73 | | (1 << MemoryChunk::IN_TO_SPACE); |
| 74 | // If non-zero, the page belongs to new-space. |
| 75 | test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 76 | static_cast<uint8_t>(mask)); |
| 77 | j(cc, condition_met, condition_met_distance); |
| 78 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 79 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 81 | void MacroAssembler::RememberedSetHelper( |
| 82 | Register object, // Only used for debug checks. |
| 83 | Register addr, |
| 84 | Register scratch, |
| 85 | SaveFPRegsMode save_fp, |
| 86 | MacroAssembler::RememberedSetFinalAction and_then) { |
| 87 | Label done; |
| 88 | if (FLAG_debug_code) { |
| 89 | Label ok; |
| 90 | JumpIfNotInNewSpace(object, scratch, &ok, Label::kNear); |
| 91 | int3(); |
| 92 | bind(&ok); |
| 93 | } |
| 94 | // Load store buffer top. |
| 95 | ExternalReference store_buffer = |
| 96 | ExternalReference::store_buffer_top(isolate()); |
| 97 | mov(scratch, Operand::StaticVariable(store_buffer)); |
| 98 | // Store pointer to buffer. |
| 99 | mov(Operand(scratch, 0), addr); |
| 100 | // Increment buffer top. |
| 101 | add(scratch, Immediate(kPointerSize)); |
| 102 | // Write back new top of buffer. |
| 103 | mov(Operand::StaticVariable(store_buffer), scratch); |
| 104 | // Call stub on end of buffer. |
| 105 | // Check for end of buffer. |
| 106 | test(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); |
| 107 | if (and_then == kReturnAtEnd) { |
| 108 | Label buffer_overflowed; |
| 109 | j(not_equal, &buffer_overflowed, Label::kNear); |
| 110 | ret(0); |
| 111 | bind(&buffer_overflowed); |
| 112 | } else { |
| 113 | ASSERT(and_then == kFallThroughAtEnd); |
| 114 | j(equal, &done, Label::kNear); |
| 115 | } |
| 116 | StoreBufferOverflowStub store_buffer_overflow = |
| 117 | StoreBufferOverflowStub(save_fp); |
| 118 | CallStub(&store_buffer_overflow); |
| 119 | if (and_then == kReturnAtEnd) { |
| 120 | ret(0); |
| 121 | } else { |
| 122 | ASSERT(and_then == kFallThroughAtEnd); |
| 123 | bind(&done); |
| 124 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
| 128 | void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, |
| 129 | XMMRegister scratch_reg, |
| 130 | Register result_reg) { |
| 131 | Label done; |
| 132 | ExternalReference zero_ref = ExternalReference::address_of_zero(); |
| 133 | movdbl(scratch_reg, Operand::StaticVariable(zero_ref)); |
| 134 | Set(result_reg, Immediate(0)); |
| 135 | ucomisd(input_reg, scratch_reg); |
| 136 | j(below, &done, Label::kNear); |
| 137 | ExternalReference half_ref = ExternalReference::address_of_one_half(); |
| 138 | movdbl(scratch_reg, Operand::StaticVariable(half_ref)); |
| 139 | addsd(scratch_reg, input_reg); |
| 140 | cvttsd2si(result_reg, Operand(scratch_reg)); |
| 141 | test(result_reg, Immediate(0xFFFFFF00)); |
| 142 | j(zero, &done, Label::kNear); |
| 143 | Set(result_reg, Immediate(255)); |
| 144 | bind(&done); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | void MacroAssembler::ClampUint8(Register reg) { |
| 149 | Label done; |
| 150 | test(reg, Immediate(0xFFFFFF00)); |
| 151 | j(zero, &done, Label::kNear); |
| 152 | setcc(negative, reg); // 1 if negative, 0 if positive. |
| 153 | dec_b(reg); // 0 if negative, 255 if positive. |
| 154 | bind(&done); |
| 155 | } |
| 156 | |
| 157 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 158 | void MacroAssembler::RecordWriteArray(Register object, |
| 159 | Register value, |
| 160 | Register index, |
| 161 | SaveFPRegsMode save_fp, |
| 162 | RememberedSetAction remembered_set_action, |
| 163 | SmiCheck smi_check) { |
| 164 | // First, check if a write barrier is even needed. The tests below |
| 165 | // catch stores of Smis. |
| 166 | Label done; |
| 167 | |
| 168 | // Skip barrier if writing a smi. |
| 169 | if (smi_check == INLINE_SMI_CHECK) { |
| 170 | ASSERT_EQ(0, kSmiTag); |
| 171 | test(value, Immediate(kSmiTagMask)); |
| 172 | j(zero, &done); |
| 173 | } |
| 174 | |
| 175 | // Array access: calculate the destination address in the same manner as |
| 176 | // KeyedStoreIC::GenerateGeneric. Multiply a smi by 2 to get an offset |
| 177 | // into an array of words. |
| 178 | Register dst = index; |
| 179 | lea(dst, Operand(object, index, times_half_pointer_size, |
| 180 | FixedArray::kHeaderSize - kHeapObjectTag)); |
| 181 | |
| 182 | RecordWrite( |
| 183 | object, dst, value, save_fp, remembered_set_action, OMIT_SMI_CHECK); |
| 184 | |
| 185 | bind(&done); |
| 186 | |
| 187 | // Clobber clobbered input registers when running with the debug-code flag |
| 188 | // turned on to provoke errors. |
| 189 | if (emit_debug_code()) { |
| 190 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 191 | mov(index, Immediate(BitCast<int32_t>(kZapValue))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 192 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 196 | void MacroAssembler::RecordWriteField( |
| 197 | Register object, |
| 198 | int offset, |
| 199 | Register value, |
| 200 | Register dst, |
| 201 | SaveFPRegsMode save_fp, |
| 202 | RememberedSetAction remembered_set_action, |
| 203 | SmiCheck smi_check) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 204 | // First, check if a write barrier is even needed. The tests below |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 205 | // catch stores of Smis. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 206 | Label done; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 207 | |
| 208 | // Skip barrier if writing a smi. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 209 | if (smi_check == INLINE_SMI_CHECK) { |
| 210 | JumpIfSmi(value, &done, Label::kNear); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 212 | |
| 213 | // Although the object register is tagged, the offset is relative to the start |
| 214 | // of the object, so so offset must be a multiple of kPointerSize. |
| 215 | ASSERT(IsAligned(offset, kPointerSize)); |
| 216 | |
| 217 | lea(dst, FieldOperand(object, offset)); |
| 218 | if (emit_debug_code()) { |
| 219 | Label ok; |
| 220 | test_b(dst, (1 << kPointerSizeLog2) - 1); |
| 221 | j(zero, &ok, Label::kNear); |
| 222 | int3(); |
| 223 | bind(&ok); |
| 224 | } |
| 225 | |
| 226 | RecordWrite( |
| 227 | object, dst, value, save_fp, remembered_set_action, OMIT_SMI_CHECK); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 228 | |
| 229 | bind(&done); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 230 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 231 | // Clobber clobbered input registers when running with the debug-code flag |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 232 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 233 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 234 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 235 | mov(dst, Immediate(BitCast<int32_t>(kZapValue))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 236 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 240 | void MacroAssembler::RecordWrite(Register object, |
| 241 | Register address, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 242 | Register value, |
| 243 | SaveFPRegsMode fp_mode, |
| 244 | RememberedSetAction remembered_set_action, |
| 245 | SmiCheck smi_check) { |
| 246 | ASSERT(!object.is(value)); |
| 247 | ASSERT(!object.is(address)); |
| 248 | ASSERT(!value.is(address)); |
| 249 | if (emit_debug_code()) { |
| 250 | AbortIfSmi(object); |
| 251 | } |
| 252 | |
| 253 | if (remembered_set_action == OMIT_REMEMBERED_SET && |
| 254 | !FLAG_incremental_marking) { |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (FLAG_debug_code) { |
| 259 | Label ok; |
| 260 | cmp(value, Operand(address, 0)); |
| 261 | j(equal, &ok, Label::kNear); |
| 262 | int3(); |
| 263 | bind(&ok); |
| 264 | } |
| 265 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 266 | // First, check if a write barrier is even needed. The tests below |
| 267 | // catch stores of Smis and stores into young gen. |
| 268 | Label done; |
| 269 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 270 | if (smi_check == INLINE_SMI_CHECK) { |
| 271 | // Skip barrier if writing a smi. |
| 272 | JumpIfSmi(value, &done, Label::kNear); |
| 273 | } |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 274 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 275 | CheckPageFlag(value, |
| 276 | value, // Used as scratch. |
| 277 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 278 | zero, |
| 279 | &done, |
| 280 | Label::kNear); |
| 281 | CheckPageFlag(object, |
| 282 | value, // Used as scratch. |
| 283 | MemoryChunk::kPointersFromHereAreInterestingMask, |
| 284 | zero, |
| 285 | &done, |
| 286 | Label::kNear); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 287 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 288 | RecordWriteStub stub(object, value, address, remembered_set_action, fp_mode); |
| 289 | CallStub(&stub); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 290 | |
| 291 | bind(&done); |
| 292 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 293 | // Clobber clobbered registers when running with the debug-code flag |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 294 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 295 | if (emit_debug_code()) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 296 | mov(address, Immediate(BitCast<int32_t>(kZapValue))); |
| 297 | mov(value, Immediate(BitCast<int32_t>(kZapValue))); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 303 | void MacroAssembler::DebugBreak() { |
| 304 | Set(eax, Immediate(0)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 305 | mov(ebx, Immediate(ExternalReference(Runtime::kDebugBreak, isolate()))); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 306 | CEntryStub ces(1); |
| 307 | call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 308 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 309 | #endif |
| 310 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 311 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | void MacroAssembler::Set(Register dst, const Immediate& x) { |
| 313 | if (x.is_zero()) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 314 | xor_(dst, dst); // Shorter than mov. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | } else { |
| 316 | mov(dst, x); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | void MacroAssembler::Set(const Operand& dst, const Immediate& x) { |
| 322 | mov(dst, x); |
| 323 | } |
| 324 | |
| 325 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 326 | bool MacroAssembler::IsUnsafeImmediate(const Immediate& x) { |
| 327 | static const int kMaxImmediateBits = 17; |
| 328 | if (x.rmode_ != RelocInfo::NONE) return false; |
| 329 | return !is_intn(x.x_, kMaxImmediateBits); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | void MacroAssembler::SafeSet(Register dst, const Immediate& x) { |
| 334 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
| 335 | Set(dst, Immediate(x.x_ ^ jit_cookie())); |
| 336 | xor_(dst, jit_cookie()); |
| 337 | } else { |
| 338 | Set(dst, x); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | |
| 343 | void MacroAssembler::SafePush(const Immediate& x) { |
| 344 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
| 345 | push(Immediate(x.x_ ^ jit_cookie())); |
| 346 | xor_(Operand(esp, 0), Immediate(jit_cookie())); |
| 347 | } else { |
| 348 | push(x); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 353 | void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { |
| 354 | // see ROOT_ACCESSOR macro in factory.h |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 355 | Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 356 | cmp(with, value); |
| 357 | } |
| 358 | |
| 359 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 360 | void MacroAssembler::CompareRoot(const Operand& with, |
| 361 | Heap::RootListIndex index) { |
| 362 | // see ROOT_ACCESSOR macro in factory.h |
| 363 | Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); |
| 364 | cmp(with, value); |
| 365 | } |
| 366 | |
| 367 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 368 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 369 | InstanceType type, |
| 370 | Register map) { |
| 371 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 372 | CmpInstanceType(map, type); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 377 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 378 | static_cast<int8_t>(type)); |
| 379 | } |
| 380 | |
| 381 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 382 | void MacroAssembler::CheckFastElements(Register map, |
| 383 | Label* fail, |
| 384 | Label::Distance distance) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 385 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 386 | STATIC_ASSERT(FAST_ELEMENTS == 1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 387 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 388 | Map::kMaximumBitField2FastElementValue); |
| 389 | j(above, fail, distance); |
| 390 | } |
| 391 | |
| 392 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 393 | void MacroAssembler::CheckFastObjectElements(Register map, |
| 394 | Label* fail, |
| 395 | Label::Distance distance) { |
| 396 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 397 | STATIC_ASSERT(FAST_ELEMENTS == 1); |
| 398 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 399 | Map::kMaximumBitField2FastSmiOnlyElementValue); |
| 400 | j(below_equal, fail, distance); |
| 401 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 402 | Map::kMaximumBitField2FastElementValue); |
| 403 | j(above, fail, distance); |
| 404 | } |
| 405 | |
| 406 | |
| 407 | void MacroAssembler::CheckFastSmiOnlyElements(Register map, |
| 408 | Label* fail, |
| 409 | Label::Distance distance) { |
| 410 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 411 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 412 | Map::kMaximumBitField2FastSmiOnlyElementValue); |
| 413 | j(above, fail, distance); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | void MacroAssembler::StoreNumberToDoubleElements( |
| 418 | Register maybe_number, |
| 419 | Register elements, |
| 420 | Register key, |
| 421 | Register scratch1, |
| 422 | XMMRegister scratch2, |
| 423 | Label* fail, |
| 424 | bool specialize_for_processor) { |
| 425 | Label smi_value, done, maybe_nan, not_nan, is_nan, have_double_value; |
| 426 | JumpIfSmi(maybe_number, &smi_value, Label::kNear); |
| 427 | |
| 428 | CheckMap(maybe_number, |
| 429 | isolate()->factory()->heap_number_map(), |
| 430 | fail, |
| 431 | DONT_DO_SMI_CHECK); |
| 432 | |
| 433 | // Double value, canonicalize NaN. |
| 434 | uint32_t offset = HeapNumber::kValueOffset + sizeof(kHoleNanLower32); |
| 435 | cmp(FieldOperand(maybe_number, offset), |
| 436 | Immediate(kNaNOrInfinityLowerBoundUpper32)); |
| 437 | j(greater_equal, &maybe_nan, Label::kNear); |
| 438 | |
| 439 | bind(¬_nan); |
| 440 | ExternalReference canonical_nan_reference = |
| 441 | ExternalReference::address_of_canonical_non_hole_nan(); |
| 442 | if (CpuFeatures::IsSupported(SSE2) && specialize_for_processor) { |
| 443 | CpuFeatures::Scope use_sse2(SSE2); |
| 444 | movdbl(scratch2, FieldOperand(maybe_number, HeapNumber::kValueOffset)); |
| 445 | bind(&have_double_value); |
| 446 | movdbl(FieldOperand(elements, key, times_4, FixedDoubleArray::kHeaderSize), |
| 447 | scratch2); |
| 448 | } else { |
| 449 | fld_d(FieldOperand(maybe_number, HeapNumber::kValueOffset)); |
| 450 | bind(&have_double_value); |
| 451 | fstp_d(FieldOperand(elements, key, times_4, FixedDoubleArray::kHeaderSize)); |
| 452 | } |
| 453 | jmp(&done); |
| 454 | |
| 455 | bind(&maybe_nan); |
| 456 | // Could be NaN or Infinity. If fraction is not zero, it's NaN, otherwise |
| 457 | // it's an Infinity, and the non-NaN code path applies. |
| 458 | j(greater, &is_nan, Label::kNear); |
| 459 | cmp(FieldOperand(maybe_number, HeapNumber::kValueOffset), Immediate(0)); |
| 460 | j(zero, ¬_nan); |
| 461 | bind(&is_nan); |
| 462 | if (CpuFeatures::IsSupported(SSE2) && specialize_for_processor) { |
| 463 | CpuFeatures::Scope use_sse2(SSE2); |
| 464 | movdbl(scratch2, Operand::StaticVariable(canonical_nan_reference)); |
| 465 | } else { |
| 466 | fld_d(Operand::StaticVariable(canonical_nan_reference)); |
| 467 | } |
| 468 | jmp(&have_double_value, Label::kNear); |
| 469 | |
| 470 | bind(&smi_value); |
| 471 | // Value is a smi. Convert to a double and store. |
| 472 | // Preserve original value. |
| 473 | mov(scratch1, maybe_number); |
| 474 | SmiUntag(scratch1); |
| 475 | if (CpuFeatures::IsSupported(SSE2) && specialize_for_processor) { |
| 476 | CpuFeatures::Scope fscope(SSE2); |
| 477 | cvtsi2sd(scratch2, scratch1); |
| 478 | movdbl(FieldOperand(elements, key, times_4, FixedDoubleArray::kHeaderSize), |
| 479 | scratch2); |
| 480 | } else { |
| 481 | push(scratch1); |
| 482 | fild_s(Operand(esp, 0)); |
| 483 | pop(scratch1); |
| 484 | fstp_d(FieldOperand(elements, key, times_4, FixedDoubleArray::kHeaderSize)); |
| 485 | } |
| 486 | bind(&done); |
| 487 | } |
| 488 | |
| 489 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 490 | void MacroAssembler::CompareMap(Register obj, |
| 491 | Handle<Map> map, |
| 492 | Label* early_success, |
| 493 | CompareMapMode mode) { |
| 494 | cmp(FieldOperand(obj, HeapObject::kMapOffset), map); |
| 495 | if (mode == ALLOW_ELEMENT_TRANSITION_MAPS) { |
| 496 | Map* transitioned_fast_element_map( |
| 497 | map->LookupElementsTransitionMap(FAST_ELEMENTS, NULL)); |
| 498 | ASSERT(transitioned_fast_element_map == NULL || |
| 499 | map->elements_kind() != FAST_ELEMENTS); |
| 500 | if (transitioned_fast_element_map != NULL) { |
| 501 | j(equal, early_success, Label::kNear); |
| 502 | cmp(FieldOperand(obj, HeapObject::kMapOffset), |
| 503 | Handle<Map>(transitioned_fast_element_map)); |
| 504 | } |
| 505 | |
| 506 | Map* transitioned_double_map( |
| 507 | map->LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, NULL)); |
| 508 | ASSERT(transitioned_double_map == NULL || |
| 509 | map->elements_kind() == FAST_SMI_ONLY_ELEMENTS); |
| 510 | if (transitioned_double_map != NULL) { |
| 511 | j(equal, early_success, Label::kNear); |
| 512 | cmp(FieldOperand(obj, HeapObject::kMapOffset), |
| 513 | Handle<Map>(transitioned_double_map)); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 519 | void MacroAssembler::CheckMap(Register obj, |
| 520 | Handle<Map> map, |
| 521 | Label* fail, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 522 | SmiCheckType smi_check_type, |
| 523 | CompareMapMode mode) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 524 | if (smi_check_type == DO_SMI_CHECK) { |
| 525 | JumpIfSmi(obj, fail); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 526 | } |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 527 | |
| 528 | Label success; |
| 529 | CompareMap(obj, map, &success, mode); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 530 | j(not_equal, fail); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 531 | bind(&success); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 535 | void MacroAssembler::DispatchMap(Register obj, |
| 536 | Handle<Map> map, |
| 537 | Handle<Code> success, |
| 538 | SmiCheckType smi_check_type) { |
| 539 | Label fail; |
| 540 | if (smi_check_type == DO_SMI_CHECK) { |
| 541 | JumpIfSmi(obj, &fail); |
| 542 | } |
| 543 | cmp(FieldOperand(obj, HeapObject::kMapOffset), Immediate(map)); |
| 544 | j(equal, success); |
| 545 | |
| 546 | bind(&fail); |
| 547 | } |
| 548 | |
| 549 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 550 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 551 | Register map, |
| 552 | Register instance_type) { |
| 553 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 554 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 555 | STATIC_ASSERT(kNotStringTag != 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 556 | test(instance_type, Immediate(kIsNotStringMask)); |
| 557 | return zero; |
| 558 | } |
| 559 | |
| 560 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 561 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 562 | Register map, |
| 563 | Register scratch, |
| 564 | Label* fail) { |
| 565 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 566 | IsInstanceJSObjectType(map, scratch, fail); |
| 567 | } |
| 568 | |
| 569 | |
| 570 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 571 | Register scratch, |
| 572 | Label* fail) { |
| 573 | movzx_b(scratch, FieldOperand(map, Map::kInstanceTypeOffset)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 574 | sub(scratch, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 575 | cmp(scratch, |
| 576 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE - FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 577 | j(above, fail); |
| 578 | } |
| 579 | |
| 580 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | void MacroAssembler::FCmp() { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 582 | if (CpuFeatures::IsSupported(CMOV)) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 583 | fucomip(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 584 | fstp(0); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 585 | } else { |
| 586 | fucompp(); |
| 587 | push(eax); |
| 588 | fnstsw_ax(); |
| 589 | sahf(); |
| 590 | pop(eax); |
| 591 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 595 | void MacroAssembler::AbortIfNotNumber(Register object) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 596 | Label ok; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 597 | JumpIfSmi(object, &ok); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 598 | cmp(FieldOperand(object, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 599 | isolate()->factory()->heap_number_map()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 600 | Assert(equal, "Operand not a number"); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 601 | bind(&ok); |
| 602 | } |
| 603 | |
| 604 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 605 | void MacroAssembler::AbortIfNotSmi(Register object) { |
| 606 | test(object, Immediate(kSmiTagMask)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 607 | Assert(equal, "Operand is not a smi"); |
| 608 | } |
| 609 | |
| 610 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 611 | void MacroAssembler::AbortIfNotString(Register object) { |
| 612 | test(object, Immediate(kSmiTagMask)); |
| 613 | Assert(not_equal, "Operand is not a string"); |
| 614 | push(object); |
| 615 | mov(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 616 | CmpInstanceType(object, FIRST_NONSTRING_TYPE); |
| 617 | pop(object); |
| 618 | Assert(below, "Operand is not a string"); |
| 619 | } |
| 620 | |
| 621 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 622 | void MacroAssembler::AbortIfSmi(Register object) { |
| 623 | test(object, Immediate(kSmiTagMask)); |
| 624 | Assert(not_equal, "Operand is a smi"); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 629 | push(ebp); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 630 | mov(ebp, esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 631 | push(esi); |
| 632 | push(Immediate(Smi::FromInt(type))); |
| 633 | push(Immediate(CodeObject())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 634 | if (emit_debug_code()) { |
| 635 | cmp(Operand(esp, 0), Immediate(isolate()->factory()->undefined_value())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 636 | Check(not_equal, "code object not properly patched"); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | |
| 641 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 642 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | cmp(Operand(ebp, StandardFrameConstants::kMarkerOffset), |
| 644 | Immediate(Smi::FromInt(type))); |
| 645 | Check(equal, "stack frame types must match"); |
| 646 | } |
| 647 | leave(); |
| 648 | } |
| 649 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 650 | |
| 651 | void MacroAssembler::EnterExitFramePrologue() { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 652 | // Set up the frame structure on the stack. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 653 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
| 654 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 655 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 656 | push(ebp); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 657 | mov(ebp, esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 658 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 659 | // Reserve room for entry stack pointer and push the code object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 660 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 661 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 662 | push(Immediate(CodeObject())); // Accessed from ExitFrame::code_slot. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 663 | |
| 664 | // Save the frame pointer and the context in top. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 665 | ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 666 | isolate()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 667 | ExternalReference context_address(Isolate::kContextAddress, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 668 | isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 669 | mov(Operand::StaticVariable(c_entry_fp_address), ebp); |
| 670 | mov(Operand::StaticVariable(context_address), esi); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 671 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 672 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 674 | void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) { |
| 675 | // Optionally save all XMM registers. |
| 676 | if (save_doubles) { |
| 677 | CpuFeatures::Scope scope(SSE2); |
| 678 | int space = XMMRegister::kNumRegisters * kDoubleSize + argc * kPointerSize; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 679 | sub(esp, Immediate(space)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 680 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 681 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 682 | XMMRegister reg = XMMRegister::from_code(i); |
| 683 | movdbl(Operand(ebp, offset - ((i + 1) * kDoubleSize)), reg); |
| 684 | } |
| 685 | } else { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 686 | sub(esp, Immediate(argc * kPointerSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 687 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 688 | |
| 689 | // Get the required frame alignment for the OS. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 690 | const int kFrameAlignment = OS::ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 691 | if (kFrameAlignment > 0) { |
| 692 | ASSERT(IsPowerOf2(kFrameAlignment)); |
| 693 | and_(esp, -kFrameAlignment); |
| 694 | } |
| 695 | |
| 696 | // Patch the saved entry sp. |
| 697 | mov(Operand(ebp, ExitFrameConstants::kSPOffset), esp); |
| 698 | } |
| 699 | |
| 700 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 701 | void MacroAssembler::EnterExitFrame(bool save_doubles) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 702 | EnterExitFramePrologue(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 703 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 704 | // Set up argc and argv in callee-saved registers. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 705 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 706 | mov(edi, eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 707 | lea(esi, Operand(ebp, eax, times_4, offset)); |
| 708 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 709 | // Reserve space for argc, argv and isolate. |
| 710 | EnterExitFrameEpilogue(3, save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 714 | void MacroAssembler::EnterApiExitFrame(int argc) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 715 | EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 716 | EnterExitFrameEpilogue(argc, false); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 720 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
| 721 | // Optionally restore all XMM registers. |
| 722 | if (save_doubles) { |
| 723 | CpuFeatures::Scope scope(SSE2); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 724 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 725 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 726 | XMMRegister reg = XMMRegister::from_code(i); |
| 727 | movdbl(reg, Operand(ebp, offset - ((i + 1) * kDoubleSize))); |
| 728 | } |
| 729 | } |
| 730 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 731 | // Get the return address from the stack and restore the frame pointer. |
| 732 | mov(ecx, Operand(ebp, 1 * kPointerSize)); |
| 733 | mov(ebp, Operand(ebp, 0 * kPointerSize)); |
| 734 | |
| 735 | // Pop the arguments and the receiver from the caller stack. |
| 736 | lea(esp, Operand(esi, 1 * kPointerSize)); |
| 737 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 738 | // Push the return address to get ready to return. |
| 739 | push(ecx); |
| 740 | |
| 741 | LeaveExitFrameEpilogue(); |
| 742 | } |
| 743 | |
| 744 | void MacroAssembler::LeaveExitFrameEpilogue() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | // Restore current context from top and clear it in debug mode. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 746 | ExternalReference context_address(Isolate::kContextAddress, isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 747 | mov(esi, Operand::StaticVariable(context_address)); |
| 748 | #ifdef DEBUG |
| 749 | mov(Operand::StaticVariable(context_address), Immediate(0)); |
| 750 | #endif |
| 751 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 752 | // Clear the top frame. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 753 | ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 754 | isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 755 | mov(Operand::StaticVariable(c_entry_fp_address), Immediate(0)); |
| 756 | } |
| 757 | |
| 758 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 759 | void MacroAssembler::LeaveApiExitFrame() { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 760 | mov(esp, ebp); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 761 | pop(ebp); |
| 762 | |
| 763 | LeaveExitFrameEpilogue(); |
| 764 | } |
| 765 | |
| 766 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 767 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 768 | HandlerType type, |
| 769 | int handler_index) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 770 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 771 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 772 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 773 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 774 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 775 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 776 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 777 | |
| 778 | // We will build up the handler from the bottom by pushing on the stack. |
| 779 | // First compute the state and push the frame pointer and context. |
| 780 | unsigned state = StackHandler::OffsetField::encode(handler_index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 781 | if (try_location == IN_JAVASCRIPT) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 782 | push(ebp); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 783 | push(esi); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 784 | state |= (type == TRY_CATCH_HANDLER) |
| 785 | ? StackHandler::KindField::encode(StackHandler::TRY_CATCH) |
| 786 | : StackHandler::KindField::encode(StackHandler::TRY_FINALLY); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 787 | } else { |
| 788 | ASSERT(try_location == IN_JS_ENTRY); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 789 | // The frame pointer does not point to a JS frame so we save NULL for |
| 790 | // ebp. We expect the code throwing an exception to check ebp before |
| 791 | // dereferencing it to restore the context. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 792 | push(Immediate(0)); // NULL frame pointer. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 793 | push(Immediate(Smi::FromInt(0))); // No context. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 794 | state |= StackHandler::KindField::encode(StackHandler::ENTRY); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 795 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 796 | |
| 797 | // Push the state and the code object. |
| 798 | push(Immediate(state)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 799 | Push(CodeObject()); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 800 | |
| 801 | // Link the current handler as the next handler. |
| 802 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
| 803 | push(Operand::StaticVariable(handler_address)); |
| 804 | // Set this new handler as the current one. |
| 805 | mov(Operand::StaticVariable(handler_address), esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 809 | void MacroAssembler::PopTryHandler() { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 810 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 811 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
| 812 | pop(Operand::StaticVariable(handler_address)); |
| 813 | add(esp, Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | void MacroAssembler::JumpToHandlerEntry() { |
| 818 | // Compute the handler entry address and jump to it. The handler table is |
| 819 | // a fixed array of (smi-tagged) code offsets. |
| 820 | // eax = exception, edi = code object, edx = state. |
| 821 | mov(ebx, FieldOperand(edi, Code::kHandlerTableOffset)); |
| 822 | shr(edx, StackHandler::kKindWidth); |
| 823 | mov(edx, FieldOperand(ebx, edx, times_4, FixedArray::kHeaderSize)); |
| 824 | SmiUntag(edx); |
| 825 | lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize)); |
| 826 | jmp(edi); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 830 | void MacroAssembler::Throw(Register value) { |
| 831 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 832 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 833 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 834 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 835 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 836 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 837 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 838 | |
| 839 | // The exception is expected in eax. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 840 | if (!value.is(eax)) { |
| 841 | mov(eax, value); |
| 842 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 843 | // Drop the stack pointer to the top of the top handler. |
| 844 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 845 | mov(esp, Operand::StaticVariable(handler_address)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 846 | // Restore the next handler. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 847 | pop(Operand::StaticVariable(handler_address)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 848 | |
| 849 | // Remove the code object and state, compute the handler address in edi. |
| 850 | pop(edi); // Code object. |
| 851 | pop(edx); // Index and state. |
| 852 | |
| 853 | // Restore the context and frame pointer. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 854 | pop(esi); // Context. |
| 855 | pop(ebp); // Frame pointer. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 856 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 857 | // If the handler is a JS frame, restore the context to the frame. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 858 | // (kind == ENTRY) == (ebp == 0) == (esi == 0), so we could test either |
| 859 | // ebp or esi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 860 | Label skip; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 861 | test(esi, esi); |
| 862 | j(zero, &skip, Label::kNear); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 863 | mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 864 | bind(&skip); |
| 865 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 866 | JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | |
| 870 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 871 | Register value) { |
| 872 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 873 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 874 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 875 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 876 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 877 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 878 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 879 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 880 | // The exception is expected in eax. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 881 | if (type == OUT_OF_MEMORY) { |
| 882 | // Set external caught exception to false. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 883 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 884 | isolate()); |
| 885 | mov(Operand::StaticVariable(external_caught), Immediate(false)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 886 | |
| 887 | // Set pending exception and eax to out of memory exception. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 888 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 889 | isolate()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 890 | mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException())); |
| 891 | mov(Operand::StaticVariable(pending_exception), eax); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 892 | } else if (!value.is(eax)) { |
| 893 | mov(eax, value); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 894 | } |
| 895 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 896 | // Drop the stack pointer to the top of the top stack handler. |
| 897 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
| 898 | mov(esp, Operand::StaticVariable(handler_address)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 899 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 900 | // Unwind the handlers until the top ENTRY handler is found. |
| 901 | Label fetch_next, check_kind; |
| 902 | jmp(&check_kind, Label::kNear); |
| 903 | bind(&fetch_next); |
| 904 | mov(esp, Operand(esp, StackHandlerConstants::kNextOffset)); |
| 905 | |
| 906 | bind(&check_kind); |
| 907 | STATIC_ASSERT(StackHandler::ENTRY == 0); |
| 908 | test(Operand(esp, StackHandlerConstants::kStateOffset), |
| 909 | Immediate(StackHandler::KindField::kMask)); |
| 910 | j(not_zero, &fetch_next); |
| 911 | |
| 912 | // Set the top handler address to next handler past the top ENTRY handler. |
| 913 | pop(Operand::StaticVariable(handler_address)); |
| 914 | |
| 915 | // Remove the code object and state, compute the handler address in edi. |
| 916 | pop(edi); // Code object. |
| 917 | pop(edx); // Index and state. |
| 918 | |
| 919 | // Clear the context pointer and frame pointer (0 was saved in the handler). |
| 920 | pop(esi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 921 | pop(ebp); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 922 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 923 | JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 927 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 928 | Register scratch, |
| 929 | Label* miss) { |
| 930 | Label same_contexts; |
| 931 | |
| 932 | ASSERT(!holder_reg.is(scratch)); |
| 933 | |
| 934 | // Load current lexical context from the stack frame. |
| 935 | mov(scratch, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 936 | |
| 937 | // When generating debug code, make sure the lexical context is set. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 938 | if (emit_debug_code()) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 939 | cmp(scratch, Immediate(0)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 940 | Check(not_equal, "we should not have an empty lexical context"); |
| 941 | } |
| 942 | // Load the global context of the current context. |
| 943 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 944 | mov(scratch, FieldOperand(scratch, offset)); |
| 945 | mov(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 946 | |
| 947 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 948 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 949 | push(scratch); |
| 950 | // Read the first word and compare to global_context_map. |
| 951 | mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 952 | cmp(scratch, isolate()->factory()->global_context_map()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 953 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 954 | pop(scratch); |
| 955 | } |
| 956 | |
| 957 | // Check if both contexts are the same. |
| 958 | cmp(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 959 | j(equal, &same_contexts); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 960 | |
| 961 | // Compare security tokens, save holder_reg on the stack so we can use it |
| 962 | // as a temporary register. |
| 963 | // |
| 964 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 965 | push(holder_reg); |
| 966 | // Check that the security token in the calling global object is |
| 967 | // compatible with the security token in the receiving global |
| 968 | // object. |
| 969 | mov(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 970 | |
| 971 | // Check the context is a global context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 972 | if (emit_debug_code()) { |
| 973 | cmp(holder_reg, isolate()->factory()->null_value()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 974 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 975 | |
| 976 | push(holder_reg); |
| 977 | // Read the first word and compare to global_context_map(), |
| 978 | mov(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 979 | cmp(holder_reg, isolate()->factory()->global_context_map()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 980 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 981 | pop(holder_reg); |
| 982 | } |
| 983 | |
| 984 | int token_offset = Context::kHeaderSize + |
| 985 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 986 | mov(scratch, FieldOperand(scratch, token_offset)); |
| 987 | cmp(scratch, FieldOperand(holder_reg, token_offset)); |
| 988 | pop(holder_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 989 | j(not_equal, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 990 | |
| 991 | bind(&same_contexts); |
| 992 | } |
| 993 | |
| 994 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 995 | // Compute the hash code from the untagged key. This must be kept in sync |
| 996 | // with ComputeIntegerHash in utils.h. |
| 997 | // |
| 998 | // Note: r0 will contain hash code |
| 999 | void MacroAssembler::GetNumberHash(Register r0, Register scratch) { |
| 1000 | // Xor original key with a seed. |
| 1001 | if (Serializer::enabled()) { |
| 1002 | ExternalReference roots_array_start = |
| 1003 | ExternalReference::roots_array_start(isolate()); |
| 1004 | mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
| 1005 | mov(scratch, |
| 1006 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
| 1007 | SmiUntag(scratch); |
| 1008 | xor_(r0, scratch); |
| 1009 | } else { |
| 1010 | int32_t seed = isolate()->heap()->HashSeed(); |
| 1011 | xor_(r0, Immediate(seed)); |
| 1012 | } |
| 1013 | |
| 1014 | // hash = ~hash + (hash << 15); |
| 1015 | mov(scratch, r0); |
| 1016 | not_(r0); |
| 1017 | shl(scratch, 15); |
| 1018 | add(r0, scratch); |
| 1019 | // hash = hash ^ (hash >> 12); |
| 1020 | mov(scratch, r0); |
| 1021 | shr(scratch, 12); |
| 1022 | xor_(r0, scratch); |
| 1023 | // hash = hash + (hash << 2); |
| 1024 | lea(r0, Operand(r0, r0, times_4, 0)); |
| 1025 | // hash = hash ^ (hash >> 4); |
| 1026 | mov(scratch, r0); |
| 1027 | shr(scratch, 4); |
| 1028 | xor_(r0, scratch); |
| 1029 | // hash = hash * 2057; |
| 1030 | imul(r0, r0, 2057); |
| 1031 | // hash = hash ^ (hash >> 16); |
| 1032 | mov(scratch, r0); |
| 1033 | shr(scratch, 16); |
| 1034 | xor_(r0, scratch); |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1039 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 1040 | Register elements, |
| 1041 | Register key, |
| 1042 | Register r0, |
| 1043 | Register r1, |
| 1044 | Register r2, |
| 1045 | Register result) { |
| 1046 | // Register use: |
| 1047 | // |
| 1048 | // elements - holds the slow-case elements of the receiver and is unchanged. |
| 1049 | // |
| 1050 | // key - holds the smi key on entry and is unchanged. |
| 1051 | // |
| 1052 | // Scratch registers: |
| 1053 | // |
| 1054 | // r0 - holds the untagged key on entry and holds the hash once computed. |
| 1055 | // |
| 1056 | // r1 - used to hold the capacity mask of the dictionary |
| 1057 | // |
| 1058 | // r2 - used for the index into the dictionary. |
| 1059 | // |
| 1060 | // result - holds the result on exit if the load succeeds and we fall through. |
| 1061 | |
| 1062 | Label done; |
| 1063 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1064 | GetNumberHash(r0, r1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1065 | |
| 1066 | // Compute capacity mask. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1067 | mov(r1, FieldOperand(elements, SeededNumberDictionary::kCapacityOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1068 | shr(r1, kSmiTagSize); // convert smi to int |
| 1069 | dec(r1); |
| 1070 | |
| 1071 | // Generate an unrolled loop that performs a few probes before giving up. |
| 1072 | const int kProbes = 4; |
| 1073 | for (int i = 0; i < kProbes; i++) { |
| 1074 | // Use r2 for index calculations and keep the hash intact in r0. |
| 1075 | mov(r2, r0); |
| 1076 | // Compute the masked index: (hash + i + i * i) & mask. |
| 1077 | if (i > 0) { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1078 | add(r2, Immediate(SeededNumberDictionary::GetProbeOffset(i))); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1079 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1080 | and_(r2, r1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1081 | |
| 1082 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1083 | ASSERT(SeededNumberDictionary::kEntrySize == 3); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1084 | lea(r2, Operand(r2, r2, times_2, 0)); // r2 = r2 * 3 |
| 1085 | |
| 1086 | // Check if the key matches. |
| 1087 | cmp(key, FieldOperand(elements, |
| 1088 | r2, |
| 1089 | times_pointer_size, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1090 | SeededNumberDictionary::kElementsStartOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1091 | if (i != (kProbes - 1)) { |
| 1092 | j(equal, &done); |
| 1093 | } else { |
| 1094 | j(not_equal, miss); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | bind(&done); |
| 1099 | // Check that the value is a normal propety. |
| 1100 | const int kDetailsOffset = |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1101 | SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1102 | ASSERT_EQ(NORMAL, 0); |
| 1103 | test(FieldOperand(elements, r2, times_pointer_size, kDetailsOffset), |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1104 | Immediate(PropertyDetails::TypeField::kMask << kSmiTagSize)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1105 | j(not_zero, miss); |
| 1106 | |
| 1107 | // Get the value at the masked, scaled index. |
| 1108 | const int kValueOffset = |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1109 | SeededNumberDictionary::kElementsStartOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1110 | mov(result, FieldOperand(elements, r2, times_pointer_size, kValueOffset)); |
| 1111 | } |
| 1112 | |
| 1113 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1114 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1115 | Register scratch, |
| 1116 | AllocationFlags flags) { |
| 1117 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1118 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1119 | |
| 1120 | // Just return if allocation top is already known. |
| 1121 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
| 1122 | // No use of scratch if allocation top is provided. |
| 1123 | ASSERT(scratch.is(no_reg)); |
| 1124 | #ifdef DEBUG |
| 1125 | // Assert that result actually contains top on entry. |
| 1126 | cmp(result, Operand::StaticVariable(new_space_allocation_top)); |
| 1127 | Check(equal, "Unexpected allocation top"); |
| 1128 | #endif |
| 1129 | return; |
| 1130 | } |
| 1131 | |
| 1132 | // Move address of new object to result. Use scratch register if available. |
| 1133 | if (scratch.is(no_reg)) { |
| 1134 | mov(result, Operand::StaticVariable(new_space_allocation_top)); |
| 1135 | } else { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1136 | mov(scratch, Immediate(new_space_allocation_top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1137 | mov(result, Operand(scratch, 0)); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 1143 | Register scratch) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1144 | if (emit_debug_code()) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1145 | test(result_end, Immediate(kObjectAlignmentMask)); |
| 1146 | Check(zero, "Unaligned allocation in new space"); |
| 1147 | } |
| 1148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1150 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1151 | |
| 1152 | // Update new top. Use scratch if available. |
| 1153 | if (scratch.is(no_reg)) { |
| 1154 | mov(Operand::StaticVariable(new_space_allocation_top), result_end); |
| 1155 | } else { |
| 1156 | mov(Operand(scratch, 0), result_end); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 1162 | Register result, |
| 1163 | Register result_end, |
| 1164 | Register scratch, |
| 1165 | Label* gc_required, |
| 1166 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1167 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1168 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1169 | // Trash the registers to simulate an allocation failure. |
| 1170 | mov(result, Immediate(0x7091)); |
| 1171 | if (result_end.is_valid()) { |
| 1172 | mov(result_end, Immediate(0x7191)); |
| 1173 | } |
| 1174 | if (scratch.is_valid()) { |
| 1175 | mov(scratch, Immediate(0x7291)); |
| 1176 | } |
| 1177 | } |
| 1178 | jmp(gc_required); |
| 1179 | return; |
| 1180 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1181 | ASSERT(!result.is(result_end)); |
| 1182 | |
| 1183 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1184 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1185 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1186 | Register top_reg = result_end.is_valid() ? result_end : result; |
| 1187 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1188 | // Calculate new top and bail out if new space is exhausted. |
| 1189 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1190 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1191 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1192 | if (!top_reg.is(result)) { |
| 1193 | mov(top_reg, result); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1194 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1195 | add(top_reg, Immediate(object_size)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1196 | j(carry, gc_required); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1197 | cmp(top_reg, Operand::StaticVariable(new_space_allocation_limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1198 | j(above, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1199 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1200 | // Update allocation top. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1201 | UpdateAllocationTopHelper(top_reg, scratch); |
| 1202 | |
| 1203 | // Tag result if requested. |
| 1204 | if (top_reg.is(result)) { |
| 1205 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1206 | sub(result, Immediate(object_size - kHeapObjectTag)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1207 | } else { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1208 | sub(result, Immediate(object_size)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1209 | } |
| 1210 | } else if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1211 | add(result, Immediate(kHeapObjectTag)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1212 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 1217 | ScaleFactor element_size, |
| 1218 | Register element_count, |
| 1219 | Register result, |
| 1220 | Register result_end, |
| 1221 | Register scratch, |
| 1222 | Label* gc_required, |
| 1223 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1224 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1225 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1226 | // Trash the registers to simulate an allocation failure. |
| 1227 | mov(result, Immediate(0x7091)); |
| 1228 | mov(result_end, Immediate(0x7191)); |
| 1229 | if (scratch.is_valid()) { |
| 1230 | mov(scratch, Immediate(0x7291)); |
| 1231 | } |
| 1232 | // Register element_count is not modified by the function. |
| 1233 | } |
| 1234 | jmp(gc_required); |
| 1235 | return; |
| 1236 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1237 | ASSERT(!result.is(result_end)); |
| 1238 | |
| 1239 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1240 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1241 | |
| 1242 | // Calculate new top and bail out if new space is exhausted. |
| 1243 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1244 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1245 | |
| 1246 | // We assume that element_count*element_size + header_size does not |
| 1247 | // overflow. |
| 1248 | lea(result_end, Operand(element_count, element_size, header_size)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1249 | add(result_end, result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1250 | j(carry, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1251 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 1252 | j(above, gc_required); |
| 1253 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1254 | // Tag result if requested. |
| 1255 | if ((flags & TAG_OBJECT) != 0) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1256 | lea(result, Operand(result, kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1257 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Update allocation top. |
| 1260 | UpdateAllocationTopHelper(result_end, scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1265 | Register result, |
| 1266 | Register result_end, |
| 1267 | Register scratch, |
| 1268 | Label* gc_required, |
| 1269 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1270 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1271 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1272 | // Trash the registers to simulate an allocation failure. |
| 1273 | mov(result, Immediate(0x7091)); |
| 1274 | mov(result_end, Immediate(0x7191)); |
| 1275 | if (scratch.is_valid()) { |
| 1276 | mov(scratch, Immediate(0x7291)); |
| 1277 | } |
| 1278 | // object_size is left unchanged by this function. |
| 1279 | } |
| 1280 | jmp(gc_required); |
| 1281 | return; |
| 1282 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1283 | ASSERT(!result.is(result_end)); |
| 1284 | |
| 1285 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1286 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1287 | |
| 1288 | // Calculate new top and bail out if new space is exhausted. |
| 1289 | ExternalReference new_space_allocation_limit = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1290 | ExternalReference::new_space_allocation_limit_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1291 | if (!object_size.is(result_end)) { |
| 1292 | mov(result_end, object_size); |
| 1293 | } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1294 | add(result_end, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1295 | j(carry, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1296 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1297 | j(above, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1299 | // Tag result if requested. |
| 1300 | if ((flags & TAG_OBJECT) != 0) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1301 | lea(result, Operand(result, kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1302 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1303 | |
| 1304 | // Update allocation top. |
| 1305 | UpdateAllocationTopHelper(result_end, scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 1310 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1311 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1312 | |
| 1313 | // Make sure the object has no tag before resetting top. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1314 | and_(object, Immediate(~kHeapObjectTagMask)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1315 | #ifdef DEBUG |
| 1316 | cmp(object, Operand::StaticVariable(new_space_allocation_top)); |
| 1317 | Check(below, "Undo allocation of non allocated memory"); |
| 1318 | #endif |
| 1319 | mov(Operand::StaticVariable(new_space_allocation_top), object); |
| 1320 | } |
| 1321 | |
| 1322 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1323 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 1324 | Register scratch1, |
| 1325 | Register scratch2, |
| 1326 | Label* gc_required) { |
| 1327 | // Allocate heap number in new space. |
| 1328 | AllocateInNewSpace(HeapNumber::kSize, |
| 1329 | result, |
| 1330 | scratch1, |
| 1331 | scratch2, |
| 1332 | gc_required, |
| 1333 | TAG_OBJECT); |
| 1334 | |
| 1335 | // Set the map. |
| 1336 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1337 | Immediate(isolate()->factory()->heap_number_map())); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1341 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1342 | Register length, |
| 1343 | Register scratch1, |
| 1344 | Register scratch2, |
| 1345 | Register scratch3, |
| 1346 | Label* gc_required) { |
| 1347 | // Calculate the number of bytes needed for the characters in the string while |
| 1348 | // observing object alignment. |
| 1349 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1350 | ASSERT(kShortSize == 2); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1351 | // scratch1 = length * 2 + kObjectAlignmentMask. |
| 1352 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1353 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1354 | |
| 1355 | // Allocate two byte string in new space. |
| 1356 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 1357 | times_1, |
| 1358 | scratch1, |
| 1359 | result, |
| 1360 | scratch2, |
| 1361 | scratch3, |
| 1362 | gc_required, |
| 1363 | TAG_OBJECT); |
| 1364 | |
| 1365 | // Set the map, length and hash field. |
| 1366 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1367 | Immediate(isolate()->factory()->string_map())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1368 | mov(scratch1, length); |
| 1369 | SmiTag(scratch1); |
| 1370 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1371 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1372 | Immediate(String::kEmptyHashField)); |
| 1373 | } |
| 1374 | |
| 1375 | |
| 1376 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1377 | Register length, |
| 1378 | Register scratch1, |
| 1379 | Register scratch2, |
| 1380 | Register scratch3, |
| 1381 | Label* gc_required) { |
| 1382 | // Calculate the number of bytes needed for the characters in the string while |
| 1383 | // observing object alignment. |
| 1384 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1385 | mov(scratch1, length); |
| 1386 | ASSERT(kCharSize == 1); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1387 | add(scratch1, Immediate(kObjectAlignmentMask)); |
| 1388 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1389 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1390 | // Allocate ASCII string in new space. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1391 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 1392 | times_1, |
| 1393 | scratch1, |
| 1394 | result, |
| 1395 | scratch2, |
| 1396 | scratch3, |
| 1397 | gc_required, |
| 1398 | TAG_OBJECT); |
| 1399 | |
| 1400 | // Set the map, length and hash field. |
| 1401 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1402 | Immediate(isolate()->factory()->ascii_string_map())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1403 | mov(scratch1, length); |
| 1404 | SmiTag(scratch1); |
| 1405 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1406 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1407 | Immediate(String::kEmptyHashField)); |
| 1408 | } |
| 1409 | |
| 1410 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1411 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1412 | int length, |
| 1413 | Register scratch1, |
| 1414 | Register scratch2, |
| 1415 | Label* gc_required) { |
| 1416 | ASSERT(length > 0); |
| 1417 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1418 | // Allocate ASCII string in new space. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1419 | AllocateInNewSpace(SeqAsciiString::SizeFor(length), |
| 1420 | result, |
| 1421 | scratch1, |
| 1422 | scratch2, |
| 1423 | gc_required, |
| 1424 | TAG_OBJECT); |
| 1425 | |
| 1426 | // Set the map, length and hash field. |
| 1427 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1428 | Immediate(isolate()->factory()->ascii_string_map())); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1429 | mov(FieldOperand(result, String::kLengthOffset), |
| 1430 | Immediate(Smi::FromInt(length))); |
| 1431 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1432 | Immediate(String::kEmptyHashField)); |
| 1433 | } |
| 1434 | |
| 1435 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1436 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1437 | Register scratch1, |
| 1438 | Register scratch2, |
| 1439 | Label* gc_required) { |
| 1440 | // Allocate heap number in new space. |
| 1441 | AllocateInNewSpace(ConsString::kSize, |
| 1442 | result, |
| 1443 | scratch1, |
| 1444 | scratch2, |
| 1445 | gc_required, |
| 1446 | TAG_OBJECT); |
| 1447 | |
| 1448 | // Set the map. The other fields are left uninitialized. |
| 1449 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1450 | Immediate(isolate()->factory()->cons_string_map())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1455 | Register scratch1, |
| 1456 | Register scratch2, |
| 1457 | Label* gc_required) { |
| 1458 | // Allocate heap number in new space. |
| 1459 | AllocateInNewSpace(ConsString::kSize, |
| 1460 | result, |
| 1461 | scratch1, |
| 1462 | scratch2, |
| 1463 | gc_required, |
| 1464 | TAG_OBJECT); |
| 1465 | |
| 1466 | // Set the map. The other fields are left uninitialized. |
| 1467 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1468 | Immediate(isolate()->factory()->cons_ascii_string_map())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1471 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1472 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1473 | Register scratch1, |
| 1474 | Register scratch2, |
| 1475 | Label* gc_required) { |
| 1476 | // Allocate heap number in new space. |
| 1477 | AllocateInNewSpace(SlicedString::kSize, |
| 1478 | result, |
| 1479 | scratch1, |
| 1480 | scratch2, |
| 1481 | gc_required, |
| 1482 | TAG_OBJECT); |
| 1483 | |
| 1484 | // Set the map. The other fields are left uninitialized. |
| 1485 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 1486 | Immediate(isolate()->factory()->sliced_string_map())); |
| 1487 | } |
| 1488 | |
| 1489 | |
| 1490 | void MacroAssembler::AllocateAsciiSlicedString(Register result, |
| 1491 | Register scratch1, |
| 1492 | Register scratch2, |
| 1493 | Label* gc_required) { |
| 1494 | // Allocate heap number in new space. |
| 1495 | AllocateInNewSpace(SlicedString::kSize, |
| 1496 | result, |
| 1497 | scratch1, |
| 1498 | scratch2, |
| 1499 | gc_required, |
| 1500 | TAG_OBJECT); |
| 1501 | |
| 1502 | // Set the map. The other fields are left uninitialized. |
| 1503 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 1504 | Immediate(isolate()->factory()->sliced_ascii_string_map())); |
| 1505 | } |
| 1506 | |
| 1507 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1508 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 1509 | // long or aligned copies. The contents of scratch and length are destroyed. |
| 1510 | // Source and destination are incremented by length. |
| 1511 | // Many variants of movsb, loop unrolling, word moves, and indexed operands |
| 1512 | // have been tried here already, and this is fastest. |
| 1513 | // A simpler loop is faster on small copies, but 30% slower on large ones. |
| 1514 | // The cld() instruction must have been emitted, to set the direction flag(), |
| 1515 | // before calling this function. |
| 1516 | void MacroAssembler::CopyBytes(Register source, |
| 1517 | Register destination, |
| 1518 | Register length, |
| 1519 | Register scratch) { |
| 1520 | Label loop, done, short_string, short_loop; |
| 1521 | // Experimentation shows that the short string loop is faster if length < 10. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1522 | cmp(length, Immediate(10)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1523 | j(less_equal, &short_string); |
| 1524 | |
| 1525 | ASSERT(source.is(esi)); |
| 1526 | ASSERT(destination.is(edi)); |
| 1527 | ASSERT(length.is(ecx)); |
| 1528 | |
| 1529 | // Because source is 4-byte aligned in our uses of this function, |
| 1530 | // we keep source aligned for the rep_movs call by copying the odd bytes |
| 1531 | // at the end of the ranges. |
| 1532 | mov(scratch, Operand(source, length, times_1, -4)); |
| 1533 | mov(Operand(destination, length, times_1, -4), scratch); |
| 1534 | mov(scratch, ecx); |
| 1535 | shr(ecx, 2); |
| 1536 | rep_movs(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1537 | and_(scratch, Immediate(0x3)); |
| 1538 | add(destination, scratch); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1539 | jmp(&done); |
| 1540 | |
| 1541 | bind(&short_string); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1542 | test(length, length); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1543 | j(zero, &done); |
| 1544 | |
| 1545 | bind(&short_loop); |
| 1546 | mov_b(scratch, Operand(source, 0)); |
| 1547 | mov_b(Operand(destination, 0), scratch); |
| 1548 | inc(source); |
| 1549 | inc(destination); |
| 1550 | dec(length); |
| 1551 | j(not_zero, &short_loop); |
| 1552 | |
| 1553 | bind(&done); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1556 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1557 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 1558 | Register end_offset, |
| 1559 | Register filler) { |
| 1560 | Label loop, entry; |
| 1561 | jmp(&entry); |
| 1562 | bind(&loop); |
| 1563 | mov(Operand(start_offset, 0), filler); |
| 1564 | add(start_offset, Immediate(kPointerSize)); |
| 1565 | bind(&entry); |
| 1566 | cmp(start_offset, end_offset); |
| 1567 | j(less, &loop); |
| 1568 | } |
| 1569 | |
| 1570 | |
| 1571 | void MacroAssembler::BooleanBitTest(Register object, |
| 1572 | int field_offset, |
| 1573 | int bit_index) { |
| 1574 | bit_index += kSmiTagSize + kSmiShiftSize; |
| 1575 | ASSERT(IsPowerOf2(kBitsPerByte)); |
| 1576 | int byte_index = bit_index / kBitsPerByte; |
| 1577 | int byte_bit_index = bit_index & (kBitsPerByte - 1); |
| 1578 | test_b(FieldOperand(object, field_offset + byte_index), |
| 1579 | static_cast<byte>(1 << byte_bit_index)); |
| 1580 | } |
| 1581 | |
| 1582 | |
| 1583 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1584 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1585 | Register op, |
| 1586 | Label* then_label) { |
| 1587 | Label ok; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1588 | test(result, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1589 | j(not_zero, &ok); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1590 | test(op, op); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1591 | j(sign, then_label); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1592 | bind(&ok); |
| 1593 | } |
| 1594 | |
| 1595 | |
| 1596 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1597 | Register op1, |
| 1598 | Register op2, |
| 1599 | Register scratch, |
| 1600 | Label* then_label) { |
| 1601 | Label ok; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1602 | test(result, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1603 | j(not_zero, &ok); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1604 | mov(scratch, op1); |
| 1605 | or_(scratch, op2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1606 | j(sign, then_label); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1607 | bind(&ok); |
| 1608 | } |
| 1609 | |
| 1610 | |
| 1611 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1612 | Register result, |
| 1613 | Register scratch, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1614 | Label* miss, |
| 1615 | bool miss_on_bound_function) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1616 | // Check that the receiver isn't a smi. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1617 | JumpIfSmi(function, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1618 | |
| 1619 | // Check that the function really is a function. |
| 1620 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1621 | j(not_equal, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1622 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1623 | if (miss_on_bound_function) { |
| 1624 | // If a bound function, go to miss label. |
| 1625 | mov(scratch, |
| 1626 | FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 1627 | BooleanBitTest(scratch, SharedFunctionInfo::kCompilerHintsOffset, |
| 1628 | SharedFunctionInfo::kBoundFunction); |
| 1629 | j(not_zero, miss); |
| 1630 | } |
| 1631 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1632 | // Make sure that the function has an instance prototype. |
| 1633 | Label non_instance; |
| 1634 | movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
| 1635 | test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1636 | j(not_zero, &non_instance); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1637 | |
| 1638 | // Get the prototype or initial map from the function. |
| 1639 | mov(result, |
| 1640 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1641 | |
| 1642 | // If the prototype or initial map is the hole, don't return it and |
| 1643 | // simply miss the cache instead. This will allow us to allocate a |
| 1644 | // prototype object on-demand in the runtime system. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1645 | cmp(result, Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1646 | j(equal, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1647 | |
| 1648 | // If the function does not have an initial map, we're done. |
| 1649 | Label done; |
| 1650 | CmpObjectType(result, MAP_TYPE, scratch); |
| 1651 | j(not_equal, &done); |
| 1652 | |
| 1653 | // Get the prototype from the initial map. |
| 1654 | mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 1655 | jmp(&done); |
| 1656 | |
| 1657 | // Non-instance prototype: Fetch prototype from constructor field |
| 1658 | // in initial map. |
| 1659 | bind(&non_instance); |
| 1660 | mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1661 | |
| 1662 | // All done. |
| 1663 | bind(&done); |
| 1664 | } |
| 1665 | |
| 1666 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1667 | void MacroAssembler::CallStub(CodeStub* stub, unsigned ast_id) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1668 | ASSERT(AllowThisStubCall(stub)); // Calls are not allowed in some stubs. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1669 | call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1673 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1674 | ASSERT(allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1675 | jmp(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 1676 | } |
| 1677 | |
| 1678 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1679 | void MacroAssembler::StubReturn(int argc) { |
| 1680 | ASSERT(argc >= 1 && generating_stub()); |
| 1681 | ret((argc - 1) * kPointerSize); |
| 1682 | } |
| 1683 | |
| 1684 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1685 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
| 1686 | if (!has_frame_ && stub->SometimesSetsUpAFrame()) return false; |
| 1687 | return allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe(); |
| 1688 | } |
| 1689 | |
| 1690 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1691 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1692 | if (num_arguments > 0) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1693 | add(esp, Immediate(num_arguments * kPointerSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1694 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1695 | mov(eax, Immediate(isolate()->factory()->undefined_value())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1699 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1700 | // The assert checks that the constants for the maximum number of digits |
| 1701 | // for an array index cached in the hash field and the number of bits |
| 1702 | // reserved for it does not conflict. |
| 1703 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1704 | (1 << String::kArrayIndexValueBits)); |
| 1705 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1706 | // the low kHashShift bits. |
| 1707 | and_(hash, String::kArrayIndexValueMask); |
| 1708 | STATIC_ASSERT(String::kHashShift >= kSmiTagSize && kSmiTag == 0); |
| 1709 | if (String::kHashShift > kSmiTagSize) { |
| 1710 | shr(hash, String::kHashShift - kSmiTagSize); |
| 1711 | } |
| 1712 | if (!index.is(hash)) { |
| 1713 | mov(index, hash); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1718 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 1719 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1720 | } |
| 1721 | |
| 1722 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1723 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1724 | const Runtime::Function* function = Runtime::FunctionForId(id); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1725 | Set(eax, Immediate(function->nargs)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1726 | mov(ebx, Immediate(ExternalReference(function, isolate()))); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1727 | CEntryStub ces(1, kSaveFPRegs); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1728 | CallStub(&ces); |
| 1729 | } |
| 1730 | |
| 1731 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1732 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 1733 | int num_arguments) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1734 | // If the expected number of arguments of the runtime function is |
| 1735 | // constant, we check that the actual number of arguments match the |
| 1736 | // expectation. |
| 1737 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1738 | IllegalOperation(num_arguments); |
| 1739 | return; |
| 1740 | } |
| 1741 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1742 | // TODO(1236192): Most runtime routines don't need the number of |
| 1743 | // arguments passed in because it is constant. At some point we |
| 1744 | // should remove this need and make the runtime routine entry code |
| 1745 | // smarter. |
| 1746 | Set(eax, Immediate(num_arguments)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1747 | mov(ebx, Immediate(ExternalReference(f, isolate()))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1748 | CEntryStub ces(1); |
| 1749 | CallStub(&ces); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1753 | void MacroAssembler::CallExternalReference(ExternalReference ref, |
| 1754 | int num_arguments) { |
| 1755 | mov(eax, Immediate(num_arguments)); |
| 1756 | mov(ebx, Immediate(ref)); |
| 1757 | |
| 1758 | CEntryStub stub(1); |
| 1759 | CallStub(&stub); |
| 1760 | } |
| 1761 | |
| 1762 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1763 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1764 | int num_arguments, |
| 1765 | int result_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1766 | // TODO(1236192): Most runtime routines don't need the number of |
| 1767 | // arguments passed in because it is constant. At some point we |
| 1768 | // should remove this need and make the runtime routine entry code |
| 1769 | // smarter. |
| 1770 | Set(eax, Immediate(num_arguments)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1771 | JumpToExternalReference(ext); |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1776 | int num_arguments, |
| 1777 | int result_size) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1778 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 1779 | num_arguments, |
| 1780 | result_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1784 | // If true, a Handle<T> returned by value from a function with cdecl calling |
| 1785 | // convention will be returned directly as a value of location_ field in a |
| 1786 | // register eax. |
| 1787 | // If false, it is returned as a pointer to a preallocated by caller memory |
| 1788 | // region. Pointer to this region should be passed to a function as an |
| 1789 | // implicit first argument. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1790 | #if defined(USING_BSD_ABI) || defined(__MINGW32__) || defined(__CYGWIN__) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1791 | static const bool kReturnHandlesDirectly = true; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1792 | #else |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1793 | static const bool kReturnHandlesDirectly = false; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1794 | #endif |
| 1795 | |
| 1796 | |
| 1797 | Operand ApiParameterOperand(int index) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1798 | return Operand( |
| 1799 | esp, (index + (kReturnHandlesDirectly ? 0 : 1)) * kPointerSize); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1803 | void MacroAssembler::PrepareCallApiFunction(int argc) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1804 | if (kReturnHandlesDirectly) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1805 | EnterApiExitFrame(argc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1806 | // When handles are returned directly we don't have to allocate extra |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1807 | // space for and pass an out parameter. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1808 | if (emit_debug_code()) { |
| 1809 | mov(esi, Immediate(BitCast<int32_t>(kZapValue))); |
| 1810 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1811 | } else { |
| 1812 | // We allocate two additional slots: return value and pointer to it. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1813 | EnterApiExitFrame(argc + 2); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1814 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1815 | // The argument slots are filled as follows: |
| 1816 | // |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1817 | // n + 1: output slot |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1818 | // n: arg n |
| 1819 | // ... |
| 1820 | // 1: arg1 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1821 | // 0: pointer to the output slot |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1822 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1823 | lea(esi, Operand(esp, (argc + 1) * kPointerSize)); |
| 1824 | mov(Operand(esp, 0 * kPointerSize), esi); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1825 | if (emit_debug_code()) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1826 | mov(Operand(esi, 0), Immediate(0)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1832 | void MacroAssembler::CallApiFunctionAndReturn(Address function_address, |
| 1833 | int stack_space) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1834 | ExternalReference next_address = |
| 1835 | ExternalReference::handle_scope_next_address(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1836 | ExternalReference limit_address = |
| 1837 | ExternalReference::handle_scope_limit_address(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1838 | ExternalReference level_address = |
| 1839 | ExternalReference::handle_scope_level_address(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1840 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1841 | // Allocate HandleScope in callee-save registers. |
| 1842 | mov(ebx, Operand::StaticVariable(next_address)); |
| 1843 | mov(edi, Operand::StaticVariable(limit_address)); |
| 1844 | add(Operand::StaticVariable(level_address), Immediate(1)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1845 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1846 | // Call the api function. |
| 1847 | call(function_address, RelocInfo::RUNTIME_ENTRY); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1848 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1849 | if (!kReturnHandlesDirectly) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1850 | // PrepareCallApiFunction saved pointer to the output slot into |
| 1851 | // callee-save register esi. |
| 1852 | mov(eax, Operand(esi, 0)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1853 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1854 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1855 | Label empty_handle; |
| 1856 | Label prologue; |
| 1857 | Label promote_scheduled_exception; |
| 1858 | Label delete_allocated_handles; |
| 1859 | Label leave_exit_frame; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1860 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1861 | // Check if the result handle holds 0. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1862 | test(eax, eax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1863 | j(zero, &empty_handle); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1864 | // It was non-zero. Dereference to get the result value. |
| 1865 | mov(eax, Operand(eax, 0)); |
| 1866 | bind(&prologue); |
| 1867 | // No more valid handles (the result handle was the last one). Restore |
| 1868 | // previous handle scope. |
| 1869 | mov(Operand::StaticVariable(next_address), ebx); |
| 1870 | sub(Operand::StaticVariable(level_address), Immediate(1)); |
| 1871 | Assert(above_equal, "Invalid HandleScope level"); |
| 1872 | cmp(edi, Operand::StaticVariable(limit_address)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1873 | j(not_equal, &delete_allocated_handles); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1874 | bind(&leave_exit_frame); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1875 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1876 | // Check if the function scheduled an exception. |
| 1877 | ExternalReference scheduled_exception_address = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1878 | ExternalReference::scheduled_exception_address(isolate()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1879 | cmp(Operand::StaticVariable(scheduled_exception_address), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1880 | Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1881 | j(not_equal, &promote_scheduled_exception); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1882 | LeaveApiExitFrame(); |
| 1883 | ret(stack_space * kPointerSize); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1884 | bind(&promote_scheduled_exception); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1885 | TailCallRuntime(Runtime::kPromoteScheduledException, 0, 1); |
| 1886 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1887 | bind(&empty_handle); |
| 1888 | // It was zero; the result is undefined. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1889 | mov(eax, isolate()->factory()->undefined_value()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1890 | jmp(&prologue); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1891 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1892 | // HandleScope limit has changed. Delete allocated extensions. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1893 | ExternalReference delete_extensions = |
| 1894 | ExternalReference::delete_handle_scope_extensions(isolate()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1895 | bind(&delete_allocated_handles); |
| 1896 | mov(Operand::StaticVariable(limit_address), edi); |
| 1897 | mov(edi, eax); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1898 | mov(Operand(esp, 0), Immediate(ExternalReference::isolate_address())); |
| 1899 | mov(eax, Immediate(delete_extensions)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1900 | call(eax); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1901 | mov(eax, edi); |
| 1902 | jmp(&leave_exit_frame); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1906 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1907 | // Set the entry point and jump to the C entry runtime stub. |
| 1908 | mov(ebx, Immediate(ext)); |
| 1909 | CEntryStub ces(1); |
| 1910 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 1911 | } |
| 1912 | |
| 1913 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1914 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 1915 | // This macro takes the dst register to make the code more readable |
| 1916 | // at the call sites. However, the dst register has to be ecx to |
| 1917 | // follow the calling convention which requires the call type to be |
| 1918 | // in ecx. |
| 1919 | ASSERT(dst.is(ecx)); |
| 1920 | if (call_kind == CALL_AS_FUNCTION) { |
| 1921 | // Set to some non-zero smi by updating the least significant |
| 1922 | // byte. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1923 | mov_b(dst, 1 << kSmiTagSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1924 | } else { |
| 1925 | // Set to smi zero by clearing the register. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1926 | xor_(dst, dst); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1931 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1932 | const ParameterCount& actual, |
| 1933 | Handle<Code> code_constant, |
| 1934 | const Operand& code_operand, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1935 | Label* done, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1936 | bool* definitely_mismatches, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1937 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1938 | Label::Distance done_near, |
| 1939 | const CallWrapper& call_wrapper, |
| 1940 | CallKind call_kind) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1941 | bool definitely_matches = false; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1942 | *definitely_mismatches = false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1943 | Label invoke; |
| 1944 | if (expected.is_immediate()) { |
| 1945 | ASSERT(actual.is_immediate()); |
| 1946 | if (expected.immediate() == actual.immediate()) { |
| 1947 | definitely_matches = true; |
| 1948 | } else { |
| 1949 | mov(eax, actual.immediate()); |
| 1950 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1951 | if (expected.immediate() == sentinel) { |
| 1952 | // Don't worry about adapting arguments for builtins that |
| 1953 | // don't want that done. Skip adaption code by making it look |
| 1954 | // like we have a match between expected and actual number of |
| 1955 | // arguments. |
| 1956 | definitely_matches = true; |
| 1957 | } else { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1958 | *definitely_mismatches = true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1959 | mov(ebx, expected.immediate()); |
| 1960 | } |
| 1961 | } |
| 1962 | } else { |
| 1963 | if (actual.is_immediate()) { |
| 1964 | // Expected is in register, actual is immediate. This is the |
| 1965 | // case when we invoke function values without going through the |
| 1966 | // IC mechanism. |
| 1967 | cmp(expected.reg(), actual.immediate()); |
| 1968 | j(equal, &invoke); |
| 1969 | ASSERT(expected.reg().is(ebx)); |
| 1970 | mov(eax, actual.immediate()); |
| 1971 | } else if (!expected.reg().is(actual.reg())) { |
| 1972 | // Both expected and actual are in (different) registers. This |
| 1973 | // is the case when we invoke functions using call and apply. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1974 | cmp(expected.reg(), actual.reg()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1975 | j(equal, &invoke); |
| 1976 | ASSERT(actual.reg().is(eax)); |
| 1977 | ASSERT(expected.reg().is(ebx)); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | if (!definitely_matches) { |
| 1982 | Handle<Code> adaptor = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1983 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1984 | if (!code_constant.is_null()) { |
| 1985 | mov(edx, Immediate(code_constant)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1986 | add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1987 | } else if (!code_operand.is_reg(edx)) { |
| 1988 | mov(edx, code_operand); |
| 1989 | } |
| 1990 | |
| 1991 | if (flag == CALL_FUNCTION) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1992 | call_wrapper.BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
| 1993 | SetCallKind(ecx, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1994 | call(adaptor, RelocInfo::CODE_TARGET); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1995 | call_wrapper.AfterCall(); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 1996 | if (!*definitely_mismatches) { |
| 1997 | jmp(done, done_near); |
| 1998 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1999 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2000 | SetCallKind(ecx, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2001 | jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2002 | } |
| 2003 | bind(&invoke); |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | |
| 2008 | void MacroAssembler::InvokeCode(const Operand& code, |
| 2009 | const ParameterCount& expected, |
| 2010 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2011 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2012 | const CallWrapper& call_wrapper, |
| 2013 | CallKind call_kind) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2014 | // You can't call a function without a valid frame. |
| 2015 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2016 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2017 | Label done; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2018 | bool definitely_mismatches = false; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2019 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2020 | &done, &definitely_mismatches, flag, Label::kNear, |
| 2021 | call_wrapper, call_kind); |
| 2022 | if (!definitely_mismatches) { |
| 2023 | if (flag == CALL_FUNCTION) { |
| 2024 | call_wrapper.BeforeCall(CallSize(code)); |
| 2025 | SetCallKind(ecx, call_kind); |
| 2026 | call(code); |
| 2027 | call_wrapper.AfterCall(); |
| 2028 | } else { |
| 2029 | ASSERT(flag == JUMP_FUNCTION); |
| 2030 | SetCallKind(ecx, call_kind); |
| 2031 | jmp(code); |
| 2032 | } |
| 2033 | bind(&done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2034 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | |
| 2038 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 2039 | const ParameterCount& expected, |
| 2040 | const ParameterCount& actual, |
| 2041 | RelocInfo::Mode rmode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2042 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2043 | const CallWrapper& call_wrapper, |
| 2044 | CallKind call_kind) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2045 | // You can't call a function without a valid frame. |
| 2046 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2047 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2048 | Label done; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2049 | Operand dummy(eax, 0); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2050 | bool definitely_mismatches = false; |
| 2051 | InvokePrologue(expected, actual, code, dummy, &done, &definitely_mismatches, |
| 2052 | flag, Label::kNear, call_wrapper, call_kind); |
| 2053 | if (!definitely_mismatches) { |
| 2054 | if (flag == CALL_FUNCTION) { |
| 2055 | call_wrapper.BeforeCall(CallSize(code, rmode)); |
| 2056 | SetCallKind(ecx, call_kind); |
| 2057 | call(code, rmode); |
| 2058 | call_wrapper.AfterCall(); |
| 2059 | } else { |
| 2060 | ASSERT(flag == JUMP_FUNCTION); |
| 2061 | SetCallKind(ecx, call_kind); |
| 2062 | jmp(code, rmode); |
| 2063 | } |
| 2064 | bind(&done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2065 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | |
| 2069 | void MacroAssembler::InvokeFunction(Register fun, |
| 2070 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2071 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2072 | const CallWrapper& call_wrapper, |
| 2073 | CallKind call_kind) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2074 | // You can't call a function without a valid frame. |
| 2075 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2077 | ASSERT(fun.is(edi)); |
| 2078 | mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2079 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 2080 | mov(ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2081 | SmiUntag(ebx); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2082 | |
| 2083 | ParameterCount expected(ebx); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2084 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2085 | expected, actual, flag, call_wrapper, call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2089 | void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2090 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2091 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2092 | const CallWrapper& call_wrapper, |
| 2093 | CallKind call_kind) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2094 | // You can't call a function without a valid frame. |
| 2095 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2096 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2097 | // Get the function and setup the context. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2098 | LoadHeapObject(edi, function); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2099 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2100 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2101 | ParameterCount expected(function->shared()->formal_parameter_count()); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2102 | // We call indirectly through the code field in the function to |
| 2103 | // allow recompilation to take effect without changing any of the |
| 2104 | // call sites. |
| 2105 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
| 2106 | expected, actual, flag, call_wrapper, call_kind); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2110 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 2111 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2112 | const CallWrapper& call_wrapper) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2113 | // You can't call a builtin without a valid frame. |
| 2114 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2115 | |
| 2116 | // Rely on the assertion to check that the number of provided |
| 2117 | // arguments match the expected number of arguments. Fake a |
| 2118 | // parameter count to avoid emitting code to do the check. |
| 2119 | ParameterCount expected(0); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2120 | GetBuiltinFunction(edi, id); |
| 2121 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2122 | expected, expected, flag, call_wrapper, CALL_AS_METHOD); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2125 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2126 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2127 | Builtins::JavaScript id) { |
| 2128 | // Load the JavaScript builtin function from the builtins object. |
| 2129 | mov(target, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2130 | mov(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
| 2131 | mov(target, FieldOperand(target, |
| 2132 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2133 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2134 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2135 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2136 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2137 | ASSERT(!target.is(edi)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2138 | // Load the JavaScript builtin function from the builtins object. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2139 | GetBuiltinFunction(edi, id); |
| 2140 | // Load the code entry point from the function into the target register. |
| 2141 | mov(target, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2145 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2146 | if (context_chain_length > 0) { |
| 2147 | // Move up the chain of contexts to the context containing the slot. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2148 | mov(dst, Operand(esi, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2149 | for (int i = 1; i < context_chain_length; i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2150 | mov(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2151 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2152 | } else { |
| 2153 | // Slot is in the current function context. Move it into the |
| 2154 | // destination register in case we store into it (the write barrier |
| 2155 | // cannot be allowed to destroy the context in esi). |
| 2156 | mov(dst, esi); |
| 2157 | } |
| 2158 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2159 | // We should not have found a with context by walking the context chain |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2160 | // (i.e., the static scope chain and runtime context chain do not agree). |
| 2161 | // A variable occurring in such a scope should have slot type LOOKUP and |
| 2162 | // not CONTEXT. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2163 | if (emit_debug_code()) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2164 | cmp(FieldOperand(dst, HeapObject::kMapOffset), |
| 2165 | isolate()->factory()->with_context_map()); |
| 2166 | Check(not_equal, "Variable resolved to with context."); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2171 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2172 | // Load the global or builtins object from the current context. |
| 2173 | mov(function, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2174 | // Load the global context from the global or builtins object. |
| 2175 | mov(function, FieldOperand(function, GlobalObject::kGlobalContextOffset)); |
| 2176 | // Load the function from the global context. |
| 2177 | mov(function, Operand(function, Context::SlotOffset(index))); |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2182 | Register map) { |
| 2183 | // Load the initial map. The global functions all have initial maps. |
| 2184 | mov(map, FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2185 | if (emit_debug_code()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2186 | Label ok, fail; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2187 | CheckMap(map, isolate()->factory()->meta_map(), &fail, DO_SMI_CHECK); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2188 | jmp(&ok); |
| 2189 | bind(&fail); |
| 2190 | Abort("Global functions must have initial map"); |
| 2191 | bind(&ok); |
| 2192 | } |
| 2193 | } |
| 2194 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2195 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2196 | // Store the value in register src in the safepoint register stack |
| 2197 | // slot for register dst. |
| 2198 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Register src) { |
| 2199 | mov(SafepointRegisterSlot(dst), src); |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Immediate src) { |
| 2204 | mov(SafepointRegisterSlot(dst), src); |
| 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 2209 | mov(dst, SafepointRegisterSlot(src)); |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | Operand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 2214 | return Operand(esp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 2215 | } |
| 2216 | |
| 2217 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2218 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 2219 | // The registers are pushed starting with the lowest encoding, |
| 2220 | // which means that lowest encodings are furthest away from |
| 2221 | // the stack pointer. |
| 2222 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 2223 | return kNumSafepointRegisters - reg_code - 1; |
| 2224 | } |
| 2225 | |
| 2226 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2227 | void MacroAssembler::LoadHeapObject(Register result, |
| 2228 | Handle<HeapObject> object) { |
| 2229 | if (isolate()->heap()->InNewSpace(*object)) { |
| 2230 | Handle<JSGlobalPropertyCell> cell = |
| 2231 | isolate()->factory()->NewJSGlobalPropertyCell(object); |
| 2232 | mov(result, Operand::Cell(cell)); |
| 2233 | } else { |
| 2234 | mov(result, object); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | void MacroAssembler::PushHeapObject(Handle<HeapObject> object) { |
| 2240 | if (isolate()->heap()->InNewSpace(*object)) { |
| 2241 | Handle<JSGlobalPropertyCell> cell = |
| 2242 | isolate()->factory()->NewJSGlobalPropertyCell(object); |
| 2243 | push(Operand::Cell(cell)); |
| 2244 | } else { |
| 2245 | Push(object); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2250 | void MacroAssembler::Ret() { |
| 2251 | ret(0); |
| 2252 | } |
| 2253 | |
| 2254 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2255 | void MacroAssembler::Ret(int bytes_dropped, Register scratch) { |
| 2256 | if (is_uint16(bytes_dropped)) { |
| 2257 | ret(bytes_dropped); |
| 2258 | } else { |
| 2259 | pop(scratch); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2260 | add(esp, Immediate(bytes_dropped)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2261 | push(scratch); |
| 2262 | ret(0); |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2267 | void MacroAssembler::Drop(int stack_elements) { |
| 2268 | if (stack_elements > 0) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2269 | add(esp, Immediate(stack_elements * kPointerSize)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2274 | void MacroAssembler::Move(Register dst, Register src) { |
| 2275 | if (!dst.is(src)) { |
| 2276 | mov(dst, src); |
| 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2281 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 2282 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2283 | mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | |
| 2288 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 2289 | ASSERT(value > 0); |
| 2290 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2291 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 2292 | if (value == 1) { |
| 2293 | inc(operand); |
| 2294 | } else { |
| 2295 | add(operand, Immediate(value)); |
| 2296 | } |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 2302 | ASSERT(value > 0); |
| 2303 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2304 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 2305 | if (value == 1) { |
| 2306 | dec(operand); |
| 2307 | } else { |
| 2308 | sub(operand, Immediate(value)); |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2314 | void MacroAssembler::IncrementCounter(Condition cc, |
| 2315 | StatsCounter* counter, |
| 2316 | int value) { |
| 2317 | ASSERT(value > 0); |
| 2318 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2319 | Label skip; |
| 2320 | j(NegateCondition(cc), &skip); |
| 2321 | pushfd(); |
| 2322 | IncrementCounter(counter, value); |
| 2323 | popfd(); |
| 2324 | bind(&skip); |
| 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | |
| 2329 | void MacroAssembler::DecrementCounter(Condition cc, |
| 2330 | StatsCounter* counter, |
| 2331 | int value) { |
| 2332 | ASSERT(value > 0); |
| 2333 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2334 | Label skip; |
| 2335 | j(NegateCondition(cc), &skip); |
| 2336 | pushfd(); |
| 2337 | DecrementCounter(counter, value); |
| 2338 | popfd(); |
| 2339 | bind(&skip); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2344 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2345 | if (emit_debug_code()) Check(cc, msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2349 | void MacroAssembler::AssertFastElements(Register elements) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2350 | if (emit_debug_code()) { |
| 2351 | Factory* factory = isolate()->factory(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2352 | Label ok; |
| 2353 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2354 | Immediate(factory->fixed_array_map())); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2355 | j(equal, &ok); |
| 2356 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2357 | Immediate(factory->fixed_double_array_map())); |
| 2358 | j(equal, &ok); |
| 2359 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2360 | Immediate(factory->fixed_cow_array_map())); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2361 | j(equal, &ok); |
| 2362 | Abort("JSObject with fast elements map has slow elements"); |
| 2363 | bind(&ok); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2368 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 2369 | Label L; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2370 | j(cc, &L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2371 | Abort(msg); |
| 2372 | // will not return here |
| 2373 | bind(&L); |
| 2374 | } |
| 2375 | |
| 2376 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2377 | void MacroAssembler::CheckStackAlignment() { |
| 2378 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2379 | int frame_alignment_mask = frame_alignment - 1; |
| 2380 | if (frame_alignment > kPointerSize) { |
| 2381 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2382 | Label alignment_as_expected; |
| 2383 | test(esp, Immediate(frame_alignment_mask)); |
| 2384 | j(zero, &alignment_as_expected); |
| 2385 | // Abort if stack is not aligned. |
| 2386 | int3(); |
| 2387 | bind(&alignment_as_expected); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2392 | void MacroAssembler::Abort(const char* msg) { |
| 2393 | // We want to pass the msg string like a smi to avoid GC |
| 2394 | // problems, however msg is not guaranteed to be aligned |
| 2395 | // properly. Instead, we pass an aligned pointer that is |
| 2396 | // a proper v8 smi, but also pass the alignment difference |
| 2397 | // from the real pointer as a smi. |
| 2398 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2399 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2400 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2401 | #ifdef DEBUG |
| 2402 | if (msg != NULL) { |
| 2403 | RecordComment("Abort message: "); |
| 2404 | RecordComment(msg); |
| 2405 | } |
| 2406 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2407 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2408 | push(eax); |
| 2409 | push(Immediate(p0)); |
| 2410 | push(Immediate(reinterpret_cast<intptr_t>(Smi::FromInt(p1 - p0)))); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2411 | // Disable stub call restrictions to always allow calls to abort. |
| 2412 | if (!has_frame_) { |
| 2413 | // We don't actually want to generate a pile of code for this, so just |
| 2414 | // claim there is a stack frame, without generating one. |
| 2415 | FrameScope scope(this, StackFrame::NONE); |
| 2416 | CallRuntime(Runtime::kAbort, 2); |
| 2417 | } else { |
| 2418 | CallRuntime(Runtime::kAbort, 2); |
| 2419 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2420 | // will not return here |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2421 | int3(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2425 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 2426 | Register descriptors) { |
| 2427 | mov(descriptors, |
| 2428 | FieldOperand(map, Map::kInstanceDescriptorsOrBitField3Offset)); |
| 2429 | Label not_smi; |
| 2430 | JumpIfNotSmi(descriptors, ¬_smi); |
| 2431 | mov(descriptors, isolate()->factory()->empty_descriptor_array()); |
| 2432 | bind(¬_smi); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2436 | void MacroAssembler::LoadPowerOf2(XMMRegister dst, |
| 2437 | Register scratch, |
| 2438 | int power) { |
| 2439 | ASSERT(is_uintn(power + HeapNumber::kExponentBias, |
| 2440 | HeapNumber::kExponentBits)); |
| 2441 | mov(scratch, Immediate(power + HeapNumber::kExponentBias)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2442 | movd(dst, scratch); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2443 | psllq(dst, HeapNumber::kMantissaBits); |
| 2444 | } |
| 2445 | |
| 2446 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2447 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( |
| 2448 | Register instance_type, |
| 2449 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2450 | Label* failure) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2451 | if (!scratch.is(instance_type)) { |
| 2452 | mov(scratch, instance_type); |
| 2453 | } |
| 2454 | and_(scratch, |
| 2455 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask); |
| 2456 | cmp(scratch, kStringTag | kSeqStringTag | kAsciiStringTag); |
| 2457 | j(not_equal, failure); |
| 2458 | } |
| 2459 | |
| 2460 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2461 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 2462 | Register object2, |
| 2463 | Register scratch1, |
| 2464 | Register scratch2, |
| 2465 | Label* failure) { |
| 2466 | // Check that both objects are not smis. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2467 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2468 | mov(scratch1, object1); |
| 2469 | and_(scratch1, object2); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2470 | JumpIfSmi(scratch1, failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2471 | |
| 2472 | // Load instance type for both strings. |
| 2473 | mov(scratch1, FieldOperand(object1, HeapObject::kMapOffset)); |
| 2474 | mov(scratch2, FieldOperand(object2, HeapObject::kMapOffset)); |
| 2475 | movzx_b(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2476 | movzx_b(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 2477 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 2478 | // Check that both are flat ASCII strings. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2479 | const int kFlatAsciiStringMask = |
| 2480 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 2481 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2482 | // Interleave bits from both instance types and compare them in one check. |
| 2483 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 2484 | and_(scratch1, kFlatAsciiStringMask); |
| 2485 | and_(scratch2, kFlatAsciiStringMask); |
| 2486 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 2487 | cmp(scratch1, kFlatAsciiStringTag | (kFlatAsciiStringTag << 3)); |
| 2488 | j(not_equal, failure); |
| 2489 | } |
| 2490 | |
| 2491 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2492 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2493 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2494 | if (frame_alignment != 0) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2495 | // Make stack end at alignment and make room for num_arguments words |
| 2496 | // and the original value of esp. |
| 2497 | mov(scratch, esp); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2498 | sub(esp, Immediate((num_arguments + 1) * kPointerSize)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2499 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2500 | and_(esp, -frame_alignment); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2501 | mov(Operand(esp, num_arguments * kPointerSize), scratch); |
| 2502 | } else { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2503 | sub(esp, Immediate(num_arguments * kPointerSize)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | |
| 2508 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2509 | int num_arguments) { |
| 2510 | // Trashing eax is ok as it will be the return value. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2511 | mov(eax, Immediate(function)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2512 | CallCFunction(eax, num_arguments); |
| 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | void MacroAssembler::CallCFunction(Register function, |
| 2517 | int num_arguments) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2518 | ASSERT(has_frame()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2519 | // Check stack alignment. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2520 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2521 | CheckStackAlignment(); |
| 2522 | } |
| 2523 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2524 | call(function); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2525 | if (OS::ActivationFrameAlignment() != 0) { |
| 2526 | mov(esp, Operand(esp, num_arguments * kPointerSize)); |
| 2527 | } else { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2528 | add(esp, Immediate(num_arguments * kPointerSize)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2533 | bool AreAliased(Register r1, Register r2, Register r3, Register r4) { |
| 2534 | if (r1.is(r2)) return true; |
| 2535 | if (r1.is(r3)) return true; |
| 2536 | if (r1.is(r4)) return true; |
| 2537 | if (r2.is(r3)) return true; |
| 2538 | if (r2.is(r4)) return true; |
| 2539 | if (r3.is(r4)) return true; |
| 2540 | return false; |
| 2541 | } |
| 2542 | |
| 2543 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2544 | CodePatcher::CodePatcher(byte* address, int size) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2545 | : address_(address), |
| 2546 | size_(size), |
| 2547 | masm_(Isolate::Current(), address, size + Assembler::kGap) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2548 | // Create a new macro assembler pointing to the address of the code to patch. |
| 2549 | // The size is adjusted with kGap on order for the assembler to generate size |
| 2550 | // bytes of instructions without failing with buffer size constraints. |
| 2551 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2552 | } |
| 2553 | |
| 2554 | |
| 2555 | CodePatcher::~CodePatcher() { |
| 2556 | // Indicate that code has changed. |
| 2557 | CPU::FlushICache(address_, size_); |
| 2558 | |
| 2559 | // Check that the code was patched as expected. |
| 2560 | ASSERT(masm_.pc_ == address_ + size_); |
| 2561 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2562 | } |
| 2563 | |
| 2564 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2565 | void MacroAssembler::CheckPageFlag( |
| 2566 | Register object, |
| 2567 | Register scratch, |
| 2568 | int mask, |
| 2569 | Condition cc, |
| 2570 | Label* condition_met, |
| 2571 | Label::Distance condition_met_distance) { |
| 2572 | ASSERT(cc == zero || cc == not_zero); |
| 2573 | if (scratch.is(object)) { |
| 2574 | and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 2575 | } else { |
| 2576 | mov(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 2577 | and_(scratch, object); |
| 2578 | } |
| 2579 | if (mask < (1 << kBitsPerByte)) { |
| 2580 | test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 2581 | static_cast<uint8_t>(mask)); |
| 2582 | } else { |
| 2583 | test(Operand(scratch, MemoryChunk::kFlagsOffset), Immediate(mask)); |
| 2584 | } |
| 2585 | j(cc, condition_met, condition_met_distance); |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | void MacroAssembler::JumpIfBlack(Register object, |
| 2590 | Register scratch0, |
| 2591 | Register scratch1, |
| 2592 | Label* on_black, |
| 2593 | Label::Distance on_black_near) { |
| 2594 | HasColor(object, scratch0, scratch1, |
| 2595 | on_black, on_black_near, |
| 2596 | 1, 0); // kBlackBitPattern. |
| 2597 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 2598 | } |
| 2599 | |
| 2600 | |
| 2601 | void MacroAssembler::HasColor(Register object, |
| 2602 | Register bitmap_scratch, |
| 2603 | Register mask_scratch, |
| 2604 | Label* has_color, |
| 2605 | Label::Distance has_color_distance, |
| 2606 | int first_bit, |
| 2607 | int second_bit) { |
| 2608 | ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, ecx)); |
| 2609 | |
| 2610 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 2611 | |
| 2612 | Label other_color, word_boundary; |
| 2613 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2614 | j(first_bit == 1 ? zero : not_zero, &other_color, Label::kNear); |
| 2615 | add(mask_scratch, mask_scratch); // Shift left 1 by adding. |
| 2616 | j(zero, &word_boundary, Label::kNear); |
| 2617 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2618 | j(second_bit == 1 ? not_zero : zero, has_color, has_color_distance); |
| 2619 | jmp(&other_color, Label::kNear); |
| 2620 | |
| 2621 | bind(&word_boundary); |
| 2622 | test_b(Operand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize), 1); |
| 2623 | |
| 2624 | j(second_bit == 1 ? not_zero : zero, has_color, has_color_distance); |
| 2625 | bind(&other_color); |
| 2626 | } |
| 2627 | |
| 2628 | |
| 2629 | void MacroAssembler::GetMarkBits(Register addr_reg, |
| 2630 | Register bitmap_reg, |
| 2631 | Register mask_reg) { |
| 2632 | ASSERT(!AreAliased(addr_reg, mask_reg, bitmap_reg, ecx)); |
| 2633 | mov(bitmap_reg, Immediate(~Page::kPageAlignmentMask)); |
| 2634 | and_(bitmap_reg, addr_reg); |
| 2635 | mov(ecx, addr_reg); |
| 2636 | int shift = |
| 2637 | Bitmap::kBitsPerCellLog2 + kPointerSizeLog2 - Bitmap::kBytesPerCellLog2; |
| 2638 | shr(ecx, shift); |
| 2639 | and_(ecx, |
| 2640 | (Page::kPageAlignmentMask >> shift) & ~(Bitmap::kBytesPerCell - 1)); |
| 2641 | |
| 2642 | add(bitmap_reg, ecx); |
| 2643 | mov(ecx, addr_reg); |
| 2644 | shr(ecx, kPointerSizeLog2); |
| 2645 | and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); |
| 2646 | mov(mask_reg, Immediate(1)); |
| 2647 | shl_cl(mask_reg); |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | void MacroAssembler::EnsureNotWhite( |
| 2652 | Register value, |
| 2653 | Register bitmap_scratch, |
| 2654 | Register mask_scratch, |
| 2655 | Label* value_is_white_and_not_data, |
| 2656 | Label::Distance distance) { |
| 2657 | ASSERT(!AreAliased(value, bitmap_scratch, mask_scratch, ecx)); |
| 2658 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 2659 | |
| 2660 | // If the value is black or grey we don't need to do anything. |
| 2661 | ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 2662 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 2663 | ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 2664 | ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 2665 | |
| 2666 | Label done; |
| 2667 | |
| 2668 | // Since both black and grey have a 1 in the first position and white does |
| 2669 | // not have a 1 there we only need to check one bit. |
| 2670 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2671 | j(not_zero, &done, Label::kNear); |
| 2672 | |
| 2673 | if (FLAG_debug_code) { |
| 2674 | // Check for impossible bit pattern. |
| 2675 | Label ok; |
| 2676 | push(mask_scratch); |
| 2677 | // shl. May overflow making the check conservative. |
| 2678 | add(mask_scratch, mask_scratch); |
| 2679 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2680 | j(zero, &ok, Label::kNear); |
| 2681 | int3(); |
| 2682 | bind(&ok); |
| 2683 | pop(mask_scratch); |
| 2684 | } |
| 2685 | |
| 2686 | // Value is white. We check whether it is data that doesn't need scanning. |
| 2687 | // Currently only checks for HeapNumber and non-cons strings. |
| 2688 | Register map = ecx; // Holds map while checking type. |
| 2689 | Register length = ecx; // Holds length of object after checking type. |
| 2690 | Label not_heap_number; |
| 2691 | Label is_data_object; |
| 2692 | |
| 2693 | // Check for heap-number |
| 2694 | mov(map, FieldOperand(value, HeapObject::kMapOffset)); |
| 2695 | cmp(map, FACTORY->heap_number_map()); |
| 2696 | j(not_equal, ¬_heap_number, Label::kNear); |
| 2697 | mov(length, Immediate(HeapNumber::kSize)); |
| 2698 | jmp(&is_data_object, Label::kNear); |
| 2699 | |
| 2700 | bind(¬_heap_number); |
| 2701 | // Check for strings. |
| 2702 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 2703 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 2704 | // If it's a string and it's not a cons string then it's an object containing |
| 2705 | // no GC pointers. |
| 2706 | Register instance_type = ecx; |
| 2707 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 2708 | test_b(instance_type, kIsIndirectStringMask | kIsNotStringMask); |
| 2709 | j(not_zero, value_is_white_and_not_data); |
| 2710 | // It's a non-indirect (non-cons and non-slice) string. |
| 2711 | // If it's external, the length is just ExternalString::kSize. |
| 2712 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 2713 | Label not_external; |
| 2714 | // External strings are the only ones with the kExternalStringTag bit |
| 2715 | // set. |
| 2716 | ASSERT_EQ(0, kSeqStringTag & kExternalStringTag); |
| 2717 | ASSERT_EQ(0, kConsStringTag & kExternalStringTag); |
| 2718 | test_b(instance_type, kExternalStringTag); |
| 2719 | j(zero, ¬_external, Label::kNear); |
| 2720 | mov(length, Immediate(ExternalString::kSize)); |
| 2721 | jmp(&is_data_object, Label::kNear); |
| 2722 | |
| 2723 | bind(¬_external); |
| 2724 | // Sequential string, either ASCII or UC16. |
| 2725 | ASSERT(kAsciiStringTag == 0x04); |
| 2726 | and_(length, Immediate(kStringEncodingMask)); |
| 2727 | xor_(length, Immediate(kStringEncodingMask)); |
| 2728 | add(length, Immediate(0x04)); |
| 2729 | // Value now either 4 (if ASCII) or 8 (if UC16), i.e., char-size shifted |
| 2730 | // by 2. If we multiply the string length as smi by this, it still |
| 2731 | // won't overflow a 32-bit value. |
| 2732 | ASSERT_EQ(SeqAsciiString::kMaxSize, SeqTwoByteString::kMaxSize); |
| 2733 | ASSERT(SeqAsciiString::kMaxSize <= |
| 2734 | static_cast<int>(0xffffffffu >> (2 + kSmiTagSize))); |
| 2735 | imul(length, FieldOperand(value, String::kLengthOffset)); |
| 2736 | shr(length, 2 + kSmiTagSize + kSmiShiftSize); |
| 2737 | add(length, Immediate(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 2738 | and_(length, Immediate(~kObjectAlignmentMask)); |
| 2739 | |
| 2740 | bind(&is_data_object); |
| 2741 | // Value is a data object, and it is white. Mark it black. Since we know |
| 2742 | // that the object is white we can make it black by flipping one bit. |
| 2743 | or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 2744 | |
| 2745 | and_(bitmap_scratch, Immediate(~Page::kPageAlignmentMask)); |
| 2746 | add(Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset), |
| 2747 | length); |
| 2748 | if (FLAG_debug_code) { |
| 2749 | mov(length, Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 2750 | cmp(length, Operand(bitmap_scratch, MemoryChunk::kSizeOffset)); |
| 2751 | Check(less_equal, "Live Bytes Count overflow chunk size"); |
| 2752 | } |
| 2753 | |
| 2754 | bind(&done); |
| 2755 | } |
| 2756 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2757 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2758 | |
| 2759 | #endif // V8_TARGET_ARCH_IA32 |