96cc39f0079cf6f7c386af974fe4985978f8ff06
[platform/upstream/v8.git] / src / type-info.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_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/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(TypeFeedbackId id);
29   InlineCacheState LoadInlineCacheState(FeedbackVectorICSlot slot);
30   bool StoreIsUninitialized(TypeFeedbackId id);
31   bool StoreIsUninitialized(FeedbackVectorICSlot slot);
32   bool CallIsUninitialized(FeedbackVectorICSlot slot);
33   bool CallIsMonomorphic(FeedbackVectorICSlot slot);
34   bool KeyedArrayCallIsHoley(TypeFeedbackId id);
35   bool CallNewIsMonomorphic(FeedbackVectorSlot slot);
36
37   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
38   // to various cycles in our headers.
39   // TODO(rossberg): once all oracle access is removed from ast.cc, it should
40   // be possible.
41   byte ForInType(FeedbackVectorSlot feedback_vector_slot);
42
43   void GetStoreModeAndKeyType(TypeFeedbackId id,
44                               KeyedAccessStoreMode* store_mode,
45                               IcCheckType* key_type);
46   void GetStoreModeAndKeyType(FeedbackVectorICSlot slot,
47                               KeyedAccessStoreMode* store_mode,
48                               IcCheckType* key_type);
49
50   void PropertyReceiverTypes(FeedbackVectorICSlot slot, Handle<Name> name,
51                              SmallMapList* receiver_types);
52   void KeyedPropertyReceiverTypes(FeedbackVectorICSlot slot,
53                                   SmallMapList* receiver_types, bool* is_string,
54                                   IcCheckType* key_type);
55   void AssignmentReceiverTypes(TypeFeedbackId id, Handle<Name> name,
56                                SmallMapList* receiver_types);
57   void AssignmentReceiverTypes(FeedbackVectorICSlot slot, Handle<Name> name,
58                                SmallMapList* receiver_types);
59   void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
60                                     SmallMapList* receiver_types,
61                                     KeyedAccessStoreMode* store_mode,
62                                     IcCheckType* key_type);
63   void KeyedAssignmentReceiverTypes(FeedbackVectorICSlot slot,
64                                     SmallMapList* receiver_types,
65                                     KeyedAccessStoreMode* store_mode,
66                                     IcCheckType* key_type);
67   void CountReceiverTypes(TypeFeedbackId id,
68                           SmallMapList* receiver_types);
69   void CountReceiverTypes(FeedbackVectorICSlot slot,
70                           SmallMapList* receiver_types);
71
72   void CollectReceiverTypes(FeedbackVectorICSlot slot, SmallMapList* types);
73   void CollectReceiverTypes(TypeFeedbackId id,
74                             SmallMapList* types);
75   template <class T>
76   void CollectReceiverTypes(T* obj, SmallMapList* types);
77
78   static bool IsRelevantFeedback(Map* map, Context* native_context) {
79     Object* constructor = map->GetConstructor();
80     return !constructor->IsJSFunction() ||
81            JSFunction::cast(constructor)->context()->native_context() ==
82                native_context;
83   }
84
85   Handle<JSFunction> GetCallTarget(FeedbackVectorICSlot slot);
86   Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorICSlot slot);
87   Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
88   Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
89
90   bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
91
92   // TODO(1571) We can't use ToBooleanStub::Types as the return value because
93   // of various cycles in our headers. Death to tons of implementations in
94   // headers!! :-P
95   uint16_t ToBooleanTypes(TypeFeedbackId id);
96
97   // Get type information for arithmetic operations and compares.
98   void BinaryType(TypeFeedbackId id,
99                   Type** left,
100                   Type** right,
101                   Type** result,
102                   Maybe<int>* fixed_right_arg,
103                   Handle<AllocationSite>* allocation_site,
104                   Token::Value operation);
105
106   void CompareType(TypeFeedbackId id,
107                    Type** left,
108                    Type** right,
109                    Type** combined);
110
111   Type* CountType(TypeFeedbackId id);
112
113   Zone* zone() const { return zone_; }
114   Isolate* isolate() const { return isolate_; }
115
116  private:
117   void CollectReceiverTypes(FeedbackVectorICSlot slot, Handle<Name> name,
118                             Code::Flags flags, SmallMapList* types);
119   void CollectReceiverTypes(TypeFeedbackId id, Handle<Name> name,
120                             Code::Flags flags, SmallMapList* types);
121   template <class T>
122   void CollectReceiverTypes(T* obj, Handle<Name> name, Code::Flags flags,
123                             SmallMapList* types);
124
125   // Returns true if there is at least one string map and if
126   // all maps are string maps.
127   bool HasOnlyStringMaps(SmallMapList* receiver_types);
128
129   void SetInfo(TypeFeedbackId id, Object* target);
130
131   void BuildDictionary(Handle<Code> code);
132   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
133   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
134   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
135                           Code* old_code,
136                           Code* new_code);
137   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
138
139   // Returns an element from the backing store. Returns undefined if
140   // there is no information.
141   Handle<Object> GetInfo(TypeFeedbackId id);
142
143   // Returns an element from the type feedback vector. Returns undefined
144   // if there is no information.
145   Handle<Object> GetInfo(FeedbackVectorSlot slot);
146   Handle<Object> GetInfo(FeedbackVectorICSlot slot);
147
148  private:
149   Handle<Context> native_context_;
150   Isolate* isolate_;
151   Zone* zone_;
152   Handle<UnseededNumberDictionary> dictionary_;
153   Handle<TypeFeedbackVector> feedback_vector_;
154
155   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
156 };
157
158 } }  // namespace v8::internal
159
160 #endif  // V8_TYPE_INFO_H_