2013-11-14 12:13:26 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2013-11-14 12:13:26 +00:00
|
|
|
|
|
|
|
#ifndef V8_ALLOCATION_TRACKER_H_
|
|
|
|
#define V8_ALLOCATION_TRACKER_H_
|
|
|
|
|
2014-03-07 16:13:22 +00:00
|
|
|
#include <map>
|
|
|
|
|
2013-11-14 12:13:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class HeapObjectsMap;
|
|
|
|
|
|
|
|
class AllocationTraceTree;
|
|
|
|
|
|
|
|
class AllocationTraceNode {
|
|
|
|
public:
|
|
|
|
AllocationTraceNode(AllocationTraceTree* tree,
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned function_info_index);
|
2013-11-14 12:13:26 +00:00
|
|
|
~AllocationTraceNode();
|
2014-03-07 11:32:01 +00:00
|
|
|
AllocationTraceNode* FindChild(unsigned function_info_index);
|
|
|
|
AllocationTraceNode* FindOrAddChild(unsigned function_info_index);
|
2013-11-14 12:13:26 +00:00
|
|
|
void AddAllocation(unsigned size);
|
|
|
|
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned function_info_index() const { return function_info_index_; }
|
2013-11-14 12:13:26 +00:00
|
|
|
unsigned allocation_size() const { return total_size_; }
|
|
|
|
unsigned allocation_count() const { return allocation_count_; }
|
|
|
|
unsigned id() const { return id_; }
|
|
|
|
Vector<AllocationTraceNode*> children() const { return children_.ToVector(); }
|
|
|
|
|
|
|
|
void Print(int indent, AllocationTracker* tracker);
|
|
|
|
|
|
|
|
private:
|
|
|
|
AllocationTraceTree* tree_;
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned function_info_index_;
|
2013-11-14 12:13:26 +00:00
|
|
|
unsigned total_size_;
|
|
|
|
unsigned allocation_count_;
|
|
|
|
unsigned id_;
|
|
|
|
List<AllocationTraceNode*> children_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AllocationTraceNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AllocationTraceTree {
|
|
|
|
public:
|
|
|
|
AllocationTraceTree();
|
|
|
|
~AllocationTraceTree();
|
2014-03-07 11:32:01 +00:00
|
|
|
AllocationTraceNode* AddPathFromEnd(const Vector<unsigned>& path);
|
2013-11-14 12:13:26 +00:00
|
|
|
AllocationTraceNode* root() { return &root_; }
|
|
|
|
unsigned next_node_id() { return next_node_id_++; }
|
|
|
|
void Print(AllocationTracker* tracker);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned next_node_id_;
|
|
|
|
AllocationTraceNode root_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AllocationTraceTree);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-07 16:13:22 +00:00
|
|
|
class AddressToTraceMap {
|
|
|
|
public:
|
|
|
|
void AddRange(Address addr, int size, unsigned node_id);
|
|
|
|
unsigned GetTraceNodeId(Address addr);
|
|
|
|
void MoveObject(Address from, Address to, int size);
|
|
|
|
void Clear();
|
|
|
|
size_t size() { return ranges_.size(); }
|
|
|
|
void Print();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct RangeStack {
|
|
|
|
RangeStack(Address start, unsigned node_id)
|
|
|
|
: start(start), trace_node_id(node_id) {}
|
|
|
|
Address start;
|
|
|
|
unsigned trace_node_id;
|
|
|
|
};
|
|
|
|
// [start, end) -> trace
|
|
|
|
typedef std::map<Address, RangeStack> RangeMap;
|
|
|
|
|
|
|
|
void RemoveRange(Address start, Address end);
|
|
|
|
|
|
|
|
RangeMap ranges_;
|
|
|
|
};
|
|
|
|
|
2013-11-14 12:13:26 +00:00
|
|
|
class AllocationTracker {
|
|
|
|
public:
|
|
|
|
struct FunctionInfo {
|
|
|
|
FunctionInfo();
|
|
|
|
const char* name;
|
2014-03-07 11:32:01 +00:00
|
|
|
SnapshotObjectId function_id;
|
2013-11-14 12:13:26 +00:00
|
|
|
const char* script_name;
|
|
|
|
int script_id;
|
|
|
|
int line;
|
|
|
|
int column;
|
|
|
|
};
|
|
|
|
|
|
|
|
AllocationTracker(HeapObjectsMap* ids, StringsStorage* names);
|
|
|
|
~AllocationTracker();
|
|
|
|
|
|
|
|
void PrepareForSerialization();
|
2013-11-29 09:54:38 +00:00
|
|
|
void AllocationEvent(Address addr, int size);
|
2013-11-14 12:13:26 +00:00
|
|
|
|
|
|
|
AllocationTraceTree* trace_tree() { return &trace_tree_; }
|
2014-03-07 11:32:01 +00:00
|
|
|
const List<FunctionInfo*>& function_info_list() const {
|
|
|
|
return function_info_list_;
|
|
|
|
}
|
2014-03-07 16:13:22 +00:00
|
|
|
AddressToTraceMap* address_to_trace() { return &address_to_trace_; }
|
2013-11-14 12:13:26 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned AddFunctionInfo(SharedFunctionInfo* info, SnapshotObjectId id);
|
|
|
|
static void DeleteFunctionInfo(FunctionInfo** info);
|
|
|
|
unsigned functionInfoIndexForVMState(StateTag state);
|
2013-11-14 12:13:26 +00:00
|
|
|
|
|
|
|
class UnresolvedLocation {
|
|
|
|
public:
|
|
|
|
UnresolvedLocation(Script* script, int start, FunctionInfo* info);
|
|
|
|
~UnresolvedLocation();
|
|
|
|
void Resolve();
|
|
|
|
|
|
|
|
private:
|
2013-12-18 08:09:37 +00:00
|
|
|
static void HandleWeakScript(
|
|
|
|
const v8::WeakCallbackData<v8::Value, void>& data);
|
|
|
|
|
2013-11-14 12:13:26 +00:00
|
|
|
Handle<Script> script_;
|
|
|
|
int start_position_;
|
|
|
|
FunctionInfo* info_;
|
|
|
|
};
|
|
|
|
static void DeleteUnresolvedLocation(UnresolvedLocation** location);
|
|
|
|
|
|
|
|
static const int kMaxAllocationTraceLength = 64;
|
|
|
|
HeapObjectsMap* ids_;
|
|
|
|
StringsStorage* names_;
|
|
|
|
AllocationTraceTree trace_tree_;
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned allocation_trace_buffer_[kMaxAllocationTraceLength];
|
|
|
|
List<FunctionInfo*> function_info_list_;
|
|
|
|
HashMap id_to_function_info_index_;
|
2013-11-14 12:13:26 +00:00
|
|
|
List<UnresolvedLocation*> unresolved_locations_;
|
2014-03-07 11:32:01 +00:00
|
|
|
unsigned info_index_for_other_state_;
|
2014-03-07 16:13:22 +00:00
|
|
|
AddressToTraceMap address_to_trace_;
|
2013-11-14 12:13:26 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AllocationTracker);
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_ALLOCATION_TRACKER_H_
|