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_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 __ popq(RAX); // Pop argument (type arguments of object). | 1208 __ popq(RAX); // Pop argument (type arguments of object). |
1209 __ popq(RAX); // Pop argument (class of object). | 1209 __ popq(RAX); // Pop argument (class of object). |
1210 __ popq(RAX); // Pop result (newly allocated object). | 1210 __ popq(RAX); // Pop result (newly allocated object). |
1211 // RAX: new object | 1211 // RAX: new object |
1212 // Restore the frame pointer. | 1212 // Restore the frame pointer. |
1213 __ LeaveStubFrame(); | 1213 __ LeaveStubFrame(); |
1214 __ ret(); | 1214 __ ret(); |
1215 } | 1215 } |
1216 | 1216 |
1217 | 1217 |
1218 // Called for inline allocation of closures. | |
1219 // Input parameters: | |
1220 // RSP + 16 : receiver (null if not an implicit instance closure). | |
1221 // RSP + 8 : type arguments object (null if class is not parameterized). | |
1222 // RSP : points to return address. | |
1223 void StubCode::GenerateAllocationStubForClosure(Assembler* assembler, | |
1224 const Function& func) { | |
1225 ASSERT(func.IsClosureFunction()); | |
1226 ASSERT(!func.IsImplicitStaticClosureFunction()); | |
1227 const bool is_implicit_instance_closure = | |
1228 func.IsImplicitInstanceClosureFunction(); | |
1229 const Class& cls = Class::ZoneHandle(func.signature_class()); | |
1230 const bool has_type_arguments = cls.NumTypeArguments() > 0; | |
1231 | |
1232 __ EnterStubFrame(true); // Uses pool pointer to refer to function. | |
1233 __ LoadObject(R12, Object::null_object(), PP); | |
1234 const intptr_t kTypeArgumentsOffset = 4 * kWordSize; | |
1235 const intptr_t kReceiverOffset = 5 * kWordSize; | |
1236 const intptr_t closure_size = Closure::InstanceSize(); | |
1237 const intptr_t context_size = Context::InstanceSize(1); // Captured receiver. | |
1238 if (FLAG_inline_alloc && | |
1239 Heap::IsAllocatableInNewSpace(closure_size + context_size)) { | |
1240 Label slow_case; | |
1241 Heap* heap = Isolate::Current()->heap(); | |
1242 __ movq(RAX, Immediate(heap->TopAddress())); | |
1243 __ movq(RAX, Address(RAX, 0)); | |
1244 __ leaq(R13, Address(RAX, closure_size)); | |
1245 if (is_implicit_instance_closure) { | |
1246 __ movq(RBX, R13); // RBX: new context address. | |
1247 __ addq(R13, Immediate(context_size)); | |
1248 } | |
1249 // Check if the allocation fits into the remaining space. | |
1250 // RAX: potential new closure object. | |
1251 // RBX: potential new context object (only if is_implicit_closure). | |
1252 // R13: potential next object start. | |
1253 __ movq(RDI, Immediate(heap->EndAddress())); | |
1254 __ cmpq(R13, Address(RDI, 0)); | |
1255 if (FLAG_use_slow_path) { | |
1256 __ jmp(&slow_case); | |
1257 } else { | |
1258 __ j(ABOVE_EQUAL, &slow_case); | |
1259 } | |
1260 | |
1261 // Successfully allocated the object, now update top to point to | |
1262 // next object start and initialize the object. | |
1263 __ movq(RDI, Immediate(heap->TopAddress())); | |
1264 __ movq(Address(RDI, 0), R13); | |
1265 | |
1266 // RAX: new closure object. | |
1267 // RBX: new context object (only if is_implicit_closure). | |
1268 if (is_implicit_instance_closure) { | |
1269 // This closure allocates a context, update allocation stats. | |
1270 // RDI: context size. | |
1271 __ movq(RDI, Immediate(context_size)); | |
1272 __ UpdateAllocationStatsWithSize(kContextCid, RDI); | |
1273 } | |
1274 // The closure allocation is attributed to the signature class. | |
1275 __ UpdateAllocationStats(cls.id()); | |
1276 | |
1277 // RAX: new closure object. | |
1278 // RBX: new context object (only if is_implicit_closure). | |
1279 // Set the tags. | |
1280 uword tags = 0; | |
1281 tags = RawObject::SizeTag::update(closure_size, tags); | |
1282 tags = RawObject::ClassIdTag::update(cls.id(), tags); | |
1283 __ movq(Address(RAX, Instance::tags_offset()), Immediate(tags)); | |
1284 | |
1285 // Initialize the function field in the object. | |
1286 // RAX: new closure object. | |
1287 // RBX: new context object (only if is_implicit_closure). | |
1288 // R13: next object start. | |
1289 // Load function of closure to be allocated. | |
1290 __ LoadObject(R10, func, PP); | |
1291 __ movq(Address(RAX, Closure::function_offset()), R10); | |
1292 | |
1293 // Setup the context for this closure. | |
1294 if (is_implicit_instance_closure) { | |
1295 // Initialize the new context capturing the receiver. | |
1296 | |
1297 const Class& context_class = Class::ZoneHandle(Object::context_class()); | |
1298 // Set the tags. | |
1299 uword tags = 0; | |
1300 tags = RawObject::SizeTag::update(context_size, tags); | |
1301 tags = RawObject::ClassIdTag::update(context_class.id(), tags); | |
1302 __ movq(Address(RBX, Context::tags_offset()), Immediate(tags)); | |
1303 | |
1304 // Set number of variables field to 1 (for captured receiver). | |
1305 __ movq(Address(RBX, Context::num_variables_offset()), Immediate(1)); | |
1306 | |
1307 // Set isolate field to isolate of current context. | |
1308 __ movq(R10, FieldAddress(CTX, Context::isolate_offset())); | |
1309 __ movq(Address(RBX, Context::isolate_offset()), R10); | |
1310 | |
1311 // Set the parent to null. | |
1312 __ movq(Address(RBX, Context::parent_offset()), R12); | |
1313 | |
1314 // Initialize the context variable to the receiver. | |
1315 __ movq(R10, Address(RSP, kReceiverOffset)); | |
1316 __ movq(Address(RBX, Context::variable_offset(0)), R10); | |
1317 | |
1318 // Set the newly allocated context in the newly allocated closure. | |
1319 __ addq(RBX, Immediate(kHeapObjectTag)); | |
1320 __ movq(Address(RAX, Closure::context_offset()), RBX); | |
1321 } else { | |
1322 __ movq(Address(RAX, Closure::context_offset()), CTX); | |
1323 } | |
1324 | |
1325 // Set the type arguments field in the newly allocated closure. | |
1326 __ movq(R10, Address(RSP, kTypeArgumentsOffset)); | |
1327 __ movq(Address(RAX, Closure::type_arguments_offset()), R10); | |
1328 | |
1329 // Done allocating and initializing the instance. | |
1330 // RAX: new object. | |
1331 __ addq(RAX, Immediate(kHeapObjectTag)); | |
1332 __ LeaveStubFrame(); | |
1333 __ ret(); | |
1334 | |
1335 __ Bind(&slow_case); | |
1336 } | |
1337 if (has_type_arguments) { | |
1338 __ movq(RCX, Address(RSP, kTypeArgumentsOffset)); | |
1339 } | |
1340 if (is_implicit_instance_closure) { | |
1341 __ movq(RAX, Address(RSP, kReceiverOffset)); | |
1342 } | |
1343 | |
1344 __ pushq(R12); // Setup space on stack for the return value. | |
1345 __ PushObject(func, PP); | |
1346 if (is_implicit_instance_closure) { | |
1347 __ pushq(RAX); // Receiver. | |
1348 } | |
1349 if (has_type_arguments) { | |
1350 __ pushq(RCX); // Push type arguments of closure to be allocated. | |
1351 } else { | |
1352 __ pushq(R12); // Push null type arguments. | |
1353 } | |
1354 if (is_implicit_instance_closure) { | |
1355 __ CallRuntime(kAllocateImplicitInstanceClosureRuntimeEntry, 3); | |
1356 __ popq(RAX); // Pop type arguments. | |
1357 __ popq(RAX); // Pop receiver. | |
1358 } else { | |
1359 ASSERT(func.IsNonImplicitClosureFunction()); | |
1360 __ CallRuntime(kAllocateClosureRuntimeEntry, 2); | |
1361 __ popq(RAX); // Pop type arguments. | |
1362 } | |
1363 __ popq(RAX); // Pop the function object. | |
1364 __ popq(RAX); // Pop the result. | |
1365 // RAX: New closure object. | |
1366 // Restore the calling frame. | |
1367 __ LeaveStubFrame(); | |
1368 __ ret(); | |
1369 } | |
1370 | |
1371 | |
1372 // Called for invoking "dynamic noSuchMethod(Invocation invocation)" function | 1218 // Called for invoking "dynamic noSuchMethod(Invocation invocation)" function |
1373 // from the entry code of a dart function after an error in passed argument | 1219 // from the entry code of a dart function after an error in passed argument |
1374 // name or number is detected. | 1220 // name or number is detected. |
1375 // Input parameters: | 1221 // Input parameters: |
1376 // RSP : points to return address. | 1222 // RSP : points to return address. |
1377 // RSP + 8 : address of last argument. | 1223 // RSP + 8 : address of last argument. |
1378 // RBX : ic-data. | 1224 // RBX : ic-data. |
1379 // R10 : arguments descriptor array. | 1225 // R10 : arguments descriptor array. |
1380 void StubCode::GenerateCallNoSuchMethodFunctionStub(Assembler* assembler) { | 1226 void StubCode::GenerateCallNoSuchMethodFunctionStub(Assembler* assembler) { |
1381 __ EnterStubFrame(); | 1227 __ EnterStubFrame(); |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 | 1941 |
2096 __ movq(left, Address(RSP, 2 * kWordSize)); | 1942 __ movq(left, Address(RSP, 2 * kWordSize)); |
2097 __ movq(right, Address(RSP, 1 * kWordSize)); | 1943 __ movq(right, Address(RSP, 1 * kWordSize)); |
2098 GenerateIdenticalWithNumberCheckStub(assembler, left, right); | 1944 GenerateIdenticalWithNumberCheckStub(assembler, left, right); |
2099 __ ret(); | 1945 __ ret(); |
2100 } | 1946 } |
2101 | 1947 |
2102 } // namespace dart | 1948 } // namespace dart |
2103 | 1949 |
2104 #endif // defined TARGET_ARCH_X64 | 1950 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |