[presubmit] Enable readability/namespace linter checking.
[platform/upstream/v8.git] / src / ic / ic.h
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
3 // found in the LICENSE file.
4
5 #ifndef V8_IC_H_
6 #define V8_IC_H_
7
8 #include "src/ic/ic-state.h"
9 #include "src/macro-assembler.h"
10 #include "src/messages.h"
11
12 namespace v8 {
13 namespace internal {
14
15 //
16 // IC is the base class for LoadIC, StoreIC, KeyedLoadIC, and KeyedStoreIC.
17 //
18 class IC {
19  public:
20   // Alias the inline cache state type to make the IC code more readable.
21   typedef InlineCacheState State;
22
23   // The IC code is either invoked with no extra frames on the stack
24   // or with a single extra frame for supporting calls.
25   enum FrameDepth { NO_EXTRA_FRAME = 0, EXTRA_CALL_FRAME = 1 };
26
27   // Construct the IC structure with the given number of extra
28   // JavaScript frames on the stack.
29   IC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL);
30   virtual ~IC() {}
31
32   State state() const { return state_; }
33   inline Address address() const;
34
35   // Compute the current IC state based on the target stub, receiver and name.
36   void UpdateState(Handle<Object> receiver, Handle<Object> name);
37
38   bool IsNameCompatibleWithPrototypeFailure(Handle<Object> name);
39   void MarkPrototypeFailure(Handle<Object> name) {
40     DCHECK(IsNameCompatibleWithPrototypeFailure(name));
41     old_state_ = state_;
42     state_ = PROTOTYPE_FAILURE;
43   }
44
45   // Clear the inline cache to initial state.
46   static void Clear(Isolate* isolate, Address address, Address constant_pool);
47
48 #ifdef DEBUG
49   bool IsLoadStub() const {
50     return target()->is_load_stub() || target()->is_keyed_load_stub();
51   }
52
53   bool IsStoreStub() const {
54     return target()->is_store_stub() || target()->is_keyed_store_stub();
55   }
56
57   bool IsCallStub() const { return target()->is_call_stub(); }
58 #endif
59
60   static inline JSFunction* GetRootConstructor(Map* receiver_map,
61                                                Context* native_context);
62   static inline Handle<Map> GetHandlerCacheHolder(Handle<Map> receiver_map,
63                                                   bool receiver_is_holder,
64                                                   Isolate* isolate,
65                                                   CacheHolderFlag* flag);
66   static inline Handle<Map> GetICCacheHolder(Handle<Map> receiver_map,
67                                              Isolate* isolate,
68                                              CacheHolderFlag* flag);
69
70   static bool IsCleared(Code* code) {
71     InlineCacheState state = code->ic_state();
72     return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC;
73   }
74
75   static bool IsCleared(FeedbackNexus* nexus) {
76     InlineCacheState state = nexus->StateFromFeedback();
77     return !FLAG_use_ic || state == UNINITIALIZED || state == PREMONOMORPHIC;
78   }
79
80   static bool ICUseVector(Code::Kind kind) {
81     return kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC ||
82            kind == Code::CALL_IC ||
83            (FLAG_vector_stores &&
84             (kind == Code::STORE_IC || kind == Code::KEYED_STORE_IC));
85   }
86
87  protected:
88   // Get the call-site target; used for determining the state.
89   Handle<Code> target() const { return target_; }
90
91   Address fp() const { return fp_; }
92   Address pc() const { return *pc_address_; }
93   Isolate* isolate() const { return isolate_; }
94
95   // Get the shared function info of the caller.
96   SharedFunctionInfo* GetSharedFunctionInfo() const;
97   // Get the code object of the caller.
98   Code* GetCode() const;
99
100   bool AddressIsOptimizedCode() const;
101   inline bool AddressIsDeoptimizedCode() const;
102   inline static bool AddressIsDeoptimizedCode(Isolate* isolate,
103                                               Address address);
104
105   // Set the call-site target.
106   inline void set_target(Code* code);
107   bool is_target_set() { return target_set_; }
108   bool is_vector_set() { return vector_set_; }
109
110   bool UseVector() const {
111     bool use = ICUseVector(kind());
112     // If we are supposed to use the nexus, verify the nexus is non-null.
113     DCHECK(!use || nexus_ != NULL);
114     return use;
115   }
116
117   // Configure for most states.
118   void ConfigureVectorState(IC::State new_state);
119   // Configure the vector for MONOMORPHIC.
120   void ConfigureVectorState(Handle<Name> name, Handle<Map> map,
121                             Handle<Code> handler);
122   // Configure the vector for POLYMORPHIC.
123   void ConfigureVectorState(Handle<Name> name, MapHandleList* maps,
124                             CodeHandleList* handlers);
125   // Configure the vector for POLYMORPHIC with transitions (only for element
126   // keyed stores).
127   void ConfigureVectorState(MapHandleList* maps,
128                             MapHandleList* transitioned_maps,
129                             CodeHandleList* handlers);
130
131   char TransitionMarkFromState(IC::State state);
132   void TraceIC(const char* type, Handle<Object> name);
133   void TraceIC(const char* type, Handle<Object> name, State old_state,
134                State new_state);
135
136   MaybeHandle<Object> TypeError(MessageTemplate::Template,
137                                 Handle<Object> object, Handle<Object> key);
138   MaybeHandle<Object> ReferenceError(Handle<Name> name);
139
140   // Access the target code for the given IC address.
141   static inline Code* GetTargetAtAddress(Address address,
142                                          Address constant_pool);
143   static inline void SetTargetAtAddress(Address address, Code* target,
144                                         Address constant_pool);
145   static void OnTypeFeedbackChanged(Isolate* isolate, Address address,
146                                     State old_state, State new_state,
147                                     bool target_remains_ic_stub);
148   // As a vector-based IC, type feedback must be updated differently.
149   static void OnTypeFeedbackChanged(Isolate* isolate, Code* host,
150                                     TypeFeedbackVector* vector, State old_state,
151                                     State new_state);
152   static void PostPatching(Address address, Code* target, Code* old_target);
153
154   // Compute the handler either by compiling or by retrieving a cached version.
155   Handle<Code> ComputeHandler(LookupIterator* lookup,
156                               Handle<Object> value = Handle<Code>::null());
157   virtual Handle<Code> CompileHandler(LookupIterator* lookup,
158                                       Handle<Object> value,
159                                       CacheHolderFlag cache_holder) {
160     UNREACHABLE();
161     return Handle<Code>::null();
162   }
163
164   void UpdateMonomorphicIC(Handle<Code> handler, Handle<Name> name);
165   bool UpdatePolymorphicIC(Handle<Name> name, Handle<Code> code);
166   void UpdateMegamorphicCache(Map* map, Name* name, Code* code);
167
168   void CopyICToMegamorphicCache(Handle<Name> name);
169   bool IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map);
170   void PatchCache(Handle<Name> name, Handle<Code> code);
171   Code::Kind kind() const { return kind_; }
172   Code::Kind handler_kind() const {
173     if (kind_ == Code::KEYED_LOAD_IC) return Code::LOAD_IC;
174     DCHECK(kind_ == Code::LOAD_IC || kind_ == Code::STORE_IC ||
175            kind_ == Code::KEYED_STORE_IC);
176     return kind_;
177   }
178   virtual Handle<Code> megamorphic_stub() {
179     UNREACHABLE();
180     return Handle<Code>::null();
181   }
182
183   bool TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver,
184                                               Handle<String> name);
185
186   ExtraICState extra_ic_state() const { return extra_ic_state_; }
187   void set_extra_ic_state(ExtraICState state) { extra_ic_state_ = state; }
188
189   Handle<Map> receiver_map() { return receiver_map_; }
190   void update_receiver_map(Handle<Object> receiver) {
191     if (receiver->IsSmi()) {
192       receiver_map_ = isolate_->factory()->heap_number_map();
193     } else {
194       receiver_map_ = handle(HeapObject::cast(*receiver)->map());
195     }
196   }
197
198   void TargetMaps(MapHandleList* list) {
199     FindTargetMaps();
200     for (int i = 0; i < target_maps_.length(); i++) {
201       list->Add(target_maps_.at(i));
202     }
203   }
204
205   Map* FirstTargetMap() {
206     FindTargetMaps();
207     return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL;
208   }
209
210   inline void UpdateTarget();
211
212   Handle<TypeFeedbackVector> vector() const { return nexus()->vector_handle(); }
213   FeedbackVectorICSlot slot() const { return nexus()->slot(); }
214   State saved_state() const {
215     return state() == PROTOTYPE_FAILURE ? old_state_ : state();
216   }
217
218   template <class NexusClass>
219   NexusClass* casted_nexus() {
220     return static_cast<NexusClass*>(nexus_);
221   }
222   FeedbackNexus* nexus() const { return nexus_; }
223
224   inline Code* get_host();
225
226  private:
227   inline Code* raw_target() const;
228   inline Address constant_pool() const;
229   inline Address raw_constant_pool() const;
230
231   void FindTargetMaps() {
232     if (target_maps_set_) return;
233     target_maps_set_ = true;
234     if (UseVector()) {
235       nexus()->ExtractMaps(&target_maps_);
236     } else {
237       if (state_ == MONOMORPHIC) {
238         Map* map = target_->FindFirstMap();
239         if (map != NULL) target_maps_.Add(handle(map));
240       } else if (state_ != UNINITIALIZED && state_ != PREMONOMORPHIC) {
241         target_->FindAllMaps(&target_maps_);
242       }
243     }
244   }
245
246   // Frame pointer for the frame that uses (calls) the IC.
247   Address fp_;
248
249   // All access to the program counter and constant pool of an IC structure is
250   // indirect to make the code GC safe. This feature is crucial since
251   // GetProperty and SetProperty are called and they in turn might
252   // invoke the garbage collector.
253   Address* pc_address_;
254
255   // The constant pool of the code which originally called the IC (which might
256   // be for the breakpointed copy of the original code).
257   Address* constant_pool_address_;
258
259   Isolate* isolate_;
260
261   // The original code target that missed.
262   Handle<Code> target_;
263   bool target_set_;
264   bool vector_set_;
265   State old_state_;  // For saving if we marked as prototype failure.
266   State state_;
267   Code::Kind kind_;
268   Handle<Map> receiver_map_;
269   MaybeHandle<Code> maybe_handler_;
270
271   ExtraICState extra_ic_state_;
272   MapHandleList target_maps_;
273   bool target_maps_set_;
274
275   FeedbackNexus* nexus_;
276
277   DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
278 };
279
280
281 class CallIC : public IC {
282  public:
283   CallIC(Isolate* isolate, CallICNexus* nexus)
284       : IC(EXTRA_CALL_FRAME, isolate, nexus) {
285     DCHECK(nexus != NULL);
286   }
287
288   void HandleMiss(Handle<Object> function);
289
290   // Code generator routines.
291   static Handle<Code> initialize_stub(Isolate* isolate, int argc,
292                                       CallICState::CallType call_type);
293   static Handle<Code> initialize_stub_in_optimized_code(
294       Isolate* isolate, int argc, CallICState::CallType call_type);
295
296   static void Clear(Isolate* isolate, Code* host, CallICNexus* nexus);
297 };
298
299
300 class LoadIC : public IC {
301  public:
302   static ExtraICState ComputeExtraICState(TypeofMode typeof_mode,
303                                           LanguageMode language_mode) {
304     return LoadICState(typeof_mode, language_mode).GetExtraICState();
305   }
306
307   TypeofMode typeof_mode() const {
308     return LoadICState::GetTypeofMode(extra_ic_state());
309   }
310
311   LanguageMode language_mode() const {
312     return LoadICState::GetLanguageMode(extra_ic_state());
313   }
314
315   LoadIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
316       : IC(depth, isolate, nexus) {
317     DCHECK(nexus != NULL);
318     DCHECK(IsLoadStub());
319   }
320
321   bool ShouldThrowReferenceError(Handle<Object> receiver) {
322     return receiver->IsGlobalObject() && typeof_mode() == NOT_INSIDE_TYPEOF;
323   }
324
325   // Code generator routines.
326
327   static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
328   static void GenerateMiss(MacroAssembler* masm);
329   static void GenerateRuntimeGetProperty(MacroAssembler* masm,
330                                          LanguageMode language_mode);
331   static void GenerateNormal(MacroAssembler* masm, LanguageMode language_mode);
332
333   static Handle<Code> initialize_stub(Isolate* isolate,
334                                       ExtraICState extra_state);
335   static Handle<Code> initialize_stub_in_optimized_code(
336       Isolate* isolate, ExtraICState extra_state, State initialization_state);
337
338   MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
339                                            Handle<Name> name);
340
341   static void Clear(Isolate* isolate, Code* host, LoadICNexus* nexus);
342
343  protected:
344   inline void set_target(Code* code);
345
346   Handle<Code> slow_stub() const {
347     if (kind() == Code::LOAD_IC) {
348       return is_strong(language_mode())
349                  ? isolate()->builtins()->LoadIC_Slow_Strong()
350                  : isolate()->builtins()->LoadIC_Slow();
351     } else {
352       DCHECK_EQ(Code::KEYED_LOAD_IC, kind());
353       return is_strong(language_mode())
354                  ? isolate()->builtins()->KeyedLoadIC_Slow_Strong()
355                  : isolate()->builtins()->KeyedLoadIC_Slow();
356     }
357   }
358
359   Handle<Code> megamorphic_stub() override;
360
361   // Update the inline cache and the global stub cache based on the
362   // lookup result.
363   void UpdateCaches(LookupIterator* lookup);
364
365   virtual Handle<Code> CompileHandler(LookupIterator* lookup,
366                                       Handle<Object> unused,
367                                       CacheHolderFlag cache_holder) override;
368
369  private:
370   Handle<Code> SimpleFieldLoad(FieldIndex index);
371
372   static void Clear(Isolate* isolate, Address address, Code* target,
373                     Address constant_pool);
374
375   friend class IC;
376 };
377
378
379 class KeyedLoadIC : public LoadIC {
380  public:
381   // ExtraICState bits (building on IC)
382   class IcCheckTypeField
383       : public BitField<IcCheckType, LoadICState::kNextBitFieldOffset, 1> {};
384
385   static ExtraICState ComputeExtraICState(TypeofMode typeof_mode,
386                                           LanguageMode language_mode,
387                                           IcCheckType key_type) {
388     return LoadICState(typeof_mode, language_mode).GetExtraICState() |
389            IcCheckTypeField::encode(key_type);
390   }
391
392   static IcCheckType GetKeyType(ExtraICState extra_state) {
393     return IcCheckTypeField::decode(extra_state);
394   }
395
396   KeyedLoadIC(FrameDepth depth, Isolate* isolate,
397               KeyedLoadICNexus* nexus = NULL)
398       : LoadIC(depth, isolate, nexus) {
399     DCHECK(nexus != NULL);
400     DCHECK(target()->is_keyed_load_stub());
401   }
402
403   MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
404                                            Handle<Object> key);
405
406   // Code generator routines.
407   static void GenerateMiss(MacroAssembler* masm);
408   static void GenerateRuntimeGetProperty(MacroAssembler* masm,
409                                          LanguageMode language_mode);
410   static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
411   static void GenerateMegamorphic(MacroAssembler* masm,
412                                   LanguageMode language_mode);
413
414   // Bit mask to be tested against bit field for the cases when
415   // generic stub should go into slow case.
416   // Access check is necessary explicitly since generic stub does not perform
417   // map checks.
418   static const int kSlowCaseBitFieldMask =
419       (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
420
421   static Handle<Code> initialize_stub(Isolate* isolate,
422                                       ExtraICState extra_state);
423   static Handle<Code> initialize_stub_in_optimized_code(
424       Isolate* isolate, State initialization_state, ExtraICState extra_state);
425   static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
426                                             ExtraICState extra_state);
427
428   static void Clear(Isolate* isolate, Code* host, KeyedLoadICNexus* nexus);
429
430  protected:
431   // receiver is HeapObject because it could be a String or a JSObject
432   Handle<Code> LoadElementStub(Handle<HeapObject> receiver);
433
434  private:
435   static void Clear(Isolate* isolate, Address address, Code* target,
436                     Address constant_pool);
437
438   friend class IC;
439 };
440
441
442 class StoreIC : public IC {
443  public:
444   static ExtraICState ComputeExtraICState(LanguageMode flag) {
445     return StoreICState(flag).GetExtraICState();
446   }
447
448   StoreIC(FrameDepth depth, Isolate* isolate, FeedbackNexus* nexus = NULL)
449       : IC(depth, isolate, nexus) {
450     DCHECK(IsStoreStub());
451   }
452
453   LanguageMode language_mode() const {
454     return StoreICState::GetLanguageMode(extra_ic_state());
455   }
456
457   // Code generators for stub routines. Only called once at startup.
458   static void GenerateSlow(MacroAssembler* masm);
459   static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
460   static void GeneratePreMonomorphic(MacroAssembler* masm) {
461     GenerateMiss(masm);
462   }
463   static void GenerateMiss(MacroAssembler* masm);
464   static void GenerateMegamorphic(MacroAssembler* masm);
465   static void GenerateNormal(MacroAssembler* masm);
466   static void GenerateRuntimeSetProperty(MacroAssembler* masm,
467                                          LanguageMode language_mode);
468
469   static Handle<Code> initialize_stub(Isolate* isolate,
470                                       LanguageMode language_mode,
471                                       State initialization_state);
472   static Handle<Code> initialize_stub_in_optimized_code(
473       Isolate* isolate, LanguageMode language_mode, State initialization_state);
474
475   MUST_USE_RESULT MaybeHandle<Object> Store(
476       Handle<Object> object, Handle<Name> name, Handle<Object> value,
477       JSReceiver::StoreFromKeyed store_mode =
478           JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED);
479
480   bool LookupForWrite(LookupIterator* it, Handle<Object> value,
481                       JSReceiver::StoreFromKeyed store_mode);
482
483   static void Clear(Isolate* isolate, Code* host, StoreICNexus* nexus);
484
485  protected:
486   // Stub accessors.
487   Handle<Code> megamorphic_stub() override;
488   Handle<Code> slow_stub() const;
489
490   virtual Handle<Code> pre_monomorphic_stub() const {
491     return pre_monomorphic_stub(isolate(), language_mode());
492   }
493
494   static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
495                                            LanguageMode language_mode);
496
497   // Update the inline cache and the global stub cache based on the
498   // lookup result.
499   void UpdateCaches(LookupIterator* lookup, Handle<Object> value,
500                     JSReceiver::StoreFromKeyed store_mode);
501   virtual Handle<Code> CompileHandler(LookupIterator* lookup,
502                                       Handle<Object> value,
503                                       CacheHolderFlag cache_holder) override;
504
505  private:
506   inline void set_target(Code* code);
507
508   static void Clear(Isolate* isolate, Address address, Code* target,
509                     Address constant_pool);
510
511   friend class IC;
512 };
513
514
515 enum KeyedStoreCheckMap { kDontCheckMap, kCheckMap };
516
517
518 enum KeyedStoreIncrementLength { kDontIncrementLength, kIncrementLength };
519
520
521 class KeyedStoreIC : public StoreIC {
522  public:
523   // ExtraICState bits (building on IC)
524   // ExtraICState bits
525   // When more language modes are added, these BitFields need to move too.
526   STATIC_ASSERT(i::LANGUAGE_END == 3);
527   class ExtraICStateKeyedAccessStoreMode
528       : public BitField<KeyedAccessStoreMode, 3, 3> {};  // NOLINT
529
530   class IcCheckTypeField : public BitField<IcCheckType, 6, 1> {};
531
532   static ExtraICState ComputeExtraICState(LanguageMode flag,
533                                           KeyedAccessStoreMode mode) {
534     return StoreICState(flag).GetExtraICState() |
535            ExtraICStateKeyedAccessStoreMode::encode(mode) |
536            IcCheckTypeField::encode(ELEMENT);
537   }
538
539   static KeyedAccessStoreMode GetKeyedAccessStoreMode(
540       ExtraICState extra_state) {
541     DCHECK(!FLAG_vector_stores);
542     return ExtraICStateKeyedAccessStoreMode::decode(extra_state);
543   }
544
545   KeyedAccessStoreMode GetKeyedAccessStoreMode() {
546     DCHECK(FLAG_vector_stores);
547     return casted_nexus<KeyedStoreICNexus>()->GetKeyedAccessStoreMode();
548   }
549
550   static IcCheckType GetKeyType(ExtraICState extra_state) {
551     DCHECK(!FLAG_vector_stores);
552     return IcCheckTypeField::decode(extra_state);
553   }
554
555   KeyedStoreIC(FrameDepth depth, Isolate* isolate,
556                KeyedStoreICNexus* nexus = NULL)
557       : StoreIC(depth, isolate, nexus) {
558     DCHECK(target()->is_keyed_store_stub());
559   }
560
561   MUST_USE_RESULT MaybeHandle<Object> Store(Handle<Object> object,
562                                             Handle<Object> name,
563                                             Handle<Object> value);
564
565   // Code generators for stub routines.  Only called once at startup.
566   static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
567   static void GeneratePreMonomorphic(MacroAssembler* masm) {
568     GenerateMiss(masm);
569   }
570   static void GenerateMiss(MacroAssembler* masm);
571   static void GenerateSlow(MacroAssembler* masm);
572   static void GenerateMegamorphic(MacroAssembler* masm,
573                                   LanguageMode language_mode);
574
575   static Handle<Code> initialize_stub(Isolate* isolate,
576                                       LanguageMode language_mode,
577                                       State initialization_state);
578
579   static Handle<Code> initialize_stub_in_optimized_code(
580       Isolate* isolate, LanguageMode language_mode, State initialization_state);
581   static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
582                                             ExtraICState extra_state);
583
584   static void Clear(Isolate* isolate, Code* host, KeyedStoreICNexus* nexus);
585
586  protected:
587   virtual Handle<Code> pre_monomorphic_stub() const {
588     return pre_monomorphic_stub(isolate(), language_mode());
589   }
590   static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
591                                            LanguageMode language_mode) {
592     if (is_strict(language_mode)) {
593       return isolate->builtins()->KeyedStoreIC_PreMonomorphic_Strict();
594     } else {
595       return isolate->builtins()->KeyedStoreIC_PreMonomorphic();
596     }
597   }
598
599   Handle<Code> StoreElementStub(Handle<Map> receiver_map,
600                                 KeyedAccessStoreMode store_mode);
601
602  private:
603   inline void set_target(Code* code);
604
605   static void Clear(Isolate* isolate, Address address, Code* target,
606                     Address constant_pool);
607
608   Handle<Map> ComputeTransitionedMap(Handle<Map> map,
609                                      KeyedAccessStoreMode store_mode);
610
611   void ValidateStoreMode(Handle<Code> stub);
612
613   friend class IC;
614 };
615
616
617 // Type Recording BinaryOpIC, that records the types of the inputs and outputs.
618 class BinaryOpIC : public IC {
619  public:
620   explicit BinaryOpIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
621
622   MaybeHandle<Object> Transition(Handle<AllocationSite> allocation_site,
623                                  Handle<Object> left,
624                                  Handle<Object> right) WARN_UNUSED_RESULT;
625 };
626
627
628 class CompareIC : public IC {
629  public:
630   CompareIC(Isolate* isolate, Token::Value op)
631       : IC(EXTRA_CALL_FRAME, isolate), op_(op) {}
632
633   // Update the inline cache for the given operands.
634   Code* UpdateCaches(Handle<Object> x, Handle<Object> y);
635
636   // Helper function for computing the condition for a compare operation.
637   static Condition ComputeCondition(Token::Value op);
638
639   // Factory method for getting an uninitialized compare stub.
640   static Handle<Code> GetUninitialized(Isolate* isolate, Token::Value op,
641                                        Strength strength);
642
643  private:
644   static bool HasInlinedSmiCode(Address address);
645
646   bool strict() const { return op_ == Token::EQ_STRICT; }
647   Condition GetCondition() const { return ComputeCondition(op_); }
648
649   static Code* GetRawUninitialized(Isolate* isolate, Token::Value op,
650                                    Strength strength);
651
652   static void Clear(Isolate* isolate, Address address, Code* target,
653                     Address constant_pool);
654
655   Token::Value op_;
656
657   friend class IC;
658 };
659
660
661 class CompareNilIC : public IC {
662  public:
663   explicit CompareNilIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
664
665   Handle<Object> CompareNil(Handle<Object> object);
666
667   static Handle<Code> GetUninitialized();
668
669   static void Clear(Address address, Code* target, Address constant_pool);
670
671   static Handle<Object> DoCompareNilSlow(Isolate* isolate, NilValue nil,
672                                          Handle<Object> object);
673 };
674
675
676 class ToBooleanIC : public IC {
677  public:
678   explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
679
680   Handle<Object> ToBoolean(Handle<Object> object);
681 };
682
683
684 // Helper for BinaryOpIC and CompareIC.
685 enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK };
686 void PatchInlinedSmiCode(Address address, InlinedSmiCheck check);
687
688 }  // namespace internal
689 }  // namespace v8
690
691 #endif  // V8_IC_H_