| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 void HeapSnapshot::Delete() { | 1188 void HeapSnapshot::Delete() { |
| 1189 collection_->RemoveSnapshot(this); | 1189 collection_->RemoveSnapshot(this); |
| 1190 delete this; | 1190 delete this; |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 | 1193 |
| 1194 void HeapSnapshot::AllocateEntries(int entries_count, | 1194 void HeapSnapshot::AllocateEntries(int entries_count, |
| 1195 int children_count, | 1195 int children_count, |
| 1196 int retainers_count) { | 1196 int retainers_count) { |
| 1197 ASSERT(raw_entries_ == NULL); | 1197 ASSERT(raw_entries_ == NULL); |
| 1198 raw_entries_ = NewArray<char>( | |
| 1199 HeapEntry::EntriesSize(entries_count, children_count, retainers_count)); | |
| 1200 #ifdef DEBUG | |
| 1201 raw_entries_size_ = | 1198 raw_entries_size_ = |
| 1202 HeapEntry::EntriesSize(entries_count, children_count, retainers_count); | 1199 HeapEntry::EntriesSize(entries_count, children_count, retainers_count); |
| 1203 #endif | 1200 raw_entries_ = NewArray<char>(raw_entries_size_); |
| 1204 } | 1201 } |
| 1205 | 1202 |
| 1206 | 1203 |
| 1207 static void HeapEntryClearPaint(HeapEntry** entry_ptr) { | 1204 static void HeapEntryClearPaint(HeapEntry** entry_ptr) { |
| 1208 (*entry_ptr)->clear_paint(); | 1205 (*entry_ptr)->clear_paint(); |
| 1209 } | 1206 } |
| 1210 | 1207 |
| 1211 void HeapSnapshot::ClearPaint() { | 1208 void HeapSnapshot::ClearPaint() { |
| 1212 entries_.Iterate(HeapEntryClearPaint); | 1209 entries_.Iterate(HeapEntryClearPaint); |
| 1213 } | 1210 } |
| (...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3019 v8::OutputStream::kAbort) aborted_ = true; | 3016 v8::OutputStream::kAbort) aborted_ = true; |
| 3020 } | 3017 } |
| 3021 | 3018 |
| 3022 v8::OutputStream* stream_; | 3019 v8::OutputStream* stream_; |
| 3023 int chunk_size_; | 3020 int chunk_size_; |
| 3024 ScopedVector<char> chunk_; | 3021 ScopedVector<char> chunk_; |
| 3025 int chunk_pos_; | 3022 int chunk_pos_; |
| 3026 bool aborted_; | 3023 bool aborted_; |
| 3027 }; | 3024 }; |
| 3028 | 3025 |
| 3026 const int HeapSnapshotJSONSerializer::kMaxSerializableSnapshotRawSize = |
| 3027 256 * MB; |
| 3028 |
| 3029 void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) { | 3029 void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) { |
| 3030 ASSERT(writer_ == NULL); | 3030 ASSERT(writer_ == NULL); |
| 3031 writer_ = new OutputStreamWriter(stream); | 3031 writer_ = new OutputStreamWriter(stream); |
| 3032 | 3032 |
| 3033 HeapSnapshot* original_snapshot = NULL; |
| 3034 if (snapshot_->raw_entries_size() >= kMaxSerializableSnapshotRawSize) { |
| 3035 // The snapshot is too big. Serialize a fake snapshot. |
| 3036 original_snapshot = snapshot_; |
| 3037 snapshot_ = CreateFakeSnapshot(); |
| 3038 } |
| 3033 // Since nodes graph is cyclic, we need the first pass to enumerate | 3039 // Since nodes graph is cyclic, we need the first pass to enumerate |
| 3034 // them. Strings can be serialized in one pass. | 3040 // them. Strings can be serialized in one pass. |
| 3035 EnumerateNodes(); | 3041 EnumerateNodes(); |
| 3036 SerializeImpl(); | 3042 SerializeImpl(); |
| 3037 | 3043 |
| 3038 delete writer_; | 3044 delete writer_; |
| 3039 writer_ = NULL; | 3045 writer_ = NULL; |
| 3046 |
| 3047 if (original_snapshot != NULL) { |
| 3048 delete snapshot_; |
| 3049 snapshot_ = original_snapshot; |
| 3050 } |
| 3040 } | 3051 } |
| 3041 | 3052 |
| 3042 | 3053 |
| 3054 HeapSnapshot* HeapSnapshotJSONSerializer::CreateFakeSnapshot() { |
| 3055 HeapSnapshot* result = new HeapSnapshot(snapshot_->collection(), |
| 3056 HeapSnapshot::kFull, |
| 3057 snapshot_->title(), |
| 3058 snapshot_->uid()); |
| 3059 result->AllocateEntries(2, 1, 0); |
| 3060 HeapEntry* root = result->AddRootEntry(1); |
| 3061 HeapEntry* message = result->AddEntry( |
| 3062 HeapEntry::kString, "The snapshot is too big", 0, 4, 0, 0); |
| 3063 root->SetUnidirElementReference(0, 1, message); |
| 3064 result->SetDominatorsToSelf(); |
| 3065 return result; |
| 3066 } |
| 3067 |
| 3068 |
| 3043 void HeapSnapshotJSONSerializer::SerializeImpl() { | 3069 void HeapSnapshotJSONSerializer::SerializeImpl() { |
| 3044 writer_->AddCharacter('{'); | 3070 writer_->AddCharacter('{'); |
| 3045 writer_->AddString("\"snapshot\":{"); | 3071 writer_->AddString("\"snapshot\":{"); |
| 3046 SerializeSnapshot(); | 3072 SerializeSnapshot(); |
| 3047 if (writer_->aborted()) return; | 3073 if (writer_->aborted()) return; |
| 3048 writer_->AddString("},\n"); | 3074 writer_->AddString("},\n"); |
| 3049 writer_->AddString("\"nodes\":["); | 3075 writer_->AddString("\"nodes\":["); |
| 3050 SerializeNodes(); | 3076 SerializeNodes(); |
| 3051 if (writer_->aborted()) return; | 3077 if (writer_->aborted()) return; |
| 3052 writer_->AddString("],\n"); | 3078 writer_->AddString("],\n"); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3310 | 3336 |
| 3311 | 3337 |
| 3312 void HeapSnapshotJSONSerializer::SortHashMap( | 3338 void HeapSnapshotJSONSerializer::SortHashMap( |
| 3313 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3339 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
| 3314 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3340 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
| 3315 sorted_entries->Add(p); | 3341 sorted_entries->Add(p); |
| 3316 sorted_entries->Sort(SortUsingEntryValue); | 3342 sorted_entries->Sort(SortUsingEntryValue); |
| 3317 } | 3343 } |
| 3318 | 3344 |
| 3319 } } // namespace v8::internal | 3345 } } // namespace v8::internal |
| OLD | NEW |