Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: src/snapshot/serialize.cc

Issue 1086363002: Serializer: collect and output memory statistics. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot/serialize.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 code_address_map_(NULL), 1210 code_address_map_(NULL),
1211 large_objects_total_size_(0), 1211 large_objects_total_size_(0),
1212 seen_large_objects_index_(0) { 1212 seen_large_objects_index_(0) {
1213 // The serializer is meant to be used only to generate initial heap images 1213 // The serializer is meant to be used only to generate initial heap images
1214 // from a context in which there is only one isolate. 1214 // from a context in which there is only one isolate.
1215 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) { 1215 for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
1216 pending_chunk_[i] = 0; 1216 pending_chunk_[i] = 0;
1217 max_chunk_size_[i] = static_cast<uint32_t>( 1217 max_chunk_size_[i] = static_cast<uint32_t>(
1218 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(i))); 1218 MemoryAllocator::PageAreaSize(static_cast<AllocationSpace>(i)));
1219 } 1219 }
1220
1221 #ifdef OBJECT_PRINT
1222 if (FLAG_serialization_statistics) {
1223 instance_type_count_ = NewArray<int>(kInstanceTypes);
1224 instance_type_size_ = NewArray<size_t>(kInstanceTypes);
1225 for (int i = 0; i < kInstanceTypes; i++) {
1226 instance_type_count_[i] = 0;
1227 instance_type_size_[i] = 0;
1228 }
1229 } else {
1230 instance_type_count_ = NULL;
1231 instance_type_size_ = NULL;
1232 }
1233 #endif // OBJECT_PRINT
1220 } 1234 }
1221 1235
1222 1236
1223 Serializer::~Serializer() { 1237 Serializer::~Serializer() {
1224 if (code_address_map_ != NULL) delete code_address_map_; 1238 if (code_address_map_ != NULL) delete code_address_map_;
1239 #ifdef OBJECT_PRINT
1240 if (instance_type_count_ != NULL) {
1241 DeleteArray(instance_type_count_);
1242 DeleteArray(instance_type_size_);
1243 }
1244 #endif // OBJECT_PRINT
1225 } 1245 }
1226 1246
1227 1247
1248 #ifdef OBJECT_PRINT
1249 void Serializer::CountInstanceType(HeapObject* obj) {
1250 int instance_type = obj->map()->instance_type();
1251 instance_type_count_[instance_type]++;
1252 instance_type_size_[instance_type] += obj->Size();
1253 }
1254 #endif // OBJECT_PRINT
1255
1256
1257 void Serializer::OutputStatistics(const char* name) {
1258 if (!FLAG_serialization_statistics) return;
1259 PrintF("%s:\n", name);
1260 PrintF(" Spaces (bytes):\n");
1261 for (int space = 0; space < kNumberOfSpaces; space++) {
1262 PrintF("%16s", AllocationSpaceName(static_cast<AllocationSpace>(space)));
1263 }
1264 PrintF("\n");
1265 for (int space = 0; space < kNumberOfPreallocatedSpaces; space++) {
1266 size_t s = pending_chunk_[space];
1267 for (uint32_t chunk_size : completed_chunks_[space]) s += chunk_size;
1268 PrintF("%16" V8_PTR_PREFIX "d", s);
1269 }
1270 PrintF("%16d\n", large_objects_total_size_);
1271 #ifdef OBJECT_PRINT
1272 PrintF(" Instance types (count and bytes):\n");
1273 #define PRINT_INSTANCE_TYPE(Name) \
1274 if (instance_type_count_[Name]) { \
1275 PrintF("%10d %10" V8_PTR_PREFIX "d %s\n", instance_type_count_[Name], \
1276 instance_type_size_[Name], #Name); \
1277 }
1278 INSTANCE_TYPE_LIST(PRINT_INSTANCE_TYPE)
1279 #undef PRINT_INSTANCE_TYPE
1280 PrintF("\n");
1281 #endif // OBJECT_PRINT
1282 }
1283
1284
1228 void StartupSerializer::SerializeStrongReferences() { 1285 void StartupSerializer::SerializeStrongReferences() {
1229 Isolate* isolate = this->isolate(); 1286 Isolate* isolate = this->isolate();
1230 // No active threads. 1287 // No active threads.
1231 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse()); 1288 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
1232 // No active or weak handles. 1289 // No active or weak handles.
1233 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); 1290 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());
1234 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); 1291 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles());
1235 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles()); 1292 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles());
1236 // We don't support serializing installed extensions. 1293 // We don't support serializing installed extensions.
1237 CHECK(!isolate->has_installed_extensions()); 1294 CHECK(!isolate->has_installed_extensions());
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 back_reference = serializer_->Allocate(space, size); 1687 back_reference = serializer_->Allocate(space, size);
1631 } 1688 }
1632 sink_->Put(kNewObject + reference_representation_ + space, "NewObject"); 1689 sink_->Put(kNewObject + reference_representation_ + space, "NewObject");
1633 if (needs_double_align) 1690 if (needs_double_align)
1634 sink_->PutInt(kDoubleAlignmentSentinel, "DoubleAlignSentinel"); 1691 sink_->PutInt(kDoubleAlignmentSentinel, "DoubleAlignSentinel");
1635 int encoded_size = size >> kObjectAlignmentBits; 1692 int encoded_size = size >> kObjectAlignmentBits;
1636 DCHECK_NE(kDoubleAlignmentSentinel, encoded_size); 1693 DCHECK_NE(kDoubleAlignmentSentinel, encoded_size);
1637 sink_->PutInt(encoded_size, "ObjectSizeInWords"); 1694 sink_->PutInt(encoded_size, "ObjectSizeInWords");
1638 } 1695 }
1639 1696
1697 #ifdef OBJECT_PRINT
1698 if (FLAG_serialization_statistics) {
1699 serializer_->CountInstanceType(object_);
1700 }
1701 #endif // OBJECT_PRINT
1702
1640 // Mark this object as already serialized. 1703 // Mark this object as already serialized.
1641 serializer_->back_reference_map()->Add(object_, back_reference); 1704 serializer_->back_reference_map()->Add(object_, back_reference);
1642 1705
1643 // Serialize the map (first word of the object). 1706 // Serialize the map (first word of the object).
1644 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0); 1707 serializer_->SerializeObject(map, kPlain, kStartOfObject, 0);
1645 } 1708 }
1646 1709
1647 1710
1648 void Serializer::ObjectSerializer::SerializeExternalString() { 1711 void Serializer::ObjectSerializer::SerializeExternalString() {
1649 // Instead of serializing this as an external string, we serialize 1712 // Instead of serializing this as an external string, we serialize
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 DisallowHeapAllocation no_gc; 2592 DisallowHeapAllocation no_gc;
2530 SerializedCodeData* scd = new SerializedCodeData(cached_data); 2593 SerializedCodeData* scd = new SerializedCodeData(cached_data);
2531 SanityCheckResult r = scd->SanityCheck(isolate, source); 2594 SanityCheckResult r = scd->SanityCheck(isolate, source);
2532 if (r == CHECK_SUCCESS) return scd; 2595 if (r == CHECK_SUCCESS) return scd;
2533 cached_data->Reject(); 2596 cached_data->Reject();
2534 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); 2597 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r);
2535 delete scd; 2598 delete scd;
2536 return NULL; 2599 return NULL;
2537 } 2600 }
2538 } } // namespace v8::internal 2601 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698