Reviewers: yurys, loislo,
Message:
ptal
Description:
Allow self_size to be larger than 2GB in heap snapshots.
LOG=N
Please review this at https://codereview.chromium.org/166383002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+45, -19 lines):
M src/api.cc
M src/heap-snapshot-generator.h
M src/heap-snapshot-generator.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
dfde26565b1393bfa4de6f36b7844e3698c29586..fe822fa826c50d164a4dd862f91c2c6f0be18ef5
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6971,7 +6971,9 @@ SnapshotObjectId HeapGraphNode::GetId() const {
int HeapGraphNode::GetSelfSize() const {
- return ToInternal(this)->self_size();
+ size_t size = ToInternal(this)->self_size();
+ CHECK(size <= static_cast<size_t>(internal::kMaxInt));
+ return static_cast<int>(size);
}
Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index
71362ffc0d36b4a2dc4c405762aea6a270136c5b..161bfe0b9ae620569c2418c8e552fd38ec18ad52
100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -73,7 +73,7 @@ HeapEntry::HeapEntry(HeapSnapshot* snapshot,
Type type,
const char* name,
SnapshotObjectId id,
- int self_size)
+ size_t self_size)
: type_(type),
children_count_(0),
children_index_(-1),
@@ -104,7 +104,7 @@ void HeapEntry::SetIndexedReference(HeapGraphEdge::Type
type,
void HeapEntry::Print(
const char* prefix, const char* edge_name, int max_depth, int indent) {
STATIC_CHECK(sizeof(unsigned) == sizeof(id()));
- OS::Print("%6d @%6u %*c %s%s: ",
+ OS::Print("%6"V8PRIuPTR" @%6u %*c %s%s: ",
self_size(), id(), indent, ' ', prefix, edge_name);
if (type() != kString) {
OS::Print("%s %.40s\n", TypeAsString(), name_);
@@ -194,7 +194,7 @@ template <> struct SnapshotSizeConstants<4> {
template <> struct SnapshotSizeConstants<8> {
static const int kExpectedHeapGraphEdgeSize = 24;
- static const int kExpectedHeapEntrySize = 32;
+ static const int kExpectedHeapEntrySize = 40;
};
} // namespace
@@ -277,7 +277,7 @@ HeapEntry* HeapSnapshot::AddGcSubrootEntry(int tag) {
HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
const char* name,
SnapshotObjectId id,
- int size) {
+ size_t size) {
HeapEntry entry(this, type, name, id, size);
entries_.Add(entry);
return &entries_.last();
@@ -907,7 +907,7 @@ HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object,
HeapEntry* V8HeapExplorer::AddEntry(Address address,
HeapEntry::Type type,
const char* name,
- int size) {
+ size_t size) {
SnapshotObjectId object_id = heap_object_map_->FindOrAddEntry(address,
size);
return snapshot_->AddEntry(type, name, object_id, size);
}
@@ -1465,11 +1465,9 @@ void V8HeapExplorer::ExtractJSArrayBufferReferences(
JSArrayBuffer::kWeakFirstViewOffset);
// Setup a reference to a native memory backing_store object.
size_t data_size = NumberToSize(heap_->isolate(), buffer->byte_length());
- CHECK(data_size <= static_cast<size_t>(kMaxInt));
HeapEntry* data_entry = AddEntry(
static_cast<Address>(buffer->backing_store()),
- HeapEntry::kNative, "system / ArrayBufferData",
- static_cast<int>(data_size));
+ HeapEntry::kNative, "system / ArrayBufferData", data_size);
filler_->SetNamedReference(HeapGraphEdge::kInternal,
entry, "backing_store", data_entry);
}
@@ -2684,9 +2682,26 @@ int HeapSnapshotJSONSerializer::GetStringId(const
char* s) {
}
-static int utoa(unsigned value, const Vector<char>& buffer, int
buffer_pos) {
+namespace {
+
+template<size_t size> struct ToUnsigned;
+
+template<> struct ToUnsigned<4> {
+ typedef uint32_t Type;
+};
+
+template<> struct ToUnsigned<8> {
+ typedef uint64_t Type;
+};
+
+} // namespace
+
+
+template<typename T>
+static int utoa_impl(T value, const Vector<char>& buffer, int buffer_pos) {
+ STATIC_CHECK(static_cast<T>(-1) > 0); // Check that T is unsigned
int number_of_digits = 0;
- unsigned t = value;
+ T t = value;
do {
++number_of_digits;
} while (t /= 10);
@@ -2694,7 +2709,7 @@ static int utoa(unsigned value, const Vector<char>&
buffer, int buffer_pos) {
buffer_pos += number_of_digits;
int result = buffer_pos;
do {
- int last_digit = value % 10;
+ int last_digit = static_cast<int>(value % 10);
buffer[--buffer_pos] = '0' + last_digit;
value /= 10;
} while (value);
@@ -2702,6 +2717,14 @@ static int utoa(unsigned value, const Vector<char>&
buffer, int buffer_pos) {
}
+template<typename T>
+static int utoa(T value, const Vector<char>& buffer, int buffer_pos) {
+ typename ToUnsigned<sizeof(value)>::Type unsigned_value = value;
+ STATIC_CHECK(sizeof(value) == sizeof(unsigned_value));
+ return utoa_impl(unsigned_value, buffer, buffer_pos);
+}
+
+
void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge,
bool first_edge) {
// The buffer needs space for 3 unsigned ints, 3 commas, \n and \0
@@ -2738,9 +2761,10 @@ void HeapSnapshotJSONSerializer::SerializeEdges() {
void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) {
- // The buffer needs space for 5 unsigned ints, 5 commas, \n and \0
+ // The buffer needs space for 4 unsigned ints, 1 size_t, 5 commas, \n
and \0
static const int kBufferSize =
- 5 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
+ 4 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
+ + MaxDecimalDigitsIn<sizeof(size_t)>::kUnsigned // NOLINT
+ 5 + 1 + 1;
EmbeddedVector<char, kBufferSize> buffer;
int buffer_pos = 0;
Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index
9ea366e6c4f6b1ee5acc63edf8675aa0eb8d758b..1cea12b3a9e4b8ef1ab5feae4fd33ddfdc6e6686
100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -114,14 +114,14 @@ class HeapEntry BASE_EMBEDDED {
Type type,
const char* name,
SnapshotObjectId id,
- int self_size);
+ size_t self_size);
HeapSnapshot* snapshot() { return snapshot_; }
Type type() { return static_cast<Type>(type_); }
const char* name() { return name_; }
void set_name(const char* name) { name_ = name; }
inline SnapshotObjectId id() { return id_; }
- int self_size() { return self_size_; }
+ size_t self_size() { return self_size_; }
INLINE(int index() const);
int children_count() const { return children_count_; }
INLINE(int set_children_index(int index));
@@ -146,7 +146,7 @@ class HeapEntry BASE_EMBEDDED {
unsigned type_: 4;
int children_count_: 28;
int children_index_;
- int self_size_;
+ size_t self_size_;
SnapshotObjectId id_;
HeapSnapshot* snapshot_;
const char* name_;
@@ -186,7 +186,7 @@ class HeapSnapshot {
HeapEntry* AddEntry(HeapEntry::Type type,
const char* name,
SnapshotObjectId id,
- int size);
+ size_t size);
HeapEntry* AddRootEntry();
HeapEntry* AddGcRootsEntry();
HeapEntry* AddGcSubrootEntry(int tag);
@@ -399,7 +399,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
HeapEntry* AddEntry(Address address,
HeapEntry::Type type,
const char* name,
- int size);
+ size_t size);
const char* GetSystemEntryName(HeapObject* object);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.