| 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 // The intrinsic code below is executed before a method has built its frame. | 5 // The intrinsic code below is executed before a method has built its frame. |
| 6 // The return address is on the stack and the arguments below it. | 6 // The return address is on the stack and the arguments below it. |
| 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. | 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. |
| 8 // Each intrinsification method returns true if the corresponding | 8 // Each intrinsification method returns true if the corresponding |
| 9 // Dart method was intrinsified. | 9 // Dart method was intrinsified. |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "vm/symbols.h" | 22 #include "vm/symbols.h" |
| 23 | 23 |
| 24 namespace dart { | 24 namespace dart { |
| 25 | 25 |
| 26 DECLARE_FLAG(bool, enable_type_checks); | 26 DECLARE_FLAG(bool, enable_type_checks); |
| 27 | 27 |
| 28 | 28 |
| 29 #define __ assembler-> | 29 #define __ assembler-> |
| 30 | 30 |
| 31 | 31 |
| 32 void Intrinsifier::ObjectArrayAllocate(Assembler* assembler) { | |
| 33 Label fall_through; | |
| 34 const intptr_t kTypeArgumentsOffset = 3 * kWordSize; | |
| 35 const intptr_t kLengthOffset = 2 * kWordSize; | |
| 36 const Immediate& raw_null = | |
| 37 Immediate(reinterpret_cast<intptr_t>(Object::null())); | |
| 38 | |
| 39 __ pushl(EDX); | |
| 40 __ movl(EDX, Address(ESP, kLengthOffset)); | |
| 41 __ movl(ECX, Address(ESP, kTypeArgumentsOffset)); | |
| 42 | |
| 43 // Compute the size to be allocated, it is based on the array length | |
| 44 // and is computed as: | |
| 45 // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)). | |
| 46 // Assert that length is a Smi. | |
| 47 __ testl(EDX, Immediate(kSmiTagMask)); | |
| 48 __ j(NOT_ZERO, &fall_through); | |
| 49 __ cmpl(EDX, Immediate(0)); | |
| 50 __ j(LESS, &fall_through); | |
| 51 | |
| 52 // Check for maximum allowed length. | |
| 53 const Immediate& max_len = | |
| 54 Immediate(reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements))); | |
| 55 __ cmpl(EDX, max_len); | |
| 56 __ j(GREATER, &fall_through); | |
| 57 | |
| 58 const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1; | |
| 59 __ leal(EDI, Address(EDX, TIMES_2, fixed_size)); // EDX is Smi. | |
| 60 ASSERT(kSmiTagShift == 1); | |
| 61 __ andl(EDI, Immediate(-kObjectAlignment)); | |
| 62 | |
| 63 // ECX: array element type. | |
| 64 // EDX: array length as Smi. | |
| 65 // EDI: allocation size. | |
| 66 | |
| 67 Isolate* isolate = Isolate::Current(); | |
| 68 Heap* heap = isolate->heap(); | |
| 69 | |
| 70 __ movl(EAX, Address::Absolute(heap->TopAddress())); | |
| 71 __ movl(EBX, EAX); | |
| 72 | |
| 73 // EDI: allocation size. | |
| 74 __ addl(EBX, EDI); | |
| 75 __ j(CARRY, &fall_through); | |
| 76 | |
| 77 // Check if the allocation fits into the remaining space. | |
| 78 // EAX: potential new object start. | |
| 79 // EBX: potential next object start. | |
| 80 // EDI: allocation size. | |
| 81 // ECX: array element type. | |
| 82 // EDX: array length as Smi). | |
| 83 __ cmpl(EBX, Address::Absolute(heap->EndAddress())); | |
| 84 __ j(ABOVE_EQUAL, &fall_through); | |
| 85 | |
| 86 // Successfully allocated the object(s), now update top to point to | |
| 87 // next object start and initialize the object. | |
| 88 __ movl(Address::Absolute(heap->TopAddress()), EBX); | |
| 89 __ addl(EAX, Immediate(kHeapObjectTag)); | |
| 90 __ UpdateAllocationStatsWithSize(kArrayCid, EDI, kNoRegister); | |
| 91 | |
| 92 // Initialize the tags. | |
| 93 // EAX: new object start as a tagged pointer. | |
| 94 // EBX: new object end address. | |
| 95 // EDI: allocation size. | |
| 96 // ECX: array element type. | |
| 97 // EDX: array length as Smi. | |
| 98 { | |
| 99 Label size_tag_overflow, done; | |
| 100 __ cmpl(EDI, Immediate(RawObject::SizeTag::kMaxSizeTag)); | |
| 101 __ j(ABOVE, &size_tag_overflow, Assembler::kNearJump); | |
| 102 __ shll(EDI, Immediate(RawObject::kSizeTagPos - kObjectAlignmentLog2)); | |
| 103 __ jmp(&done, Assembler::kNearJump); | |
| 104 | |
| 105 __ Bind(&size_tag_overflow); | |
| 106 __ movl(EDI, Immediate(0)); | |
| 107 __ Bind(&done); | |
| 108 | |
| 109 // Get the class index and insert it into the tags. | |
| 110 const Class& cls = Class::Handle(isolate->object_store()->array_class()); | |
| 111 __ orl(EDI, Immediate(RawObject::ClassIdTag::encode(cls.id()))); | |
| 112 __ movl(FieldAddress(EAX, Array::tags_offset()), EDI); // Tags. | |
| 113 } | |
| 114 // EAX: new object start as a tagged pointer. | |
| 115 // EBX: new object end address. | |
| 116 // ECX: array element type. | |
| 117 // EDX: Array length as Smi (preserved). | |
| 118 // Store the type argument field. | |
| 119 __ StoreIntoObjectNoBarrier(EAX, | |
| 120 FieldAddress(EAX, Array::type_arguments_offset()), | |
| 121 ECX); | |
| 122 | |
| 123 // Set the length field. | |
| 124 __ StoreIntoObjectNoBarrier(EAX, | |
| 125 FieldAddress(EAX, Array::length_offset()), | |
| 126 EDX); | |
| 127 | |
| 128 // Initialize all array elements to raw_null. | |
| 129 // EAX: new object start as a tagged pointer. | |
| 130 // EBX: new object end address. | |
| 131 // EDI: iterator which initially points to the start of the variable | |
| 132 // data area to be initialized. | |
| 133 // ECX: array element type. | |
| 134 // EDX: array length as Smi. | |
| 135 __ leal(EDI, FieldAddress(EAX, sizeof(RawArray))); | |
| 136 Label done; | |
| 137 Label init_loop; | |
| 138 __ Bind(&init_loop); | |
| 139 __ cmpl(EDI, EBX); | |
| 140 __ j(ABOVE_EQUAL, &done, Assembler::kNearJump); | |
| 141 __ movl(Address(EDI, 0), raw_null); | |
| 142 __ addl(EDI, Immediate(kWordSize)); | |
| 143 __ jmp(&init_loop, Assembler::kNearJump); | |
| 144 __ Bind(&done); | |
| 145 __ popl(EDX); | |
| 146 __ ret(); // returns the newly allocated object in EAX. | |
| 147 __ Bind(&fall_through); | |
| 148 __ popl(EDX); | |
| 149 } | |
| 150 | |
| 151 | |
| 152 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { | 32 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { |
| 153 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 33 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 154 __ movl(EAX, FieldAddress(EAX, Array::length_offset())); | 34 __ movl(EAX, FieldAddress(EAX, Array::length_offset())); |
| 155 __ ret(); | 35 __ ret(); |
| 156 } | 36 } |
| 157 | 37 |
| 158 | 38 |
| 159 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { | 39 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { |
| 160 ObjectArrayLength(assembler); | 40 ObjectArrayLength(assembler); |
| 161 } | 41 } |
| (...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 Isolate::current_tag_offset()); | 1790 Isolate::current_tag_offset()); |
| 1911 // Set return value to Isolate::current_tag_. | 1791 // Set return value to Isolate::current_tag_. |
| 1912 __ movl(EAX, current_tag_addr); | 1792 __ movl(EAX, current_tag_addr); |
| 1913 __ ret(); | 1793 __ ret(); |
| 1914 } | 1794 } |
| 1915 | 1795 |
| 1916 #undef __ | 1796 #undef __ |
| 1917 } // namespace dart | 1797 } // namespace dart |
| 1918 | 1798 |
| 1919 #endif // defined TARGET_ARCH_IA32 | 1799 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |