OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 | 1336 |
1337 static void GenerateRecordCallTarget(MacroAssembler* masm) { | 1337 static void GenerateRecordCallTarget(MacroAssembler* masm) { |
1338 // Cache the called function in a feedback vector slot. Cache states | 1338 // Cache the called function in a feedback vector slot. Cache states |
1339 // are uninitialized, monomorphic (indicated by a JSFunction), and | 1339 // are uninitialized, monomorphic (indicated by a JSFunction), and |
1340 // megamorphic. | 1340 // megamorphic. |
1341 // rax : number of arguments to the construct function | 1341 // rax : number of arguments to the construct function |
1342 // rbx : feedback vector | 1342 // rbx : feedback vector |
1343 // rdx : slot in feedback vector (Smi) | 1343 // rdx : slot in feedback vector (Smi) |
1344 // rdi : the function to call | 1344 // rdi : the function to call |
1345 Isolate* isolate = masm->isolate(); | 1345 Isolate* isolate = masm->isolate(); |
1346 Label initialize, done, miss, megamorphic, not_array_function, | 1346 Label initialize, done, miss, megamorphic, not_array_function; |
1347 done_no_smi_convert; | 1347 Label done_initialize_count, done_increment_count; |
1348 | 1348 |
1349 // Load the cache state into r11. | 1349 // Load the cache state into r11. |
1350 __ SmiToInteger32(rdx, rdx); | 1350 __ SmiToInteger32(rdx, rdx); |
1351 __ movp(r11, | 1351 __ movp(r11, |
1352 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); | 1352 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); |
1353 | 1353 |
1354 // A monomorphic cache hit or an already megamorphic state: invoke the | 1354 // A monomorphic cache hit or an already megamorphic state: invoke the |
1355 // function without changing the state. | 1355 // function without changing the state. |
1356 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read | 1356 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read |
1357 // at this position in a symbol (see static asserts in | 1357 // at this position in a symbol (see static asserts in |
1358 // type-feedback-vector.h). | 1358 // type-feedback-vector.h). |
1359 Label check_allocation_site; | 1359 Label check_allocation_site; |
1360 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset)); | 1360 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset)); |
1361 __ j(equal, &done, Label::kFar); | 1361 __ j(equal, &done_increment_count, Label::kFar); |
1362 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex); | 1362 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex); |
1363 __ j(equal, &done, Label::kFar); | 1363 __ j(equal, &done, Label::kFar); |
1364 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset), | 1364 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset), |
1365 Heap::kWeakCellMapRootIndex); | 1365 Heap::kWeakCellMapRootIndex); |
1366 __ j(not_equal, &check_allocation_site); | 1366 __ j(not_equal, &check_allocation_site); |
1367 | 1367 |
1368 // If the weak cell is cleared, we have a new chance to become monomorphic. | 1368 // If the weak cell is cleared, we have a new chance to become monomorphic. |
1369 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset)); | 1369 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset)); |
1370 __ j(equal, &initialize); | 1370 __ j(equal, &initialize); |
1371 __ jmp(&megamorphic); | 1371 __ jmp(&megamorphic); |
1372 | 1372 |
1373 __ bind(&check_allocation_site); | 1373 __ bind(&check_allocation_site); |
1374 // If we came here, we need to see if we are the array function. | 1374 // If we came here, we need to see if we are the array function. |
1375 // If we didn't have a matching function, and we didn't find the megamorph | 1375 // If we didn't have a matching function, and we didn't find the megamorph |
1376 // sentinel, then we have in the slot either some other function or an | 1376 // sentinel, then we have in the slot either some other function or an |
1377 // AllocationSite. | 1377 // AllocationSite. |
1378 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex); | 1378 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex); |
1379 __ j(not_equal, &miss); | 1379 __ j(not_equal, &miss); |
1380 | 1380 |
1381 // Make sure the function is the Array() function | 1381 // Make sure the function is the Array() function |
1382 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); | 1382 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); |
1383 __ cmpp(rdi, r11); | 1383 __ cmpp(rdi, r11); |
1384 __ j(not_equal, &megamorphic); | 1384 __ j(not_equal, &megamorphic); |
1385 __ jmp(&done); | 1385 __ jmp(&done_increment_count); |
1386 | 1386 |
1387 __ bind(&miss); | 1387 __ bind(&miss); |
1388 | 1388 |
1389 // A monomorphic miss (i.e, here the cache is not uninitialized) goes | 1389 // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
1390 // megamorphic. | 1390 // megamorphic. |
1391 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex); | 1391 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex); |
1392 __ j(equal, &initialize); | 1392 __ j(equal, &initialize); |
1393 // MegamorphicSentinel is an immortal immovable object (undefined) so no | 1393 // MegamorphicSentinel is an immortal immovable object (undefined) so no |
1394 // write-barrier is needed. | 1394 // write-barrier is needed. |
1395 __ bind(&megamorphic); | 1395 __ bind(&megamorphic); |
1396 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize), | 1396 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize), |
1397 TypeFeedbackVector::MegamorphicSentinel(isolate)); | 1397 TypeFeedbackVector::MegamorphicSentinel(isolate)); |
1398 __ jmp(&done); | 1398 __ jmp(&done); |
1399 | 1399 |
1400 // An uninitialized cache is patched with the function or sentinel to | 1400 // An uninitialized cache is patched with the function or sentinel to |
1401 // indicate the ElementsKind if function is the Array constructor. | 1401 // indicate the ElementsKind if function is the Array constructor. |
1402 __ bind(&initialize); | 1402 __ bind(&initialize); |
1403 | 1403 |
1404 // Make sure the function is the Array() function | 1404 // Make sure the function is the Array() function |
1405 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); | 1405 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); |
1406 __ cmpp(rdi, r11); | 1406 __ cmpp(rdi, r11); |
1407 __ j(not_equal, ¬_array_function); | 1407 __ j(not_equal, ¬_array_function); |
1408 | 1408 |
1409 CreateAllocationSiteStub create_stub(isolate); | 1409 CreateAllocationSiteStub create_stub(isolate); |
1410 CallStubInRecordCallTarget(masm, &create_stub); | 1410 CallStubInRecordCallTarget(masm, &create_stub); |
1411 __ jmp(&done_no_smi_convert); | 1411 __ jmp(&done_initialize_count); |
1412 | 1412 |
1413 __ bind(¬_array_function); | 1413 __ bind(¬_array_function); |
1414 CreateWeakCellStub weak_cell_stub(isolate); | 1414 CreateWeakCellStub weak_cell_stub(isolate); |
1415 CallStubInRecordCallTarget(masm, &weak_cell_stub); | 1415 CallStubInRecordCallTarget(masm, &weak_cell_stub); |
1416 __ jmp(&done_no_smi_convert); | 1416 |
| 1417 __ bind(&done_initialize_count); |
| 1418 // Initialize the call counter. |
| 1419 __ SmiToInteger32(rdx, rdx); |
| 1420 __ Move(FieldOperand(rbx, rdx, times_pointer_size, |
| 1421 FixedArray::kHeaderSize + kPointerSize), |
| 1422 Smi::FromInt(1)); |
| 1423 __ jmp(&done); |
| 1424 |
| 1425 __ bind(&done_increment_count); |
| 1426 |
| 1427 // Increment the call count for monomorphic function calls. |
| 1428 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size, |
| 1429 FixedArray::kHeaderSize + kPointerSize), |
| 1430 Smi::FromInt(1)); |
1417 | 1431 |
1418 __ bind(&done); | 1432 __ bind(&done); |
1419 __ Integer32ToSmi(rdx, rdx); | 1433 __ Integer32ToSmi(rdx, rdx); |
1420 | |
1421 __ bind(&done_no_smi_convert); | |
1422 } | 1434 } |
1423 | 1435 |
1424 | 1436 |
1425 void CallConstructStub::Generate(MacroAssembler* masm) { | 1437 void CallConstructStub::Generate(MacroAssembler* masm) { |
1426 // rax : number of arguments | 1438 // rax : number of arguments |
1427 // rbx : feedback vector | 1439 // rbx : feedback vector |
1428 // rdx : slot in feedback vector (Smi) | 1440 // rdx : slot in feedback vector (Smi) |
1429 // rdi : constructor function | 1441 // rdi : constructor function |
1430 | 1442 |
1431 Label non_function; | 1443 Label non_function; |
(...skipping 4019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5451 kStackUnwindSpace, nullptr, return_value_operand, | 5463 kStackUnwindSpace, nullptr, return_value_operand, |
5452 NULL); | 5464 NULL); |
5453 } | 5465 } |
5454 | 5466 |
5455 #undef __ | 5467 #undef __ |
5456 | 5468 |
5457 } // namespace internal | 5469 } // namespace internal |
5458 } // namespace v8 | 5470 } // namespace v8 |
5459 | 5471 |
5460 #endif // V8_TARGET_ARCH_X64 | 5472 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |