type-info.h 6.3 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 49
                     Isolate* isolate,
                     Zone* zone);
50

51 52
  bool LoadIsUninitialized(TypeFeedbackId id);
  bool LoadIsPreMonomorphic(TypeFeedbackId id);
53 54 55 56 57 58
  bool StoreIsUninitialized(TypeFeedbackId id);
  bool StoreIsPreMonomorphic(TypeFeedbackId id);
  bool StoreIsKeyedPolymorphic(TypeFeedbackId id);
  bool CallIsMonomorphic(TypeFeedbackId aid);
  bool KeyedArrayCallIsHoley(TypeFeedbackId id);
  bool CallNewIsMonomorphic(TypeFeedbackId id);
59

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

66
  KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id);
67

68
  void CallReceiverTypes(TypeFeedbackId id,
69
                         Handle<String> name,
70
                         int arity,
71
                         SmallMapList* types);
72 73 74 75 76 77 78
  void PropertyReceiverTypes(TypeFeedbackId id,
                             Handle<String> name,
                             SmallMapList* receiver_types,
                             bool* is_prototype);
  void KeyedPropertyReceiverTypes(TypeFeedbackId id,
                                  SmallMapList* receiver_types,
                                  bool* is_string);
79 80 81 82 83 84
  void AssignmentReceiverTypes(TypeFeedbackId id,
                               Handle<String> name,
                               SmallMapList* receiver_types);
  void KeyedAssignmentReceiverTypes(TypeFeedbackId id,
                                    SmallMapList* receiver_types,
                                    KeyedAccessStoreMode* store_mode);
85 86 87
  void CountReceiverTypes(TypeFeedbackId id,
                          SmallMapList* receiver_types);

88 89 90
  void CollectReceiverTypes(TypeFeedbackId id,
                            SmallMapList* types);

91
  static bool CanRetainOtherContext(Map* map, Context* native_context);
92
  static bool CanRetainOtherContext(JSFunction* function,
93
                                    Context* native_context);
94

95 96 97 98
  CheckType GetCallCheckType(TypeFeedbackId id);
  Handle<JSFunction> GetCallTarget(TypeFeedbackId id);
  Handle<JSFunction> GetCallNewTarget(TypeFeedbackId id);
  Handle<Cell> GetCallNewAllocationInfoCell(TypeFeedbackId id);
99

100 101
  bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id);
  bool LoadIsStub(TypeFeedbackId id, ICStub* stub);
102

103
  // TODO(1571) We can't use ToBooleanStub::Types as the return value because
104
  // of various cycles in our headers. Death to tons of implementations in
105
  // headers!! :-P
106
  byte ToBooleanTypes(TypeFeedbackId id);
107

108
  // Get type information for arithmetic operations and compares.
109 110 111 112
  void BinaryType(TypeFeedbackId id,
                  Handle<Type>* left,
                  Handle<Type>* right,
                  Handle<Type>* result,
113
                  Maybe<int>* fixed_right_arg,
114
                  Handle<AllocationSite>* allocation_site,
115
                  Token::Value operation);
116 117

  void CompareType(TypeFeedbackId id,
118 119 120
                   Handle<Type>* left,
                   Handle<Type>* right,
                   Handle<Type>* combined);
121

122
  Handle<Type> CountType(TypeFeedbackId id);
123

124
  Zone* zone() const { return zone_; }
125
  Isolate* isolate() const { return isolate_; }
126

127
 private:
128
  void CollectReceiverTypes(TypeFeedbackId id,
129 130 131
                            Handle<String> name,
                            Code::Flags flags,
                            SmallMapList* types);
132

133
  void SetInfo(TypeFeedbackId id, Object* target);
134

135 136 137 138 139 140 141
  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,
                          byte* old_start,
                          byte* new_start);
  void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
142
  void ProcessTypeFeedbackCells(Handle<Code> code);
143

144 145
  // Returns an element from the backing store. Returns undefined if
  // there is no information.
146
  Handle<Object> GetInfo(TypeFeedbackId id);
147

148
  // Return the cell that contains type feedback.
149
  Handle<Cell> GetInfoCell(TypeFeedbackId id);
150

151
 private:
152
  Handle<Context> native_context_;
153
  Isolate* isolate_;
154
  Zone* zone_;
155
  Handle<UnseededNumberDictionary> dictionary_;
156

157 158
  DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
};
159

160 161
} }  // namespace v8::internal

162
#endif  // V8_TYPE_INFO_H_