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" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
12 #include "vm/flow_graph_compiler.h" | 12 #include "vm/flow_graph_compiler.h" |
13 #include "vm/heap.h" | 13 #include "vm/heap.h" |
14 #include "vm/instructions.h" | 14 #include "vm/instructions.h" |
15 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
16 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
17 #include "vm/stub_code.h" | 17 #include "vm/stub_code.h" |
18 | 18 |
19 #define __ assembler-> | 19 #define __ assembler-> |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects."); | 23 DEFINE_FLAG(bool, inline_alloc, true, "Inline allocation of objects."); |
24 DEFINE_FLAG(bool, use_slow_path, false, | 24 DEFINE_FLAG(bool, use_slow_path, false, |
25 "Set to true for debugging & verifying the slow paths."); | 25 "Set to true for debugging & verifying the slow paths."); |
| 26 DECLARE_FLAG(bool, trace_optimized_ic_calls); |
26 DECLARE_FLAG(int, optimization_counter_threshold); | 27 DECLARE_FLAG(int, optimization_counter_threshold); |
27 DECLARE_FLAG(bool, trace_optimized_ic_calls); | |
28 | 28 |
29 | 29 |
30 // Input parameters: | 30 // Input parameters: |
31 // LR : return address. | 31 // LR : return address. |
32 // SP : address of last argument in argument array. | 32 // SP : address of last argument in argument array. |
33 // SP + 4*R4 - 4 : address of first argument in argument array. | 33 // SP + 4*R4 - 4 : address of first argument in argument array. |
34 // SP + 4*R4 : address of return value. | 34 // SP + 4*R4 : address of return value. |
35 // R5 : address of the runtime function to call. | 35 // R5 : address of the runtime function to call. |
36 // R4 : number of arguments to the call. | 36 // R4 : number of arguments to the call. |
37 void StubCode::GenerateCallToRuntimeStub(Assembler* assembler) { | 37 void StubCode::GenerateCallToRuntimeStub(Assembler* assembler) { |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 // The generated code is different if the class is parameterized. | 1104 // The generated code is different if the class is parameterized. |
1105 const bool is_cls_parameterized = cls.NumTypeArguments() > 0; | 1105 const bool is_cls_parameterized = cls.NumTypeArguments() > 0; |
1106 ASSERT(!is_cls_parameterized || | 1106 ASSERT(!is_cls_parameterized || |
1107 (cls.type_arguments_field_offset() != Class::kNoTypeArguments)); | 1107 (cls.type_arguments_field_offset() != Class::kNoTypeArguments)); |
1108 // kInlineInstanceSize is a constant used as a threshold for determining | 1108 // kInlineInstanceSize is a constant used as a threshold for determining |
1109 // when the object initialization should be done as a loop or as | 1109 // when the object initialization should be done as a loop or as |
1110 // straight line code. | 1110 // straight line code. |
1111 const int kInlineInstanceSize = 12; | 1111 const int kInlineInstanceSize = 12; |
1112 const intptr_t instance_size = cls.instance_size(); | 1112 const intptr_t instance_size = cls.instance_size(); |
1113 ASSERT(instance_size > 0); | 1113 ASSERT(instance_size > 0); |
1114 const intptr_t type_args_size = InstantiatedTypeArguments::InstanceSize(); | 1114 Label slow_case_with_type_arguments; |
1115 if (FLAG_inline_alloc && | 1115 if (FLAG_inline_alloc && Heap::IsAllocatableInNewSpace(instance_size)) { |
1116 Heap::IsAllocatableInNewSpace(instance_size + type_args_size)) { | 1116 Label slow_case_reload_type_arguments; |
1117 Label slow_case; | 1117 if (is_cls_parameterized) { |
| 1118 // Instantiation of the type arguments vector is only required if an |
| 1119 // instantiator is provided (not kNoInstantiator, but may be null). |
| 1120 __ ldm(IA, SP, (1 << R0) | (1 << R1)); |
| 1121 // R1: type arguments, instantiated or not. |
| 1122 // R0: instantiator type arguments or kNoInstantiator. |
| 1123 Label type_arguments_ready; |
| 1124 __ CompareImmediate(R0, Smi::RawValue(StubCode::kNoInstantiator)); |
| 1125 __ b(&type_arguments_ready, EQ); |
| 1126 // Lookup instantiator R0 in instantiations array of type arguments R1 |
| 1127 // and, if found, use cached instantiated type arguments. |
| 1128 __ ldr(R2, FieldAddress(R1, TypeArguments::instantiations_offset())); |
| 1129 __ ldr(R3, FieldAddress(R2, Array::length_offset())); |
| 1130 __ AddImmediate(R2, Array::data_offset() - kHeapObjectTag); |
| 1131 __ add(R3, R2, ShifterOperand(R3, LSL, 1)); // R3 is Smi. |
| 1132 Label loop, found; |
| 1133 __ Bind(&loop); |
| 1134 __ cmp(R2, ShifterOperand(R3)); |
| 1135 __ b(&slow_case_reload_type_arguments, CS); // Unsigned higher or equal. |
| 1136 __ ldr(R1, Address(R2, 0 * kWordSize)); // Cached instantiator. |
| 1137 __ cmp(R1, ShifterOperand(R0)); |
| 1138 __ b(&found, EQ); |
| 1139 __ CompareImmediate(R1, Smi::RawValue(StubCode::kNoInstantiator)); |
| 1140 __ b(&slow_case_reload_type_arguments, EQ); |
| 1141 __ AddImmediate(R2, 2 * kWordSize); |
| 1142 __ b(&loop); |
| 1143 __ Bind(&found); |
| 1144 __ ldr(R1, Address(R2, 1 * kWordSize)); // Cached instantiated args. |
| 1145 __ LoadImmediate(R0, Smi::RawValue(StubCode::kNoInstantiator)); |
| 1146 __ Bind(&type_arguments_ready); |
| 1147 // R1: instantiated type arguments. |
| 1148 // R0: kNoInstantiator. |
| 1149 } |
| 1150 // Allocate the object and update top to point to |
| 1151 // next object start and initialize the allocated object. |
| 1152 // R1: instantiated type arguments (if is_cls_parameterized). |
| 1153 // R0: kNoInstantiator (if is_cls_parameterized). |
1118 Heap* heap = Isolate::Current()->heap(); | 1154 Heap* heap = Isolate::Current()->heap(); |
1119 __ LoadImmediate(R5, heap->TopAddress()); | 1155 __ LoadImmediate(R5, heap->TopAddress()); |
1120 __ ldr(R2, Address(R5, 0)); | 1156 __ ldr(R2, Address(R5, 0)); |
1121 __ AddImmediate(R3, R2, instance_size); | 1157 __ AddImmediate(R3, R2, instance_size); |
1122 if (is_cls_parameterized) { | |
1123 __ ldm(IA, SP, (1 << R0) | (1 << R1)); | |
1124 __ mov(R4, ShifterOperand(R3)); | |
1125 // A new InstantiatedTypeArguments object only needs to be allocated if | |
1126 // the instantiator is provided (not kNoInstantiator, but may be null). | |
1127 __ CompareImmediate(R0, Smi::RawValue(StubCode::kNoInstantiator)); | |
1128 __ AddImmediate(R3, type_args_size, NE); | |
1129 // R4: potential new object end and, if R4 != R3, potential new | |
1130 // InstantiatedTypeArguments object start. | |
1131 } | |
1132 // Check if the allocation fits into the remaining space. | 1158 // Check if the allocation fits into the remaining space. |
1133 // R2: potential new object start. | 1159 // R2: potential new object start. |
1134 // R3: potential next object start. | 1160 // R3: potential next object start. |
1135 __ LoadImmediate(IP, heap->EndAddress()); | 1161 __ LoadImmediate(IP, heap->EndAddress()); |
1136 __ ldr(IP, Address(IP, 0)); | 1162 __ ldr(IP, Address(IP, 0)); |
1137 __ cmp(R3, ShifterOperand(IP)); | 1163 __ cmp(R3, ShifterOperand(IP)); |
1138 if (FLAG_use_slow_path) { | 1164 if (FLAG_use_slow_path) { |
1139 __ b(&slow_case); | 1165 __ b(&slow_case_with_type_arguments); |
1140 } else { | 1166 } else { |
1141 __ b(&slow_case, CS); // Branch if unsigned higher or equal. | 1167 __ b(&slow_case_with_type_arguments, CS); // Unsigned higher or equal. |
1142 } | 1168 } |
1143 | |
1144 // Successfully allocated the object(s), now update top to point to | |
1145 // next object start and initialize the object. | |
1146 __ str(R3, Address(R5, 0)); | 1169 __ str(R3, Address(R5, 0)); |
1147 __ UpdateAllocationStats(cls.id(), R5); | 1170 __ UpdateAllocationStats(cls.id(), R5); |
1148 | 1171 |
1149 if (is_cls_parameterized) { | |
1150 // Initialize the type arguments field in the object. | |
1151 // R2: new object start. | |
1152 // R4: potential new object end and, if R4 != R3, potential new | |
1153 // InstantiatedTypeArguments object start. | |
1154 // R3: next object start. | |
1155 Label type_arguments_ready; | |
1156 __ cmp(R4, ShifterOperand(R3)); | |
1157 __ b(&type_arguments_ready, EQ); | |
1158 // Initialize InstantiatedTypeArguments object at R4. | |
1159 __ str(R1, Address(R4, | |
1160 InstantiatedTypeArguments::uninstantiated_type_arguments_offset())); | |
1161 __ str(R0, Address(R4, | |
1162 InstantiatedTypeArguments::instantiator_type_arguments_offset())); | |
1163 const Class& ita_cls = | |
1164 Class::ZoneHandle(Object::instantiated_type_arguments_class()); | |
1165 // Set the tags. | |
1166 uword tags = 0; | |
1167 tags = RawObject::SizeTag::update(type_args_size, tags); | |
1168 tags = RawObject::ClassIdTag::update(ita_cls.id(), tags); | |
1169 __ LoadImmediate(R0, tags); | |
1170 __ str(R0, Address(R4, Instance::tags_offset())); | |
1171 // Set the new InstantiatedTypeArguments object (R4) as the type | |
1172 // arguments (R1) of the new object (R2). | |
1173 __ add(R1, R4, ShifterOperand(kHeapObjectTag)); | |
1174 // Set R3 to new object end. | |
1175 __ mov(R3, ShifterOperand(R4)); | |
1176 __ Bind(&type_arguments_ready); | |
1177 // R2: new object. | |
1178 // R1: new object type arguments. | |
1179 } | |
1180 | |
1181 // R2: new object start. | 1172 // R2: new object start. |
1182 // R3: next object start. | 1173 // R3: next object start. |
1183 // R1: new object type arguments (if is_cls_parameterized). | 1174 // R1: new object type arguments (if is_cls_parameterized). |
1184 // Set the tags. | 1175 // Set the tags. |
1185 uword tags = 0; | 1176 uword tags = 0; |
1186 tags = RawObject::SizeTag::update(instance_size, tags); | 1177 tags = RawObject::SizeTag::update(instance_size, tags); |
1187 ASSERT(cls.id() != kIllegalCid); | 1178 ASSERT(cls.id() != kIllegalCid); |
1188 tags = RawObject::ClassIdTag::update(cls.id(), tags); | 1179 tags = RawObject::ClassIdTag::update(cls.id(), tags); |
1189 __ LoadImmediate(R0, tags); | 1180 __ LoadImmediate(R0, tags); |
1190 __ str(R0, Address(R2, Instance::tags_offset())); | 1181 __ str(R0, Address(R2, Instance::tags_offset())); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 // R1: new object type arguments. | 1218 // R1: new object type arguments. |
1228 // Set the type arguments in the new object. | 1219 // Set the type arguments in the new object. |
1229 __ StoreToOffset(kWord, R1, R2, cls.type_arguments_field_offset()); | 1220 __ StoreToOffset(kWord, R1, R2, cls.type_arguments_field_offset()); |
1230 } | 1221 } |
1231 // Done allocating and initializing the instance. | 1222 // Done allocating and initializing the instance. |
1232 // R2: new object still missing its heap tag. | 1223 // R2: new object still missing its heap tag. |
1233 __ add(R0, R2, ShifterOperand(kHeapObjectTag)); | 1224 __ add(R0, R2, ShifterOperand(kHeapObjectTag)); |
1234 // R0: new object. | 1225 // R0: new object. |
1235 __ Ret(); | 1226 __ Ret(); |
1236 | 1227 |
1237 __ Bind(&slow_case); | 1228 __ Bind(&slow_case_reload_type_arguments); |
1238 } | 1229 } |
1239 if (is_cls_parameterized) { | 1230 if (is_cls_parameterized) { |
1240 __ ldm(IA, SP, (1 << R0) | (1 << R1)); | 1231 __ ldm(IA, SP, (1 << R0) | (1 << R1)); |
1241 } | 1232 } |
| 1233 __ Bind(&slow_case_with_type_arguments); |
| 1234 // If is_cls_parameterized: |
| 1235 // R1: new object type arguments (instantiated or not). |
| 1236 // R0: instantiator type arguments or kNoInstantiator. |
1242 // Create a stub frame as we are pushing some objects on the stack before | 1237 // Create a stub frame as we are pushing some objects on the stack before |
1243 // calling into the runtime. | 1238 // calling into the runtime. |
1244 __ EnterStubFrame(true); // Uses pool pointer to pass cls to runtime. | 1239 __ EnterStubFrame(true); // Uses pool pointer to pass cls to runtime. |
1245 __ LoadImmediate(R2, reinterpret_cast<intptr_t>(Object::null())); | 1240 __ LoadImmediate(R2, reinterpret_cast<intptr_t>(Object::null())); |
1246 __ Push(R2); // Setup space on stack for return value. | 1241 __ Push(R2); // Setup space on stack for return value. |
1247 __ PushObject(cls); // Push class of object to be allocated. | 1242 __ PushObject(cls); // Push class of object to be allocated. |
1248 if (is_cls_parameterized) { | 1243 if (is_cls_parameterized) { |
1249 // Push type arguments of object to be allocated and of instantiator. | 1244 // Push type arguments of object to be allocated and of instantiator. |
1250 __ PushList((1 << R0) | (1 << R1)); | 1245 __ PushList((1 << R0) | (1 << R1)); |
1251 } else { | 1246 } else { |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 // R1: instantiator type arguments or NULL. | 1869 // R1: instantiator type arguments or NULL. |
1875 // R2: cache array. | 1870 // R2: cache array. |
1876 // Result in R1: null -> not found, otherwise result (true or false). | 1871 // Result in R1: null -> not found, otherwise result (true or false). |
1877 static void GenerateSubtypeNTestCacheStub(Assembler* assembler, int n) { | 1872 static void GenerateSubtypeNTestCacheStub(Assembler* assembler, int n) { |
1878 ASSERT((1 <= n) && (n <= 3)); | 1873 ASSERT((1 <= n) && (n <= 3)); |
1879 if (n > 1) { | 1874 if (n > 1) { |
1880 // Get instance type arguments. | 1875 // Get instance type arguments. |
1881 __ LoadClass(R3, R0, R4); | 1876 __ LoadClass(R3, R0, R4); |
1882 // Compute instance type arguments into R4. | 1877 // Compute instance type arguments into R4. |
1883 Label has_no_type_arguments; | 1878 Label has_no_type_arguments; |
| 1879 __ LoadImmediate(R4, reinterpret_cast<intptr_t>(Object::null())); |
1884 __ ldr(R5, FieldAddress(R3, | 1880 __ ldr(R5, FieldAddress(R3, |
1885 Class::type_arguments_field_offset_in_words_offset())); | 1881 Class::type_arguments_field_offset_in_words_offset())); |
1886 __ CompareImmediate(R5, Class::kNoTypeArguments); | 1882 __ CompareImmediate(R5, Class::kNoTypeArguments); |
1887 __ b(&has_no_type_arguments, EQ); | 1883 __ b(&has_no_type_arguments, EQ); |
1888 __ add(R5, R0, ShifterOperand(R5, LSL, 2)); | 1884 __ add(R5, R0, ShifterOperand(R5, LSL, 2)); |
1889 __ ldr(R4, FieldAddress(R5, 0)); | 1885 __ ldr(R4, FieldAddress(R5, 0)); |
1890 __ Bind(&has_no_type_arguments); | 1886 __ Bind(&has_no_type_arguments); |
1891 } | 1887 } |
1892 __ LoadClassId(R3, R0); | 1888 __ LoadClassId(R3, R0); |
1893 // R0: instance. | 1889 // R0: instance. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 const Register right = R0; | 2131 const Register right = R0; |
2136 __ ldr(left, Address(SP, 1 * kWordSize)); | 2132 __ ldr(left, Address(SP, 1 * kWordSize)); |
2137 __ ldr(right, Address(SP, 0 * kWordSize)); | 2133 __ ldr(right, Address(SP, 0 * kWordSize)); |
2138 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp); | 2134 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp); |
2139 __ Ret(); | 2135 __ Ret(); |
2140 } | 2136 } |
2141 | 2137 |
2142 } // namespace dart | 2138 } // namespace dart |
2143 | 2139 |
2144 #endif // defined TARGET_ARCH_ARM | 2140 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |