65af76865e2b0cf7d0221d7d77c80f0c908cbc30
[platform/upstream/nodejs.git] / deps / v8 / 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/globals.h"
10 #include "src/types.h"
11 #include "src/zone.h"
12
13 namespace v8 {
14 namespace internal {
15
16 // Forward declarations.
17 class SmallMapList;
18
19
20 class TypeFeedbackOracle: public ZoneObject {
21  public:
22   TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
23                      Handle<TypeFeedbackVector> feedback_vector,
24                      Handle<Context> native_context);
25
26   bool LoadIsUninitialized(TypeFeedbackId id);
27   bool LoadIsUninitialized(FeedbackVectorICSlot slot);
28   bool StoreIsUninitialized(TypeFeedbackId id);
29   bool CallIsUninitialized(FeedbackVectorICSlot slot);
30   bool CallIsMonomorphic(FeedbackVectorICSlot slot);
31   bool KeyedArrayCallIsHoley(TypeFeedbackId id);
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(TypeFeedbackId id,
41                               KeyedAccessStoreMode* store_mode,
42                               IcCheckType* key_type);
43   void GetLoadKeyType(TypeFeedbackId id, IcCheckType* key_type);
44
45   void PropertyReceiverTypes(TypeFeedbackId id, Handle<String> name,
46                              SmallMapList* receiver_types);
47   void PropertyReceiverTypes(FeedbackVectorICSlot slot, Handle<String> name,
48                              SmallMapList* receiver_types);
49   void KeyedPropertyReceiverTypes(TypeFeedbackId id,
50                                   SmallMapList* receiver_types,
51                                   bool* is_string,
52                                   IcCheckType* key_type);
53   void KeyedPropertyReceiverTypes(FeedbackVectorICSlot slot,
54                                   SmallMapList* receiver_types, bool* is_string,
55                                   IcCheckType* key_type);
56   void AssignmentReceiverTypes(TypeFeedbackId id,
57                                Handle<String> name,
58                                SmallMapList* receiver_types);
59   void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
60                                     SmallMapList* receiver_types,
61                                     KeyedAccessStoreMode* store_mode,
62                                     IcCheckType* key_type);
63   void CountReceiverTypes(TypeFeedbackId id,
64                           SmallMapList* receiver_types);
65
66   void CollectReceiverTypes(TypeFeedbackId id,
67                             SmallMapList* types);
68   template <class T>
69   void CollectReceiverTypes(T* obj, SmallMapList* types);
70
71   static bool CanRetainOtherContext(Map* map, Context* native_context);
72   static bool CanRetainOtherContext(JSFunction* function,
73                                     Context* native_context);
74
75   Handle<JSFunction> GetCallTarget(FeedbackVectorICSlot slot);
76   Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorICSlot slot);
77   Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
78   Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
79
80   bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
81
82   // TODO(1571) We can't use ToBooleanStub::Types as the return value because
83   // of various cycles in our headers. Death to tons of implementations in
84   // headers!! :-P
85   byte ToBooleanTypes(TypeFeedbackId id);
86
87   // Get type information for arithmetic operations and compares.
88   void BinaryType(TypeFeedbackId id,
89                   Type** left,
90                   Type** right,
91                   Type** result,
92                   Maybe<int>* fixed_right_arg,
93                   Handle<AllocationSite>* allocation_site,
94                   Token::Value operation);
95
96   void CompareType(TypeFeedbackId id,
97                    Type** left,
98                    Type** right,
99                    Type** combined);
100
101   Type* CountType(TypeFeedbackId id);
102
103   Zone* zone() const { return zone_; }
104   Isolate* isolate() const { return isolate_; }
105
106  private:
107   void CollectReceiverTypes(TypeFeedbackId id,
108                             Handle<String> name,
109                             Code::Flags flags,
110                             SmallMapList* types);
111   template <class T>
112   void CollectReceiverTypes(T* obj, Handle<String> name, Code::Flags flags,
113                             SmallMapList* types);
114
115   // Returns true if there is at least one string map and if
116   // all maps are string maps.
117   bool HasOnlyStringMaps(SmallMapList* receiver_types);
118
119   void SetInfo(TypeFeedbackId id, Object* target);
120
121   void BuildDictionary(Handle<Code> code);
122   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
123   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
124   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
125                           Code* old_code,
126                           Code* new_code);
127   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
128
129   // Returns an element from the backing store. Returns undefined if
130   // there is no information.
131   Handle<Object> GetInfo(TypeFeedbackId id);
132
133   // Returns an element from the type feedback vector. Returns undefined
134   // if there is no information.
135   Handle<Object> GetInfo(FeedbackVectorSlot slot);
136   Handle<Object> GetInfo(FeedbackVectorICSlot slot);
137
138  private:
139   Handle<Context> native_context_;
140   Isolate* isolate_;
141   Zone* zone_;
142   Handle<UnseededNumberDictionary> dictionary_;
143   Handle<TypeFeedbackVector> feedback_vector_;
144
145   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
146 };
147
148 } }  // namespace v8::internal
149
150 #endif  // V8_TYPE_INFO_H_