• 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/contexts.h"
10 #include "src/globals.h"
11 #include "src/parsing/token.h"
12 #include "src/types.h"
13 #include "src/zone.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // Forward declarations.
19 class SmallMapList;
20 
21 
22 class TypeFeedbackOracle: public ZoneObject {
23  public:
24   TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
25                      Handle<TypeFeedbackVector> feedback_vector,
26                      Handle<Context> native_context);
27 
28   InlineCacheState LoadInlineCacheState(FeedbackVectorSlot slot);
29   bool StoreIsUninitialized(FeedbackVectorSlot slot);
30   bool CallIsUninitialized(FeedbackVectorSlot slot);
31   bool CallIsMonomorphic(FeedbackVectorSlot slot);
32   bool CallNewIsMonomorphic(FeedbackVectorSlot slot);
33 
34   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
35   // to various cycles in our headers.
36   // TODO(rossberg): once all oracle access is removed from ast.cc, it should
37   // be possible.
38   byte ForInType(FeedbackVectorSlot feedback_vector_slot);
39 
40   void GetStoreModeAndKeyType(FeedbackVectorSlot slot,
41                               KeyedAccessStoreMode* store_mode,
42                               IcCheckType* key_type);
43 
44   void PropertyReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
45                              SmallMapList* receiver_types);
46   void KeyedPropertyReceiverTypes(FeedbackVectorSlot slot,
47                                   SmallMapList* receiver_types, bool* is_string,
48                                   IcCheckType* key_type);
49   void AssignmentReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
50                                SmallMapList* receiver_types);
51   void KeyedAssignmentReceiverTypes(FeedbackVectorSlot slot,
52                                     SmallMapList* receiver_types,
53                                     KeyedAccessStoreMode* store_mode,
54                                     IcCheckType* key_type);
55   void CountReceiverTypes(FeedbackVectorSlot slot,
56                           SmallMapList* receiver_types);
57 
58   void CollectReceiverTypes(FeedbackVectorSlot slot, SmallMapList* types);
59   template <class T>
60   void CollectReceiverTypes(T* obj, 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 ToBooleanStub::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,
81                   Type** left,
82                   Type** right,
83                   Type** result,
84                   Maybe<int>* fixed_right_arg,
85                   Handle<AllocationSite>* allocation_site,
86                   Token::Value operation);
87 
88   void CompareType(TypeFeedbackId id,
89                    Type** left,
90                    Type** right,
91                    Type** combined);
92 
93   Type* CountType(TypeFeedbackId id);
94 
zone()95   Zone* zone() const { return zone_; }
isolate()96   Isolate* isolate() const { return isolate_; }
97 
98  private:
99   void CollectReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
100                             Code::Flags flags, SmallMapList* types);
101   template <class T>
102   void CollectReceiverTypes(T* obj, Handle<Name> name, Code::Flags flags,
103                             SmallMapList* types);
104 
105   // Returns true if there is at least one string map and if
106   // all maps are string maps.
107   bool HasOnlyStringMaps(SmallMapList* receiver_types);
108 
109   void SetInfo(TypeFeedbackId id, Object* target);
110 
111   void BuildDictionary(Handle<Code> code);
112   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
113   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
114   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
115                           Code* old_code,
116                           Code* new_code);
117   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
118 
119   // Returns an element from the backing store. Returns undefined if
120   // there is no information.
121   Handle<Object> GetInfo(TypeFeedbackId id);
122 
123   // Returns an element from the type feedback vector. Returns undefined
124   // if there is no information.
125   Handle<Object> GetInfo(FeedbackVectorSlot slot);
126 
127  private:
128   Handle<Context> native_context_;
129   Isolate* isolate_;
130   Zone* zone_;
131   Handle<UnseededNumberDictionary> dictionary_;
132   Handle<TypeFeedbackVector> feedback_vector_;
133 
134   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
135 };
136 
137 }  // namespace internal
138 }  // namespace v8
139 
140 #endif  // V8_TYPE_INFO_H_
141