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/globals.h"
10 #include "src/types.h"
16 // Forward declarations.
20 class TypeFeedbackOracle: public ZoneObject {
22 TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
23 Handle<TypeFeedbackVector> feedback_vector,
24 Handle<Context> native_context);
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);
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
38 byte ForInType(FeedbackVectorSlot feedback_vector_slot);
40 void GetStoreModeAndKeyType(TypeFeedbackId id,
41 KeyedAccessStoreMode* store_mode,
42 IcCheckType* key_type);
43 void GetLoadKeyType(TypeFeedbackId id, IcCheckType* key_type);
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,
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,
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);
66 void CollectReceiverTypes(TypeFeedbackId id,
69 void CollectReceiverTypes(T* obj, SmallMapList* types);
71 static bool CanRetainOtherContext(Map* map, Context* native_context);
72 static bool CanRetainOtherContext(JSFunction* function,
73 Context* native_context);
75 Handle<JSFunction> GetCallTarget(FeedbackVectorICSlot slot);
76 Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorICSlot slot);
77 Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
78 Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
80 bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
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
85 byte ToBooleanTypes(TypeFeedbackId id);
87 // Get type information for arithmetic operations and compares.
88 void BinaryType(TypeFeedbackId id,
92 Maybe<int>* fixed_right_arg,
93 Handle<AllocationSite>* allocation_site,
94 Token::Value operation);
96 void CompareType(TypeFeedbackId id,
101 Type* CountType(TypeFeedbackId id);
103 Zone* zone() const { return zone_; }
104 Isolate* isolate() const { return isolate_; }
107 void CollectReceiverTypes(TypeFeedbackId id,
110 SmallMapList* types);
112 void CollectReceiverTypes(T* obj, Handle<String> name, Code::Flags flags,
113 SmallMapList* types);
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);
119 void SetInfo(TypeFeedbackId id, Object* target);
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,
127 void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
129 // Returns an element from the backing store. Returns undefined if
130 // there is no information.
131 Handle<Object> GetInfo(TypeFeedbackId id);
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);
139 Handle<Context> native_context_;
142 Handle<UnseededNumberDictionary> dictionary_;
143 Handle<TypeFeedbackVector> feedback_vector_;
145 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
148 } } // namespace v8::internal
150 #endif // V8_TYPE_INFO_H_