blob: 434ddd675983b6457aa325b0bb3d2f9e2ae41560 [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"
9#include "src/globals.h"
10#include "src/types.h"
11#include "src/zone-inl.h"
Steve Block6ded16b2010-05-10 14:33:55 +010012
13namespace v8 {
14namespace internal {
15
Ben Murdochb0fe1622011-05-05 13:52:32 +010016// Forward declarations.
Ben Murdoch69a99ed2011-11-30 16:03:39 +000017class SmallMapList;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000018
Steve Block6ded16b2010-05-10 14:33:55 +010019
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020class TypeFeedbackOracle: public ZoneObject {
Ben Murdochb0fe1622011-05-05 13:52:32 +010021 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +010022 TypeFeedbackOracle(Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000023 Handle<TypeFeedbackVector> feedback_vector,
24 Handle<Context> native_context, Zone* zone);
Steve Block6ded16b2010-05-10 14:33:55 +010025
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026 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 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.
38 byte ForInType(int feedback_vector_slot);
Steve Block6ded16b2010-05-10 14:33:55 +010039
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040 KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id);
Steve Block6ded16b2010-05-10 14:33:55 +010041
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 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 Block44f0eee2011-05-26 01:26:41 +010055
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 void CollectReceiverTypes(TypeFeedbackId id,
57 SmallMapList* types);
58
59 static bool CanRetainOtherContext(Map* map, Context* native_context);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010060 static bool CanRetainOtherContext(JSFunction* function,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 Context* native_context);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010062
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 Handle<JSFunction> GetCallTarget(int slot);
64 Handle<AllocationSite> GetCallAllocationSite(int slot);
65 Handle<JSFunction> GetCallNewTarget(int slot);
66 Handle<AllocationSite> GetCallNewAllocationSite(int slot);
Ben Murdochb8e0da22011-05-16 14:20:40 +010067
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
Steve Block6ded16b2010-05-10 14:33:55 +010069
Ben Murdoch69a99ed2011-11-30 16:03:39 +000070 // TODO(1571) We can't use ToBooleanStub::Types as the return value because
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 // of various cycles in our headers. Death to tons of implementations in
Ben Murdoch69a99ed2011-11-30 16:03:39 +000072 // headers!! :-P
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073 byte ToBooleanTypes(TypeFeedbackId id);
Ben Murdoch69a99ed2011-11-30 16:03:39 +000074
Ben Murdochb0fe1622011-05-05 13:52:32 +010075 // Get type information for arithmetic operations and compares.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076 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 Block6ded16b2010-05-10 14:33:55 +010093
Ben Murdochb0fe1622011-05-05 13:52:32 +010094 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 void CollectReceiverTypes(TypeFeedbackId id,
Ben Murdoch69a99ed2011-11-30 16:03:39 +000096 Handle<String> name,
97 Code::Flags flags,
98 SmallMapList* types);
Steve Block6ded16b2010-05-10 14:33:55 +010099
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100 void SetInfo(TypeFeedbackId id, Object* target);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100101
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000102 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 Murdochb8a8cc12014-11-26 15:28:44 +0000106 Code* old_code,
107 Code* new_code);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000108 void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
Steve Block6ded16b2010-05-10 14:33:55 +0100109
Steve Block44f0eee2011-05-26 01:26:41 +0100110 // Returns an element from the backing store. Returns undefined if
111 // there is no information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112 Handle<Object> GetInfo(TypeFeedbackId id);
Steve Block44f0eee2011-05-26 01:26:41 +0100113
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114 // 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 Murdochc7cc0282012-03-05 14:35:55 +0000121 Handle<UnseededNumberDictionary> dictionary_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 Handle<TypeFeedbackVector> feedback_vector_;
Steve Block6ded16b2010-05-10 14:33:55 +0100123
Ben Murdochb0fe1622011-05-05 13:52:32 +0100124 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
125};
Steve Block6ded16b2010-05-10 14:33:55 +0100126
127} } // namespace v8::internal
128
129#endif // V8_TYPE_INFO_H_