OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/cpu-profiler.h" | 9 #include "src/cpu-profiler.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
11 #include "src/gdb-jit.h" | 11 #include "src/gdb-jit.h" |
12 #include "src/macro-assembler.h" | 12 #include "src/macro-assembler.h" |
13 #include "src/stub-cache.h" | 13 #include "src/stub-cache.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 | 18 |
| 19 InterfaceDescriptor::InterfaceDescriptor() |
| 20 : register_param_count_(-1) { } |
| 21 |
| 22 |
19 CodeStubInterfaceDescriptor::CodeStubInterfaceDescriptor() | 23 CodeStubInterfaceDescriptor::CodeStubInterfaceDescriptor() |
20 : register_param_count_(-1), | 24 : stack_parameter_count_(no_reg), |
21 stack_parameter_count_(no_reg), | |
22 hint_stack_parameter_count_(-1), | 25 hint_stack_parameter_count_(-1), |
23 function_mode_(NOT_JS_FUNCTION_STUB_MODE), | 26 function_mode_(NOT_JS_FUNCTION_STUB_MODE), |
24 deoptimization_handler_(NULL), | 27 deoptimization_handler_(NULL), |
25 handler_arguments_mode_(DONT_PASS_ARGUMENTS), | 28 handler_arguments_mode_(DONT_PASS_ARGUMENTS), |
26 miss_handler_(), | 29 miss_handler_(), |
27 has_miss_handler_(false) { } | 30 has_miss_handler_(false) { } |
28 | 31 |
29 | 32 |
30 void CodeStubInterfaceDescriptor::Initialize( | 33 void InterfaceDescriptor::Initialize( |
31 int register_parameter_count, | 34 int register_parameter_count, |
32 Register* registers, | 35 Register* registers, |
33 Address deoptimization_handler, | |
34 Representation* register_param_representations, | 36 Representation* register_param_representations, |
35 int hint_stack_parameter_count, | 37 PlatformInterfaceDescriptor* platform_descriptor) { |
36 StubFunctionMode function_mode) { | 38 platform_specific_descriptor_ = platform_descriptor; |
37 // CodeStubInterfaceDescriptor owns a copy of the registers array. | |
38 register_param_count_ = register_parameter_count; | 39 register_param_count_ = register_parameter_count; |
| 40 |
| 41 // An interface descriptor must have a context register. |
| 42 ASSERT(register_parameter_count > 0 && registers[0].is(ContextRegister())); |
| 43 |
| 44 // InterfaceDescriptor owns a copy of the registers array. |
39 register_params_.Reset(NewArray<Register>(register_parameter_count)); | 45 register_params_.Reset(NewArray<Register>(register_parameter_count)); |
40 for (int i = 0; i < register_parameter_count; i++) { | 46 for (int i = 0; i < register_parameter_count; i++) { |
41 register_params_[i] = registers[i]; | 47 register_params_[i] = registers[i]; |
42 } | 48 } |
43 | 49 |
44 // If a representations array is specified, then the descriptor owns that as | 50 // If a representations array is specified, then the descriptor owns that as |
45 // well. | 51 // well. |
46 if (register_param_representations != NULL) { | 52 if (register_param_representations != NULL) { |
47 register_param_representations_.Reset( | 53 register_param_representations_.Reset( |
48 NewArray<Representation>(register_parameter_count)); | 54 NewArray<Representation>(register_parameter_count)); |
49 for (int i = 0; i < register_parameter_count; i++) { | 55 for (int i = 0; i < register_parameter_count; i++) { |
| 56 // If there is a context register, the representation must be tagged. |
| 57 ASSERT(i != 0 || register_param_representations[i].Equals( |
| 58 Representation::Tagged())); |
50 register_param_representations_[i] = register_param_representations[i]; | 59 register_param_representations_[i] = register_param_representations[i]; |
51 } | 60 } |
52 } | 61 } |
| 62 } |
| 63 |
| 64 |
| 65 void CodeStubInterfaceDescriptor::Initialize( |
| 66 int register_parameter_count, |
| 67 Register* registers, |
| 68 Address deoptimization_handler, |
| 69 Representation* register_param_representations, |
| 70 int hint_stack_parameter_count, |
| 71 StubFunctionMode function_mode) { |
| 72 InterfaceDescriptor::Initialize(register_parameter_count, registers, |
| 73 register_param_representations); |
53 | 74 |
54 deoptimization_handler_ = deoptimization_handler; | 75 deoptimization_handler_ = deoptimization_handler; |
55 | 76 |
56 hint_stack_parameter_count_ = hint_stack_parameter_count; | 77 hint_stack_parameter_count_ = hint_stack_parameter_count; |
57 function_mode_ = function_mode; | 78 function_mode_ = function_mode; |
58 } | 79 } |
59 | 80 |
60 | 81 |
61 void CodeStubInterfaceDescriptor::Initialize( | 82 void CodeStubInterfaceDescriptor::Initialize( |
62 int register_parameter_count, | 83 int register_parameter_count, |
(...skipping 11 matching lines...) Expand all Loading... |
74 function_mode); | 95 function_mode); |
75 stack_parameter_count_ = stack_parameter_count; | 96 stack_parameter_count_ = stack_parameter_count; |
76 handler_arguments_mode_ = handler_mode; | 97 handler_arguments_mode_ = handler_mode; |
77 } | 98 } |
78 | 99 |
79 | 100 |
80 void CallInterfaceDescriptor::Initialize( | 101 void CallInterfaceDescriptor::Initialize( |
81 int register_parameter_count, | 102 int register_parameter_count, |
82 Register* registers, | 103 Register* registers, |
83 Representation* param_representations, | 104 Representation* param_representations, |
84 PlatformCallInterfaceDescriptor* platform_descriptor) { | 105 PlatformInterfaceDescriptor* platform_descriptor) { |
85 // CallInterfaceDescriptor owns a copy of the registers array. | 106 InterfaceDescriptor::Initialize(register_parameter_count, registers, |
86 register_param_count_ = register_parameter_count; | 107 param_representations, platform_descriptor); |
87 register_params_.Reset(NewArray<Register>(register_parameter_count)); | |
88 for (int i = 0; i < register_parameter_count; i++) { | |
89 register_params_[i] = registers[i]; | |
90 } | |
91 | |
92 // Also the register parameter representations. | |
93 param_representations_.Reset( | |
94 NewArray<Representation>(register_parameter_count)); | |
95 for (int i = 0; i < register_parameter_count; i++) { | |
96 param_representations_[i] = param_representations[i]; | |
97 } | |
98 | |
99 platform_specific_descriptor_ = platform_descriptor; | |
100 } | 108 } |
101 | 109 |
102 | 110 |
103 bool CodeStub::FindCodeInCache(Code** code_out) { | 111 bool CodeStub::FindCodeInCache(Code** code_out) { |
104 UnseededNumberDictionary* stubs = isolate()->heap()->code_stubs(); | 112 UnseededNumberDictionary* stubs = isolate()->heap()->code_stubs(); |
105 int index = stubs->FindEntry(GetKey()); | 113 int index = stubs->FindEntry(GetKey()); |
106 if (index != UnseededNumberDictionary::kNotFound) { | 114 if (index != UnseededNumberDictionary::kNotFound) { |
107 *code_out = Code::cast(stubs->ValueAt(index)); | 115 *code_out = Code::cast(stubs->ValueAt(index)); |
108 return true; | 116 return true; |
109 } | 117 } |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 void JSEntryStub::FinishCode(Handle<Code> code) { | 575 void JSEntryStub::FinishCode(Handle<Code> code) { |
568 Handle<FixedArray> handler_table = | 576 Handle<FixedArray> handler_table = |
569 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); | 577 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); |
570 handler_table->set(0, Smi::FromInt(handler_offset_)); | 578 handler_table->set(0, Smi::FromInt(handler_offset_)); |
571 code->set_handler_table(*handler_table); | 579 code->set_handler_table(*handler_table); |
572 } | 580 } |
573 | 581 |
574 | 582 |
575 void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( | 583 void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
576 CodeStubInterfaceDescriptor* descriptor) { | 584 CodeStubInterfaceDescriptor* descriptor) { |
577 Register registers[] = { LoadIC::ReceiverRegister(), | 585 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 586 LoadIC::ReceiverRegister(), |
578 LoadIC::NameRegister() }; | 587 LoadIC::NameRegister() }; |
579 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); | 588 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); |
580 descriptor->Initialize(ARRAY_SIZE(registers), registers, | 589 descriptor->Initialize(ARRAY_SIZE(registers), registers, |
581 FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); | 590 FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); |
582 } | 591 } |
583 | 592 |
584 | 593 |
585 void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor( | 594 void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor( |
586 CodeStubInterfaceDescriptor* descriptor) { | 595 CodeStubInterfaceDescriptor* descriptor) { |
587 Register registers[] = { LoadIC::ReceiverRegister(), | 596 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 597 LoadIC::ReceiverRegister(), |
588 LoadIC::NameRegister() }; | 598 LoadIC::NameRegister() }; |
589 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); | 599 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); |
590 descriptor->Initialize(ARRAY_SIZE(registers), registers, | 600 descriptor->Initialize(ARRAY_SIZE(registers), registers, |
591 FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); | 601 FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure)); |
592 } | 602 } |
593 | 603 |
594 | 604 |
595 void KeyedLoadGenericElementStub::InitializeInterfaceDescriptor( | 605 void KeyedLoadGenericElementStub::InitializeInterfaceDescriptor( |
596 CodeStubInterfaceDescriptor* descriptor) { | 606 CodeStubInterfaceDescriptor* descriptor) { |
597 Register registers[] = { LoadIC::ReceiverRegister(), | 607 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 608 LoadIC::ReceiverRegister(), |
598 LoadIC::NameRegister() }; | 609 LoadIC::NameRegister() }; |
599 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); | 610 STATIC_ASSERT(LoadIC::kRegisterArgumentCount == 2); |
600 descriptor->Initialize( | 611 descriptor->Initialize( |
601 ARRAY_SIZE(registers), registers, | 612 ARRAY_SIZE(registers), registers, |
602 Runtime::FunctionForId(Runtime::kKeyedGetProperty)->entry); | 613 Runtime::FunctionForId(Runtime::kKeyedGetProperty)->entry); |
603 } | 614 } |
604 | 615 |
605 | 616 |
606 void LoadFieldStub::InitializeInterfaceDescriptor( | 617 void LoadFieldStub::InitializeInterfaceDescriptor( |
607 CodeStubInterfaceDescriptor* descriptor) { | 618 CodeStubInterfaceDescriptor* descriptor) { |
608 Register registers[] = { LoadIC::ReceiverRegister() }; | 619 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 620 LoadIC::ReceiverRegister() }; |
609 descriptor->Initialize(ARRAY_SIZE(registers), registers); | 621 descriptor->Initialize(ARRAY_SIZE(registers), registers); |
610 } | 622 } |
611 | 623 |
612 | 624 |
613 void KeyedLoadFieldStub::InitializeInterfaceDescriptor( | 625 void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
614 CodeStubInterfaceDescriptor* descriptor) { | 626 CodeStubInterfaceDescriptor* descriptor) { |
615 Register registers[] = { LoadIC::ReceiverRegister() }; | 627 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 628 LoadIC::ReceiverRegister() }; |
616 descriptor->Initialize(ARRAY_SIZE(registers), registers); | 629 descriptor->Initialize(ARRAY_SIZE(registers), registers); |
617 } | 630 } |
618 | 631 |
619 | 632 |
620 void StringLengthStub::InitializeInterfaceDescriptor( | 633 void StringLengthStub::InitializeInterfaceDescriptor( |
621 CodeStubInterfaceDescriptor* descriptor) { | 634 CodeStubInterfaceDescriptor* descriptor) { |
622 Register registers[] = { LoadIC::ReceiverRegister(), | 635 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 636 LoadIC::ReceiverRegister(), |
623 LoadIC::NameRegister() }; | 637 LoadIC::NameRegister() }; |
624 descriptor->Initialize(ARRAY_SIZE(registers), registers); | 638 descriptor->Initialize(ARRAY_SIZE(registers), registers); |
625 } | 639 } |
626 | 640 |
627 | 641 |
628 void KeyedStringLengthStub::InitializeInterfaceDescriptor( | 642 void KeyedStringLengthStub::InitializeInterfaceDescriptor( |
629 CodeStubInterfaceDescriptor* descriptor) { | 643 CodeStubInterfaceDescriptor* descriptor) { |
630 Register registers[] = { LoadIC::ReceiverRegister(), | 644 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 645 LoadIC::ReceiverRegister(), |
631 LoadIC::NameRegister() }; | 646 LoadIC::NameRegister() }; |
632 descriptor->Initialize(ARRAY_SIZE(registers), registers); | 647 descriptor->Initialize(ARRAY_SIZE(registers), registers); |
633 } | 648 } |
634 | 649 |
635 | 650 |
636 void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( | 651 void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
637 CodeStubInterfaceDescriptor* descriptor) { | 652 CodeStubInterfaceDescriptor* descriptor) { |
638 Register registers[] = { KeyedStoreIC::ReceiverRegister(), | 653 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 654 KeyedStoreIC::ReceiverRegister(), |
639 KeyedStoreIC::NameRegister(), | 655 KeyedStoreIC::NameRegister(), |
640 KeyedStoreIC::ValueRegister() }; | 656 KeyedStoreIC::ValueRegister() }; |
641 descriptor->Initialize( | 657 descriptor->Initialize( |
642 ARRAY_SIZE(registers), registers, | 658 ARRAY_SIZE(registers), registers, |
643 FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure)); | 659 FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure)); |
644 } | 660 } |
645 | 661 |
646 | 662 |
647 void StoreGlobalStub::InitializeInterfaceDescriptor( | 663 void StoreGlobalStub::InitializeInterfaceDescriptor( |
648 CodeStubInterfaceDescriptor* descriptor) { | 664 CodeStubInterfaceDescriptor* descriptor) { |
649 Register registers[] = { StoreIC::ReceiverRegister(), | 665 Register registers[] = { InterfaceDescriptor::ContextRegister(), |
| 666 StoreIC::ReceiverRegister(), |
650 StoreIC::NameRegister(), | 667 StoreIC::NameRegister(), |
651 StoreIC::ValueRegister() }; | 668 StoreIC::ValueRegister() }; |
652 descriptor->Initialize(ARRAY_SIZE(registers), registers, | 669 descriptor->Initialize(ARRAY_SIZE(registers), registers, |
653 FUNCTION_ADDR(StoreIC_MissFromStubFailure)); | 670 FUNCTION_ADDR(StoreIC_MissFromStubFailure)); |
654 } | 671 } |
655 | 672 |
656 | 673 |
657 void KeyedLoadDictionaryElementPlatformStub::Generate( | 674 void KeyedLoadDictionaryElementPlatformStub::Generate( |
658 MacroAssembler* masm) { | 675 MacroAssembler* masm) { |
659 KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); | 676 KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 FunctionEntryHook entry_hook = isolate->function_entry_hook(); | 863 FunctionEntryHook entry_hook = isolate->function_entry_hook(); |
847 ASSERT(entry_hook != NULL); | 864 ASSERT(entry_hook != NULL); |
848 entry_hook(function, stack_pointer); | 865 entry_hook(function, stack_pointer); |
849 } | 866 } |
850 | 867 |
851 | 868 |
852 static void InstallDescriptor(Isolate* isolate, HydrogenCodeStub* stub) { | 869 static void InstallDescriptor(Isolate* isolate, HydrogenCodeStub* stub) { |
853 int major_key = stub->MajorKey(); | 870 int major_key = stub->MajorKey(); |
854 CodeStubInterfaceDescriptor* descriptor = | 871 CodeStubInterfaceDescriptor* descriptor = |
855 isolate->code_stub_interface_descriptor(major_key); | 872 isolate->code_stub_interface_descriptor(major_key); |
856 if (!descriptor->initialized()) { | 873 if (!descriptor->IsInitialized()) { |
857 stub->InitializeInterfaceDescriptor(descriptor); | 874 stub->InitializeInterfaceDescriptor(descriptor); |
858 } | 875 } |
859 } | 876 } |
860 | 877 |
861 | 878 |
862 void ArrayConstructorStubBase::InstallDescriptors(Isolate* isolate) { | 879 void ArrayConstructorStubBase::InstallDescriptors(Isolate* isolate) { |
863 ArrayNoArgumentConstructorStub stub1(isolate, GetInitialFastElementsKind()); | 880 ArrayNoArgumentConstructorStub stub1(isolate, GetInitialFastElementsKind()); |
864 InstallDescriptor(isolate, &stub1); | 881 InstallDescriptor(isolate, &stub1); |
865 ArraySingleArgumentConstructorStub stub2(isolate, | 882 ArraySingleArgumentConstructorStub stub2(isolate, |
866 GetInitialFastElementsKind()); | 883 GetInitialFastElementsKind()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 InstallDescriptor(isolate, &stub3); | 978 InstallDescriptor(isolate, &stub3); |
962 } | 979 } |
963 | 980 |
964 InternalArrayConstructorStub::InternalArrayConstructorStub( | 981 InternalArrayConstructorStub::InternalArrayConstructorStub( |
965 Isolate* isolate) : PlatformCodeStub(isolate) { | 982 Isolate* isolate) : PlatformCodeStub(isolate) { |
966 InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); | 983 InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
967 } | 984 } |
968 | 985 |
969 | 986 |
970 } } // namespace v8::internal | 987 } } // namespace v8::internal |
OLD | NEW |