v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocation-tracker.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ALLOCATION_TRACKER_H_
29 #define V8_ALLOCATION_TRACKER_H_
30 
31 #include <map>
32 
33 namespace v8 {
34 namespace internal {
35 
36 class HeapObjectsMap;
37 
38 class AllocationTraceTree;
39 
41  public:
43  unsigned function_info_index);
45  AllocationTraceNode* FindChild(unsigned function_info_index);
46  AllocationTraceNode* FindOrAddChild(unsigned function_info_index);
47  void AddAllocation(unsigned size);
48 
49  unsigned function_info_index() const { return function_info_index_; }
50  unsigned allocation_size() const { return total_size_; }
51  unsigned allocation_count() const { return allocation_count_; }
52  unsigned id() const { return id_; }
53  Vector<AllocationTraceNode*> children() const { return children_.ToVector(); }
54 
55  void Print(int indent, AllocationTracker* tracker);
56 
57  private:
58  AllocationTraceTree* tree_;
59  unsigned function_info_index_;
60  unsigned total_size_;
61  unsigned allocation_count_;
62  unsigned id_;
64 
65  DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode);
66 };
67 
68 
70  public:
74  AllocationTraceNode* root() { return &root_; }
75  unsigned next_node_id() { return next_node_id_++; }
76  void Print(AllocationTracker* tracker);
77 
78  private:
79  unsigned next_node_id_;
80  AllocationTraceNode root_;
81 
82  DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree);
83 };
84 
85 
87  public:
88  void AddRange(Address addr, int size, unsigned node_id);
89  unsigned GetTraceNodeId(Address addr);
90  void MoveObject(Address from, Address to, int size);
91  void Clear();
92  size_t size() { return ranges_.size(); }
93  void Print();
94 
95  private:
96  struct RangeStack {
97  RangeStack(Address start, unsigned node_id)
98  : start(start), trace_node_id(node_id) {}
99  Address start;
100  unsigned trace_node_id;
101  };
102  // [start, end) -> trace
103  typedef std::map<Address, RangeStack> RangeMap;
104 
105  void RemoveRange(Address start, Address end);
106 
107  RangeMap ranges_;
108 };
109 
111  public:
112  struct FunctionInfo {
113  FunctionInfo();
114  const char* name;
116  const char* script_name;
118  int line;
119  int column;
120  };
121 
124 
126  void AllocationEvent(Address addr, int size);
127 
128  AllocationTraceTree* trace_tree() { return &trace_tree_; }
130  return function_info_list_;
131  }
132  AddressToTraceMap* address_to_trace() { return &address_to_trace_; }
133 
134  private:
135  unsigned AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id);
136  static void DeleteFunctionInfo(FunctionInfo** info);
137  unsigned functionInfoIndexForVMState(StateTag state);
138 
139  class UnresolvedLocation {
140  public:
141  UnresolvedLocation(Script* script, int start, FunctionInfo* info);
142  ~UnresolvedLocation();
143  void Resolve();
144 
145  private:
146  static void HandleWeakScript(
148 
149  Handle<Script> script_;
150  int start_position_;
151  FunctionInfo* info_;
152  };
153  static void DeleteUnresolvedLocation(UnresolvedLocation** location);
154 
155  static const int kMaxAllocationTraceLength = 64;
156  HeapObjectsMap* ids_;
157  StringsStorage* names_;
158  AllocationTraceTree trace_tree_;
159  unsigned allocation_trace_buffer_[kMaxAllocationTraceLength];
160  List<FunctionInfo*> function_info_list_;
161  HashMap id_to_function_info_index_;
162  List<UnresolvedLocation*> unresolved_locations_;
163  unsigned info_index_for_other_state_;
164  AddressToTraceMap address_to_trace_;
165 
166  DISALLOW_COPY_AND_ASSIGN(AllocationTracker);
167 };
168 
169 } } // namespace v8::internal
170 
171 #endif // V8_ALLOCATION_TRACKER_H_
byte * Address
Definition: globals.h:186
void Print(AllocationTracker *tracker)
AllocationTraceNode * FindChild(unsigned function_info_index)
void AddRange(Address addr, int size, unsigned node_id)
AddressToTraceMap * address_to_trace()
AllocationTraceNode * AddPathFromEnd(const Vector< unsigned > &path)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
Definition: flags.cc:211
Vector< AllocationTraceNode * > children() const
AllocationTraceNode * FindOrAddChild(unsigned function_info_index)
unsigned GetTraceNodeId(Address addr)
void AllocationEvent(Address addr, int size)
const List< FunctionInfo * > & function_info_list() const
AllocationTraceTree * trace_tree()
AllocationTracker(HeapObjectsMap *ids, StringsStorage *names)
void MoveObject(Address from, Address to, int size)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
Definition: flags.cc:317
uint32_t SnapshotObjectId
Definition: v8-profiler.h:39
TemplateHashMapImpl< FreeStoreAllocationPolicy > HashMap
Definition: hashmap.h:113
void Print(int indent, AllocationTracker *tracker)
AllocationTraceNode(AllocationTraceTree *tree, unsigned function_info_index)