| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/intrinsifier.h" | 8 #include "vm/intrinsifier.h" |
| 9 | 9 |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Allocate a GrowableObjectArray using the backing array specified. | 91 // Allocate a GrowableObjectArray using the backing array specified. |
| 92 // On stack: type argument (+2), data (+1), return-address (+0). | 92 // On stack: type argument (+2), data (+1), return-address (+0). |
| 93 void Intrinsifier::GrowableList_Allocate(Assembler* assembler) { | 93 void Intrinsifier::GrowableList_Allocate(Assembler* assembler) { |
| 94 // This snippet of inlined code uses the following registers: | 94 // This snippet of inlined code uses the following registers: |
| 95 // RAX, RCX, R13 | 95 // RAX, RCX, R13 |
| 96 // and the newly allocated object is returned in RAX. | 96 // and the newly allocated object is returned in RAX. |
| 97 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; | 97 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; |
| 98 const intptr_t kArrayOffset = 1 * kWordSize; | 98 const intptr_t kArrayOffset = 1 * kWordSize; |
| 99 Label fall_through; | 99 Label fall_through; |
| 100 | 100 |
| 101 // Compute the size to be allocated, it is based on the array length | 101 // Try allocating in new space. |
| 102 // and is computed as: | |
| 103 // RoundedAllocationSize(sizeof(RawGrowableObjectArray)) + | |
| 104 intptr_t fixed_size = GrowableObjectArray::InstanceSize(); | |
| 105 | |
| 106 Isolate* isolate = Isolate::Current(); | |
| 107 Heap* heap = isolate->heap(); | |
| 108 | |
| 109 __ movq(RAX, Immediate(heap->TopAddress())); | |
| 110 __ movq(RAX, Address(RAX, 0)); | |
| 111 __ leaq(RCX, Address(RAX, fixed_size)); | |
| 112 | |
| 113 // Check if the allocation fits into the remaining space. | |
| 114 // RAX: potential new backing array object start. | |
| 115 // RCX: potential next object start. | |
| 116 __ movq(R13, Immediate(heap->EndAddress())); | |
| 117 __ cmpq(RCX, Address(R13, 0)); | |
| 118 __ j(ABOVE_EQUAL, &fall_through); | |
| 119 | |
| 120 // Successfully allocated the object(s), now update top to point to | |
| 121 // next object start and initialize the object. | |
| 122 __ movq(R13, Immediate(heap->TopAddress())); | |
| 123 __ movq(Address(R13, 0), RCX); | |
| 124 __ addq(RAX, Immediate(kHeapObjectTag)); | |
| 125 | |
| 126 // Initialize the tags. | |
| 127 // EAX: new growable array object start as a tagged pointer. | |
| 128 const Class& cls = Class::Handle( | 102 const Class& cls = Class::Handle( |
| 129 isolate->object_store()->growable_object_array_class()); | 103 Isolate::Current()->object_store()->growable_object_array_class()); |
| 130 uword tags = 0; | 104 __ TryAllocate(cls, &fall_through, Assembler::kNearJump, RAX, PP); |
| 131 tags = RawObject::SizeTag::update(fixed_size, tags); | |
| 132 tags = RawObject::ClassIdTag::update(cls.id(), tags); | |
| 133 __ movq(FieldAddress(RAX, GrowableObjectArray::tags_offset()), | |
| 134 Immediate(tags)); | |
| 135 | 105 |
| 136 // Store backing array object in growable array object. | 106 // Store backing array object in growable array object. |
| 137 __ movq(RCX, Address(RSP, kArrayOffset)); // data argument. | 107 __ movq(RCX, Address(RSP, kArrayOffset)); // data argument. |
| 138 // RAX is new, no barrier needed. | 108 // RAX is new, no barrier needed. |
| 139 __ StoreIntoObjectNoBarrier( | 109 __ StoreIntoObjectNoBarrier( |
| 140 RAX, | 110 RAX, |
| 141 FieldAddress(RAX, GrowableObjectArray::data_offset()), | 111 FieldAddress(RAX, GrowableObjectArray::data_offset()), |
| 142 RCX); | 112 RCX); |
| 143 | 113 |
| 144 // RAX: new growable array object start as a tagged pointer. | 114 // RAX: new growable array object start as a tagged pointer. |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 // Set return value to Isolate::current_tag_. | 1652 // Set return value to Isolate::current_tag_. |
| 1683 __ movq(RAX, Address(RBX, Isolate::current_tag_offset())); | 1653 __ movq(RAX, Address(RBX, Isolate::current_tag_offset())); |
| 1684 __ ret(); | 1654 __ ret(); |
| 1685 } | 1655 } |
| 1686 | 1656 |
| 1687 #undef __ | 1657 #undef __ |
| 1688 | 1658 |
| 1689 } // namespace dart | 1659 } // namespace dart |
| 1690 | 1660 |
| 1691 #endif // defined TARGET_ARCH_X64 | 1661 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |