• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TYPE_INFO_H_
6 #define V8_TYPE_INFO_H_
7 
8 #include "src/allocation.h"
9 #include "src/ast/ast-types.h"
10 #include "src/contexts.h"
11 #include "src/globals.h"
12 #include "src/parsing/token.h"
13 #include "src/zone/zone.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // Forward declarations.
19 class SmallMapList;
20 class FeedbackNexus;
21 class StubCache;
22 
23 class TypeFeedbackOracle: public ZoneObject {
24  public:
25   TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
26                      Handle<TypeFeedbackVector> feedback_vector,
27                      Handle<Context> native_context);
28 
29   InlineCacheState LoadInlineCacheState(FeedbackVectorSlot slot);
30   bool StoreIsUninitialized(FeedbackVectorSlot slot);
31   bool CallIsUninitialized(FeedbackVectorSlot slot);
32   bool CallIsMonomorphic(FeedbackVectorSlot slot);
33   bool CallNewIsMonomorphic(FeedbackVectorSlot slot);
34 
35   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
36   // to various cycles in our headers.
37   // TODO(rossberg): once all oracle access is removed from ast.cc, it should
38   // be possible.
39   byte ForInType(FeedbackVectorSlot feedback_vector_slot);
40 
41   void GetStoreModeAndKeyType(FeedbackVectorSlot slot,
42                               KeyedAccessStoreMode* store_mode,
43                               IcCheckType* key_type);
44 
45   void PropertyReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
46                              SmallMapList* receiver_types);
47   void KeyedPropertyReceiverTypes(FeedbackVectorSlot slot,
48                                   SmallMapList* receiver_types, bool* is_string,
49                                   IcCheckType* key_type);
50   void AssignmentReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
51                                SmallMapList* receiver_types);
52   void KeyedAssignmentReceiverTypes(FeedbackVectorSlot slot,
53                                     SmallMapList* receiver_types,
54                                     KeyedAccessStoreMode* store_mode,
55                                     IcCheckType* key_type);
56   void CountReceiverTypes(FeedbackVectorSlot slot,
57                           SmallMapList* receiver_types);
58 
59   void CollectReceiverTypes(FeedbackVectorSlot slot, SmallMapList* types);
60   void CollectReceiverTypes(FeedbackNexus* nexus, SmallMapList* types);
61 
IsRelevantFeedback(Map * map,Context * native_context)62   static bool IsRelevantFeedback(Map* map, Context* native_context) {
63     Object* constructor = map->GetConstructor();
64     return !constructor->IsJSFunction() ||
65            JSFunction::cast(constructor)->context()->native_context() ==
66                native_context;
67   }
68 
69   Handle<JSFunction> GetCallTarget(FeedbackVectorSlot slot);
70   Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorSlot slot);
71   Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
72   Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
73 
74   // TODO(1571) We can't use ToBooleanICStub::Types as the return value because
75   // of various cycles in our headers. Death to tons of implementations in
76   // headers!! :-P
77   uint16_t ToBooleanTypes(TypeFeedbackId id);
78 
79   // Get type information for arithmetic operations and compares.
80   void BinaryType(TypeFeedbackId id, FeedbackVectorSlot slot, AstType** left,
81                   AstType** right, AstType** result,
82                   Maybe<int>* fixed_right_arg,
83                   Handle<AllocationSite>* allocation_site,
84                   Token::Value operation);
85 
86   void CompareType(TypeFeedbackId id, FeedbackVectorSlot slot, AstType** left,
87                    AstType** right, AstType** combined);
88 
89   AstType* CountType(TypeFeedbackId id, FeedbackVectorSlot slot);
90 
zone()91   Zone* zone() const { return zone_; }
isolate()92   Isolate* isolate() const { return isolate_; }
93 
94  private:
95   void CollectReceiverTypes(StubCache* stub_cache, FeedbackVectorSlot slot,
96                             Handle<Name> name, SmallMapList* types);
97   void CollectReceiverTypes(StubCache* stub_cache, FeedbackNexus* nexus,
98                             Handle<Name> name, SmallMapList* types);
99 
100   // Returns true if there is at least one string map and if
101   // all maps are string maps.
102   bool HasOnlyStringMaps(SmallMapList* receiver_types);
103 
104   void SetInfo(TypeFeedbackId id, Object* target);
105 
106   void BuildDictionary(Handle<Code> code);
107   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
108   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
109   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
110                           Code* old_code,
111                           Code* new_code);
112   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
113 
114   // Returns an element from the backing store. Returns undefined if
115   // there is no information.
116   Handle<Object> GetInfo(TypeFeedbackId id);
117 
118   // Returns an element from the type feedback vector. Returns undefined
119   // if there is no information.
120   Handle<Object> GetInfo(FeedbackVectorSlot slot);
121 
122  private:
123   Handle<Context> native_context_;
124   Isolate* isolate_;
125   Zone* zone_;
126   Handle<UnseededNumberDictionary> dictionary_;
127   Handle<TypeFeedbackVector> feedback_vector_;
128 
129   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
130 };
131 
132 }  // namespace internal
133 }  // namespace v8
134 
135 #endif  // V8_TYPE_INFO_H_
136