Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: build retainers #1 #3

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/memory/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void Parser::Parse(const Nan::FunctionCallbackInfo<Value>& info) {
std::string mode_search = "search";
if(strcmp(*mode, mode_search.c_str()) == 0) {
parser->snapshotParser->CreateAddressMap();
parser->snapshotParser->BuildTotalRetainer();
}
}
}
Expand Down
41 changes: 40 additions & 1 deletion src/memory/snapshot_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,45 @@ int SnapshotParser::SearchOrdinalByAddress(int address) {
}

void SnapshotParser::BuildTotalRetainer() {

retaining_nodes_ = new int[edge_count] {0};
retaining_edges_ = new int[edge_count] {0};
first_retainer_index_ = new int[node_count + 1] {0};
// every node's retainer count
for(int to_node_field_index = edge_to_node_offset, l = edge_count; to_node_field_index < l; to_node_field_index += edge_field_length) {
int to_node_index = edges[to_node_field_index];
if(to_node_index % node_field_length != 0) {
Nan::ThrowTypeError(Nan::New<v8::String>("node index id is wrong!").ToLocalChecked());
return;
}
int ordinal_id = to_node_index / node_field_length;
first_retainer_index_[ordinal_id] += 1;
}
// set first retainer index
for(int i = 0, first_unused_retainer_slot = 0; i < node_count; i++) {
int retainers_count = first_retainer_index_[i];
first_retainer_index_[i] = first_unused_retainer_slot;
retaining_nodes_[first_unused_retainer_slot] = retainers_count;
first_unused_retainer_slot += retainers_count;
}
// for (index ~ index + 1)
first_retainer_index_[node_count] = edge_count;
// set retaining slot
int next_node_first_edge_index = first_edge_indexes[0];
for(int src_node_ordinal = 0; src_node_ordinal < node_count; src_node_ordinal++) {
int first_edge_index = next_node_first_edge_index;
next_node_first_edge_index = first_edge_indexes[src_node_ordinal + 1];
for(int edge_index = first_edge_index; edge_index < next_node_first_edge_index; edge_index += edge_field_length) {
int to_node_index = edges[edge_index + edge_to_node_offset];
if(to_node_index % node_field_length != 0) {
Nan::ThrowTypeError(Nan::New<v8::String>("to_node id is wrong!").ToLocalChecked());
return;
}
int first_retainer_slot_index = first_retainer_index_[to_node_index / node_field_length];
int next_unused_retainer_slot_index = first_retainer_slot_index + (--retaining_nodes_[first_retainer_slot_index]);
// save retainer & edge
retaining_nodes_[next_unused_retainer_slot_index] = src_node_ordinal;
retaining_edges_[next_unused_retainer_slot_index] = edge_index;
}
}
}
}
5 changes: 5 additions & 0 deletions src/memory/snapshot_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ class SnapshotParser {
int* first_edge_indexes;
snapshot_node::Node* node_util;
snapshot_edge::Edge* edge_util;

private:
int* GetFirstEdgeIndexes();
// address -> node ordinal id
AddressMap address_map_;
// total retainers
int* retaining_nodes_;
int* retaining_edges_;
int* first_retainer_index_;
};
}

Expand Down