From e74b8c0952d6bfd6a0a00b82b8a90b77a99fb26f Mon Sep 17 00:00:00 2001 From: "alexeif@chromium.org" Date: Sat, 12 May 2012 16:41:13 +0000 Subject: [PATCH] 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 --- src/profile-generator.cc | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/profile-generator.cc b/src/profile-generator.cc index b31b77b..c03e526 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -3499,16 +3499,9 @@ int HeapSnapshotJSONSerializer::GetStringId(const char* s) { } -// This function won't work correctly for MIN_INT but this is not -// a problem in case of heap snapshots serialization. -static int itoa(int value, const Vector& buffer, int buffer_pos) { - if (value < 0) { - buffer[buffer_pos++] = '-'; - value = -value; - } - +static int utoa(unsigned value, const Vector& buffer, int buffer_pos) { int number_of_digits = 0; - int t = value; + unsigned t = value; do { ++number_of_digits; } while (t /= 10); @@ -3538,11 +3531,11 @@ void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge, if (!first_edge) { buffer[buffer_pos++] = ','; } - buffer_pos = itoa(edge->type(), buffer, buffer_pos); + buffer_pos = utoa(edge->type(), 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_pos = itoa(entry_index(edge->to()), buffer, buffer_pos); + buffer_pos = utoa(entry_index(edge->to()), buffer, buffer_pos); buffer[buffer_pos++] = '\0'; writer_->AddString(buffer.start()); } @@ -3571,23 +3564,23 @@ void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry, + 7 + 1 + 1; EmbeddedVector buffer; int buffer_pos = 0; - buffer[buffer_pos++] = '\n'; if (entry_index(entry) != 0) { buffer[buffer_pos++] = ','; } - buffer_pos = itoa(entry->type(), buffer, buffer_pos); + buffer_pos = utoa(entry->type(), 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_pos = itoa(entry->id(), buffer, buffer_pos); + buffer_pos = utoa(entry->id(), 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_pos = itoa(entry->retained_size(), buffer, buffer_pos); + buffer_pos = utoa(entry->retained_size(), 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_pos = itoa(edges_index, buffer, buffer_pos); + buffer_pos = utoa(edges_index, buffer, buffer_pos); + buffer[buffer_pos++] = '\n'; buffer[buffer_pos++] = '\0'; writer_->AddString(buffer.start()); } -- 2.7.4