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