Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/interpreter/interpreter-assembler.h" | 5 #include "src/interpreter/interpreter-assembler.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 void InterpreterAssembler::CallEpilogue() { | 431 void InterpreterAssembler::CallEpilogue() { |
| 432 if (FLAG_debug_code && !disable_stack_check_across_call_) { | 432 if (FLAG_debug_code && !disable_stack_check_across_call_) { |
| 433 Node* stack_pointer_after_call = LoadStackPointer(); | 433 Node* stack_pointer_after_call = LoadStackPointer(); |
| 434 Node* stack_pointer_before_call = stack_pointer_before_call_; | 434 Node* stack_pointer_before_call = stack_pointer_before_call_; |
| 435 stack_pointer_before_call_ = nullptr; | 435 stack_pointer_before_call_ = nullptr; |
| 436 AbortIfWordNotEqual(stack_pointer_before_call, stack_pointer_after_call, | 436 AbortIfWordNotEqual(stack_pointer_before_call, stack_pointer_after_call, |
| 437 kUnexpectedStackPointer); | 437 kUnexpectedStackPointer); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 Node* InterpreterAssembler::CallJSWithFeedback(Node* function, Node* context, | |
| 442 Node* first_arg, Node* arg_count, | |
| 443 Node* slot_id, | |
| 444 Node* type_feedback_vector, | |
| 445 TailCallMode tail_call_mode) { | |
| 446 // Static checks to assert it is safe to examine the type feedback element. | |
| 447 // We don't know that we have a weak cell. We might have a private symbol | |
| 448 // or an AllocationSite, but the memory is safe to examine. | |
| 449 // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to | |
| 450 // FixedArray. | |
| 451 // WeakCell::kValueOffset - contains a JSFunction or Smi(0) | |
| 452 // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not | |
| 453 // computed, meaning that it can't appear to be a pointer. If the low bit is | |
| 454 // 0, then hash is computed, but the 0 bit prevents the field from appearing | |
| 455 // to be a pointer. | |
| 456 STATIC_ASSERT(WeakCell::kSize >= kPointerSize); | |
| 457 STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == | |
| 458 WeakCell::kValueOffset && | |
| 459 WeakCell::kValueOffset == Symbol::kHashFieldSlot); | |
| 460 | |
| 461 Variable return_value(this, MachineRepresentation::kTagged); | |
| 462 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); | |
| 463 | |
| 464 // Slot id of 0 is used to indicate no typefeedback is available. Call using | |
| 465 // call builtin. | |
| 466 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
| 467 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
| 468 GotoIf(is_feedback_unavailable, &call); | |
|
mythria
2016/07/12 09:01:34
@mvstanton: I use slot id 0 to indicate we don't n
| |
| 469 | |
| 470 // The checks. First, does rdi match the recorded monomorphic target? | |
| 471 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
| 472 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
| 473 Node* is_monomorphic = WordEqual(function, feedback_value); | |
| 474 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); | |
| 475 | |
| 476 Bind(&handle_monomorphic); | |
| 477 { | |
| 478 // The compare above could have been a SMI/SMI comparison. Guard against | |
| 479 // this convincing us that we have a monomorphic JSFunction. | |
| 480 Node* is_smi = WordIsSmi(function); | |
| 481 GotoIf(is_smi, &extra_checks); | |
| 482 | |
| 483 // Increment the call count. | |
| 484 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 485 Node* call_count = | |
| 486 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
| 487 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
| 488 // Count is Smi, so we don't need a write barrier. | |
| 489 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
| 490 SKIP_WRITE_BARRIER); | |
| 491 | |
| 492 // Call using call function builtin. | |
| 493 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | |
| 494 isolate(), tail_call_mode, CallableType::kJSFunction); | |
| 495 Node* code_target = HeapConstant(callable.code()); | |
| 496 Node* ret_value = CallStub(callable.descriptor(), code_target, context, | |
| 497 arg_count, first_arg, function); | |
| 498 return_value.Bind(ret_value); | |
| 499 Goto(&end); | |
| 500 } | |
| 501 | |
| 502 Bind(&extra_checks); | |
| 503 { | |
| 504 Label check_initialized(this, Label::kDeferred), mark_megamorphic(this); | |
| 505 // Check if it is a megamorphic target | |
| 506 Node* is_megamorphic = WordEqual( | |
| 507 feedback_element, | |
| 508 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
| 509 BranchIf(is_megamorphic, &call, &check_initialized); | |
| 510 | |
| 511 Bind(&check_initialized); | |
| 512 { | |
| 513 Label possibly_monomorphic(this); | |
| 514 // Check if it is uninitialized. | |
| 515 Node* is_uninitialized = WordEqual( | |
| 516 feedback_element, | |
| 517 HeapConstant(TypeFeedbackVector::UninitializedSentinel(isolate()))); | |
| 518 GotoUnless(is_uninitialized, &mark_megamorphic); | |
| 519 | |
| 520 Node* is_smi = WordIsSmi(function); | |
| 521 GotoIf(is_smi, &mark_megamorphic); | |
| 522 | |
| 523 // Check if function is an object of JSFunction type | |
| 524 Node* instance_type = LoadInstanceType(function); | |
| 525 Node* is_js_function = | |
| 526 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
| 527 GotoUnless(is_js_function, &mark_megamorphic); | |
| 528 | |
| 529 // Check that it is not the Array() function. | |
| 530 Node* context_slot = | |
| 531 LoadFixedArrayElement(LoadNativeContext(context), | |
| 532 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
| 533 Node* is_array_function = WordEqual(context_slot, function); | |
| 534 GotoIf(is_array_function, &mark_megamorphic); | |
| 535 | |
| 536 // Check if the function belongs to the same native context | |
| 537 Node* native_context = LoadNativeContext( | |
| 538 LoadObjectField(function, JSFunction::kContextOffset)); | |
| 539 Node* is_same_native_context = | |
| 540 WordEqual(native_context, LoadNativeContext(context)); | |
| 541 GotoUnless(is_same_native_context, &mark_megamorphic); | |
| 542 | |
| 543 // Initialize it to a monomorphic target. | |
| 544 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
| 545 // Count is Smi, so we don't need a write barrier. | |
| 546 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
| 547 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
| 548 | |
| 549 CreateWeakCellStub weak_cell_stub(isolate()); | |
| 550 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | |
| 551 HeapConstant(weak_cell_stub.GetCode()), context, | |
| 552 type_feedback_vector, SmiTag(slot_id), function); | |
| 553 | |
| 554 // Call using call function builtin. | |
| 555 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | |
| 556 isolate(), tail_call_mode, CallableType::kJSFunction); | |
| 557 Node* code_target = HeapConstant(callable.code()); | |
| 558 Node* ret_value = CallStub(callable.descriptor(), code_target, context, | |
| 559 arg_count, first_arg, function); | |
| 560 return_value.Bind(ret_value); | |
| 561 Goto(&end); | |
| 562 } | |
| 563 | |
| 564 Bind(&mark_megamorphic); | |
| 565 { | |
| 566 // Mark it as a megamorphic. | |
| 567 // MegamorphicSentinel is created as a part of Heap::InitialObjects | |
| 568 // and will not move during a GC. So it is safe to skip write barrier. | |
| 569 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
| 570 StoreFixedArrayElement( | |
| 571 type_feedback_vector, slot_id, | |
| 572 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
| 573 SKIP_WRITE_BARRIER); | |
| 574 Goto(&call); | |
| 575 } | |
| 576 } | |
| 577 | |
| 578 Bind(&call); | |
| 579 { | |
| 580 // Call using call builtin. | |
| 581 Callable callable_call = CodeFactory::InterpreterPushArgsAndCall( | |
| 582 isolate(), tail_call_mode, CallableType::kAny); | |
| 583 Node* code_target_call = HeapConstant(callable_call.code()); | |
| 584 Node* ret_value = CallStub(callable_call.descriptor(), code_target_call, | |
| 585 context, arg_count, first_arg, function); | |
| 586 return_value.Bind(ret_value); | |
| 587 Goto(&end); | |
| 588 } | |
| 589 | |
| 590 Bind(&end); | |
| 591 return return_value.value(); | |
| 592 } | |
| 593 | |
| 441 Node* InterpreterAssembler::CallJS(Node* function, Node* context, | 594 Node* InterpreterAssembler::CallJS(Node* function, Node* context, |
| 442 Node* first_arg, Node* arg_count, | 595 Node* first_arg, Node* arg_count, |
| 443 TailCallMode tail_call_mode) { | 596 TailCallMode tail_call_mode) { |
| 444 Callable callable = | 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
| 445 CodeFactory::InterpreterPushArgsAndCall(isolate(), tail_call_mode); | 598 isolate(), tail_call_mode, CallableType::kAny); |
| 446 Node* code_target = HeapConstant(callable.code()); | 599 Node* code_target = HeapConstant(callable.code()); |
| 447 return CallStub(callable.descriptor(), code_target, context, arg_count, | 600 return CallStub(callable.descriptor(), code_target, context, arg_count, |
| 448 first_arg, function); | 601 first_arg, function); |
| 449 } | 602 } |
| 450 | 603 |
| 451 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
| 452 Node* new_target, Node* first_arg, | 605 Node* new_target, Node* first_arg, |
| 453 Node* arg_count) { | 606 Node* arg_count) { |
| 454 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); | 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); |
| 455 Node* code_target = HeapConstant(callable.code()); | 608 Node* code_target = HeapConstant(callable.code()); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 Goto(&loop); | 932 Goto(&loop); |
| 780 } | 933 } |
| 781 Bind(&done_loop); | 934 Bind(&done_loop); |
| 782 | 935 |
| 783 return array; | 936 return array; |
| 784 } | 937 } |
| 785 | 938 |
| 786 } // namespace interpreter | 939 } // namespace interpreter |
| 787 } // namespace internal | 940 } // namespace internal |
| 788 } // namespace v8 | 941 } // namespace v8 |
| OLD | NEW |