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 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 | 1324 |
1325 static void GenerateRecordCallTarget(MacroAssembler* masm) { | 1325 static void GenerateRecordCallTarget(MacroAssembler* masm) { |
1326 // Cache the called function in a feedback vector slot. Cache states | 1326 // Cache the called function in a feedback vector slot. Cache states |
1327 // are uninitialized, monomorphic (indicated by a JSFunction), and | 1327 // are uninitialized, monomorphic (indicated by a JSFunction), and |
1328 // megamorphic. | 1328 // megamorphic. |
1329 // rax : number of arguments to the construct function | 1329 // rax : number of arguments to the construct function |
1330 // rbx : feedback vector | 1330 // rbx : feedback vector |
1331 // rdx : slot in feedback vector (Smi) | 1331 // rdx : slot in feedback vector (Smi) |
1332 // rdi : the function to call | 1332 // rdi : the function to call |
1333 Isolate* isolate = masm->isolate(); | 1333 Isolate* isolate = masm->isolate(); |
1334 Label initialize, done, miss, megamorphic, not_array_function, | 1334 Label initialize, done, miss, megamorphic, not_array_function; |
1335 done_no_smi_convert; | 1335 Label done_initialize_count, done_increment_count; |
1336 | 1336 |
1337 // Load the cache state into r11. | 1337 // Load the cache state into r11. |
1338 __ SmiToInteger32(rdx, rdx); | 1338 __ SmiToInteger32(rdx, rdx); |
1339 __ movp(r11, | 1339 __ movp(r11, |
1340 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); | 1340 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); |
1341 | 1341 |
1342 // A monomorphic cache hit or an already megamorphic state: invoke the | 1342 // A monomorphic cache hit or an already megamorphic state: invoke the |
1343 // function without changing the state. | 1343 // function without changing the state. |
1344 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read | 1344 // We don't know if r11 is a WeakCell or a Symbol, but it's harmless to read |
1345 // at this position in a symbol (see static asserts in | 1345 // at this position in a symbol (see static asserts in |
1346 // type-feedback-vector.h). | 1346 // type-feedback-vector.h). |
1347 Label check_allocation_site; | 1347 Label check_allocation_site; |
1348 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset)); | 1348 __ cmpp(rdi, FieldOperand(r11, WeakCell::kValueOffset)); |
1349 __ j(equal, &done, Label::kFar); | 1349 __ j(equal, &done_increment_count, Label::kFar); |
1350 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex); | 1350 __ CompareRoot(r11, Heap::kmegamorphic_symbolRootIndex); |
1351 __ j(equal, &done, Label::kFar); | 1351 __ j(equal, &done, Label::kFar); |
1352 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset), | 1352 __ CompareRoot(FieldOperand(r11, HeapObject::kMapOffset), |
1353 Heap::kWeakCellMapRootIndex); | 1353 Heap::kWeakCellMapRootIndex); |
1354 __ j(not_equal, &check_allocation_site); | 1354 __ j(not_equal, &check_allocation_site); |
1355 | 1355 |
1356 // If the weak cell is cleared, we have a new chance to become monomorphic. | 1356 // If the weak cell is cleared, we have a new chance to become monomorphic. |
1357 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset)); | 1357 __ CheckSmi(FieldOperand(r11, WeakCell::kValueOffset)); |
1358 __ j(equal, &initialize); | 1358 __ j(equal, &initialize); |
1359 __ jmp(&megamorphic); | 1359 __ jmp(&megamorphic); |
1360 | 1360 |
1361 __ bind(&check_allocation_site); | 1361 __ bind(&check_allocation_site); |
1362 // If we came here, we need to see if we are the array function. | 1362 // If we came here, we need to see if we are the array function. |
1363 // If we didn't have a matching function, and we didn't find the megamorph | 1363 // If we didn't have a matching function, and we didn't find the megamorph |
1364 // sentinel, then we have in the slot either some other function or an | 1364 // sentinel, then we have in the slot either some other function or an |
1365 // AllocationSite. | 1365 // AllocationSite. |
1366 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex); | 1366 __ CompareRoot(FieldOperand(r11, 0), Heap::kAllocationSiteMapRootIndex); |
1367 __ j(not_equal, &miss); | 1367 __ j(not_equal, &miss); |
1368 | 1368 |
1369 // Make sure the function is the Array() function | 1369 // Make sure the function is the Array() function |
1370 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); | 1370 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); |
1371 __ cmpp(rdi, r11); | 1371 __ cmpp(rdi, r11); |
1372 __ j(not_equal, &megamorphic); | 1372 __ j(not_equal, &megamorphic); |
1373 __ jmp(&done); | 1373 __ jmp(&done_increment_count); |
1374 | 1374 |
1375 __ bind(&miss); | 1375 __ bind(&miss); |
1376 | 1376 |
1377 // A monomorphic miss (i.e, here the cache is not uninitialized) goes | 1377 // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
1378 // megamorphic. | 1378 // megamorphic. |
1379 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex); | 1379 __ CompareRoot(r11, Heap::kuninitialized_symbolRootIndex); |
1380 __ j(equal, &initialize); | 1380 __ j(equal, &initialize); |
1381 // MegamorphicSentinel is an immortal immovable object (undefined) so no | 1381 // MegamorphicSentinel is an immortal immovable object (undefined) so no |
1382 // write-barrier is needed. | 1382 // write-barrier is needed. |
1383 __ bind(&megamorphic); | 1383 __ bind(&megamorphic); |
1384 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize), | 1384 __ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize), |
1385 TypeFeedbackVector::MegamorphicSentinel(isolate)); | 1385 TypeFeedbackVector::MegamorphicSentinel(isolate)); |
1386 __ jmp(&done); | 1386 __ jmp(&done); |
1387 | 1387 |
1388 // An uninitialized cache is patched with the function or sentinel to | 1388 // An uninitialized cache is patched with the function or sentinel to |
1389 // indicate the ElementsKind if function is the Array constructor. | 1389 // indicate the ElementsKind if function is the Array constructor. |
1390 __ bind(&initialize); | 1390 __ bind(&initialize); |
1391 | 1391 |
1392 // Make sure the function is the Array() function | 1392 // Make sure the function is the Array() function |
1393 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); | 1393 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, r11); |
1394 __ cmpp(rdi, r11); | 1394 __ cmpp(rdi, r11); |
1395 __ j(not_equal, ¬_array_function); | 1395 __ j(not_equal, ¬_array_function); |
1396 | 1396 |
1397 CreateAllocationSiteStub create_stub(isolate); | 1397 CreateAllocationSiteStub create_stub(isolate); |
1398 CallStubInRecordCallTarget(masm, &create_stub); | 1398 CallStubInRecordCallTarget(masm, &create_stub); |
1399 __ jmp(&done_no_smi_convert); | 1399 __ jmp(&done_initialize_count); |
1400 | 1400 |
1401 __ bind(¬_array_function); | 1401 __ bind(¬_array_function); |
1402 CreateWeakCellStub weak_cell_stub(isolate); | 1402 CreateWeakCellStub weak_cell_stub(isolate); |
1403 CallStubInRecordCallTarget(masm, &weak_cell_stub); | 1403 CallStubInRecordCallTarget(masm, &weak_cell_stub); |
1404 __ jmp(&done_no_smi_convert); | 1404 |
| 1405 __ bind(&done_initialize_count); |
| 1406 // Initialize the call counter. |
| 1407 __ SmiToInteger32(rdx, rdx); |
| 1408 __ Move(FieldOperand(rbx, rdx, times_pointer_size, |
| 1409 FixedArray::kHeaderSize + kPointerSize), |
| 1410 Smi::FromInt(1)); |
| 1411 __ jmp(&done); |
| 1412 |
| 1413 __ bind(&done_increment_count); |
| 1414 |
| 1415 // Increment the call count for monomorphic function calls. |
| 1416 __ SmiAddConstant(FieldOperand(rbx, rdx, times_pointer_size, |
| 1417 FixedArray::kHeaderSize + kPointerSize), |
| 1418 Smi::FromInt(1)); |
1405 | 1419 |
1406 __ bind(&done); | 1420 __ bind(&done); |
1407 __ Integer32ToSmi(rdx, rdx); | 1421 __ Integer32ToSmi(rdx, rdx); |
1408 | |
1409 __ bind(&done_no_smi_convert); | |
1410 } | 1422 } |
1411 | 1423 |
1412 | 1424 |
1413 void CallConstructStub::Generate(MacroAssembler* masm) { | 1425 void CallConstructStub::Generate(MacroAssembler* masm) { |
1414 // rax : number of arguments | 1426 // rax : number of arguments |
1415 // rbx : feedback vector | 1427 // rbx : feedback vector |
1416 // rdx : slot in feedback vector (Smi) | 1428 // rdx : slot in feedback vector (Smi) |
1417 // rdi : constructor function | 1429 // rdi : constructor function |
1418 | 1430 |
1419 Label non_function; | 1431 Label non_function; |
(...skipping 4019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5439 kStackUnwindSpace, nullptr, return_value_operand, | 5451 kStackUnwindSpace, nullptr, return_value_operand, |
5440 NULL); | 5452 NULL); |
5441 } | 5453 } |
5442 | 5454 |
5443 #undef __ | 5455 #undef __ |
5444 | 5456 |
5445 } // namespace internal | 5457 } // namespace internal |
5446 } // namespace v8 | 5458 } // namespace v8 |
5447 | 5459 |
5448 #endif // V8_TARGET_ARCH_X64 | 5460 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |