Index: src/allocation-tracker.cc |
diff --git a/src/allocation-tracker.cc b/src/allocation-tracker.cc |
index 83e1bb4b396a6c371f99a922d44b9c6781d46072..ecc7a4ca4d25e8d3660538a47c85394e117550d3 100644 |
--- a/src/allocation-tracker.cc |
+++ b/src/allocation-tracker.cc |
@@ -36,9 +36,9 @@ namespace v8 { |
namespace internal { |
AllocationTraceNode::AllocationTraceNode( |
- AllocationTraceTree* tree, SnapshotObjectId shared_function_info_id) |
+ AllocationTraceTree* tree, unsigned function_info_index) |
: tree_(tree), |
- function_id_(shared_function_info_id), |
+ function_info_index_(function_info_index), |
total_size_(0), |
allocation_count_(0), |
id_(tree->next_node_id()) { |
@@ -50,19 +50,21 @@ AllocationTraceNode::~AllocationTraceNode() { |
} |
-AllocationTraceNode* AllocationTraceNode::FindChild(SnapshotObjectId id) { |
+AllocationTraceNode* AllocationTraceNode::FindChild( |
+ unsigned function_info_index) { |
for (int i = 0; i < children_.length(); i++) { |
AllocationTraceNode* node = children_[i]; |
- if (node->function_id() == id) return node; |
+ if (node->function_info_index() == function_info_index) return node; |
} |
return NULL; |
} |
-AllocationTraceNode* AllocationTraceNode::FindOrAddChild(SnapshotObjectId id) { |
- AllocationTraceNode* child = FindChild(id); |
+AllocationTraceNode* AllocationTraceNode::FindOrAddChild( |
+ unsigned function_info_index) { |
+ AllocationTraceNode* child = FindChild(function_info_index); |
if (child == NULL) { |
- child = new AllocationTraceNode(tree_, id); |
+ child = new AllocationTraceNode(tree_, function_info_index); |
children_.Add(child); |
} |
return child; |
@@ -78,17 +80,11 @@ void AllocationTraceNode::AddAllocation(unsigned size) { |
void AllocationTraceNode::Print(int indent, AllocationTracker* tracker) { |
OS::Print("%10u %10u %*c", total_size_, allocation_count_, indent, ' '); |
if (tracker != NULL) { |
- const char* name = "<unknown function>"; |
- if (function_id_ != 0) { |
- AllocationTracker::FunctionInfo* info = |
- tracker->GetFunctionInfo(function_id_); |
- if (info != NULL) { |
- name = info->name; |
- } |
- } |
- OS::Print("%s #%u", name, id_); |
+ AllocationTracker::FunctionInfo* info = |
+ tracker->function_info_list()[function_info_index_]; |
+ OS::Print("%s #%u", info->name, id_); |
} else { |
- OS::Print("%u #%u", function_id_, id_); |
+ OS::Print("%u #%u", function_info_index_, id_); |
} |
OS::Print("\n"); |
indent += 2; |
@@ -109,9 +105,9 @@ AllocationTraceTree::~AllocationTraceTree() { |
AllocationTraceNode* AllocationTraceTree::AddPathFromEnd( |
- const Vector<SnapshotObjectId>& path) { |
+ const Vector<unsigned>& path) { |
AllocationTraceNode* node = root(); |
- for (SnapshotObjectId* entry = path.start() + path.length() - 1; |
+ for (unsigned* entry = path.start() + path.length() - 1; |
entry != path.start() - 1; |
--entry) { |
node = node->FindOrAddChild(*entry); |
@@ -126,6 +122,7 @@ void AllocationTraceTree::Print(AllocationTracker* tracker) { |
root()->Print(0, tracker); |
} |
+ |
void AllocationTracker::DeleteUnresolvedLocation( |
UnresolvedLocation** location) { |
delete *location; |
@@ -134,6 +131,7 @@ void AllocationTracker::DeleteUnresolvedLocation( |
AllocationTracker::FunctionInfo::FunctionInfo() |
: name(""), |
+ function_id(0), |
script_name(""), |
script_id(0), |
line(-1), |
@@ -146,21 +144,26 @@ static bool AddressesMatch(void* key1, void* key2) { |
} |
+void AllocationTracker::DeleteFunctionInfo(FunctionInfo** info) { |
+ delete *info; |
+} |
+ |
+ |
AllocationTracker::AllocationTracker( |
HeapObjectsMap* ids, StringsStorage* names) |
: ids_(ids), |
names_(names), |
- id_to_function_info_(AddressesMatch) { |
+ id_to_function_info_index_(AddressesMatch), |
+ info_index_for_other_state_(0) { |
+ FunctionInfo* info = new FunctionInfo(); |
+ info->name = "(root)"; |
+ function_info_list_.Add(info); |
} |
AllocationTracker::~AllocationTracker() { |
unresolved_locations_.Iterate(DeleteUnresolvedLocation); |
- for (HashMap::Entry* p = id_to_function_info_.Start(); |
- p != NULL; |
- p = id_to_function_info_.Next(p)) { |
- delete reinterpret_cast<AllocationTracker::FunctionInfo* >(p->value); |
- } |
+ function_info_list_.Iterate(&DeleteFunctionInfo); |
} |
@@ -193,12 +196,17 @@ void AllocationTracker::AllocationEvent(Address addr, int size) { |
SharedFunctionInfo* shared = frame->function()->shared(); |
SnapshotObjectId id = ids_->FindOrAddEntry( |
shared->address(), shared->Size(), false); |
- allocation_trace_buffer_[length++] = id; |
- AddFunctionInfo(shared, id); |
+ allocation_trace_buffer_[length++] = AddFunctionInfo(shared, id); |
it.Advance(); |
} |
+ if (length == 0) { |
+ unsigned index = functionInfoIndexForVMState(isolate->current_vm_state()); |
+ if (index != 0) { |
+ allocation_trace_buffer_[length++] = index; |
+ } |
+ } |
AllocationTraceNode* top_node = trace_tree_.AddPathFromEnd( |
- Vector<SnapshotObjectId>(allocation_trace_buffer_, length)); |
+ Vector<unsigned>(allocation_trace_buffer_, length)); |
top_node->AddAllocation(size); |
} |
@@ -209,24 +217,14 @@ static uint32_t SnapshotObjectIdHash(SnapshotObjectId id) { |
} |
-AllocationTracker::FunctionInfo* AllocationTracker::GetFunctionInfo( |
- SnapshotObjectId id) { |
- HashMap::Entry* entry = id_to_function_info_.Lookup( |
- reinterpret_cast<void*>(id), SnapshotObjectIdHash(id), false); |
- if (entry == NULL) { |
- return NULL; |
- } |
- return reinterpret_cast<FunctionInfo*>(entry->value); |
-} |
- |
- |
-void AllocationTracker::AddFunctionInfo(SharedFunctionInfo* shared, |
- SnapshotObjectId id) { |
- HashMap::Entry* entry = id_to_function_info_.Lookup( |
+unsigned AllocationTracker::AddFunctionInfo(SharedFunctionInfo* shared, |
+ SnapshotObjectId id) { |
+ HashMap::Entry* entry = id_to_function_info_index_.Lookup( |
reinterpret_cast<void*>(id), SnapshotObjectIdHash(id), true); |
if (entry->value == NULL) { |
FunctionInfo* info = new FunctionInfo(); |
info->name = names_->GetFunctionName(shared->DebugName()); |
+ info->function_id = id; |
if (shared->script()->IsScript()) { |
Script* script = Script::cast(shared->script()); |
if (script->name()->IsName()) { |
@@ -241,8 +239,22 @@ void AllocationTracker::AddFunctionInfo(SharedFunctionInfo* shared, |
shared->start_position(), |
info)); |
} |
- entry->value = info; |
+ entry->value = reinterpret_cast<void*>(function_info_list_.length()); |
+ function_info_list_.Add(info); |
+ } |
+ return static_cast<unsigned>(reinterpret_cast<intptr_t>((entry->value))); |
+} |
+ |
+ |
+unsigned AllocationTracker::functionInfoIndexForVMState(StateTag state) { |
+ if (state != OTHER) return 0; |
+ if (info_index_for_other_state_ == 0) { |
+ FunctionInfo* info = new FunctionInfo(); |
+ info->name = "(V8 API)"; |
+ info_index_for_other_state_ = function_info_list_.length(); |
+ function_info_list_.Add(info); |
} |
+ return info_index_for_other_state_; |
} |