Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / 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-inl.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(Handle<Code> code,
23                      Handle<TypeFeedbackVector> feedback_vector,
24                      Handle<Context> native_context, Zone* zone);
25
26   bool LoadIsUninitialized(TypeFeedbackId id);
27   bool StoreIsUninitialized(TypeFeedbackId id);
28   bool StoreIsKeyedPolymorphic(TypeFeedbackId id);
29   bool CallIsMonomorphic(int slot);
30   bool CallIsMonomorphic(TypeFeedbackId aid);
31   bool KeyedArrayCallIsHoley(TypeFeedbackId id);
32   bool CallNewIsMonomorphic(int 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(int feedback_vector_slot);
39
40   KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id);
41
42   void PropertyReceiverTypes(TypeFeedbackId id, Handle<String> name,
43                              SmallMapList* receiver_types);
44   void KeyedPropertyReceiverTypes(TypeFeedbackId id,
45                                   SmallMapList* receiver_types,
46                                   bool* is_string);
47   void AssignmentReceiverTypes(TypeFeedbackId id,
48                                Handle<String> name,
49                                SmallMapList* receiver_types);
50   void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
51                                     SmallMapList* receiver_types,
52                                     KeyedAccessStoreMode* store_mode);
53   void CountReceiverTypes(TypeFeedbackId id,
54                           SmallMapList* receiver_types);
55
56   void CollectReceiverTypes(TypeFeedbackId id,
57                             SmallMapList* types);
58
59   static bool CanRetainOtherContext(Map* map, Context* native_context);
60   static bool CanRetainOtherContext(JSFunction* function,
61                                     Context* native_context);
62
63   Handle<JSFunction> GetCallTarget(int slot);
64   Handle<AllocationSite> GetCallAllocationSite(int slot);
65   Handle<JSFunction> GetCallNewTarget(int slot);
66   Handle<AllocationSite> GetCallNewAllocationSite(int slot);
67
68   bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
69
70   // TODO(1571) We can't use ToBooleanStub::Types as the return value because
71   // of various cycles in our headers. Death to tons of implementations in
72   // headers!! :-P
73   byte ToBooleanTypes(TypeFeedbackId id);
74
75   // Get type information for arithmetic operations and compares.
76   void BinaryType(TypeFeedbackId id,
77                   Type** left,
78                   Type** right,
79                   Type** result,
80                   Maybe<int>* fixed_right_arg,
81                   Handle<AllocationSite>* allocation_site,
82                   Token::Value operation);
83
84   void CompareType(TypeFeedbackId id,
85                    Type** left,
86                    Type** right,
87                    Type** combined);
88
89   Type* CountType(TypeFeedbackId id);
90
91   Zone* zone() const { return zone_; }
92   Isolate* isolate() const { return zone_->isolate(); }
93
94  private:
95   void CollectReceiverTypes(TypeFeedbackId id,
96                             Handle<String> name,
97                             Code::Flags flags,
98                             SmallMapList* types);
99
100   void SetInfo(TypeFeedbackId id, Object* target);
101
102   void BuildDictionary(Handle<Code> code);
103   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
104   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
105   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
106                           Code* old_code,
107                           Code* new_code);
108   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
109
110   // Returns an element from the backing store. Returns undefined if
111   // there is no information.
112   Handle<Object> GetInfo(TypeFeedbackId id);
113
114   // Returns an element from the type feedback vector. Returns undefined
115   // if there is no information.
116   Handle<Object> GetInfo(int slot);
117
118  private:
119   Handle<Context> native_context_;
120   Zone* zone_;
121   Handle<UnseededNumberDictionary> dictionary_;
122   Handle<TypeFeedbackVector> feedback_vector_;
123
124   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
125 };
126
127 } }  // namespace v8::internal
128
129 #endif  // V8_TYPE_INFO_H_