blob: 3c734be0cdb28759f5f23ff86e945445f28a2c26 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Block6ded16b2010-05-10 14:33:55 +01004
5#ifndef V8_TYPE_INFO_H_
6#define V8_TYPE_INFO_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/allocation.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/contexts.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/globals.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include "src/parsing/token.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012#include "src/types.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/zone.h"
Steve Block6ded16b2010-05-10 14:33:55 +010014
15namespace v8 {
16namespace internal {
17
Ben Murdochb0fe1622011-05-05 13:52:32 +010018// Forward declarations.
Ben Murdoch69a99ed2011-11-30 16:03:39 +000019class SmallMapList;
Ben Murdochc5610432016-08-08 18:44:38 +010020class FeedbackNexus;
Steve Block6ded16b2010-05-10 14:33:55 +010021
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022class TypeFeedbackOracle: public ZoneObject {
Ben Murdochb0fe1622011-05-05 13:52:32 +010023 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024 TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025 Handle<TypeFeedbackVector> feedback_vector,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 Handle<Context> native_context);
Steve Block6ded16b2010-05-10 14:33:55 +010027
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028 InlineCacheState LoadInlineCacheState(FeedbackVectorSlot slot);
29 bool StoreIsUninitialized(FeedbackVectorSlot slot);
30 bool CallIsUninitialized(FeedbackVectorSlot slot);
31 bool CallIsMonomorphic(FeedbackVectorSlot slot);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040032 bool CallNewIsMonomorphic(FeedbackVectorSlot slot);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010033
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 // 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 Bernierd0a1eb72015-03-24 16:35:39 -040038 byte ForInType(FeedbackVectorSlot feedback_vector_slot);
Steve Block6ded16b2010-05-10 14:33:55 +010039
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040 void GetStoreModeAndKeyType(FeedbackVectorSlot slot,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040041 KeyedAccessStoreMode* store_mode,
42 IcCheckType* key_type);
Steve Block6ded16b2010-05-10 14:33:55 +010043
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044 void PropertyReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 SmallMapList* receiver_types);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046 void KeyedPropertyReceiverTypes(FeedbackVectorSlot slot,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040047 SmallMapList* receiver_types, bool* is_string,
48 IcCheckType* key_type);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 void AssignmentReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 SmallMapList* receiver_types);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051 void KeyedAssignmentReceiverTypes(FeedbackVectorSlot slot,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052 SmallMapList* receiver_types,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040053 KeyedAccessStoreMode* store_mode,
54 IcCheckType* key_type);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055 void CountReceiverTypes(FeedbackVectorSlot slot,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 SmallMapList* receiver_types);
Steve Block44f0eee2011-05-26 01:26:41 +010057
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 void CollectReceiverTypes(FeedbackVectorSlot slot, SmallMapList* types);
Ben Murdochc5610432016-08-08 18:44:38 +010059 void CollectReceiverTypes(FeedbackNexus* nexus, SmallMapList* types);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000061 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 Murdoch3ef787d2012-04-12 10:51:47 +010067
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068 Handle<JSFunction> GetCallTarget(FeedbackVectorSlot slot);
69 Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorSlot slot);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070 Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
71 Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
Ben Murdochb8e0da22011-05-16 14:20:40 +010072
Ben Murdochda12d292016-06-02 14:46:10 +010073 // TODO(1571) We can't use ToBooleanICStub::Types as the return value because
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 // of various cycles in our headers. Death to tons of implementations in
Ben Murdoch69a99ed2011-11-30 16:03:39 +000075 // headers!! :-P
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 uint16_t ToBooleanTypes(TypeFeedbackId id);
Ben Murdoch69a99ed2011-11-30 16:03:39 +000077
Ben Murdochb0fe1622011-05-05 13:52:32 +010078 // Get type information for arithmetic operations and compares.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 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 Murdoch4a90d5f2016-03-22 12:00:34 +000095 Isolate* isolate() const { return isolate_; }
Steve Block6ded16b2010-05-10 14:33:55 +010096
Ben Murdochb0fe1622011-05-05 13:52:32 +010097 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098 void CollectReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
99 Code::Flags flags, SmallMapList* types);
Ben Murdochc5610432016-08-08 18:44:38 +0100100 void CollectReceiverTypes(FeedbackNexus* nexus, Handle<Name> name,
101 Code::Flags flags, SmallMapList* types);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102
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 Block6ded16b2010-05-10 14:33:55 +0100106
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 void SetInfo(TypeFeedbackId id, Object* target);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100108
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000109 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 Murdochb8a8cc12014-11-26 15:28:44 +0000113 Code* old_code,
114 Code* new_code);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000115 void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
Steve Block6ded16b2010-05-10 14:33:55 +0100116
Steve Block44f0eee2011-05-26 01:26:41 +0100117 // Returns an element from the backing store. Returns undefined if
118 // there is no information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000119 Handle<Object> GetInfo(TypeFeedbackId id);
Steve Block44f0eee2011-05-26 01:26:41 +0100120
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000121 // Returns an element from the type feedback vector. Returns undefined
122 // if there is no information.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123 Handle<Object> GetInfo(FeedbackVectorSlot slot);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124
125 private:
126 Handle<Context> native_context_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 Isolate* isolate_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 Zone* zone_;
Ben Murdochc7cc0282012-03-05 14:35:55 +0000129 Handle<UnseededNumberDictionary> dictionary_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130 Handle<TypeFeedbackVector> feedback_vector_;
Steve Block6ded16b2010-05-10 14:33:55 +0100131
Ben Murdochb0fe1622011-05-05 13:52:32 +0100132 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
133};
Steve Block6ded16b2010-05-10 14:33:55 +0100134
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000135} // namespace internal
136} // namespace v8
Steve Block6ded16b2010-05-10 14:33:55 +0100137
138#endif // V8_TYPE_INFO_H_