OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_X64) |
| 7 |
| 8 #include "vm/assembler_macros.h" |
| 9 |
| 10 #include "vm/assembler.h" |
| 11 |
| 12 namespace dart { |
| 13 |
| 14 DECLARE_FLAG(bool, inline_alloc); |
| 15 |
| 16 #define __ assembler-> |
| 17 |
| 18 // Static. |
| 19 void AssemblerMacros::TryAllocate(Assembler* assembler, |
| 20 const Class& cls, |
| 21 Register class_reg, |
| 22 Label* failure, |
| 23 Register instance_reg) { |
| 24 #if defined(DEBUG) |
| 25 __ Untested("AssemblerMacros::TryAllocate"); |
| 26 Label ok; |
| 27 __ LoadObject(instance_reg, cls); |
| 28 __ cmpl(instance_reg, class_reg); |
| 29 __ j(EQUAL, &ok, Assembler::kNearJump); |
| 30 __ Stop("AssemblerMacros::TryAllocate, wrong arguments"); |
| 31 __ Bind(&ok); |
| 32 #endif |
| 33 ASSERT(failure != NULL); |
| 34 ASSERT(class_reg != instance_reg); |
| 35 if (FLAG_inline_alloc) { |
| 36 Heap* heap = Isolate::Current()->heap(); |
| 37 const intptr_t instance_size = cls.instance_size(); |
| 38 __ movq(instance_reg, Address::Absolute(heap->TopAddress())); |
| 39 __ addq(instance_reg, Immediate(instance_size)); |
| 40 // instance_reg: potential next object start. |
| 41 __ cmpq(instance_reg, Address::Absolute(heap->EndAddress())); |
| 42 __ j(ABOVE_EQUAL, failure, Assembler::kNearJump); |
| 43 // Successfully allocated the object, now update top to point to |
| 44 // next object start and store the class in the class field of object. |
| 45 __ movq(Address::Absolute(heap->TopAddress()), instance_reg); |
| 46 ASSERT(instance_size >= kHeapObjectTag); |
| 47 __ subq(instance_reg, Immediate(instance_size - kHeapObjectTag)); |
| 48 __ movq(FieldAddress(instance_reg, Instance::class_offset()), class_reg); |
| 49 } else { |
| 50 __ jmp(failure); |
| 51 } |
| 52 } |
| 53 |
| 54 #undef __ |
| 55 |
| 56 } // namespace dart |
| 57 |
| 58 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |