Serialize heap snapshot data as an array of unsigned values.

None of the values can in fact be negative, while object IDs
can have the highest bit set which lead to negative values appear
in the snapshot that front-end is unable to parse.

Review URL: https://chromiumcodereview.appspot.com/10356143

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11553 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
alexeif@chromium.org 2012-05-12 16:41:13 +00:00
parent 3f748cf5da
commit e74b8c0952

View File

@ -3499,16 +3499,9 @@ int HeapSnapshotJSONSerializer::GetStringId(const char* s) {
} }
// This function won't work correctly for MIN_INT but this is not static int utoa(unsigned value, const Vector<char>& buffer, int buffer_pos) {
// a problem in case of heap snapshots serialization.
static int itoa(int value, const Vector<char>& buffer, int buffer_pos) {
if (value < 0) {
buffer[buffer_pos++] = '-';
value = -value;
}
int number_of_digits = 0; int number_of_digits = 0;
int t = value; unsigned t = value;
do { do {
++number_of_digits; ++number_of_digits;
} while (t /= 10); } while (t /= 10);
@ -3538,11 +3531,11 @@ void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge,
if (!first_edge) { if (!first_edge) {
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
} }
buffer_pos = itoa(edge->type(), buffer, buffer_pos); buffer_pos = utoa(edge->type(), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(edge_name_or_index, buffer, buffer_pos); buffer_pos = utoa(edge_name_or_index, buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(entry_index(edge->to()), buffer, buffer_pos); buffer_pos = utoa(entry_index(edge->to()), buffer, buffer_pos);
buffer[buffer_pos++] = '\0'; buffer[buffer_pos++] = '\0';
writer_->AddString(buffer.start()); writer_->AddString(buffer.start());
} }
@ -3571,23 +3564,23 @@ void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry,
+ 7 + 1 + 1; + 7 + 1 + 1;
EmbeddedVector<char, kBufferSize> buffer; EmbeddedVector<char, kBufferSize> buffer;
int buffer_pos = 0; int buffer_pos = 0;
buffer[buffer_pos++] = '\n';
if (entry_index(entry) != 0) { if (entry_index(entry) != 0) {
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
} }
buffer_pos = itoa(entry->type(), buffer, buffer_pos); buffer_pos = utoa(entry->type(), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(GetStringId(entry->name()), buffer, buffer_pos); buffer_pos = utoa(GetStringId(entry->name()), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(entry->id(), buffer, buffer_pos); buffer_pos = utoa(entry->id(), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(entry->self_size(), buffer, buffer_pos); buffer_pos = utoa(entry->self_size(), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(entry->retained_size(), buffer, buffer_pos); buffer_pos = utoa(entry->retained_size(), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(entry_index(entry->dominator()), buffer, buffer_pos); buffer_pos = utoa(entry_index(entry->dominator()), buffer, buffer_pos);
buffer[buffer_pos++] = ','; buffer[buffer_pos++] = ',';
buffer_pos = itoa(edges_index, buffer, buffer_pos); buffer_pos = utoa(edges_index, buffer, buffer_pos);
buffer[buffer_pos++] = '\n';
buffer[buffer_pos++] = '\0'; buffer[buffer_pos++] = '\0';
writer_->AddString(buffer.start()); writer_->AddString(buffer.start());
} }