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.
5 #ifndef V8_TYPE_INFO_H_
6 #define V8_TYPE_INFO_H_
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"
18 // Forward declarations.
22 class TypeFeedbackOracle: public ZoneObject {
24 TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
25 Handle<TypeFeedbackVector> feedback_vector,
26 Handle<Context> native_context);
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);
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
41 byte ForInType(FeedbackVectorSlot feedback_vector_slot);
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);
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);
72 void CollectReceiverTypes(FeedbackVectorICSlot slot, SmallMapList* types);
73 void CollectReceiverTypes(TypeFeedbackId id,
76 void CollectReceiverTypes(T* obj, SmallMapList* types);
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() ==
85 Handle<JSFunction> GetCallTarget(FeedbackVectorICSlot slot);
86 Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorICSlot slot);
87 Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
88 Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
90 bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
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
95 uint16_t ToBooleanTypes(TypeFeedbackId id);
97 // Get type information for arithmetic operations and compares.
98 void BinaryType(TypeFeedbackId id,
102 Maybe<int>* fixed_right_arg,
103 Handle<AllocationSite>* allocation_site,
104 Token::Value operation);
106 void CompareType(TypeFeedbackId id,
111 Type* CountType(TypeFeedbackId id);
113 Zone* zone() const { return zone_; }
114 Isolate* isolate() const { return isolate_; }
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);
122 void CollectReceiverTypes(T* obj, Handle<Name> name, Code::Flags flags,
123 SmallMapList* types);
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);
129 void SetInfo(TypeFeedbackId id, Object* target);
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,
137 void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
139 // Returns an element from the backing store. Returns undefined if
140 // there is no information.
141 Handle<Object> GetInfo(TypeFeedbackId id);
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);
149 Handle<Context> native_context_;
152 Handle<UnseededNumberDictionary> dictionary_;
153 Handle<TypeFeedbackVector> feedback_vector_;
155 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
158 } } // namespace v8::internal
160 #endif // V8_TYPE_INFO_H_