type-info.h 5.22 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_TYPE_INFO_H_
#define V8_TYPE_INFO_H_
7

8
#include "src/allocation.h"
9
#include "src/ast/ast-types.h"
10
#include "src/contexts.h"
11
#include "src/globals.h"
12
#include "src/parsing/token.h"
13
#include "src/zone/zone.h"
14

15 16 17
namespace v8 {
namespace internal {

18
// Forward declarations.
19
class SmallMapList;
verwaest's avatar
verwaest committed
20
class FeedbackNexus;
21
class StubCache;
22

23
class TypeFeedbackOracle: public ZoneObject {
24
 public:
25
  TypeFeedbackOracle(Isolate* isolate, Zone* zone, Handle<Code> code,
26
                     Handle<TypeFeedbackVector> feedback_vector,
27
                     Handle<Context> native_context);
28

29 30 31 32
  InlineCacheState LoadInlineCacheState(FeedbackVectorSlot slot);
  bool StoreIsUninitialized(FeedbackVectorSlot slot);
  bool CallIsUninitialized(FeedbackVectorSlot slot);
  bool CallIsMonomorphic(FeedbackVectorSlot slot);
33
  bool CallNewIsMonomorphic(FeedbackVectorSlot slot);
34

35 36
  // TODO(1571) We can't use ForInStatement::ForInType as the return value due
  // to various cycles in our headers.
37 38
  // TODO(rossberg): once all oracle access is removed from ast.cc, it should
  // be possible.
39
  byte ForInType(FeedbackVectorSlot feedback_vector_slot);
40

41
  void GetStoreModeAndKeyType(FeedbackVectorSlot slot,
42 43
                              KeyedAccessStoreMode* store_mode,
                              IcCheckType* key_type);
44

45
  void PropertyReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
46
                             SmallMapList* receiver_types);
47
  void KeyedPropertyReceiverTypes(FeedbackVectorSlot slot,
48 49
                                  SmallMapList* receiver_types, bool* is_string,
                                  IcCheckType* key_type);
50
  void AssignmentReceiverTypes(FeedbackVectorSlot slot, Handle<Name> name,
51
                               SmallMapList* receiver_types);
52
  void KeyedAssignmentReceiverTypes(FeedbackVectorSlot slot,
53 54 55
                                    SmallMapList* receiver_types,
                                    KeyedAccessStoreMode* store_mode,
                                    IcCheckType* key_type);
56
  void CountReceiverTypes(FeedbackVectorSlot slot,
57
                          SmallMapList* receiver_types);
58

59
  void CollectReceiverTypes(FeedbackVectorSlot slot, SmallMapList* types);
verwaest's avatar
verwaest committed
60
  void CollectReceiverTypes(FeedbackNexus* nexus, SmallMapList* types);
61

62 63 64 65 66 67
  static bool IsRelevantFeedback(Map* map, Context* native_context) {
    Object* constructor = map->GetConstructor();
    return !constructor->IsJSFunction() ||
           JSFunction::cast(constructor)->context()->native_context() ==
               native_context;
  }
68

69 70
  Handle<JSFunction> GetCallTarget(FeedbackVectorSlot slot);
  Handle<AllocationSite> GetCallAllocationSite(FeedbackVectorSlot slot);
71 72
  Handle<JSFunction> GetCallNewTarget(FeedbackVectorSlot slot);
  Handle<AllocationSite> GetCallNewAllocationSite(FeedbackVectorSlot slot);
73

74
  // TODO(1571) We can't use ToBooleanICStub::Types as the return value because
75
  // of various cycles in our headers. Death to tons of implementations in
76
  // headers!! :-P
77
  uint16_t ToBooleanTypes(TypeFeedbackId id);
78

79
  // Get type information for arithmetic operations and compares.
80 81 82
  void BinaryType(TypeFeedbackId id, FeedbackVectorSlot slot, AstType** left,
                  AstType** right, AstType** result,
                  Maybe<int>* fixed_right_arg,
83
                  Handle<AllocationSite>* allocation_site,
84
                  Token::Value operation);
85

86 87
  void CompareType(TypeFeedbackId id, FeedbackVectorSlot slot, AstType** left,
                   AstType** right, AstType** combined);
88

89
  AstType* CountType(TypeFeedbackId id, FeedbackVectorSlot slot);
90

91
  Zone* zone() const { return zone_; }
92
  Isolate* isolate() const { return isolate_; }
93

94
 private:
95
  void CollectReceiverTypes(StubCache* stub_cache, FeedbackVectorSlot slot,
96
                            Handle<Name> name, SmallMapList* types);
97
  void CollectReceiverTypes(StubCache* stub_cache, FeedbackNexus* nexus,
98
                            Handle<Name> name, SmallMapList* types);
99 100 101 102

  // Returns true if there is at least one string map and if
  // all maps are string maps.
  bool HasOnlyStringMaps(SmallMapList* receiver_types);
103

104
  void SetInfo(TypeFeedbackId id, Object* target);
105

106 107 108 109
  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,
110 111
                          Code* old_code,
                          Code* new_code);
112
  void ProcessRelocInfos(ZoneList<RelocInfo>* infos);
113

114 115
  // Returns an element from the backing store. Returns undefined if
  // there is no information.
116
  Handle<Object> GetInfo(TypeFeedbackId id);
117

118 119
  // Returns an element from the type feedback vector. Returns undefined
  // if there is no information.
120
  Handle<Object> GetInfo(FeedbackVectorSlot slot);
121

122
 private:
123
  Handle<Context> native_context_;
124
  Isolate* isolate_;
125
  Zone* zone_;
126
  Handle<UnseededNumberDictionary> dictionary_;
127
  Handle<TypeFeedbackVector> feedback_vector_;
128

129 130
  DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
};
131

132 133
}  // namespace internal
}  // namespace v8
134

135
#endif  // V8_TYPE_INFO_H_