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