type-info.h 5.93 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

28 29
#ifndef V8_TYPE_INFO_H_
#define V8_TYPE_INFO_H_
30

31
#include "allocation.h"
32
#include "globals.h"
33
#include "types.h"
34
#include "zone-inl.h"
35

36 37 38
namespace v8 {
namespace internal {

39
// Forward declarations.
40
class ICStub;
41 42
class SmallMapList;

43

44
class TypeFeedbackOracle: public ZoneObject {
45
 public:
46
  TypeFeedbackOracle(Handle<Code> code,
47
                     Handle<Context> native_context,
48
                     Zone* zone);
49

50
  bool LoadIsUninitialized(TypeFeedbackId id);
51 52
  bool StoreIsUninitialized(TypeFeedbackId id);
  bool StoreIsKeyedPolymorphic(TypeFeedbackId id);
53
  bool CallIsMonomorphic(int slot);
54
  bool CallIsMonomorphic(TypeFeedbackId aid);
55 56
  bool KeyedArrayCallIsHoley(TypeFeedbackId id);
  bool CallNewIsMonomorphic(int slot);
57

58 59
  // TODO(1571) We can't use ForInStatement::ForInType as the return value due
  // to various cycles in our headers.
60 61
  // TODO(rossberg): once all oracle access is removed from ast.cc, it should
  // be possible.
62
  byte ForInType(int feedback_vector_slot);
63

64
  KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id);
65

66 67 68 69 70 71 72
  void PropertyReceiverTypes(TypeFeedbackId id,
                             Handle<String> name,
                             SmallMapList* receiver_types,
                             bool* is_prototype);
  void KeyedPropertyReceiverTypes(TypeFeedbackId id,
                                  SmallMapList* receiver_types,
                                  bool* is_string);
73 74 75 76 77 78
  void AssignmentReceiverTypes(TypeFeedbackId id,
                               Handle<String> name,
                               SmallMapList* receiver_types);
  void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
                                    SmallMapList* receiver_types,
                                    KeyedAccessStoreMode* store_mode);
79 80 81
  void CountReceiverTypes(TypeFeedbackId id,
                          SmallMapList* receiver_types);

82 83 84
  void CollectReceiverTypes(TypeFeedbackId id,
                            SmallMapList* types);

85
  static bool CanRetainOtherContext(Map* map, Context* native_context);
86
  static bool CanRetainOtherContext(JSFunction* function,
87
                                    Context* native_context);
88

89 90 91
  Handle<JSFunction> GetCallTarget(int slot);
  Handle<JSFunction> GetCallNewTarget(int slot);
  Handle<AllocationSite> GetCallNewAllocationSite(int slot);
92

93 94
  bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
  bool LoadIsStub(TypeFeedbackId id, ICStub* stub);
95

96
  // TODO(1571) We can't use ToBooleanStub::Types as the return value because
97
  // of various cycles in our headers. Death to tons of implementations in
98
  // headers!! :-P
99
  byte ToBooleanTypes(TypeFeedbackId id);
100

101
  // Get type information for arithmetic operations and compares.
102
  void BinaryType(TypeFeedbackId id,
103 104 105
                  Type** left,
                  Type** right,
                  Type** result,
106
                  Maybe<int>* fixed_right_arg,
107
                  Handle<AllocationSite>* allocation_site,
108
                  Token::Value operation);
109 110

  void CompareType(TypeFeedbackId id,
111 112 113
                   Type** left,
                   Type** right,
                   Type** combined);
114

115
  Type* CountType(TypeFeedbackId id);
116

117
  Zone* zone() const { return zone_; }
118
  Isolate* isolate() const { return zone_->isolate(); }
119

120
 private:
121
  void CollectReceiverTypes(TypeFeedbackId id,
122 123 124
                            Handle<String> name,
                            Code::Flags flags,
                            SmallMapList* types);
125

126
  void SetInfo(TypeFeedbackId id, Object* target);
127

128 129 130 131
  void BuildDictionary(Handle<Code> code);
  void GetRelocInfos(Handle<Code> code, ZoneList<RelocInfo>* infos);
  void CreateDictionary(Handle<Code> code, ZoneList<RelocInfo>* infos);
  void RelocateRelocInfos(ZoneList<RelocInfo>* infos,
132 133
                          Code* old_code,
                          Code* new_code);
134
  void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
135

136 137
  // Returns an element from the backing store. Returns undefined if
  // there is no information.
138
  Handle<Object> GetInfo(TypeFeedbackId id);
139

140 141 142 143
  // Returns an element from the type feedback vector. Returns undefined
  // if there is no information.
  Handle<Object> GetInfo(int slot);

144
 private:
145
  Handle<Context> native_context_;
146
  Zone* zone_;
147
  Handle<UnseededNumberDictionary> dictionary_;
148
  Handle<FixedArray> feedback_vector_;
149

150 151
  DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
};
152

153 154
} }  // namespace v8::internal

155
#endif  // V8_TYPE_INFO_H_