| 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_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
| 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" |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 | 1119 |
| 1120 // Called for inline allocation of objects. | 1120 // Called for inline allocation of objects. |
| 1121 // Input parameters: | 1121 // Input parameters: |
| 1122 // RA : return address. | 1122 // RA : return address. |
| 1123 // SP + 4 : type arguments object (only if class is parameterized). | 1123 // SP + 4 : type arguments object (only if class is parameterized). |
| 1124 // SP + 0 : type arguments of instantiator (only if class is parameterized). | 1124 // SP + 0 : type arguments of instantiator (only if class is parameterized). |
| 1125 void StubCode::GenerateAllocationStubForClass(Assembler* assembler, | 1125 void StubCode::GenerateAllocationStubForClass(Assembler* assembler, |
| 1126 const Class& cls) { | 1126 const Class& cls) { |
| 1127 __ TraceSimMsg("AllocationStubForClass"); | 1127 __ TraceSimMsg("AllocationStubForClass"); |
| 1128 // The generated code is different if the class is parameterized. | 1128 // The generated code is different if the class is parameterized. |
| 1129 const bool is_cls_parameterized = | 1129 const bool is_cls_parameterized = cls.HasTypeArguments(); |
| 1130 cls.type_arguments_field_offset() != Class::kNoTypeArguments; | 1130 ASSERT(!cls.HasTypeArguments() || |
| 1131 cls.type_arguments_field_offset() != Class::kNoTypeArguments); |
| 1131 // kInlineInstanceSize is a constant used as a threshold for determining | 1132 // kInlineInstanceSize is a constant used as a threshold for determining |
| 1132 // when the object initialization should be done as a loop or as | 1133 // when the object initialization should be done as a loop or as |
| 1133 // straight line code. | 1134 // straight line code. |
| 1134 const int kInlineInstanceSize = 12; | 1135 const int kInlineInstanceSize = 12; |
| 1135 const intptr_t instance_size = cls.instance_size(); | 1136 const intptr_t instance_size = cls.instance_size(); |
| 1136 ASSERT(instance_size > 0); | 1137 ASSERT(instance_size > 0); |
| 1137 const intptr_t type_args_size = InstantiatedTypeArguments::InstanceSize(); | 1138 const intptr_t type_args_size = InstantiatedTypeArguments::InstanceSize(); |
| 1138 if (FLAG_inline_alloc && | 1139 if (FLAG_inline_alloc && |
| 1139 Heap::IsAllocatableInNewSpace(instance_size + type_args_size)) { | 1140 Heap::IsAllocatableInNewSpace(instance_size + type_args_size)) { |
| 1140 Label slow_case; | 1141 Label slow_case; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 | 1294 |
| 1294 | 1295 |
| 1295 // Called for inline allocation of closures. | 1296 // Called for inline allocation of closures. |
| 1296 // Input parameters: | 1297 // Input parameters: |
| 1297 // RA: return address. | 1298 // RA: return address. |
| 1298 // SP + 4 : receiver (null if not an implicit instance closure). | 1299 // SP + 4 : receiver (null if not an implicit instance closure). |
| 1299 // SP + 0 : type arguments object (null if class is no parameterized). | 1300 // SP + 0 : type arguments object (null if class is no parameterized). |
| 1300 void StubCode::GenerateAllocationStubForClosure(Assembler* assembler, | 1301 void StubCode::GenerateAllocationStubForClosure(Assembler* assembler, |
| 1301 const Function& func) { | 1302 const Function& func) { |
| 1302 ASSERT(func.IsClosureFunction()); | 1303 ASSERT(func.IsClosureFunction()); |
| 1303 const bool is_implicit_static_closure = | 1304 ASSERT(!func.IsImplicitStaticClosureFunction()); |
| 1304 func.IsImplicitStaticClosureFunction(); | |
| 1305 const bool is_implicit_instance_closure = | 1305 const bool is_implicit_instance_closure = |
| 1306 func.IsImplicitInstanceClosureFunction(); | 1306 func.IsImplicitInstanceClosureFunction(); |
| 1307 const Class& cls = Class::ZoneHandle(func.signature_class()); | 1307 const Class& cls = Class::ZoneHandle(func.signature_class()); |
| 1308 const bool has_type_arguments = cls.HasTypeArguments(); | 1308 const bool has_type_arguments = cls.HasTypeArguments(); |
| 1309 | 1309 |
| 1310 __ TraceSimMsg("AllocationStubForClosure"); | 1310 __ TraceSimMsg("AllocationStubForClosure"); |
| 1311 __ EnterStubFrame(true); // Uses pool pointer to refer to function. | 1311 __ EnterStubFrame(true); // Uses pool pointer to refer to function. |
| 1312 const intptr_t kTypeArgumentsFPOffset = 3 * kWordSize; | 1312 const intptr_t kTypeArgumentsFPOffset = 3 * kWordSize; |
| 1313 const intptr_t kReceiverFPOffset = 4 * kWordSize; | 1313 const intptr_t kReceiverFPOffset = 4 * kWordSize; |
| 1314 const intptr_t closure_size = Closure::InstanceSize(); | 1314 const intptr_t closure_size = Closure::InstanceSize(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 __ LoadImmediate(T0, tags); | 1349 __ LoadImmediate(T0, tags); |
| 1350 __ sw(T0, Address(T2, Instance::tags_offset())); | 1350 __ sw(T0, Address(T2, Instance::tags_offset())); |
| 1351 | 1351 |
| 1352 // Initialize the function field in the object. | 1352 // Initialize the function field in the object. |
| 1353 // T2: new closure object. | 1353 // T2: new closure object. |
| 1354 // T4: new context object (only if is_implicit_closure). | 1354 // T4: new context object (only if is_implicit_closure). |
| 1355 __ LoadObject(T0, func); // Load function of closure to be allocated. | 1355 __ LoadObject(T0, func); // Load function of closure to be allocated. |
| 1356 __ sw(T0, Address(T2, Closure::function_offset())); | 1356 __ sw(T0, Address(T2, Closure::function_offset())); |
| 1357 | 1357 |
| 1358 // Setup the context for this closure. | 1358 // Setup the context for this closure. |
| 1359 if (is_implicit_static_closure) { | 1359 if (is_implicit_instance_closure) { |
| 1360 ObjectStore* object_store = Isolate::Current()->object_store(); | |
| 1361 ASSERT(object_store != NULL); | |
| 1362 const Context& empty_context = | |
| 1363 Context::ZoneHandle(object_store->empty_context()); | |
| 1364 __ LoadObject(T0, empty_context); | |
| 1365 __ sw(T0, Address(T0, Closure::context_offset())); | |
| 1366 } else if (is_implicit_instance_closure) { | |
| 1367 // Initialize the new context capturing the receiver. | 1360 // Initialize the new context capturing the receiver. |
| 1368 const Class& context_class = Class::ZoneHandle(Object::context_class()); | 1361 const Class& context_class = Class::ZoneHandle(Object::context_class()); |
| 1369 // Set the tags. | 1362 // Set the tags. |
| 1370 uword tags = 0; | 1363 uword tags = 0; |
| 1371 tags = RawObject::SizeTag::update(context_size, tags); | 1364 tags = RawObject::SizeTag::update(context_size, tags); |
| 1372 tags = RawObject::ClassIdTag::update(context_class.id(), tags); | 1365 tags = RawObject::ClassIdTag::update(context_class.id(), tags); |
| 1373 __ LoadImmediate(T0, tags); | 1366 __ LoadImmediate(T0, tags); |
| 1374 __ sw(T0, Address(T4, Context::tags_offset())); | 1367 __ sw(T0, Address(T4, Context::tags_offset())); |
| 1375 | 1368 |
| 1376 // Set number of variables field to 1 (for captured receiver). | 1369 // Set number of variables field to 1 (for captured receiver). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1402 | 1395 |
| 1403 // Done allocating and initializing the instance. | 1396 // Done allocating and initializing the instance. |
| 1404 // V0: new object. | 1397 // V0: new object. |
| 1405 __ addiu(V0, T2, Immediate(kHeapObjectTag)); | 1398 __ addiu(V0, T2, Immediate(kHeapObjectTag)); |
| 1406 | 1399 |
| 1407 __ LeaveStubFrameAndReturn(RA, true); | 1400 __ LeaveStubFrameAndReturn(RA, true); |
| 1408 | 1401 |
| 1409 __ Bind(&slow_case); | 1402 __ Bind(&slow_case); |
| 1410 } | 1403 } |
| 1411 | 1404 |
| 1412 // If it's an implicit static closure we need 2 stack slots. Otherwise, | |
| 1413 // If it's an implicit instance closure we need 4 stack slots, o/w only 3. | 1405 // If it's an implicit instance closure we need 4 stack slots, o/w only 3. |
| 1414 int num_slots = 2; | 1406 intptr_t num_slots = is_implicit_instance_closure ? 4 : 3; |
| 1415 if (!is_implicit_static_closure) { | |
| 1416 num_slots = is_implicit_instance_closure ? 4 : 3; | |
| 1417 } | |
| 1418 __ addiu(SP, SP, Immediate(-num_slots * kWordSize)); | 1407 __ addiu(SP, SP, Immediate(-num_slots * kWordSize)); |
| 1419 // Setup space on stack for return value. | 1408 // Setup space on stack for return value. |
| 1420 __ LoadImmediate(T7, reinterpret_cast<intptr_t>(Object::null())); | 1409 __ LoadImmediate(T7, reinterpret_cast<intptr_t>(Object::null())); |
| 1421 __ sw(T7, Address(SP, (num_slots - 1) * kWordSize)); | 1410 __ sw(T7, Address(SP, (num_slots - 1) * kWordSize)); |
| 1422 __ LoadObject(TMP1, func); | 1411 __ LoadObject(TMP1, func); |
| 1423 __ sw(TMP1, Address(SP, (num_slots - 2) * kWordSize)); | 1412 __ sw(TMP1, Address(SP, (num_slots - 2) * kWordSize)); |
| 1424 if (is_implicit_static_closure) { | 1413 __ mov(T2, T7); |
| 1425 __ CallRuntime(kAllocateImplicitStaticClosureRuntimeEntry); | 1414 if (is_implicit_instance_closure) { |
| 1415 __ lw(T1, Address(FP, kReceiverFPOffset)); |
| 1416 __ sw(T1, Address(SP, (num_slots - 3) * kWordSize)); // Receiver. |
| 1417 } |
| 1418 if (has_type_arguments) { |
| 1419 __ lw(T2, Address(FP, kTypeArgumentsFPOffset)); |
| 1420 } |
| 1421 __ sw(T2, Address(SP, 0 * kWordSize)); |
| 1422 |
| 1423 if (is_implicit_instance_closure) { |
| 1424 __ CallRuntime(kAllocateImplicitInstanceClosureRuntimeEntry); |
| 1426 __ TraceSimMsg("AllocationStubForClosure return"); | 1425 __ TraceSimMsg("AllocationStubForClosure return"); |
| 1427 } else { | 1426 } else { |
| 1428 __ mov(T2, T7); | 1427 ASSERT(func.IsNonImplicitClosureFunction()); |
| 1429 if (is_implicit_instance_closure) { | 1428 __ CallRuntime(kAllocateClosureRuntimeEntry); |
| 1430 __ lw(T1, Address(FP, kReceiverFPOffset)); | 1429 __ TraceSimMsg("AllocationStubForClosure return"); |
| 1431 __ sw(T1, Address(SP, (num_slots - 3) * kWordSize)); // Receiver. | |
| 1432 } | |
| 1433 if (has_type_arguments) { | |
| 1434 __ lw(T2, Address(FP, kTypeArgumentsFPOffset)); | |
| 1435 } | |
| 1436 __ sw(T2, Address(SP, 0 * kWordSize)); | |
| 1437 | |
| 1438 if (is_implicit_instance_closure) { | |
| 1439 __ CallRuntime(kAllocateImplicitInstanceClosureRuntimeEntry); | |
| 1440 __ TraceSimMsg("AllocationStubForClosure return"); | |
| 1441 } else { | |
| 1442 ASSERT(func.IsNonImplicitClosureFunction()); | |
| 1443 __ CallRuntime(kAllocateClosureRuntimeEntry); | |
| 1444 __ TraceSimMsg("AllocationStubForClosure return"); | |
| 1445 } | |
| 1446 } | 1430 } |
| 1447 __ lw(V0, Address(SP, (num_slots - 1) * kWordSize)); // Pop function object. | 1431 __ lw(V0, Address(SP, (num_slots - 1) * kWordSize)); // Pop function object. |
| 1448 __ addiu(SP, SP, Immediate(num_slots * kWordSize)); | 1432 __ addiu(SP, SP, Immediate(num_slots * kWordSize)); |
| 1449 | 1433 |
| 1450 // V0: new object | 1434 // V0: new object |
| 1451 // Restore the frame pointer. | 1435 // Restore the frame pointer. |
| 1452 __ LeaveStubFrameAndReturn(RA, true); | 1436 __ LeaveStubFrameAndReturn(RA, true); |
| 1453 } | 1437 } |
| 1454 | 1438 |
| 1455 | 1439 |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 __ lw(left, Address(SP, 1 * kWordSize)); | 2364 __ lw(left, Address(SP, 1 * kWordSize)); |
| 2381 __ lw(temp2, Address(SP, 2 * kWordSize)); | 2365 __ lw(temp2, Address(SP, 2 * kWordSize)); |
| 2382 __ lw(temp1, Address(SP, 3 * kWordSize)); | 2366 __ lw(temp1, Address(SP, 3 * kWordSize)); |
| 2383 __ Ret(); | 2367 __ Ret(); |
| 2384 __ delay_slot()->addiu(SP, SP, Immediate(4 * kWordSize)); | 2368 __ delay_slot()->addiu(SP, SP, Immediate(4 * kWordSize)); |
| 2385 } | 2369 } |
| 2386 | 2370 |
| 2387 } // namespace dart | 2371 } // namespace dart |
| 2388 | 2372 |
| 2389 #endif // defined TARGET_ARCH_MIPS | 2373 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |