Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_TYPE_INFO_H_ |
| 6 | #define V8_TYPE_INFO_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 8 | #include "src/allocation.h" |
| 9 | #include "src/globals.h" |
| 10 | #include "src/types.h" |
| 11 | #include "src/zone-inl.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 16 | // Forward declarations. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 17 | class SmallMapList; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 18 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 19 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 20 | class TypeFeedbackOracle: public ZoneObject { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 21 | public: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 22 | TypeFeedbackOracle(Handle<Code> code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 23 | Handle<TypeFeedbackVector> feedback_vector, |
| 24 | Handle<Context> native_context, Zone* zone); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 25 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 33 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 39 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 40 | KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 41 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 55 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 56 | void CollectReceiverTypes(TypeFeedbackId id, |
| 57 | SmallMapList* types); |
| 58 | |
| 59 | static bool CanRetainOtherContext(Map* map, Context* native_context); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 60 | static bool CanRetainOtherContext(JSFunction* function, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 61 | Context* native_context); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 63 | Handle<JSFunction> GetCallTarget(int slot); |
| 64 | Handle<AllocationSite> GetCallAllocationSite(int slot); |
| 65 | Handle<JSFunction> GetCallNewTarget(int slot); |
| 66 | Handle<AllocationSite> GetCallNewAllocationSite(int slot); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 67 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 68 | bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 69 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 70 | // TODO(1571) We can't use ToBooleanStub::Types as the return value because |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 71 | // of various cycles in our headers. Death to tons of implementations in |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 72 | // headers!! :-P |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 73 | byte ToBooleanTypes(TypeFeedbackId id); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 74 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 75 | // Get type information for arithmetic operations and compares. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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(); } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 93 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 94 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 95 | void CollectReceiverTypes(TypeFeedbackId id, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 96 | Handle<String> name, |
| 97 | Code::Flags flags, |
| 98 | SmallMapList* types); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 99 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 100 | void SetInfo(TypeFeedbackId id, Object* target); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 101 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 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, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 106 | Code* old_code, |
| 107 | Code* new_code); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 108 | void ProcessRelocInfos(ZoneList<RelocInfo>* infos); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 109 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 110 | // Returns an element from the backing store. Returns undefined if |
| 111 | // there is no information. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 112 | Handle<Object> GetInfo(TypeFeedbackId id); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 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_; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 121 | Handle<UnseededNumberDictionary> dictionary_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 122 | Handle<TypeFeedbackVector> feedback_vector_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 123 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 124 | DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); |
| 125 | }; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 126 | |
| 127 | } } // namespace v8::internal |
| 128 | |
| 129 | #endif // V8_TYPE_INFO_H_ |