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