Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / src / type-info.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_TYPE_INFO_H_
29 #define V8_TYPE_INFO_H_
30
31 #include "allocation.h"
32 #include "globals.h"
33 #include "types.h"
34 #include "zone-inl.h"
35
36 namespace v8 {
37 namespace internal {
38
39 // Forward declarations.
40 class ICStub;
41 class SmallMapList;
42
43
44 class TypeFeedbackOracle: public ZoneObject {
45  public:
46   TypeFeedbackOracle(Handle<Code> code,
47                      Handle<Context> native_context,
48                      Zone* zone);
49
50   bool LoadIsUninitialized(TypeFeedbackId id);
51   bool StoreIsUninitialized(TypeFeedbackId id);
52   bool StoreIsKeyedPolymorphic(TypeFeedbackId id);
53   bool CallIsMonomorphic(TypeFeedbackId aid);
54   bool CallNewIsMonomorphic(TypeFeedbackId id);
55
56   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
57   // to various cycles in our headers.
58   // TODO(rossberg): once all oracle access is removed from ast.cc, it should
59   // be possible.
60   byte ForInType(TypeFeedbackId id);
61
62   KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id);
63
64   void PropertyReceiverTypes(TypeFeedbackId id,
65                              Handle<String> name,
66                              SmallMapList* receiver_types,
67                              bool* is_prototype);
68   void KeyedPropertyReceiverTypes(TypeFeedbackId id,
69                                   SmallMapList* receiver_types,
70                                   bool* is_string);
71   void AssignmentReceiverTypes(TypeFeedbackId id,
72                                Handle<String> name,
73                                SmallMapList* receiver_types);
74   void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
75                                     SmallMapList* receiver_types,
76                                     KeyedAccessStoreMode* store_mode);
77   void CountReceiverTypes(TypeFeedbackId id,
78                           SmallMapList* receiver_types);
79
80   void CollectReceiverTypes(TypeFeedbackId id,
81                             SmallMapList* types);
82
83   static bool CanRetainOtherContext(Map* map, Context* native_context);
84   static bool CanRetainOtherContext(JSFunction* function,
85                                     Context* native_context);
86
87   Handle<JSFunction> GetCallTarget(TypeFeedbackId id);
88   Handle<JSFunction> GetCallNewTarget(TypeFeedbackId id);
89   Handle<AllocationSite> GetCallNewAllocationSite(TypeFeedbackId id);
90
91   bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
92   bool LoadIsStub(TypeFeedbackId id, ICStub* stub);
93
94   // TODO(1571) We can't use ToBooleanStub::Types as the return value because
95   // of various cycles in our headers. Death to tons of implementations in
96   // headers!! :-P
97   byte ToBooleanTypes(TypeFeedbackId id);
98
99   // Get type information for arithmetic operations and compares.
100   void BinaryType(TypeFeedbackId id,
101                   Type** left,
102                   Type** right,
103                   Type** result,
104                   Maybe<int>* fixed_right_arg,
105                   Handle<AllocationSite>* allocation_site,
106                   Token::Value operation);
107
108   void CompareType(TypeFeedbackId id,
109                    Type** left,
110                    Type** right,
111                    Type** combined);
112
113   Type* CountType(TypeFeedbackId id);
114
115   Zone* zone() const { return zone_; }
116   Isolate* isolate() const { return zone_->isolate(); }
117
118  private:
119   void CollectReceiverTypes(TypeFeedbackId id,
120                             Handle<String> name,
121                             Code::Flags flags,
122                             SmallMapList* types);
123
124   void SetInfo(TypeFeedbackId id, Object* target);
125
126   void BuildDictionary(Handle<Code> code);
127   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
128   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
129   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
130                           byte* old_start,
131                           byte* new_start);
132   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
133   void ProcessTypeFeedbackCells(Handle<Code> code);
134
135   // Returns an element from the backing store. Returns undefined if
136   // there is no information.
137   Handle<Object> GetInfo(TypeFeedbackId id);
138
139  private:
140   Handle<Context> native_context_;
141   Zone* zone_;
142   Handle<UnseededNumberDictionary> dictionary_;
143
144   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
145 };
146
147 } }  // namespace v8::internal
148
149 #endif  // V8_TYPE_INFO_H_