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