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