Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: src/ic.h

Issue 142893003: Merge bleeding_edge 18658:18677 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/stub-cache-ia32.cc ('k') | src/ic.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 276
308 Address address() const { return address_; } 277 Address address() const { return address_; }
309 278
310 IC::UtilityId id() const { return id_; } 279 IC::UtilityId id() const { return id_; }
311 private: 280 private:
312 Address address_; 281 Address address_;
313 IC::UtilityId id_; 282 IC::UtilityId id_;
314 }; 283 };
315 284
316 285
317 enum StringStubFeedback {
318 DEFAULT_STRING_STUB = 0,
319 STRING_INDEX_OUT_OF_BOUNDS = 1
320 };
321
322
323 class CallICBase: public IC { 286 class CallICBase: public IC {
324 public: 287 public:
325 // ExtraICState bits
326 class StringStubState: public BitField<StringStubFeedback, 0, 1> {};
327 static ExtraICState ComputeExtraICState(StringStubFeedback feedback) {
328 return StringStubState::encode(feedback);
329 }
330
331 // Returns a JSFunction or a Failure. 288 // Returns a JSFunction or a Failure.
332 MUST_USE_RESULT MaybeObject* LoadFunction(Handle<Object> object, 289 MUST_USE_RESULT MaybeObject* LoadFunction(Handle<Object> object,
333 Handle<String> name); 290 Handle<String> name);
334 291
335 protected: 292 protected:
336 CallICBase(Code::Kind kind, Isolate* isolate) 293 CallICBase(Code::Kind kind, Isolate* isolate)
337 : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {} 294 : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {}
338 295
339 // Compute a monomorphic stub if possible, otherwise return a null handle. 296 // Compute a monomorphic stub if possible, otherwise return a null handle.
340 Handle<Code> ComputeMonomorphicStub(LookupResult* lookup, 297 Handle<Code> ComputeMonomorphicStub(LookupResult* lookup,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 389 }
433 390
434 static void GenerateMegamorphic(MacroAssembler* masm, int argc); 391 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
435 static void GenerateNormal(MacroAssembler* masm, int argc); 392 static void GenerateNormal(MacroAssembler* masm, int argc);
436 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); 393 static void GenerateNonStrictArguments(MacroAssembler* masm, int argc);
437 }; 394 };
438 395
439 396
440 class LoadIC: public IC { 397 class LoadIC: public IC {
441 public: 398 public:
399 // ExtraICState bits
400 class Contextual: public BitField<ContextualMode, 0, 1> {};
401 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0);
402
403 static ExtraICState ComputeExtraICState(ContextualMode mode) {
404 return Contextual::encode(mode);
405 }
406
407 static ContextualMode GetContextualMode(ExtraICState state) {
408 return Contextual::decode(state);
409 }
410
411 ContextualMode contextual_mode() const {
412 return Contextual::decode(extra_ic_state());
413 }
414
442 explicit LoadIC(FrameDepth depth, Isolate* isolate) 415 explicit LoadIC(FrameDepth depth, Isolate* isolate)
443 : IC(depth, isolate) { 416 : IC(depth, isolate) {
444 ASSERT(IsLoadStub()); 417 ASSERT(IsLoadStub());
445 } 418 }
446 419
420 // Returns if this IC is for contextual (no explicit receiver)
421 // access to properties.
422 bool IsUndeclaredGlobal(Handle<Object> receiver) {
423 if (receiver->IsGlobalObject()) {
424 return contextual_mode() == CONTEXTUAL;
425 } else {
426 ASSERT(contextual_mode() != CONTEXTUAL);
427 return false;
428 }
429 }
430
447 // Code generator routines. 431 // Code generator routines.
448 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } 432 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
449 static void GeneratePreMonomorphic(MacroAssembler* masm) { 433 static void GeneratePreMonomorphic(MacroAssembler* masm) {
450 GenerateMiss(masm); 434 GenerateMiss(masm);
451 } 435 }
452 static void GenerateMiss(MacroAssembler* masm); 436 static void GenerateMiss(MacroAssembler* masm);
453 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode); 437 static void GenerateMegamorphic(MacroAssembler* masm, ContextualMode mode);
454 static void GenerateNormal(MacroAssembler* masm); 438 static void GenerateNormal(MacroAssembler* masm);
455 static void GenerateRuntimeGetProperty(MacroAssembler* masm); 439 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
456 440
457 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode); 441 static Handle<Code> initialize_stub(Isolate* isolate, ContextualMode mode);
458 442
459 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object, 443 MUST_USE_RESULT MaybeObject* Load(Handle<Object> object,
460 Handle<String> name); 444 Handle<String> name);
461 445
462 protected: 446 protected:
463 virtual Code::Kind kind() const { return Code::LOAD_IC; } 447 virtual Code::Kind kind() const { return Code::LOAD_IC; }
464 448
449 void set_target(Code* code) {
450 // The contextual mode must be preserved across IC patching.
451 ASSERT(GetContextualMode(code->extra_ic_state()) ==
452 GetContextualMode(target()->extra_ic_state()));
453
454 IC::set_target(code);
455 }
456
465 virtual Handle<Code> slow_stub() const { 457 virtual Handle<Code> slow_stub() const {
466 return isolate()->builtins()->LoadIC_Slow(); 458 return isolate()->builtins()->LoadIC_Slow();
467 } 459 }
468 460
469 virtual Handle<Code> megamorphic_stub(); 461 virtual Handle<Code> megamorphic_stub();
470 462
471 // Update the inline cache and the global stub cache based on the 463 // Update the inline cache and the global stub cache based on the
472 // lookup result. 464 // lookup result.
473 void UpdateCaches(LookupResult* lookup, 465 void UpdateCaches(LookupResult* lookup,
474 Handle<Object> object, 466 Handle<Object> object,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 557 }
566 558
567 static void Clear(Isolate* isolate, Address address, Code* target); 559 static void Clear(Isolate* isolate, Address address, Code* target);
568 560
569 friend class IC; 561 friend class IC;
570 }; 562 };
571 563
572 564
573 class StoreIC: public IC { 565 class StoreIC: public IC {
574 public: 566 public:
575 // ExtraICState bits
576 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {}; 567 class StrictModeState: public BitField<StrictModeFlag, 1, 1> {};
577 static ExtraICState ComputeExtraICState(StrictModeFlag flag) { 568 static ExtraICState ComputeExtraICState(StrictModeFlag flag) {
578 return StrictModeState::encode(flag); 569 return StrictModeState::encode(flag);
579 } 570 }
580 571
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) { 572 static StrictModeFlag GetStrictMode(ExtraICState state) {
587 return StrictModeState::decode(state); 573 return StrictModeState::decode(state);
588 } 574 }
589 575
590 // For convenience, a statically declared encoding of strict mode extra 576 // For convenience, a statically declared encoding of strict mode extra
591 // IC state. 577 // IC state.
592 static const ExtraICState kStrictModeState = 578 static const ExtraICState kStrictModeState =
593 1 << StrictModeState::kShift; 579 1 << StrictModeState::kShift;
594 580
595 StoreIC(FrameDepth depth, Isolate* isolate) 581 StoreIC(FrameDepth depth, Isolate* isolate)
(...skipping 12 matching lines...) Expand all
608 GenerateMiss(masm); 594 GenerateMiss(masm);
609 } 595 }
610 static void GenerateMiss(MacroAssembler* masm); 596 static void GenerateMiss(MacroAssembler* masm);
611 static void GenerateMegamorphic(MacroAssembler* masm, 597 static void GenerateMegamorphic(MacroAssembler* masm,
612 ExtraICState extra_ic_state); 598 ExtraICState extra_ic_state);
613 static void GenerateNormal(MacroAssembler* masm); 599 static void GenerateNormal(MacroAssembler* masm);
614 static void GenerateRuntimeSetProperty(MacroAssembler* masm, 600 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
615 StrictModeFlag strict_mode); 601 StrictModeFlag strict_mode);
616 602
617 static Handle<Code> initialize_stub(Isolate* isolate, 603 static Handle<Code> initialize_stub(Isolate* isolate,
618 StrictModeFlag strict_mode, 604 StrictModeFlag strict_mode);
619 ContextualMode mode);
620 605
621 MUST_USE_RESULT MaybeObject* Store( 606 MUST_USE_RESULT MaybeObject* Store(
622 Handle<Object> object, 607 Handle<Object> object,
623 Handle<String> name, 608 Handle<String> name,
624 Handle<Object> value, 609 Handle<Object> value,
625 JSReceiver::StoreFromKeyed store_mode = 610 JSReceiver::StoreFromKeyed store_mode =
626 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED); 611 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED);
627 612
628 protected: 613 protected:
629 virtual Code::Kind kind() const { return Code::STORE_IC; } 614 virtual Code::Kind kind() const { return Code::STORE_IC; }
630 virtual Handle<Code> megamorphic_stub(); 615 virtual Handle<Code> megamorphic_stub();
631 616
632 // Stub accessors. 617 // Stub accessors.
633 virtual Handle<Code> generic_stub() const; 618 virtual Handle<Code> generic_stub() const;
634 619
635 virtual Handle<Code> slow_stub() const { 620 virtual Handle<Code> slow_stub() const {
636 return isolate()->builtins()->StoreIC_Slow(); 621 return isolate()->builtins()->StoreIC_Slow();
637 } 622 }
638 623
639 virtual Handle<Code> pre_monomorphic_stub() { 624 virtual Handle<Code> pre_monomorphic_stub() {
640 return pre_monomorphic_stub(isolate(), strict_mode(), contextual_mode()); 625 return pre_monomorphic_stub(isolate(), strict_mode());
641 } 626 }
642 627
643 static Handle<Code> pre_monomorphic_stub(Isolate* isolate, 628 static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
644 StrictModeFlag strict_mode, 629 StrictModeFlag strict_mode);
645 ContextualMode contextual_mode);
646 630
647 // Update the inline cache and the global stub cache based on the 631 // Update the inline cache and the global stub cache based on the
648 // lookup result. 632 // lookup result.
649 void UpdateCaches(LookupResult* lookup, 633 void UpdateCaches(LookupResult* lookup,
650 Handle<JSObject> receiver, 634 Handle<JSObject> receiver,
651 Handle<String> name, 635 Handle<String> name,
652 Handle<Object> value); 636 Handle<Object> value);
653 virtual Handle<Code> CompileHandler(LookupResult* lookup, 637 virtual Handle<Code> CompileHandler(LookupResult* lookup,
654 Handle<Object> object, 638 Handle<Object> object,
655 Handle<String> name, 639 Handle<String> name,
656 Handle<Object> value, 640 Handle<Object> value,
657 InlineCacheHolderFlag cache_holder); 641 InlineCacheHolderFlag cache_holder);
658 642
659 private: 643 private:
660 void set_target(Code* code) { 644 void set_target(Code* code) {
661 // Strict mode must be preserved across IC patching. 645 // Strict mode must be preserved across IC patching.
662 ASSERT(GetStrictMode(code->extra_ic_state()) == 646 ASSERT(GetStrictMode(code->extra_ic_state()) ==
663 GetStrictMode(target()->extra_ic_state())); 647 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); 648 IC::set_target(code);
668 } 649 }
669 650
670 static void Clear(Isolate* isolate, Address address, Code* target); 651 static void Clear(Isolate* isolate, Address address, Code* target);
671 652
672 friend class IC; 653 friend class IC;
673 }; 654 };
674 655
675 656
676 enum KeyedStoreCheckMap { 657 enum KeyedStoreCheckMap {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss); 1005 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss);
1025 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss); 1006 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss);
1026 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite); 1007 DECLARE_RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite);
1027 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss); 1008 DECLARE_RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss);
1028 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss); 1009 DECLARE_RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss);
1029 1010
1030 1011
1031 } } // namespace v8::internal 1012 } } // namespace v8::internal
1032 1013
1033 #endif // V8_IC_H_ 1014 #endif // V8_IC_H_
OLDNEW
« no previous file with comments | « src/ia32/stub-cache-ia32.cc ('k') | src/ic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698