ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 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 | |
| 30 | #include "bootstrapper.h" |
| 31 | #include "codegen-inl.h" |
| 32 | #include "debug.h" |
| 33 | #include "runtime.h" |
| 34 | #include "serialize.h" |
| 35 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | namespace v8 { |
| 37 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 39 | // ------------------------------------------------------------------------- |
| 40 | // MacroAssembler implementation. |
| 41 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 43 | : Assembler(buffer, size), |
| 44 | unresolved_(0), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 45 | generating_stub_(false), |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 46 | allow_stub_calls_(true), |
| 47 | code_object_(Heap::undefined_value()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | |
| 51 | static void RecordWriteHelper(MacroAssembler* masm, |
| 52 | Register object, |
| 53 | Register addr, |
| 54 | Register scratch) { |
| 55 | Label fast; |
| 56 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 57 | // Compute the page start address from the heap object pointer, and reuse |
| 58 | // the 'object' register for it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 59 | masm->and_(object, ~Page::kPageAlignmentMask); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 60 | Register page_start = object; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 61 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 62 | // Compute the bit addr in the remembered set/index of the pointer in the |
| 63 | // page. Reuse 'addr' as pointer_offset. |
| 64 | masm->sub(addr, Operand(page_start)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | masm->shr(addr, kObjectAlignmentBits); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 66 | Register pointer_offset = addr; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 67 | |
| 68 | // If the bit offset lies beyond the normal remembered set range, it is in |
| 69 | // the extra remembered set area of a large object. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 70 | masm->cmp(pointer_offset, Page::kPageSize / kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | masm->j(less, &fast); |
| 72 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 73 | // Adjust 'page_start' so that addressing using 'pointer_offset' hits the |
| 74 | // extra remembered set after the large object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 76 | // Find the length of the large object (FixedArray). |
| 77 | masm->mov(scratch, Operand(page_start, Page::kObjectStartOffset |
| 78 | + FixedArray::kLengthOffset)); |
| 79 | Register array_length = scratch; |
| 80 | |
| 81 | // Extra remembered set starts right after the large object (a FixedArray), at |
| 82 | // page_start + kObjectStartOffset + objectSize |
| 83 | // where objectSize is FixedArray::kHeaderSize + kPointerSize * array_length. |
| 84 | // Add the delta between the end of the normal RSet and the start of the |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 85 | // extra RSet to 'page_start', so that addressing the bit using |
| 86 | // 'pointer_offset' hits the extra RSet words. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 87 | masm->lea(page_start, |
| 88 | Operand(page_start, array_length, times_pointer_size, |
| 89 | Page::kObjectStartOffset + FixedArray::kHeaderSize |
| 90 | - Page::kRSetEndOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 91 | |
| 92 | // NOTE: For now, we use the bit-test-and-set (bts) x86 instruction |
| 93 | // to limit code size. We should probably evaluate this decision by |
| 94 | // measuring the performance of an equivalent implementation using |
| 95 | // "simpler" instructions |
| 96 | masm->bind(&fast); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 97 | masm->bts(Operand(page_start, Page::kRSetOffset), pointer_offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | class RecordWriteStub : public CodeStub { |
| 102 | public: |
| 103 | RecordWriteStub(Register object, Register addr, Register scratch) |
| 104 | : object_(object), addr_(addr), scratch_(scratch) { } |
| 105 | |
| 106 | void Generate(MacroAssembler* masm); |
| 107 | |
| 108 | private: |
| 109 | Register object_; |
| 110 | Register addr_; |
| 111 | Register scratch_; |
| 112 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | #ifdef DEBUG |
| 114 | void Print() { |
| 115 | PrintF("RecordWriteStub (object reg %d), (addr reg %d), (scratch reg %d)\n", |
| 116 | object_.code(), addr_.code(), scratch_.code()); |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | // Minor key encoding in 12 bits of three registers (object, address and |
| 121 | // scratch) OOOOAAAASSSS. |
| 122 | class ScratchBits: public BitField<uint32_t, 0, 4> {}; |
| 123 | class AddressBits: public BitField<uint32_t, 4, 4> {}; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 124 | class ObjectBits: public BitField<uint32_t, 8, 4> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | |
| 126 | Major MajorKey() { return RecordWrite; } |
| 127 | |
| 128 | int MinorKey() { |
| 129 | // Encode the registers. |
| 130 | return ObjectBits::encode(object_.code()) | |
| 131 | AddressBits::encode(addr_.code()) | |
| 132 | ScratchBits::encode(scratch_.code()); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 138 | RecordWriteHelper(masm, object_, addr_, scratch_); |
| 139 | masm->ret(0); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | // Set the remembered set bit for [object+offset]. |
| 144 | // object is the object being stored into, value is the object being stored. |
| 145 | // If offset is zero, then the scratch register contains the array index into |
| 146 | // the elements array represented as a Smi. |
| 147 | // All registers are clobbered by the operation. |
| 148 | void MacroAssembler::RecordWrite(Register object, int offset, |
| 149 | Register value, Register scratch) { |
| 150 | // First, check if a remembered set write is even needed. The tests below |
| 151 | // catch stores of Smis and stores into young gen (which does not have space |
| 152 | // for the remembered set bits. |
| 153 | Label done; |
| 154 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 155 | // Skip barrier if writing a smi. |
| 156 | ASSERT_EQ(0, kSmiTag); |
| 157 | test(value, Immediate(kSmiTagMask)); |
| 158 | j(zero, &done); |
| 159 | |
| 160 | if (Serializer::enabled()) { |
| 161 | // Can't do arithmetic on external references if it might get serialized. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | mov(value, Operand(object)); |
| 163 | and_(value, Heap::NewSpaceMask()); |
| 164 | cmp(Operand(value), Immediate(ExternalReference::new_space_start())); |
| 165 | j(equal, &done); |
| 166 | } else { |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 167 | int32_t new_space_start = reinterpret_cast<int32_t>( |
| 168 | ExternalReference::new_space_start().address()); |
| 169 | lea(value, Operand(object, -new_space_start)); |
| 170 | and_(value, Heap::NewSpaceMask()); |
| 171 | j(equal, &done); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | if ((offset > 0) && (offset < Page::kMaxHeapObjectSize)) { |
| 175 | // Compute the bit offset in the remembered set, leave it in 'value'. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 176 | lea(value, Operand(object, offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | and_(value, Page::kPageAlignmentMask); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 178 | shr(value, kPointerSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 179 | |
| 180 | // Compute the page address from the heap object pointer, leave it in |
| 181 | // 'object'. |
| 182 | and_(object, ~Page::kPageAlignmentMask); |
| 183 | |
| 184 | // NOTE: For now, we use the bit-test-and-set (bts) x86 instruction |
| 185 | // to limit code size. We should probably evaluate this decision by |
| 186 | // measuring the performance of an equivalent implementation using |
| 187 | // "simpler" instructions |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 188 | bts(Operand(object, Page::kRSetOffset), value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 189 | } else { |
| 190 | Register dst = scratch; |
| 191 | if (offset != 0) { |
| 192 | lea(dst, Operand(object, offset)); |
| 193 | } else { |
| 194 | // array access: calculate the destination address in the same manner as |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 195 | // KeyedStoreIC::GenerateGeneric. Multiply a smi by 2 to get an offset |
| 196 | // into an array of words. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 197 | ASSERT_EQ(1, kSmiTagSize); |
| 198 | ASSERT_EQ(0, kSmiTag); |
| 199 | lea(dst, Operand(object, dst, times_half_pointer_size, |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 200 | FixedArray::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | } |
| 202 | // If we are already generating a shared stub, not inlining the |
| 203 | // record write code isn't going to save us any memory. |
| 204 | if (generating_stub()) { |
| 205 | RecordWriteHelper(this, object, dst, value); |
| 206 | } else { |
| 207 | RecordWriteStub stub(object, dst, value); |
| 208 | CallStub(&stub); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | bind(&done); |
| 213 | } |
| 214 | |
| 215 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 216 | void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) { |
| 217 | cmp(esp, |
| 218 | Operand::StaticVariable(ExternalReference::address_of_stack_limit())); |
| 219 | j(below, on_stack_overflow); |
| 220 | } |
| 221 | |
| 222 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 223 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | void MacroAssembler::SaveRegistersToMemory(RegList regs) { |
| 225 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 226 | // Copy the content of registers to memory location. |
| 227 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 228 | int r = JSCallerSavedCode(i); |
| 229 | if ((regs & (1 << r)) != 0) { |
| 230 | Register reg = { r }; |
| 231 | ExternalReference reg_addr = |
| 232 | ExternalReference(Debug_Address::Register(i)); |
| 233 | mov(Operand::StaticVariable(reg_addr), reg); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void MacroAssembler::RestoreRegistersFromMemory(RegList regs) { |
| 240 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 241 | // Copy the content of memory location to registers. |
| 242 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 243 | int r = JSCallerSavedCode(i); |
| 244 | if ((regs & (1 << r)) != 0) { |
| 245 | Register reg = { r }; |
| 246 | ExternalReference reg_addr = |
| 247 | ExternalReference(Debug_Address::Register(i)); |
| 248 | mov(reg, Operand::StaticVariable(reg_addr)); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void MacroAssembler::PushRegistersFromMemory(RegList regs) { |
| 255 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 256 | // Push the content of the memory location to the stack. |
| 257 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 258 | int r = JSCallerSavedCode(i); |
| 259 | if ((regs & (1 << r)) != 0) { |
| 260 | ExternalReference reg_addr = |
| 261 | ExternalReference(Debug_Address::Register(i)); |
| 262 | push(Operand::StaticVariable(reg_addr)); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | |
| 268 | void MacroAssembler::PopRegistersToMemory(RegList regs) { |
| 269 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 270 | // Pop the content from the stack to the memory location. |
| 271 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 272 | int r = JSCallerSavedCode(i); |
| 273 | if ((regs & (1 << r)) != 0) { |
| 274 | ExternalReference reg_addr = |
| 275 | ExternalReference(Debug_Address::Register(i)); |
| 276 | pop(Operand::StaticVariable(reg_addr)); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | |
| 282 | void MacroAssembler::CopyRegistersFromStackToMemory(Register base, |
| 283 | Register scratch, |
| 284 | RegList regs) { |
| 285 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 286 | // Copy the content of the stack to the memory location and adjust base. |
| 287 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 288 | int r = JSCallerSavedCode(i); |
| 289 | if ((regs & (1 << r)) != 0) { |
| 290 | mov(scratch, Operand(base, 0)); |
| 291 | ExternalReference reg_addr = |
| 292 | ExternalReference(Debug_Address::Register(i)); |
| 293 | mov(Operand::StaticVariable(reg_addr), scratch); |
| 294 | lea(base, Operand(base, kPointerSize)); |
| 295 | } |
| 296 | } |
| 297 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 298 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | |
| 300 | void MacroAssembler::Set(Register dst, const Immediate& x) { |
| 301 | if (x.is_zero()) { |
| 302 | xor_(dst, Operand(dst)); // shorter than mov |
| 303 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 304 | mov(dst, x); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
| 308 | |
| 309 | void MacroAssembler::Set(const Operand& dst, const Immediate& x) { |
| 310 | mov(dst, x); |
| 311 | } |
| 312 | |
| 313 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 314 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 315 | InstanceType type, |
| 316 | Register map) { |
| 317 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 318 | CmpInstanceType(map, type); |
| 319 | } |
| 320 | |
| 321 | |
| 322 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 323 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 324 | static_cast<int8_t>(type)); |
| 325 | } |
| 326 | |
| 327 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | void MacroAssembler::FCmp() { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 329 | if (CpuFeatures::IsSupported(CMOV)) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 330 | fucomip(); |
| 331 | ffree(0); |
| 332 | fincstp(); |
| 333 | } else { |
| 334 | fucompp(); |
| 335 | push(eax); |
| 336 | fnstsw_ax(); |
| 337 | sahf(); |
| 338 | pop(eax); |
| 339 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 343 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | push(ebp); |
| 345 | mov(ebp, Operand(esp)); |
| 346 | push(esi); |
| 347 | push(Immediate(Smi::FromInt(type))); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 348 | push(Immediate(CodeObject())); |
| 349 | if (FLAG_debug_code) { |
| 350 | cmp(Operand(esp, 0), Immediate(Factory::undefined_value())); |
| 351 | Check(not_equal, "code object not properly patched"); |
| 352 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 356 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | if (FLAG_debug_code) { |
| 358 | cmp(Operand(ebp, StandardFrameConstants::kMarkerOffset), |
| 359 | Immediate(Smi::FromInt(type))); |
| 360 | Check(equal, "stack frame types must match"); |
| 361 | } |
| 362 | leave(); |
| 363 | } |
| 364 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 365 | void MacroAssembler::EnterExitFramePrologue(ExitFrame::Mode mode) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 366 | // Setup the frame structure on the stack. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 367 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 368 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 369 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 370 | push(ebp); |
| 371 | mov(ebp, Operand(esp)); |
| 372 | |
| 373 | // Reserve room for entry stack pointer and push the debug marker. |
| 374 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
| 375 | push(Immediate(0)); // saved entry sp, patched before call |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 376 | if (mode == ExitFrame::MODE_DEBUG) { |
| 377 | push(Immediate(0)); |
| 378 | } else { |
| 379 | push(Immediate(CodeObject())); |
| 380 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 381 | |
| 382 | // Save the frame pointer and the context in top. |
| 383 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 384 | ExternalReference context_address(Top::k_context_address); |
| 385 | mov(Operand::StaticVariable(c_entry_fp_address), ebp); |
| 386 | mov(Operand::StaticVariable(context_address), esi); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 387 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 388 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 389 | void MacroAssembler::EnterExitFrameEpilogue(ExitFrame::Mode mode, int argc) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 390 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 391 | // Save the state of all registers to the stack from the memory |
| 392 | // location. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 393 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 394 | // TODO(1243899): This should be symmetric to |
| 395 | // CopyRegistersFromStackToMemory() but it isn't! esp is assumed |
| 396 | // correct here, but computed for the other call. Very error |
| 397 | // prone! FIX THIS. Actually there are deeper problems with |
| 398 | // register saving than this asymmetry (see the bug report |
| 399 | // associated with this issue). |
| 400 | PushRegistersFromMemory(kJSCallerSaved); |
| 401 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 402 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 403 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 404 | // Reserve space for arguments. |
| 405 | sub(Operand(esp), Immediate(argc * kPointerSize)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 406 | |
| 407 | // Get the required frame alignment for the OS. |
| 408 | static const int kFrameAlignment = OS::ActivationFrameAlignment(); |
| 409 | if (kFrameAlignment > 0) { |
| 410 | ASSERT(IsPowerOf2(kFrameAlignment)); |
| 411 | and_(esp, -kFrameAlignment); |
| 412 | } |
| 413 | |
| 414 | // Patch the saved entry sp. |
| 415 | mov(Operand(ebp, ExitFrameConstants::kSPOffset), esp); |
| 416 | } |
| 417 | |
| 418 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 419 | void MacroAssembler::EnterExitFrame(ExitFrame::Mode mode) { |
| 420 | EnterExitFramePrologue(mode); |
| 421 | |
| 422 | // Setup argc and argv in callee-saved registers. |
| 423 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 424 | mov(edi, Operand(eax)); |
| 425 | lea(esi, Operand(ebp, eax, times_4, offset)); |
| 426 | |
| 427 | EnterExitFrameEpilogue(mode, 2); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | void MacroAssembler::EnterApiExitFrame(ExitFrame::Mode mode, |
| 432 | int stack_space, |
| 433 | int argc) { |
| 434 | EnterExitFramePrologue(mode); |
| 435 | |
| 436 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 437 | lea(esi, Operand(ebp, (stack_space * kPointerSize) + offset)); |
| 438 | |
| 439 | EnterExitFrameEpilogue(mode, argc); |
| 440 | } |
| 441 | |
| 442 | |
| 443 | void MacroAssembler::LeaveExitFrame(ExitFrame::Mode mode) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 444 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 445 | // Restore the memory copy of the registers by digging them out from |
| 446 | // the stack. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 447 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 448 | // It's okay to clobber register ebx below because we don't need |
| 449 | // the function pointer after this. |
| 450 | const int kCallerSavedSize = kNumJSCallerSaved * kPointerSize; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 451 | int kOffset = ExitFrameConstants::kCodeOffset - kCallerSavedSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 452 | lea(ebx, Operand(ebp, kOffset)); |
| 453 | CopyRegistersFromStackToMemory(ebx, ecx, kJSCallerSaved); |
| 454 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 455 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 456 | |
| 457 | // Get the return address from the stack and restore the frame pointer. |
| 458 | mov(ecx, Operand(ebp, 1 * kPointerSize)); |
| 459 | mov(ebp, Operand(ebp, 0 * kPointerSize)); |
| 460 | |
| 461 | // Pop the arguments and the receiver from the caller stack. |
| 462 | lea(esp, Operand(esi, 1 * kPointerSize)); |
| 463 | |
| 464 | // Restore current context from top and clear it in debug mode. |
| 465 | ExternalReference context_address(Top::k_context_address); |
| 466 | mov(esi, Operand::StaticVariable(context_address)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 467 | #ifdef DEBUG |
| 468 | mov(Operand::StaticVariable(context_address), Immediate(0)); |
| 469 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 470 | |
| 471 | // Push the return address to get ready to return. |
| 472 | push(ecx); |
| 473 | |
| 474 | // Clear the top frame. |
| 475 | ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address); |
| 476 | mov(Operand::StaticVariable(c_entry_fp_address), Immediate(0)); |
| 477 | } |
| 478 | |
| 479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 481 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 482 | // Adjust this code if not the case. |
| 483 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 484 | // The pc (return address) is already on TOS. |
| 485 | if (try_location == IN_JAVASCRIPT) { |
| 486 | if (type == TRY_CATCH_HANDLER) { |
| 487 | push(Immediate(StackHandler::TRY_CATCH)); |
| 488 | } else { |
| 489 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 490 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | push(ebp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 492 | } else { |
| 493 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 494 | // The frame pointer does not point to a JS frame so we save NULL |
| 495 | // for ebp. We expect the code throwing an exception to check ebp |
| 496 | // before dereferencing it to restore the context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 497 | push(Immediate(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 498 | push(Immediate(0)); // NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 500 | // Save the current handler as the next handler. |
| 501 | push(Operand::StaticVariable(ExternalReference(Top::k_handler_address))); |
| 502 | // Link this handler as the new current one. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | mov(Operand::StaticVariable(ExternalReference(Top::k_handler_address)), esp); |
| 504 | } |
| 505 | |
| 506 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 507 | void MacroAssembler::PopTryHandler() { |
| 508 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 509 | pop(Operand::StaticVariable(ExternalReference(Top::k_handler_address))); |
| 510 | add(Operand(esp), Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 511 | } |
| 512 | |
| 513 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | Register MacroAssembler::CheckMaps(JSObject* object, Register object_reg, |
| 515 | JSObject* holder, Register holder_reg, |
| 516 | Register scratch, |
| 517 | Label* miss) { |
| 518 | // Make sure there's no overlap between scratch and the other |
| 519 | // registers. |
| 520 | ASSERT(!scratch.is(object_reg) && !scratch.is(holder_reg)); |
| 521 | |
| 522 | // Keep track of the current object in register reg. |
| 523 | Register reg = object_reg; |
| 524 | int depth = 1; |
| 525 | |
| 526 | // Check the maps in the prototype chain. |
| 527 | // Traverse the prototype chain from the object and do map checks. |
| 528 | while (object != holder) { |
| 529 | depth++; |
| 530 | |
| 531 | // Only global objects and objects that do not require access |
| 532 | // checks are allowed in stubs. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 533 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | |
| 535 | JSObject* prototype = JSObject::cast(object->GetPrototype()); |
| 536 | if (Heap::InNewSpace(prototype)) { |
| 537 | // Get the map of the current object. |
| 538 | mov(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 539 | cmp(Operand(scratch), Immediate(Handle<Map>(object->map()))); |
| 540 | // Branch on the result of the map check. |
| 541 | j(not_equal, miss, not_taken); |
| 542 | // Check access rights to the global object. This has to happen |
| 543 | // after the map check so that we know that the object is |
| 544 | // actually a global object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 545 | if (object->IsJSGlobalProxy()) { |
| 546 | CheckAccessGlobalProxy(reg, scratch, miss); |
| 547 | |
| 548 | // Restore scratch register to be the map of the object. |
| 549 | // We load the prototype from the map in the scratch register. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | mov(scratch, FieldOperand(reg, HeapObject::kMapOffset)); |
| 551 | } |
| 552 | // The prototype is in new space; we cannot store a reference |
| 553 | // to it in the code. Load it from the map. |
| 554 | reg = holder_reg; // from now the object is in holder_reg |
| 555 | mov(reg, FieldOperand(scratch, Map::kPrototypeOffset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 556 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | } else { |
| 558 | // Check the map of the current object. |
| 559 | cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 560 | Immediate(Handle<Map>(object->map()))); |
| 561 | // Branch on the result of the map check. |
| 562 | j(not_equal, miss, not_taken); |
| 563 | // Check access rights to the global object. This has to happen |
| 564 | // after the map check so that we know that the object is |
| 565 | // actually a global object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 566 | if (object->IsJSGlobalProxy()) { |
| 567 | CheckAccessGlobalProxy(reg, scratch, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | } |
| 569 | // The prototype is in old space; load it directly. |
| 570 | reg = holder_reg; // from now the object is in holder_reg |
| 571 | mov(reg, Handle<JSObject>(prototype)); |
| 572 | } |
| 573 | |
| 574 | // Go to the next object in the prototype chain. |
| 575 | object = prototype; |
| 576 | } |
| 577 | |
| 578 | // Check the holder map. |
| 579 | cmp(FieldOperand(reg, HeapObject::kMapOffset), |
| 580 | Immediate(Handle<Map>(holder->map()))); |
| 581 | j(not_equal, miss, not_taken); |
| 582 | |
| 583 | // Log the check depth. |
| 584 | LOG(IntEvent("check-maps-depth", depth)); |
| 585 | |
| 586 | // Perform security check for access to the global object and return |
| 587 | // the holder register. |
| 588 | ASSERT(object == holder); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 589 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 590 | if (object->IsJSGlobalProxy()) { |
| 591 | CheckAccessGlobalProxy(reg, scratch, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 592 | } |
| 593 | return reg; |
| 594 | } |
| 595 | |
| 596 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 597 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 598 | Register scratch, |
| 599 | Label* miss) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 600 | Label same_contexts; |
| 601 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 602 | ASSERT(!holder_reg.is(scratch)); |
| 603 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 604 | // Load current lexical context from the stack frame. |
| 605 | mov(scratch, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 606 | |
| 607 | // When generating debug code, make sure the lexical context is set. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | if (FLAG_debug_code) { |
| 609 | cmp(Operand(scratch), Immediate(0)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 610 | Check(not_equal, "we should not have an empty lexical context"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 612 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 614 | mov(scratch, FieldOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 615 | mov(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 616 | |
| 617 | // Check the context is a global context. |
| 618 | if (FLAG_debug_code) { |
| 619 | push(scratch); |
| 620 | // Read the first word and compare to global_context_map. |
| 621 | mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 622 | cmp(scratch, Factory::global_context_map()); |
| 623 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 624 | pop(scratch); |
| 625 | } |
| 626 | |
| 627 | // Check if both contexts are the same. |
| 628 | cmp(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 629 | j(equal, &same_contexts, taken); |
| 630 | |
| 631 | // Compare security tokens, save holder_reg on the stack so we can use it |
| 632 | // as a temporary register. |
| 633 | // |
| 634 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 635 | push(holder_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | // Check that the security token in the calling global object is |
| 637 | // compatible with the security token in the receiving global |
| 638 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 639 | mov(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 640 | |
| 641 | // Check the context is a global context. |
| 642 | if (FLAG_debug_code) { |
| 643 | cmp(holder_reg, Factory::null_value()); |
| 644 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 645 | |
| 646 | push(holder_reg); |
| 647 | // Read the first word and compare to global_context_map(), |
| 648 | mov(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
| 649 | cmp(holder_reg, Factory::global_context_map()); |
| 650 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 651 | pop(holder_reg); |
| 652 | } |
| 653 | |
| 654 | int token_offset = Context::kHeaderSize + |
| 655 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 656 | mov(scratch, FieldOperand(scratch, token_offset)); |
| 657 | cmp(scratch, FieldOperand(holder_reg, token_offset)); |
| 658 | pop(holder_reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | j(not_equal, miss, not_taken); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 660 | |
| 661 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 665 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
| 666 | Register result_end, |
| 667 | Register scratch, |
| 668 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 669 | ExternalReference new_space_allocation_top = |
| 670 | ExternalReference::new_space_allocation_top_address(); |
| 671 | |
| 672 | // Just return if allocation top is already known. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 673 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 674 | // No use of scratch if allocation top is provided. |
| 675 | ASSERT(scratch.is(no_reg)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 676 | #ifdef DEBUG |
| 677 | // Assert that result actually contains top on entry. |
| 678 | cmp(result, Operand::StaticVariable(new_space_allocation_top)); |
| 679 | Check(equal, "Unexpected allocation top"); |
| 680 | #endif |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 681 | return; |
| 682 | } |
| 683 | |
| 684 | // Move address of new object to result. Use scratch register if available. |
| 685 | if (scratch.is(no_reg)) { |
| 686 | mov(result, Operand::StaticVariable(new_space_allocation_top)); |
| 687 | } else { |
| 688 | ASSERT(!scratch.is(result_end)); |
| 689 | mov(Operand(scratch), Immediate(new_space_allocation_top)); |
| 690 | mov(result, Operand(scratch, 0)); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 696 | Register scratch) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 697 | if (FLAG_debug_code) { |
| 698 | test(result_end, Immediate(kObjectAlignmentMask)); |
| 699 | Check(zero, "Unaligned allocation in new space"); |
| 700 | } |
| 701 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 702 | ExternalReference new_space_allocation_top = |
| 703 | ExternalReference::new_space_allocation_top_address(); |
| 704 | |
| 705 | // Update new top. Use scratch if available. |
| 706 | if (scratch.is(no_reg)) { |
| 707 | mov(Operand::StaticVariable(new_space_allocation_top), result_end); |
| 708 | } else { |
| 709 | mov(Operand(scratch, 0), result_end); |
| 710 | } |
| 711 | } |
| 712 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 713 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 714 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 715 | Register result, |
| 716 | Register result_end, |
| 717 | Register scratch, |
| 718 | Label* gc_required, |
| 719 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 720 | ASSERT(!result.is(result_end)); |
| 721 | |
| 722 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 723 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 724 | |
| 725 | // Calculate new top and bail out if new space is exhausted. |
| 726 | ExternalReference new_space_allocation_limit = |
| 727 | ExternalReference::new_space_allocation_limit_address(); |
| 728 | lea(result_end, Operand(result, object_size)); |
| 729 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 730 | j(above, gc_required, not_taken); |
| 731 | |
| 732 | // Update allocation top. |
| 733 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 734 | |
| 735 | // Tag result if requested. |
| 736 | if ((flags & TAG_OBJECT) != 0) { |
| 737 | or_(Operand(result), Immediate(kHeapObjectTag)); |
| 738 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 742 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 743 | ScaleFactor element_size, |
| 744 | Register element_count, |
| 745 | Register result, |
| 746 | Register result_end, |
| 747 | Register scratch, |
| 748 | Label* gc_required, |
| 749 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 750 | ASSERT(!result.is(result_end)); |
| 751 | |
| 752 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 753 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 754 | |
| 755 | // Calculate new top and bail out if new space is exhausted. |
| 756 | ExternalReference new_space_allocation_limit = |
| 757 | ExternalReference::new_space_allocation_limit_address(); |
| 758 | lea(result_end, Operand(result, element_count, element_size, header_size)); |
| 759 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 760 | j(above, gc_required); |
| 761 | |
| 762 | // Update allocation top. |
| 763 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 764 | |
| 765 | // Tag result if requested. |
| 766 | if ((flags & TAG_OBJECT) != 0) { |
| 767 | or_(Operand(result), Immediate(kHeapObjectTag)); |
| 768 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 772 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 773 | Register result, |
| 774 | Register result_end, |
| 775 | Register scratch, |
| 776 | Label* gc_required, |
| 777 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 778 | ASSERT(!result.is(result_end)); |
| 779 | |
| 780 | // Load address of new object into result. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 781 | LoadAllocationTopHelper(result, result_end, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 782 | |
| 783 | // Calculate new top and bail out if new space is exhausted. |
| 784 | ExternalReference new_space_allocation_limit = |
| 785 | ExternalReference::new_space_allocation_limit_address(); |
| 786 | if (!object_size.is(result_end)) { |
| 787 | mov(result_end, object_size); |
| 788 | } |
| 789 | add(result_end, Operand(result)); |
| 790 | cmp(result_end, Operand::StaticVariable(new_space_allocation_limit)); |
| 791 | j(above, gc_required, not_taken); |
| 792 | |
| 793 | // Update allocation top. |
| 794 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 795 | |
| 796 | // Tag result if requested. |
| 797 | if ((flags & TAG_OBJECT) != 0) { |
| 798 | or_(Operand(result), Immediate(kHeapObjectTag)); |
| 799 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
| 803 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 804 | ExternalReference new_space_allocation_top = |
| 805 | ExternalReference::new_space_allocation_top_address(); |
| 806 | |
| 807 | // Make sure the object has no tag before resetting top. |
| 808 | and_(Operand(object), Immediate(~kHeapObjectTagMask)); |
| 809 | #ifdef DEBUG |
| 810 | cmp(object, Operand::StaticVariable(new_space_allocation_top)); |
| 811 | Check(below, "Undo allocation of non allocated memory"); |
| 812 | #endif |
| 813 | mov(Operand::StaticVariable(new_space_allocation_top), object); |
| 814 | } |
| 815 | |
| 816 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 817 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 818 | Register scratch1, |
| 819 | Register scratch2, |
| 820 | Label* gc_required) { |
| 821 | // Allocate heap number in new space. |
| 822 | AllocateInNewSpace(HeapNumber::kSize, |
| 823 | result, |
| 824 | scratch1, |
| 825 | scratch2, |
| 826 | gc_required, |
| 827 | TAG_OBJECT); |
| 828 | |
| 829 | // Set the map. |
| 830 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 831 | Immediate(Factory::heap_number_map())); |
| 832 | } |
| 833 | |
| 834 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 835 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 836 | Register length, |
| 837 | Register scratch1, |
| 838 | Register scratch2, |
| 839 | Register scratch3, |
| 840 | Label* gc_required) { |
| 841 | // Calculate the number of bytes needed for the characters in the string while |
| 842 | // observing object alignment. |
| 843 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 844 | ASSERT(kShortSize == 2); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 845 | // scratch1 = length * 2 + kObjectAlignmentMask. |
| 846 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 847 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 848 | |
| 849 | // Allocate two byte string in new space. |
| 850 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 851 | times_1, |
| 852 | scratch1, |
| 853 | result, |
| 854 | scratch2, |
| 855 | scratch3, |
| 856 | gc_required, |
| 857 | TAG_OBJECT); |
| 858 | |
| 859 | // Set the map, length and hash field. |
| 860 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 861 | Immediate(Factory::string_map())); |
| 862 | mov(FieldOperand(result, String::kLengthOffset), length); |
| 863 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 864 | Immediate(String::kEmptyHashField)); |
| 865 | } |
| 866 | |
| 867 | |
| 868 | void MacroAssembler::AllocateAsciiString(Register result, |
| 869 | Register length, |
| 870 | Register scratch1, |
| 871 | Register scratch2, |
| 872 | Register scratch3, |
| 873 | Label* gc_required) { |
| 874 | // Calculate the number of bytes needed for the characters in the string while |
| 875 | // observing object alignment. |
| 876 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 877 | mov(scratch1, length); |
| 878 | ASSERT(kCharSize == 1); |
| 879 | add(Operand(scratch1), Immediate(kObjectAlignmentMask)); |
| 880 | and_(Operand(scratch1), Immediate(~kObjectAlignmentMask)); |
| 881 | |
| 882 | // Allocate ascii string in new space. |
| 883 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 884 | times_1, |
| 885 | scratch1, |
| 886 | result, |
| 887 | scratch2, |
| 888 | scratch3, |
| 889 | gc_required, |
| 890 | TAG_OBJECT); |
| 891 | |
| 892 | // Set the map, length and hash field. |
| 893 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 894 | Immediate(Factory::ascii_string_map())); |
| 895 | mov(FieldOperand(result, String::kLengthOffset), length); |
| 896 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 897 | Immediate(String::kEmptyHashField)); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | void MacroAssembler::AllocateConsString(Register result, |
| 902 | Register scratch1, |
| 903 | Register scratch2, |
| 904 | Label* gc_required) { |
| 905 | // Allocate heap number in new space. |
| 906 | AllocateInNewSpace(ConsString::kSize, |
| 907 | result, |
| 908 | scratch1, |
| 909 | scratch2, |
| 910 | gc_required, |
| 911 | TAG_OBJECT); |
| 912 | |
| 913 | // Set the map. The other fields are left uninitialized. |
| 914 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 915 | Immediate(Factory::cons_string_map())); |
| 916 | } |
| 917 | |
| 918 | |
| 919 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 920 | Register scratch1, |
| 921 | Register scratch2, |
| 922 | Label* gc_required) { |
| 923 | // Allocate heap number in new space. |
| 924 | AllocateInNewSpace(ConsString::kSize, |
| 925 | result, |
| 926 | scratch1, |
| 927 | scratch2, |
| 928 | gc_required, |
| 929 | TAG_OBJECT); |
| 930 | |
| 931 | // Set the map. The other fields are left uninitialized. |
| 932 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 933 | Immediate(Factory::cons_ascii_string_map())); |
| 934 | } |
| 935 | |
| 936 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 937 | void MacroAssembler::NegativeZeroTest(CodeGenerator* cgen, |
| 938 | Register result, |
| 939 | Register op, |
| 940 | JumpTarget* then_target) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 941 | JumpTarget ok; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 942 | test(result, Operand(result)); |
| 943 | ok.Branch(not_zero, taken); |
| 944 | test(op, Operand(op)); |
| 945 | then_target->Branch(sign, not_taken); |
| 946 | ok.Bind(); |
| 947 | } |
| 948 | |
| 949 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 950 | void MacroAssembler::NegativeZeroTest(Register result, |
| 951 | Register op, |
| 952 | Label* then_label) { |
| 953 | Label ok; |
| 954 | test(result, Operand(result)); |
| 955 | j(not_zero, &ok, taken); |
| 956 | test(op, Operand(op)); |
| 957 | j(sign, then_label, not_taken); |
| 958 | bind(&ok); |
| 959 | } |
| 960 | |
| 961 | |
| 962 | void MacroAssembler::NegativeZeroTest(Register result, |
| 963 | Register op1, |
| 964 | Register op2, |
| 965 | Register scratch, |
| 966 | Label* then_label) { |
| 967 | Label ok; |
| 968 | test(result, Operand(result)); |
| 969 | j(not_zero, &ok, taken); |
| 970 | mov(scratch, Operand(op1)); |
| 971 | or_(scratch, Operand(op2)); |
| 972 | j(sign, then_label, not_taken); |
| 973 | bind(&ok); |
| 974 | } |
| 975 | |
| 976 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 977 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 978 | Register result, |
| 979 | Register scratch, |
| 980 | Label* miss) { |
| 981 | // Check that the receiver isn't a smi. |
| 982 | test(function, Immediate(kSmiTagMask)); |
| 983 | j(zero, miss, not_taken); |
| 984 | |
| 985 | // Check that the function really is a function. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 986 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 987 | j(not_equal, miss, not_taken); |
| 988 | |
| 989 | // Make sure that the function has an instance prototype. |
| 990 | Label non_instance; |
| 991 | movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
| 992 | test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
| 993 | j(not_zero, &non_instance, not_taken); |
| 994 | |
| 995 | // Get the prototype or initial map from the function. |
| 996 | mov(result, |
| 997 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 998 | |
| 999 | // If the prototype or initial map is the hole, don't return it and |
| 1000 | // simply miss the cache instead. This will allow us to allocate a |
| 1001 | // prototype object on-demand in the runtime system. |
| 1002 | cmp(Operand(result), Immediate(Factory::the_hole_value())); |
| 1003 | j(equal, miss, not_taken); |
| 1004 | |
| 1005 | // If the function does not have an initial map, we're done. |
| 1006 | Label done; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1007 | CmpObjectType(result, MAP_TYPE, scratch); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1008 | j(not_equal, &done); |
| 1009 | |
| 1010 | // Get the prototype from the initial map. |
| 1011 | mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
| 1012 | jmp(&done); |
| 1013 | |
| 1014 | // Non-instance prototype: Fetch prototype from constructor field |
| 1015 | // in initial map. |
| 1016 | bind(&non_instance); |
| 1017 | mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1018 | |
| 1019 | // All done. |
| 1020 | bind(&done); |
| 1021 | } |
| 1022 | |
| 1023 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | void MacroAssembler::CallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1025 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1026 | call(stub->GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1030 | Object* MacroAssembler::TryCallStub(CodeStub* stub) { |
| 1031 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
| 1032 | Object* result = stub->TryGetCode(); |
| 1033 | if (!result->IsFailure()) { |
| 1034 | call(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
| 1035 | } |
| 1036 | return result; |
| 1037 | } |
| 1038 | |
| 1039 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1040 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1041 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1042 | jmp(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 1043 | } |
| 1044 | |
| 1045 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1046 | Object* MacroAssembler::TryTailCallStub(CodeStub* stub) { |
| 1047 | ASSERT(allow_stub_calls()); // Calls are not allowed in some stubs. |
| 1048 | Object* result = stub->TryGetCode(); |
| 1049 | if (!result->IsFailure()) { |
| 1050 | jmp(Handle<Code>(Code::cast(result)), RelocInfo::CODE_TARGET); |
| 1051 | } |
| 1052 | return result; |
| 1053 | } |
| 1054 | |
| 1055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | void MacroAssembler::StubReturn(int argc) { |
| 1057 | ASSERT(argc >= 1 && generating_stub()); |
| 1058 | ret((argc - 1) * kPointerSize); |
| 1059 | } |
| 1060 | |
| 1061 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1062 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1063 | if (num_arguments > 0) { |
| 1064 | add(Operand(esp), Immediate(num_arguments * kPointerSize)); |
| 1065 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1066 | mov(eax, Immediate(Factory::undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 1071 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1072 | } |
| 1073 | |
| 1074 | |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame^] | 1075 | Object* MacroAssembler::TryCallRuntime(Runtime::FunctionId id, |
| 1076 | int num_arguments) { |
| 1077 | return TryCallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 1078 | } |
| 1079 | |
| 1080 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1081 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1082 | // If the expected number of arguments of the runtime function is |
| 1083 | // constant, we check that the actual number of arguments match the |
| 1084 | // expectation. |
| 1085 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1086 | IllegalOperation(num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1087 | return; |
| 1088 | } |
| 1089 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1090 | Runtime::FunctionId function_id = |
| 1091 | static_cast<Runtime::FunctionId>(f->stub_id); |
| 1092 | RuntimeStub stub(function_id, num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | CallStub(&stub); |
| 1094 | } |
| 1095 | |
| 1096 | |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame^] | 1097 | Object* MacroAssembler::TryCallRuntime(Runtime::Function* f, |
| 1098 | int num_arguments) { |
| 1099 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1100 | IllegalOperation(num_arguments); |
| 1101 | // Since we did not call the stub, there was no allocation failure. |
| 1102 | // Return some non-failure object. |
| 1103 | return Heap::undefined_value(); |
| 1104 | } |
| 1105 | |
| 1106 | Runtime::FunctionId function_id = |
| 1107 | static_cast<Runtime::FunctionId>(f->stub_id); |
| 1108 | RuntimeStub stub(function_id, num_arguments); |
| 1109 | return TryCallStub(&stub); |
| 1110 | } |
| 1111 | |
| 1112 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1113 | void MacroAssembler::TailCallRuntime(const ExternalReference& ext, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1114 | int num_arguments, |
| 1115 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1116 | // TODO(1236192): Most runtime routines don't need the number of |
| 1117 | // arguments passed in because it is constant. At some point we |
| 1118 | // should remove this need and make the runtime routine entry code |
| 1119 | // smarter. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1120 | Set(eax, Immediate(num_arguments)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1121 | JumpToRuntime(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1125 | void MacroAssembler::PushHandleScope(Register scratch) { |
| 1126 | // Push the number of extensions, smi-tagged so the gc will ignore it. |
| 1127 | ExternalReference extensions_address = |
| 1128 | ExternalReference::handle_scope_extensions_address(); |
| 1129 | mov(scratch, Operand::StaticVariable(extensions_address)); |
| 1130 | ASSERT_EQ(0, kSmiTag); |
| 1131 | shl(scratch, kSmiTagSize); |
| 1132 | push(scratch); |
| 1133 | mov(Operand::StaticVariable(extensions_address), Immediate(0)); |
| 1134 | // Push next and limit pointers which will be wordsize aligned and |
| 1135 | // hence automatically smi tagged. |
| 1136 | ExternalReference next_address = |
| 1137 | ExternalReference::handle_scope_next_address(); |
| 1138 | push(Operand::StaticVariable(next_address)); |
| 1139 | ExternalReference limit_address = |
| 1140 | ExternalReference::handle_scope_limit_address(); |
| 1141 | push(Operand::StaticVariable(limit_address)); |
| 1142 | } |
| 1143 | |
| 1144 | |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame^] | 1145 | Object* MacroAssembler::PopHandleScopeHelper(Register saved, |
| 1146 | Register scratch, |
| 1147 | bool gc_allowed) { |
| 1148 | Object* result = NULL; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1149 | ExternalReference extensions_address = |
| 1150 | ExternalReference::handle_scope_extensions_address(); |
| 1151 | Label write_back; |
| 1152 | mov(scratch, Operand::StaticVariable(extensions_address)); |
| 1153 | cmp(Operand(scratch), Immediate(0)); |
| 1154 | j(equal, &write_back); |
| 1155 | // Calling a runtime function messes with registers so we save and |
| 1156 | // restore any one we're asked not to change |
| 1157 | if (saved.is_valid()) push(saved); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame^] | 1158 | if (gc_allowed) { |
| 1159 | CallRuntime(Runtime::kDeleteHandleScopeExtensions, 0); |
| 1160 | } else { |
| 1161 | result = TryCallRuntime(Runtime::kDeleteHandleScopeExtensions, 0); |
| 1162 | if (result->IsFailure()) return result; |
| 1163 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1164 | if (saved.is_valid()) pop(saved); |
| 1165 | |
| 1166 | bind(&write_back); |
| 1167 | ExternalReference limit_address = |
| 1168 | ExternalReference::handle_scope_limit_address(); |
| 1169 | pop(Operand::StaticVariable(limit_address)); |
| 1170 | ExternalReference next_address = |
| 1171 | ExternalReference::handle_scope_next_address(); |
| 1172 | pop(Operand::StaticVariable(next_address)); |
| 1173 | pop(scratch); |
| 1174 | shr(scratch, kSmiTagSize); |
| 1175 | mov(Operand::StaticVariable(extensions_address), scratch); |
kmillikin@chromium.org | 2d5475f | 2009-12-20 18:15:52 +0000 | [diff] [blame^] | 1176 | |
| 1177 | return result; |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | void MacroAssembler::PopHandleScope(Register saved, Register scratch) { |
| 1182 | PopHandleScopeHelper(saved, scratch, true); |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | Object* MacroAssembler::TryPopHandleScope(Register saved, Register scratch) { |
| 1187 | return PopHandleScopeHelper(saved, scratch, false); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1191 | void MacroAssembler::JumpToRuntime(const ExternalReference& ext) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1192 | // 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] | 1193 | mov(ebx, Immediate(ext)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1194 | CEntryStub ces(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1195 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 1200 | const ParameterCount& actual, |
| 1201 | Handle<Code> code_constant, |
| 1202 | const Operand& code_operand, |
| 1203 | Label* done, |
| 1204 | InvokeFlag flag) { |
| 1205 | bool definitely_matches = false; |
| 1206 | Label invoke; |
| 1207 | if (expected.is_immediate()) { |
| 1208 | ASSERT(actual.is_immediate()); |
| 1209 | if (expected.immediate() == actual.immediate()) { |
| 1210 | definitely_matches = true; |
| 1211 | } else { |
| 1212 | mov(eax, actual.immediate()); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1213 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 1214 | if (expected.immediate() == sentinel) { |
| 1215 | // Don't worry about adapting arguments for builtins that |
| 1216 | // don't want that done. Skip adaption code by making it look |
| 1217 | // like we have a match between expected and actual number of |
| 1218 | // arguments. |
| 1219 | definitely_matches = true; |
| 1220 | } else { |
| 1221 | mov(ebx, expected.immediate()); |
| 1222 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | } |
| 1224 | } else { |
| 1225 | if (actual.is_immediate()) { |
| 1226 | // Expected is in register, actual is immediate. This is the |
| 1227 | // case when we invoke function values without going through the |
| 1228 | // IC mechanism. |
| 1229 | cmp(expected.reg(), actual.immediate()); |
| 1230 | j(equal, &invoke); |
| 1231 | ASSERT(expected.reg().is(ebx)); |
| 1232 | mov(eax, actual.immediate()); |
| 1233 | } else if (!expected.reg().is(actual.reg())) { |
| 1234 | // Both expected and actual are in (different) registers. This |
| 1235 | // is the case when we invoke functions using call and apply. |
| 1236 | cmp(expected.reg(), Operand(actual.reg())); |
| 1237 | j(equal, &invoke); |
| 1238 | ASSERT(actual.reg().is(eax)); |
| 1239 | ASSERT(expected.reg().is(ebx)); |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | if (!definitely_matches) { |
| 1244 | Handle<Code> adaptor = |
| 1245 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 1246 | if (!code_constant.is_null()) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1247 | mov(edx, Immediate(code_constant)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1248 | add(Operand(edx), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1249 | } else if (!code_operand.is_reg(edx)) { |
| 1250 | mov(edx, code_operand); |
| 1251 | } |
| 1252 | |
| 1253 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1254 | call(adaptor, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1255 | jmp(done); |
| 1256 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1257 | jmp(adaptor, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | } |
| 1259 | bind(&invoke); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | void MacroAssembler::InvokeCode(const Operand& code, |
| 1265 | const ParameterCount& expected, |
| 1266 | const ParameterCount& actual, |
| 1267 | InvokeFlag flag) { |
| 1268 | Label done; |
| 1269 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); |
| 1270 | if (flag == CALL_FUNCTION) { |
| 1271 | call(code); |
| 1272 | } else { |
| 1273 | ASSERT(flag == JUMP_FUNCTION); |
| 1274 | jmp(code); |
| 1275 | } |
| 1276 | bind(&done); |
| 1277 | } |
| 1278 | |
| 1279 | |
| 1280 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 1281 | const ParameterCount& expected, |
| 1282 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1283 | RelocInfo::Mode rmode, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | InvokeFlag flag) { |
| 1285 | Label done; |
| 1286 | Operand dummy(eax); |
| 1287 | InvokePrologue(expected, actual, code, dummy, &done, flag); |
| 1288 | if (flag == CALL_FUNCTION) { |
| 1289 | call(code, rmode); |
| 1290 | } else { |
| 1291 | ASSERT(flag == JUMP_FUNCTION); |
| 1292 | jmp(code, rmode); |
| 1293 | } |
| 1294 | bind(&done); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | void MacroAssembler::InvokeFunction(Register fun, |
| 1299 | const ParameterCount& actual, |
| 1300 | InvokeFlag flag) { |
| 1301 | ASSERT(fun.is(edi)); |
| 1302 | mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1303 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1304 | mov(ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 1305 | mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 1306 | lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 1307 | |
| 1308 | ParameterCount expected(ebx); |
| 1309 | InvokeCode(Operand(edx), expected, actual, flag); |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, InvokeFlag flag) { |
| 1314 | bool resolved; |
| 1315 | Handle<Code> code = ResolveBuiltin(id, &resolved); |
| 1316 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1317 | // Calls are not allowed in some stubs. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1318 | ASSERT(flag == JUMP_FUNCTION || allow_stub_calls()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Rely on the assertion to check that the number of provided |
| 1321 | // arguments match the expected number of arguments. Fake a |
| 1322 | // parameter count to avoid emitting code to do the check. |
| 1323 | ParameterCount expected(0); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1324 | InvokeCode(Handle<Code>(code), expected, expected, |
| 1325 | RelocInfo::CODE_TARGET, flag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | |
| 1327 | const char* name = Builtins::GetName(id); |
| 1328 | int argc = Builtins::GetArgumentsCount(id); |
| 1329 | |
| 1330 | if (!resolved) { |
| 1331 | uint32_t flags = |
| 1332 | Bootstrapper::FixupFlagsArgumentsCount::encode(argc) | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1333 | Bootstrapper::FixupFlagsUseCodeObject::encode(false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | Unresolved entry = { pc_offset() - sizeof(int32_t), flags, name }; |
| 1335 | unresolved_.Add(entry); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 1341 | bool resolved; |
| 1342 | Handle<Code> code = ResolveBuiltin(id, &resolved); |
| 1343 | |
| 1344 | const char* name = Builtins::GetName(id); |
| 1345 | int argc = Builtins::GetArgumentsCount(id); |
| 1346 | |
| 1347 | mov(Operand(target), Immediate(code)); |
| 1348 | if (!resolved) { |
| 1349 | uint32_t flags = |
| 1350 | Bootstrapper::FixupFlagsArgumentsCount::encode(argc) | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1351 | Bootstrapper::FixupFlagsUseCodeObject::encode(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | Unresolved entry = { pc_offset() - sizeof(int32_t), flags, name }; |
| 1353 | unresolved_.Add(entry); |
| 1354 | } |
| 1355 | add(Operand(target), Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id, |
| 1360 | bool* resolved) { |
| 1361 | // Move the builtin function into the temporary function slot by |
| 1362 | // reading it from the builtins object. NOTE: We should be able to |
| 1363 | // reduce this to two instructions by putting the function table in |
| 1364 | // the global object instead of the "builtins" object and by using a |
| 1365 | // real register for the function. |
| 1366 | mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1367 | mov(edx, FieldOperand(edx, GlobalObject::kBuiltinsOffset)); |
| 1368 | int builtins_offset = |
| 1369 | JSBuiltinsObject::kJSBuiltinsOffset + (id * kPointerSize); |
| 1370 | mov(edi, FieldOperand(edx, builtins_offset)); |
| 1371 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1372 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1373 | return Builtins::GetCode(id, resolved); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1377 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 1378 | if (context_chain_length > 0) { |
| 1379 | // Move up the chain of contexts to the context containing the slot. |
| 1380 | mov(dst, Operand(esi, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1381 | // Load the function context (which is the incoming, outer context). |
| 1382 | mov(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 1383 | for (int i = 1; i < context_chain_length; i++) { |
| 1384 | mov(dst, Operand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1385 | mov(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 1386 | } |
| 1387 | // The context may be an intermediate context, not a function context. |
| 1388 | mov(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1389 | } else { // Slot is in the current function context. |
| 1390 | // The context may be an intermediate context, not a function context. |
| 1391 | mov(dst, Operand(esi, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | void MacroAssembler::Ret() { |
| 1398 | ret(0); |
| 1399 | } |
| 1400 | |
| 1401 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1402 | void MacroAssembler::Drop(int stack_elements) { |
| 1403 | if (stack_elements > 0) { |
| 1404 | add(Operand(esp), Immediate(stack_elements * kPointerSize)); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 1410 | mov(dst, value); |
| 1411 | } |
| 1412 | |
| 1413 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1414 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 1415 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1416 | mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | |
| 1421 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 1422 | ASSERT(value > 0); |
| 1423 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1424 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1425 | if (value == 1) { |
| 1426 | inc(operand); |
| 1427 | } else { |
| 1428 | add(operand, Immediate(value)); |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 1435 | ASSERT(value > 0); |
| 1436 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1437 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 1438 | if (value == 1) { |
| 1439 | dec(operand); |
| 1440 | } else { |
| 1441 | sub(operand, Immediate(value)); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 1448 | if (FLAG_debug_code) Check(cc, msg); |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 1453 | Label L; |
| 1454 | j(cc, &L, taken); |
| 1455 | Abort(msg); |
| 1456 | // will not return here |
| 1457 | bind(&L); |
| 1458 | } |
| 1459 | |
| 1460 | |
| 1461 | void MacroAssembler::Abort(const char* msg) { |
| 1462 | // We want to pass the msg string like a smi to avoid GC |
| 1463 | // problems, however msg is not guaranteed to be aligned |
| 1464 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1465 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1466 | // from the real pointer as a smi. |
| 1467 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 1468 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 1469 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 1470 | #ifdef DEBUG |
| 1471 | if (msg != NULL) { |
| 1472 | RecordComment("Abort message: "); |
| 1473 | RecordComment(msg); |
| 1474 | } |
| 1475 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1476 | // Disable stub call restrictions to always allow calls to abort. |
| 1477 | set_allow_stub_calls(true); |
| 1478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | push(eax); |
| 1480 | push(Immediate(p0)); |
| 1481 | push(Immediate(reinterpret_cast<intptr_t>(Smi::FromInt(p1 - p0)))); |
| 1482 | CallRuntime(Runtime::kAbort, 2); |
| 1483 | // will not return here |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1484 | int3(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | CodePatcher::CodePatcher(byte* address, int size) |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1489 | : address_(address), size_(size), masm_(address, size + Assembler::kGap) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1490 | // 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] | 1491 | // The size is adjusted with kGap on order for the assembler to generate size |
| 1492 | // bytes of instructions without failing with buffer size constraints. |
| 1493 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | CodePatcher::~CodePatcher() { |
| 1498 | // Indicate that code has changed. |
| 1499 | CPU::FlushICache(address_, size_); |
| 1500 | |
| 1501 | // Check that the code was patched as expected. |
| 1502 | ASSERT(masm_.pc_ == address_ + size_); |
| 1503 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1504 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1505 | |
| 1506 | |
| 1507 | } } // namespace v8::internal |