| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Alias the inline cache state type to make the IC code more readable. | 82 // Alias the inline cache state type to make the IC code more readable. |
| 83 typedef InlineCacheState State; | 83 typedef InlineCacheState State; |
| 84 | 84 |
| 85 // The IC code is either invoked with no extra frames on the stack | 85 // The IC code is either invoked with no extra frames on the stack |
| 86 // or with a single extra frame for supporting calls. | 86 // or with a single extra frame for supporting calls. |
| 87 enum FrameDepth { | 87 enum FrameDepth { |
| 88 NO_EXTRA_FRAME = 0, | 88 NO_EXTRA_FRAME = 0, |
| 89 EXTRA_CALL_FRAME = 1 | 89 EXTRA_CALL_FRAME = 1 |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // ExtraICState shared by all ICs. | |
| 93 class Contextual: public BitField<ContextualMode, 0, 1> {}; | |
| 94 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); | |
| 95 static ExtraICState ComputeExtraICState(ContextualMode mode) { | |
| 96 return Contextual::encode(mode); | |
| 97 } | |
| 98 | |
| 99 static ContextualMode GetContextualMode(ExtraICState state) { | |
| 100 return Contextual::decode(state); | |
| 101 } | |
| 102 | |
| 103 static const ExtraICState kContextualState = | |
| 104 static_cast<int>(CONTEXTUAL) << Contextual::kShift; | |
| 105 | |
| 106 // Construct the IC structure with the given number of extra | 92 // Construct the IC structure with the given number of extra |
| 107 // JavaScript frames on the stack. | 93 // JavaScript frames on the stack. |
| 108 IC(FrameDepth depth, Isolate* isolate); | 94 IC(FrameDepth depth, Isolate* isolate); |
| 109 virtual ~IC() {} | 95 virtual ~IC() {} |
| 110 | 96 |
| 111 State state() const { return state_; } | 97 State state() const { return state_; } |
| 112 inline Address address() const; | 98 inline Address address() const; |
| 113 | 99 |
| 114 // Compute the current IC state based on the target stub, receiver and name. | 100 // Compute the current IC state based on the target stub, receiver and name. |
| 115 void UpdateState(Handle<Object> receiver, Handle<Object> name); | 101 void UpdateState(Handle<Object> receiver, Handle<Object> name); |
| 116 void MarkMonomorphicPrototypeFailure() { | 102 void MarkMonomorphicPrototypeFailure() { |
| 117 state_ = MONOMORPHIC_PROTOTYPE_FAILURE; | 103 state_ = MONOMORPHIC_PROTOTYPE_FAILURE; |
| 118 } | 104 } |
| 119 | 105 |
| 120 // Clear the inline cache to initial state. | 106 // Clear the inline cache to initial state. |
| 121 static void Clear(Isolate* isolate, Address address); | 107 static void Clear(Isolate* isolate, Address address); |
| 122 | 108 |
| 123 // Returns if this IC is for contextual (no explicit receiver) | 109 #ifdef DEBUG |
| 124 // access to properties. | 110 bool IsStoreStub() const { |
| 125 bool IsUndeclaredGlobal(Handle<Object> receiver) { | 111 return target()->is_store_stub() || target()->is_keyed_store_stub(); |
| 126 if (receiver->IsGlobalObject()) { | |
| 127 return IsCallStub() || IsContextual(); | |
| 128 } else { | |
| 129 ASSERT(!IsContextual()); | |
| 130 return false; | |
| 131 } | |
| 132 } | 112 } |
| 133 | 113 |
| 134 #ifdef DEBUG | 114 bool IsCallStub() const { |
| 135 bool IsLoadStub() { | 115 return target()->is_call_stub() || target()->is_keyed_call_stub(); |
| 116 } |
| 117 #endif |
| 118 bool IsLoadStub() const { |
| 136 return target()->is_load_stub() || target()->is_keyed_load_stub(); | 119 return target()->is_load_stub() || target()->is_keyed_load_stub(); |
| 137 } | 120 } |
| 138 | 121 |
| 139 bool IsStoreStub() { | |
| 140 return target()->is_store_stub() || target()->is_keyed_store_stub(); | |
| 141 } | |
| 142 | |
| 143 #endif | |
| 144 bool IsCallStub() { | |
| 145 return target()->is_call_stub() || target()->is_keyed_call_stub(); | |
| 146 } | |
| 147 | 122 |
| 148 // Determines which map must be used for keeping the code stub. | 123 // Determines which map must be used for keeping the code stub. |
| 149 // These methods should not be called with undefined or null. | 124 // These methods should not be called with undefined or null. |
| 150 static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object); | 125 static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object); |
| 151 // TODO(verwaest): This currently returns a HeapObject rather than JSObject* | 126 // TODO(verwaest): This currently returns a HeapObject rather than JSObject* |
| 152 // since loading the IC for loading the length from strings are stored on | 127 // since loading the IC for loading the length from strings are stored on |
| 153 // the string map directly, rather than on the JSObject-typed prototype. | 128 // the string map directly, rather than on the JSObject-typed prototype. |
| 154 static inline HeapObject* GetCodeCacheHolder(Isolate* isolate, | 129 static inline HeapObject* GetCodeCacheHolder(Isolate* isolate, |
| 155 Object* object, | 130 Object* object, |
| 156 InlineCacheHolderFlag holder); | 131 InlineCacheHolderFlag holder); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 167 | 142 |
| 168 // Utility functions to convert maps to types and back. There are two special | 143 // Utility functions to convert maps to types and back. There are two special |
| 169 // cases: | 144 // cases: |
| 170 // - The heap_number_map is used as a marker which includes heap numbers as | 145 // - The heap_number_map is used as a marker which includes heap numbers as |
| 171 // well as smis. | 146 // well as smis. |
| 172 // - The oddball map is only used for booleans. | 147 // - The oddball map is only used for booleans. |
| 173 static Handle<Map> TypeToMap(Type* type, Isolate* isolate); | 148 static Handle<Map> TypeToMap(Type* type, Isolate* isolate); |
| 174 static Handle<Type> MapToType(Handle<Map> type); | 149 static Handle<Type> MapToType(Handle<Map> type); |
| 175 static Handle<Type> CurrentTypeOf(Handle<Object> object, Isolate* isolate); | 150 static Handle<Type> CurrentTypeOf(Handle<Object> object, Isolate* isolate); |
| 176 | 151 |
| 177 ContextualMode contextual_mode() const { | 152 // Returns true if the ic is a contextual load ic. |
| 178 return Contextual::decode(extra_ic_state()); | 153 bool IsContextualLoad() const; |
| 179 } | |
| 180 | |
| 181 bool IsContextual() const { return contextual_mode() == CONTEXTUAL; } | |
| 182 | 154 |
| 183 protected: | 155 protected: |
| 184 // Get the call-site target; used for determining the state. | 156 // Get the call-site target; used for determining the state. |
| 185 Handle<Code> target() const { return target_; } | 157 Handle<Code> target() const { return target_; } |
| 186 | 158 |
| 187 Address fp() const { return fp_; } | 159 Address fp() const { return fp_; } |
| 188 Address pc() const { return *pc_address_; } | 160 Address pc() const { return *pc_address_; } |
| 189 Isolate* isolate() const { return isolate_; } | 161 Isolate* isolate() const { return isolate_; } |
| 190 | 162 |
| 191 #ifdef ENABLE_DEBUGGER_SUPPORT | 163 #ifdef ENABLE_DEBUGGER_SUPPORT |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 404 } |
| 433 | 405 |
| 434 static void GenerateMegamorphic(MacroAssembler* masm, int argc); | 406 static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 435 static void GenerateNormal(MacroAssembler* masm, int argc); | 407 static void GenerateNormal(MacroAssembler* masm, int argc); |
| 436 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); | 408 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
| 437 }; | 409 }; |
| 438 | 410 |
| 439 | 411 |
| 440 class LoadIC: public IC { | 412 class LoadIC: public IC { |
| 441 public: | 413 public: |
| 414 // ExtraICState bits |
| 415 class Contextual: public BitField<ContextualMode, 0, 1> {}; |
| 416 // STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); |
| 417 |
| 418 static ExtraICState ComputeExtraICState(ContextualMode mode) { |
| 419 return Contextual::encode(mode); |
| 420 } |
| 421 |
| 422 static ContextualMode GetContextualMode(ExtraICState state) { |
| 423 return Contextual::decode(state); |
| 424 } |
| 425 |
| 426 ContextualMode contextual_mode() const { |
| 427 return Contextual::decode(extra_ic_state()); |
| 428 } |
| 429 |
| 442 explicit LoadIC(FrameDepth depth, Isolate* isolate) | 430 explicit LoadIC(FrameDepth depth, Isolate* isolate) |
| 443 : IC(depth, isolate) { | 431 : IC(depth, isolate) { |
| 444 ASSERT(IsLoadStub()); | 432 ASSERT(IsLoadStub()); |
| 445 } | 433 } |
| 446 | 434 |
| 435 // Returns if this IC is for contextual (no explicit receiver) |
| 436 // access to properties. |
| 437 bool IsUndeclaredGlobal(Handle<Object> receiver) { |
| 438 if (receiver->IsGlobalObject()) { |
| 439 return contextual_mode() == CONTEXTUAL; |
| 440 } else { |
| 441 ASSERT(contextual_mode() != CONTEXTUAL); |
| 442 return false; |
| 443 } |
| 444 } |
| 445 |
| 447 // Code generator routines. | 446 // Code generator routines. |
| 448 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } | 447 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 449 static void GeneratePreMonomorphic(MacroAssembler* masm) { | 448 static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 450 GenerateMiss(masm); | 449 GenerateMiss(masm); |
| 451 } | 450 } |
| 452 static void GenerateMiss(MacroAssembler* masm); | 451 static void GenerateMiss(MacroAssembler* masm); |
| 453 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); | 452 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); |
| 454 static void GenerateNormal(MacroAssembler* masm); | 453 static void GenerateNormal(MacroAssembler* masm); |
| 455 static void GenerateRuntimeGetProperty(MacroAssembler* masm); | 454 static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 456 | 455 |
| 457 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode); | 456 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode); |
| 458 | 457 |
| 459 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, | 458 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, |
| 460 Handle<String> name); | 459 Handle<String> name); |
| 461 | 460 |
| 462 protected: | 461 protected: |
| 463 virtual Code::Kind kind() const { return Code::LOAD_IC; } | 462 virtual Code::Kind kind() const { return Code::LOAD_IC; } |
| 464 | 463 |
| 464 void set_target(Code* code) { |
| 465 // The contextual mode must be preserved across IC patching. |
| 466 ASSERT(GetContextualMode(code->extra_ic_state()) == |
| 467 GetContextualMode(target()->extra_ic_state())); |
| 468 |
| 469 IC::set_target(code); |
| 470 } |
| 471 |
| 465 virtual Handle<Code> slow_stub() const { | 472 virtual Handle<Code> slow_stub() const { |
| 466 return isolate()->builtins()->LoadIC_Slow(); | 473 return isolate()->builtins()->LoadIC_Slow(); |
| 467 } | 474 } |
| 468 | 475 |
| 469 virtual Handle<Code> megamorphic_stub(); | 476 virtual Handle<Code> megamorphic_stub(); |
| 470 | 477 |
| 471 // Update the inline cache and the global stub cache based on the | 478 // Update the inline cache and the global stub cache based on the |
| 472 // lookup result. | 479 // lookup result. |
| 473 void UpdateCaches(LookupResult* lookup, | 480 void UpdateCaches(LookupResult* lookup, |
| 474 Handle<Object> object, | 481 Handle<Object> object, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 572 } |
| 566 | 573 |
| 567 static void Clear(Isolate* isolate, Address address, Code* target); | 574 static void Clear(Isolate* isolate, Address address, Code* target); |
| 568 | 575 |
| 569 friend class IC; | 576 friend class IC; |
| 570 }; | 577 }; |
| 571 | 578 |
| 572 | 579 |
| 573 class StoreIC: public IC { | 580 class StoreIC: public IC { |
| 574 public: | 581 public: |
| 575 // ExtraICState bits | |
| 576 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; | 582 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; |
| 577 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { | 583 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { |
| 578 return StrictModeState::encode(flag); | 584 return StrictModeState::encode(flag); |
| 579 } | 585 } |
| 580 | 586 |
| 581 static ExtraICState ComputeExtraICState(StrictModeFlag flag, | |
| 582 ContextualMode mode) { | |
| 583 return StrictModeState::encode(flag) | Contextual::encode(mode); | |
| 584 } | |
| 585 | |
| 586 static StrictModeFlag GetStrictMode(ExtraICState state) { | 587 static StrictModeFlag GetStrictMode(ExtraICState state) { |
| 587 return StrictModeState::decode(state); | 588 return StrictModeState::decode(state); |
| 588 } | 589 } |
| 589 | 590 |
| 590 // For convenience, a statically declared encoding of strict mode extra | 591 // For convenience, a statically declared encoding of strict mode extra |
| 591 // IC state. | 592 // IC state. |
| 592 static const ExtraICState kStrictModeState = | 593 static const ExtraICState kStrictModeState = |
| 593 1 << StrictModeState::kShift; | 594 1 << StrictModeState::kShift; |
| 594 | 595 |
| 595 StoreIC(FrameDepth depth, Isolate* isolate) | 596 StoreIC(FrameDepth depth, Isolate* isolate) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 608 GenerateMiss(masm); | 609 GenerateMiss(masm); |
| 609 } | 610 } |
| 610 static void GenerateMiss(MacroAssembler* masm); | 611 static void GenerateMiss(MacroAssembler* masm); |
| 611 static void GenerateMegamorphic(MacroAssembler* masm, | 612 static void GenerateMegamorphic(MacroAssembler* masm, |
| 612 ExtraICState extra_ic_state); | 613 ExtraICState extra_ic_state); |
| 613 static void GenerateNormal(MacroAssembler* masm); | 614 static void GenerateNormal(MacroAssembler* masm); |
| 614 static void GenerateRuntimeSetProperty(MacroAssembler* masm, | 615 static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 615 StrictModeFlag strict_mode); | 616 StrictModeFlag strict_mode); |
| 616 | 617 |
| 617 static Handle<Code> initialize_stub(Isolate* isolate, | 618 static Handle<Code> initialize_stub(Isolate* isolate, |
| 618 StrictModeFlag strict_mode, | 619 StrictModeFlag strict_mode); |
| 619 ContextualMode mode); | |
| 620 | 620 |
| 621 MUST_USE_RESULT MaybeObject* Store( | 621 MUST_USE_RESULT MaybeObject* Store( |
| 622 Handle<Object> object, | 622 Handle<Object> object, |
| 623 Handle<String> name, | 623 Handle<String> name, |
| 624 Handle<Object> value, | 624 Handle<Object> value, |
| 625 JSReceiver::StoreFromKeyed store_mode = | 625 JSReceiver::StoreFromKeyed store_mode = |
| 626 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); | 626 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 627 | 627 |
| 628 protected: | 628 protected: |
| 629 virtual Code::Kind kind() const { return Code::STORE_IC; } | 629 virtual Code::Kind kind() const { return Code::STORE_IC; } |
| 630 virtual Handle<Code> megamorphic_stub(); | 630 virtual Handle<Code> megamorphic_stub(); |
| 631 | 631 |
| 632 // Stub accessors. | 632 // Stub accessors. |
| 633 virtual Handle<Code> generic_stub() const; | 633 virtual Handle<Code> generic_stub() const; |
| 634 | 634 |
| 635 virtual Handle<Code> slow_stub() const { | 635 virtual Handle<Code> slow_stub() const { |
| 636 return isolate()->builtins()->StoreIC_Slow(); | 636 return isolate()->builtins()->StoreIC_Slow(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 virtual Handle<Code> pre_monomorphic_stub() { | 639 virtual Handle<Code> pre_monomorphic_stub() { |
| 640 return pre_monomorphic_stub(isolate(), strict_mode(), contextual_mode()); | 640 return pre_monomorphic_stub(isolate(), strict_mode()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, | 643 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
| 644 StrictModeFlag strict_mode, | 644 StrictModeFlag strict_mode); |
| 645 ContextualMode contextual_mode); | |
| 646 | 645 |
| 647 // Update the inline cache and the global stub cache based on the | 646 // Update the inline cache and the global stub cache based on the |
| 648 // lookup result. | 647 // lookup result. |
| 649 void UpdateCaches(LookupResult* lookup, | 648 void UpdateCaches(LookupResult* lookup, |
| 650 Handle<JSObject> receiver, | 649 Handle<JSObject> receiver, |
| 651 Handle<String> name, | 650 Handle<String> name, |
| 652 Handle<Object> value); | 651 Handle<Object> value); |
| 653 virtual Handle<Code> CompileHandler(LookupResult* lookup, | 652 virtual Handle<Code> CompileHandler(LookupResult* lookup, |
| 654 Handle<Object> object, | 653 Handle<Object> object, |
| 655 Handle<String> name, | 654 Handle<String> name, |
| 656 Handle<Object> value, | 655 Handle<Object> value, |
| 657 InlineCacheHolderFlag cache_holder); | 656 InlineCacheHolderFlag cache_holder); |
| 658 | 657 |
| 659 private: | 658 private: |
| 660 void set_target(Code* code) { | 659 void set_target(Code* code) { |
| 661 // Strict mode must be preserved across IC patching. | 660 // Strict mode must be preserved across IC patching. |
| 662 ASSERT(GetStrictMode(code->extra_ic_state()) == | 661 ASSERT(GetStrictMode(code->extra_ic_state()) == |
| 663 GetStrictMode(target()->extra_ic_state())); | 662 GetStrictMode(target()->extra_ic_state())); |
| 664 // As must the contextual mode | |
| 665 ASSERT(GetContextualMode(code->extra_ic_state()) == | |
| 666 GetContextualMode(target()->extra_ic_state())); | |
| 667 IC::set_target(code); | 663 IC::set_target(code); |
| 668 } | 664 } |
| 669 | 665 |
| 670 static void Clear(Isolate* isolate, Address address, Code* target); | 666 static void Clear(Isolate* isolate, Address address, Code* target); |
| 671 | 667 |
| 672 friend class IC; | 668 friend class IC; |
| 673 }; | 669 }; |
| 674 | 670 |
| 675 | 671 |
| 676 enum KeyedStoreCheckMap { | 672 enum KeyedStoreCheckMap { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); | 1020 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); |
| 1025 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); | 1021 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); |
| 1026 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite); | 1022 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite); |
| 1027 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); | 1023 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); |
| 1028 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); | 1024 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); |
| 1029 | 1025 |
| 1030 | 1026 |
| 1031 } } // namespace v8::internal | 1027 } } // namespace v8::internal |
| 1032 | 1028 |
| 1033 #endif // V8_IC_H_ | 1029 #endif // V8_IC_H_ |
| OLD | NEW |