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" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/contexts.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/globals.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | #include "src/parsing/token.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | #include "src/types.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/zone.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 18 | // Forward declarations. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 19 | class SmallMapList; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 20 | class FeedbackNexus; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 21 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | class TypeFeedbackOracle: public ZoneObject { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 23 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | Handle<TypeFeedbackVector> feedback_vector, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | Handle<Context> native_context); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 27 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | InlineCacheState LoadInlineCacheState(FeedbackVectorSlot slot); |
| 29 | bool StoreIsUninitialized(FeedbackVectorSlot slot); |
| 30 | bool CallIsUninitialized(FeedbackVectorSlot slot); |
| 31 | bool CallIsMonomorphic(FeedbackVectorSlot slot); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 32 | bool CallNewIsMonomorphic(FeedbackVectorSlot 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. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 38 | byte ForInType(FeedbackVectorSlot feedback_vector_slot); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 39 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 40 | void GetStoreModeAndKeyType(FeedbackVectorSlot slot, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | KeyedAccessStoreMode* store_mode, |
| 42 | IcCheckType* key_type); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 43 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | void PropertyReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | SmallMapList* receiver_types); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | void KeyedPropertyReceiverTypes(FeedbackVectorSlot slot, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 47 | SmallMapList* receiver_types, bool* is_string, |
| 48 | IcCheckType* key_type); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | void AssignmentReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | SmallMapList* receiver_types); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | void KeyedAssignmentReceiverTypes(FeedbackVectorSlot slot, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | SmallMapList* receiver_types, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 53 | KeyedAccessStoreMode* store_mode, |
| 54 | IcCheckType* key_type); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | void CountReceiverTypes(FeedbackVectorSlot slot, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | SmallMapList* receiver_types); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 57 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | void CollectReceiverTypes(FeedbackVectorSlot slot, SmallMapList* types); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 59 | void CollectReceiverTypes(FeedbackNexus* nexus, SmallMapList* types); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 67 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | Handle<JSFunction> GetCallTarget(FeedbackVectorSlot slot); |
| 69 | Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorSlot slot); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 70 | Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot); |
| 71 | Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 72 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 73 | // TODO(1571) We can't use ToBooleanICStub::Types as the return value because |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | // of various cycles in our headers. Death to tons of implementations in |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 75 | // headers!! :-P |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | uint16_t ToBooleanTypes(TypeFeedbackId id); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 77 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 78 | // Get type information for arithmetic operations and compares. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | void BinaryType(TypeFeedbackId id, |
| 80 | Type** left, |
| 81 | Type** right, |
| 82 | Type** result, |
| 83 | Maybe<int>* fixed_right_arg, |
| 84 | Handle<AllocationSite>* allocation_site, |
| 85 | Token::Value operation); |
| 86 | |
| 87 | void CompareType(TypeFeedbackId id, |
| 88 | Type** left, |
| 89 | Type** right, |
| 90 | Type** combined); |
| 91 | |
| 92 | Type* CountType(TypeFeedbackId id); |
| 93 | |
| 94 | Zone* zone() const { return zone_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | Isolate* isolate() const { return isolate_; } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 96 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 97 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 | void CollectReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name, |
| 99 | Code::Flags flags, SmallMapList* types); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 100 | void CollectReceiverTypes(FeedbackNexus* nexus, Handle<Name> name, |
| 101 | Code::Flags flags, SmallMapList* types); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 102 | |
| 103 | // Returns true if there is at least one string map and if |
| 104 | // all maps are string maps. |
| 105 | bool HasOnlyStringMaps(SmallMapList* receiver_types); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | void SetInfo(TypeFeedbackId id, Object* target); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 108 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 109 | void BuildDictionary(Handle<Code> code); |
| 110 | void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos); |
| 111 | void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos); |
| 112 | void RelocateRelocInfos(ZoneList<RelocInfo>* infos, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | Code* old_code, |
| 114 | Code* new_code); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 115 | void ProcessRelocInfos(ZoneList<RelocInfo>* infos); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 116 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 117 | // Returns an element from the backing store. Returns undefined if |
| 118 | // there is no information. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 119 | Handle<Object> GetInfo(TypeFeedbackId id); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 120 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 121 | // Returns an element from the type feedback vector. Returns undefined |
| 122 | // if there is no information. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 123 | Handle<Object> GetInfo(FeedbackVectorSlot slot); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | |
| 125 | private: |
| 126 | Handle<Context> native_context_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | Isolate* isolate_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | Zone* zone_; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 129 | Handle<UnseededNumberDictionary> dictionary_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | Handle<TypeFeedbackVector> feedback_vector_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 131 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 132 | DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); |
| 133 | }; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 134 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 135 | } // namespace internal |
| 136 | } // namespace v8 |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 137 | |
| 138 | #endif // V8_TYPE_INFO_H_ |