| 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) | |
| 124 // access to properties. | |
| 125 bool IsUndeclaredGlobal(Handle<Object> receiver) { | |
| 126 if (receiver->IsGlobalObject()) { | |
| 127 return IsCallStub() || IsContextual(); | |
| 128 } else { | |
| 129 ASSERT(!IsContextual()); | |
| 130 return false; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 #ifdef DEBUG | 109 #ifdef DEBUG |
| 135 bool IsLoadStub() { | 110 bool IsLoadStub() const { |
| 136 return target()->is_load_stub() || target()->is_keyed_load_stub(); | 111 return target()->is_load_stub() || target()->is_keyed_load_stub(); |
| 137 } | 112 } |
| 138 | 113 |
| 139 bool IsStoreStub() { | 114 bool IsStoreStub() const { |
| 140 return target()->is_store_stub() || target()->is_keyed_store_stub(); | 115 return target()->is_store_stub() || target()->is_keyed_store_stub(); |
| 141 } | 116 } |
| 142 | 117 |
| 143 #endif | 118 bool IsCallStub() const { |
| 144 bool IsCallStub() { | |
| 145 return target()->is_call_stub() || target()->is_keyed_call_stub(); | 119 return target()->is_call_stub() || target()->is_keyed_call_stub(); |
| 146 } | 120 } |
| 121 #endif |
| 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 { | |
| 178 return Contextual::decode(extra_ic_state()); | |
| 179 } | |
| 180 | |
| 181 bool IsContextual() const { return contextual_mode() == CONTEXTUAL; } | |
| 182 | |
| 183 protected: | 152 protected: |
| 184 // Get the call-site target; used for determining the state. | 153 // Get the call-site target; used for determining the state. |
| 185 Handle<Code> target() const { return target_; } | 154 Handle<Code> target() const { return target_; } |
| 186 | 155 |
| 187 Address fp() const { return fp_; } | 156 Address fp() const { return fp_; } |
| 188 Address pc() const { return *pc_address_; } | 157 Address pc() const { return *pc_address_; } |
| 189 Isolate* isolate() const { return isolate_; } | 158 Isolate* isolate() const { return isolate_; } |
| 190 | 159 |
| 191 #ifdef ENABLE_DEBUGGER_SUPPORT | 160 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 192 // Computes the address in the original code when the code running is | 161 // Computes the address in the original code when the code running is |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 401 } |
| 433 | 402 |
| 434 static void GenerateMegamorphic(MacroAssembler* masm, int argc); | 403 static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 435 static void GenerateNormal(MacroAssembler* masm, int argc); | 404 static void GenerateNormal(MacroAssembler* masm, int argc); |
| 436 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); | 405 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
| 437 }; | 406 }; |
| 438 | 407 |
| 439 | 408 |
| 440 class LoadIC: public IC { | 409 class LoadIC: public IC { |
| 441 public: | 410 public: |
| 411 // ExtraICState bits |
| 412 class Contextual: public BitField<ContextualMode, 0, 1> {}; |
| 413 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0); |
| 414 |
| 415 static ExtraICState ComputeExtraICState(ContextualMode mode) { |
| 416 return Contextual::encode(mode); |
| 417 } |
| 418 |
| 419 static ContextualMode GetContextualMode(ExtraICState state) { |
| 420 return Contextual::decode(state); |
| 421 } |
| 422 |
| 423 ContextualMode contextual_mode() const { |
| 424 return Contextual::decode(extra_ic_state()); |
| 425 } |
| 426 |
| 442 explicit LoadIC(FrameDepth depth, Isolate* isolate) | 427 explicit LoadIC(FrameDepth depth, Isolate* isolate) |
| 443 : IC(depth, isolate) { | 428 : IC(depth, isolate) { |
| 444 ASSERT(IsLoadStub()); | 429 ASSERT(IsLoadStub()); |
| 445 } | 430 } |
| 446 | 431 |
| 432 // Returns if this IC is for contextual (no explicit receiver) |
| 433 // access to properties. |
| 434 bool IsUndeclaredGlobal(Handle<Object> receiver) { |
| 435 if (receiver->IsGlobalObject()) { |
| 436 return contextual_mode() == CONTEXTUAL; |
| 437 } else { |
| 438 ASSERT(contextual_mode() != CONTEXTUAL); |
| 439 return false; |
| 440 } |
| 441 } |
| 442 |
| 447 // Code generator routines. | 443 // Code generator routines. |
| 448 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } | 444 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 449 static void GeneratePreMonomorphic(MacroAssembler* masm) { | 445 static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 450 GenerateMiss(masm); | 446 GenerateMiss(masm); |
| 451 } | 447 } |
| 452 static void GenerateMiss(MacroAssembler* masm); | 448 static void GenerateMiss(MacroAssembler* masm); |
| 453 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); | 449 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); |
| 454 static void GenerateNormal(MacroAssembler* masm); | 450 static void GenerateNormal(MacroAssembler* masm); |
| 455 static void GenerateRuntimeGetProperty(MacroAssembler* masm); | 451 static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 456 | 452 |
| 457 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode); | 453 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode); |
| 458 | 454 |
| 459 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, | 455 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, |
| 460 Handle<String> name); | 456 Handle<String> name); |
| 461 | 457 |
| 462 protected: | 458 protected: |
| 463 virtual Code::Kind kind() const { return Code::LOAD_IC; } | 459 virtual Code::Kind kind() const { return Code::LOAD_IC; } |
| 464 | 460 |
| 461 void set_target(Code* code) { |
| 462 // The contextual mode must be preserved across IC patching. |
| 463 ASSERT(GetContextualMode(code->extra_ic_state()) == |
| 464 GetContextualMode(target()->extra_ic_state())); |
| 465 |
| 466 IC::set_target(code); |
| 467 } |
| 468 |
| 465 virtual Handle<Code> slow_stub() const { | 469 virtual Handle<Code> slow_stub() const { |
| 466 return isolate()->builtins()->LoadIC_Slow(); | 470 return isolate()->builtins()->LoadIC_Slow(); |
| 467 } | 471 } |
| 468 | 472 |
| 469 virtual Handle<Code> megamorphic_stub(); | 473 virtual Handle<Code> megamorphic_stub(); |
| 470 | 474 |
| 471 // Update the inline cache and the global stub cache based on the | 475 // Update the inline cache and the global stub cache based on the |
| 472 // lookup result. | 476 // lookup result. |
| 473 void UpdateCaches(LookupResult* lookup, | 477 void UpdateCaches(LookupResult* lookup, |
| 474 Handle<Object> object, | 478 Handle<Object> object, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 569 } |
| 566 | 570 |
| 567 static void Clear(Isolate* isolate, Address address, Code* target); | 571 static void Clear(Isolate* isolate, Address address, Code* target); |
| 568 | 572 |
| 569 friend class IC; | 573 friend class IC; |
| 570 }; | 574 }; |
| 571 | 575 |
| 572 | 576 |
| 573 class StoreIC: public IC { | 577 class StoreIC: public IC { |
| 574 public: | 578 public: |
| 575 // ExtraICState bits | |
| 576 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; | 579 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; |
| 577 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { | 580 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { |
| 578 return StrictModeState::encode(flag); | 581 return StrictModeState::encode(flag); |
| 579 } | 582 } |
| 580 | 583 |
| 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) { | 584 static StrictModeFlag GetStrictMode(ExtraICState state) { |
| 587 return StrictModeState::decode(state); | 585 return StrictModeState::decode(state); |
| 588 } | 586 } |
| 589 | 587 |
| 590 // For convenience, a statically declared encoding of strict mode extra | 588 // For convenience, a statically declared encoding of strict mode extra |
| 591 // IC state. | 589 // IC state. |
| 592 static const ExtraICState kStrictModeState = | 590 static const ExtraICState kStrictModeState = |
| 593 1 << StrictModeState::kShift; | 591 1 << StrictModeState::kShift; |
| 594 | 592 |
| 595 StoreIC(FrameDepth depth, Isolate* isolate) | 593 StoreIC(FrameDepth depth, Isolate* isolate) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 608 GenerateMiss(masm); | 606 GenerateMiss(masm); |
| 609 } | 607 } |
| 610 static void GenerateMiss(MacroAssembler* masm); | 608 static void GenerateMiss(MacroAssembler* masm); |
| 611 static void GenerateMegamorphic(MacroAssembler* masm, | 609 static void GenerateMegamorphic(MacroAssembler* masm, |
| 612 ExtraICState extra_ic_state); | 610 ExtraICState extra_ic_state); |
| 613 static void GenerateNormal(MacroAssembler* masm); | 611 static void GenerateNormal(MacroAssembler* masm); |
| 614 static void GenerateRuntimeSetProperty(MacroAssembler* masm, | 612 static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 615 StrictModeFlag strict_mode); | 613 StrictModeFlag strict_mode); |
| 616 | 614 |
| 617 static Handle<Code> initialize_stub(Isolate* isolate, | 615 static Handle<Code> initialize_stub(Isolate* isolate, |
| 618 StrictModeFlag strict_mode, | 616 StrictModeFlag strict_mode); |
| 619 ContextualMode mode); | |
| 620 | 617 |
| 621 MUST_USE_RESULT MaybeObject* Store( | 618 MUST_USE_RESULT MaybeObject* Store( |
| 622 Handle<Object> object, | 619 Handle<Object> object, |
| 623 Handle<String> name, | 620 Handle<String> name, |
| 624 Handle<Object> value, | 621 Handle<Object> value, |
| 625 JSReceiver::StoreFromKeyed store_mode = | 622 JSReceiver::StoreFromKeyed store_mode = |
| 626 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); | 623 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 627 | 624 |
| 628 protected: | 625 protected: |
| 629 virtual Code::Kind kind() const { return Code::STORE_IC; } | 626 virtual Code::Kind kind() const { return Code::STORE_IC; } |
| 630 virtual Handle<Code> megamorphic_stub(); | 627 virtual Handle<Code> megamorphic_stub(); |
| 631 | 628 |
| 632 // Stub accessors. | 629 // Stub accessors. |
| 633 virtual Handle<Code> generic_stub() const; | 630 virtual Handle<Code> generic_stub() const; |
| 634 | 631 |
| 635 virtual Handle<Code> slow_stub() const { | 632 virtual Handle<Code> slow_stub() const { |
| 636 return isolate()->builtins()->StoreIC_Slow(); | 633 return isolate()->builtins()->StoreIC_Slow(); |
| 637 } | 634 } |
| 638 | 635 |
| 639 virtual Handle<Code> pre_monomorphic_stub() { | 636 virtual Handle<Code> pre_monomorphic_stub() { |
| 640 return pre_monomorphic_stub(isolate(), strict_mode(), contextual_mode()); | 637 return pre_monomorphic_stub(isolate(), strict_mode()); |
| 641 } | 638 } |
| 642 | 639 |
| 643 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, | 640 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, |
| 644 StrictModeFlag strict_mode, | 641 StrictModeFlag strict_mode); |
| 645 ContextualMode contextual_mode); | |
| 646 | 642 |
| 647 // Update the inline cache and the global stub cache based on the | 643 // Update the inline cache and the global stub cache based on the |
| 648 // lookup result. | 644 // lookup result. |
| 649 void UpdateCaches(LookupResult* lookup, | 645 void UpdateCaches(LookupResult* lookup, |
| 650 Handle<JSObject> receiver, | 646 Handle<JSObject> receiver, |
| 651 Handle<String> name, | 647 Handle<String> name, |
| 652 Handle<Object> value); | 648 Handle<Object> value); |
| 653 virtual Handle<Code> CompileHandler(LookupResult* lookup, | 649 virtual Handle<Code> CompileHandler(LookupResult* lookup, |
| 654 Handle<Object> object, | 650 Handle<Object> object, |
| 655 Handle<String> name, | 651 Handle<String> name, |
| 656 Handle<Object> value, | 652 Handle<Object> value, |
| 657 InlineCacheHolderFlag cache_holder); | 653 InlineCacheHolderFlag cache_holder); |
| 658 | 654 |
| 659 private: | 655 private: |
| 660 void set_target(Code* code) { | 656 void set_target(Code* code) { |
| 661 // Strict mode must be preserved across IC patching. | 657 // Strict mode must be preserved across IC patching. |
| 662 ASSERT(GetStrictMode(code->extra_ic_state()) == | 658 ASSERT(GetStrictMode(code->extra_ic_state()) == |
| 663 GetStrictMode(target()->extra_ic_state())); | 659 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); | 660 IC::set_target(code); |
| 668 } | 661 } |
| 669 | 662 |
| 670 static void Clear(Isolate* isolate, Address address, Code* target); | 663 static void Clear(Isolate* isolate, Address address, Code* target); |
| 671 | 664 |
| 672 friend class IC; | 665 friend class IC; |
| 673 }; | 666 }; |
| 674 | 667 |
| 675 | 668 |
| 676 enum KeyedStoreCheckMap { | 669 enum KeyedStoreCheckMap { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); | 1017 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); |
| 1025 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); | 1018 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); |
| 1026 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite); | 1019 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite); |
| 1027 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); | 1020 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); |
| 1028 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); | 1021 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); |
| 1029 | 1022 |
| 1030 | 1023 |
| 1031 } } // namespace v8::internal | 1024 } } // namespace v8::internal |
| 1032 | 1025 |
| 1033 #endif // V8_IC_H_ | 1026 #endif // V8_IC_H_ |
| OLD | NEW |