• 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/ast/ast-types.h"
10 #include "src/contexts.h"
11 #include "src/globals.h"
12 #include "src/parsing/token.h"
13 #include "src/zone/zone.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 // Forward declarations.
19 class SmallMapList;
20 class FeedbackNexus;
21 class StubCache;
22 
23 class TypeFeedbackOracle: public ZoneObject {
24  public:
25   TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
26                      Handle<FeedbackVector> feedback_vector,
27                      Handle<Context> native_context);
28 
29   InlineCacheState LoadInlineCacheState(FeedbackSlot slot);
30   bool StoreIsUninitialized(FeedbackSlot slot);
31   bool CallIsUninitialized(FeedbackSlot slot);
32   bool CallIsMonomorphic(FeedbackSlot slot);
33   bool CallNewIsMonomorphic(FeedbackSlot slot);
34 
35   // TODO(1571) We can't use ForInStatement::ForInType as the return value due
36   // to various cycles in our headers.
37   // TODO(rossberg): once all oracle access is removed from ast.cc, it should
38   // be possible.
39   byte ForInType(FeedbackSlot feedback_vector_slot);
40 
41   void GetStoreModeAndKeyType(FeedbackSlot slot,
42                               KeyedAccessStoreMode* store_mode,
43                               IcCheckType* key_type);
44 
45   void PropertyReceiverTypes(FeedbackSlot slot, Handle<Name> name,
46                              SmallMapList* receiver_types);
47   void KeyedPropertyReceiverTypes(FeedbackSlot slot,
48                                   SmallMapList* receiver_types, bool* is_string,
49                                   IcCheckType* key_type);
50   void AssignmentReceiverTypes(FeedbackSlot slot, Handle<Name> name,
51                                SmallMapList* receiver_types);
52   void KeyedAssignmentReceiverTypes(FeedbackSlot slot,
53                                     SmallMapList* receiver_types,
54                                     KeyedAccessStoreMode* store_mode,
55                                     IcCheckType* key_type);
56   void CountReceiverTypes(FeedbackSlot slot, SmallMapList* receiver_types);
57 
58   void CollectReceiverTypes(FeedbackSlot slot, SmallMapList* types);
59   void CollectReceiverTypes(FeedbackNexus* nexus, SmallMapList* types);
60 
IsRelevantFeedback(Map * map,Context * native_context)61   static bool IsRelevantFeedback(Map* map, Context* native_context) {
62     Object* constructor = map->GetConstructor();
63     return !constructor->IsJSFunction() ||
64            JSFunction::cast(constructor)->context()->native_context() ==
65                native_context;
66   }
67 
68   Handle<JSFunction> GetCallTarget(FeedbackSlot slot);
69   Handle<AllocationSite> GetCallAllocationSite(FeedbackSlot slot);
70   Handle<JSFunction> GetCallNewTarget(FeedbackSlot slot);
71   Handle<AllocationSite> GetCallNewAllocationSite(FeedbackSlot slot);
72 
73   // TODO(1571) We can't use ToBooleanICStub::Types as the return value because
74   // of various cycles in our headers. Death to tons of implementations in
75   // headers!! :-P
76   uint16_t ToBooleanTypes(TypeFeedbackId id);
77 
78   // Get type information for arithmetic operations and compares.
79   void BinaryType(TypeFeedbackId id, FeedbackSlot slot, AstType** left,
80                   AstType** right, AstType** result,
81                   Maybe<int>* fixed_right_arg,
82                   Handle<AllocationSite>* allocation_site,
83                   Token::Value operation);
84 
85   void CompareType(TypeFeedbackId id, FeedbackSlot slot, AstType** left,
86                    AstType** right, AstType** combined);
87 
88   AstType* CountType(TypeFeedbackId id, FeedbackSlot slot);
89 
zone()90   Zone* zone() const { return zone_; }
isolate()91   Isolate* isolate() const { return isolate_; }
92 
93  private:
94   void CollectReceiverTypes(StubCache* stub_cache, FeedbackSlot slot,
95                             Handle<Name> name, SmallMapList* types);
96   void CollectReceiverTypes(StubCache* stub_cache, FeedbackNexus* nexus,
97                             Handle<Name> name, SmallMapList* types);
98 
99   // Returns true if there is at least one string map and if
100   // all maps are string maps.
101   bool HasOnlyStringMaps(SmallMapList* receiver_types);
102 
103   void SetInfo(TypeFeedbackId id, Object* target);
104 
105   void BuildDictionary(Handle<Code> code);
106   void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
107   void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
108   void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
109                           Code* old_code,
110                           Code* new_code);
111   void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
112 
113   // Returns an element from the backing store. Returns undefined if
114   // there is no information.
115   Handle<Object> GetInfo(TypeFeedbackId id);
116 
117   // Returns an element from the type feedback vector. Returns undefined
118   // if there is no information.
119   Handle<Object> GetInfo(FeedbackSlot slot);
120 
121  private:
122   Handle<Context> native_context_;
123   Isolate* isolate_;
124   Zone* zone_;
125   Handle<UnseededNumberDictionary> dictionary_;
126   Handle<FeedbackVector> feedback_vector_;
127 
128   DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
129 };
130 
131 }  // namespace internal
132 }  // namespace v8
133 
134 #endif  // V8_TYPE_INFO_H_
135