OLD | NEW |
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/heap/heap.h" | 5 #include "src/heap/heap.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/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 void Step(int bytes_allocated, Address, size_t) override { | 62 void Step(int bytes_allocated, Address, size_t) override { |
63 heap_.ScheduleIdleScavengeIfNeeded(bytes_allocated); | 63 heap_.ScheduleIdleScavengeIfNeeded(bytes_allocated); |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 Heap& heap_; | 67 Heap& heap_; |
68 }; | 68 }; |
69 | 69 |
70 Heap::Heap() | 70 Heap::Heap() |
71 : amount_of_external_allocated_memory_(0), | 71 : external_memory_(0), |
72 amount_of_external_allocated_memory_at_last_global_gc_(0), | 72 external_memory_limit_(kExternalAllocationLimit), |
| 73 external_memory_at_last_mark_compact_(0), |
73 isolate_(nullptr), | 74 isolate_(nullptr), |
74 code_range_size_(0), | 75 code_range_size_(0), |
75 // semispace_size_ should be a power of 2 and old_generation_size_ should | 76 // semispace_size_ should be a power of 2 and old_generation_size_ should |
76 // be a multiple of Page::kPageSize. | 77 // be a multiple of Page::kPageSize. |
77 max_semi_space_size_(8 * (kPointerSize / 4) * MB), | 78 max_semi_space_size_(8 * (kPointerSize / 4) * MB), |
78 initial_semispace_size_(Page::kPageSize), | 79 initial_semispace_size_(Page::kPageSize), |
79 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), | 80 max_old_generation_size_(700ul * (kPointerSize / 4) * MB), |
80 initial_old_generation_size_(max_old_generation_size_ / | 81 initial_old_generation_size_(max_old_generation_size_ / |
81 kInitalOldGenerationLimitFactor), | 82 kInitalOldGenerationLimitFactor), |
82 old_generation_size_configured_(false), | 83 old_generation_size_configured_(false), |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 ", committed: %6" V8PRIdPTR " KB\n", | 377 ", committed: %6" V8PRIdPTR " KB\n", |
377 lo_space_->SizeOfObjects() / KB, lo_space_->Available() / KB, | 378 lo_space_->SizeOfObjects() / KB, lo_space_->Available() / KB, |
378 lo_space_->CommittedMemory() / KB); | 379 lo_space_->CommittedMemory() / KB); |
379 PrintIsolate(isolate_, "All spaces, used: %6" V8PRIdPTR | 380 PrintIsolate(isolate_, "All spaces, used: %6" V8PRIdPTR |
380 " KB" | 381 " KB" |
381 ", available: %6" V8PRIdPTR | 382 ", available: %6" V8PRIdPTR |
382 " KB" | 383 " KB" |
383 ", committed: %6" V8PRIdPTR " KB\n", | 384 ", committed: %6" V8PRIdPTR " KB\n", |
384 this->SizeOfObjects() / KB, this->Available() / KB, | 385 this->SizeOfObjects() / KB, this->Available() / KB, |
385 this->CommittedMemory() / KB); | 386 this->CommittedMemory() / KB); |
386 PrintIsolate( | 387 PrintIsolate(isolate_, "External memory reported: %6" V8PRIdPTR " KB\n", |
387 isolate_, "External memory reported: %6" V8PRIdPTR " KB\n", | 388 static_cast<intptr_t>(external_memory_ / KB)); |
388 static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB)); | |
389 PrintIsolate(isolate_, "Total time spent in GC : %.1f ms\n", | 389 PrintIsolate(isolate_, "Total time spent in GC : %.1f ms\n", |
390 total_gc_time_ms_); | 390 total_gc_time_ms_); |
391 } | 391 } |
392 | 392 |
393 // TODO(1238405): Combine the infrastructure for --heap-stats and | 393 // TODO(1238405): Combine the infrastructure for --heap-stats and |
394 // --log-gc to avoid the complicated preprocessor and flag testing. | 394 // --log-gc to avoid the complicated preprocessor and flag testing. |
395 void Heap::ReportStatisticsAfterGC() { | 395 void Heap::ReportStatisticsAfterGC() { |
396 // Similar to the before GC, we use some complicated logic to ensure that | 396 // Similar to the before GC, we use some complicated logic to ensure that |
397 // NewSpace statistics are logged exactly once when --log-gc is turned on. | 397 // NewSpace statistics are logged exactly once when --log-gc is turned on. |
398 #if defined(DEBUG) | 398 #if defined(DEBUG) |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 | 1332 |
1333 // Update relocatables. | 1333 // Update relocatables. |
1334 Relocatable::PostGarbageCollectionProcessing(isolate_); | 1334 Relocatable::PostGarbageCollectionProcessing(isolate_); |
1335 | 1335 |
1336 double gc_speed = tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond(); | 1336 double gc_speed = tracer()->CombinedMarkCompactSpeedInBytesPerMillisecond(); |
1337 double mutator_speed = | 1337 double mutator_speed = |
1338 tracer()->CurrentOldGenerationAllocationThroughputInBytesPerMillisecond(); | 1338 tracer()->CurrentOldGenerationAllocationThroughputInBytesPerMillisecond(); |
1339 intptr_t old_gen_size = PromotedSpaceSizeOfObjects(); | 1339 intptr_t old_gen_size = PromotedSpaceSizeOfObjects(); |
1340 if (collector == MARK_COMPACTOR) { | 1340 if (collector == MARK_COMPACTOR) { |
1341 // Register the amount of external allocated memory. | 1341 // Register the amount of external allocated memory. |
1342 amount_of_external_allocated_memory_at_last_global_gc_ = | 1342 external_memory_at_last_mark_compact_ = external_memory_; |
1343 amount_of_external_allocated_memory_; | 1343 external_memory_limit_ = external_memory_ + kExternalAllocationLimit; |
1344 SetOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); | 1344 SetOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); |
1345 } else if (HasLowYoungGenerationAllocationRate() && | 1345 } else if (HasLowYoungGenerationAllocationRate() && |
1346 old_generation_size_configured_) { | 1346 old_generation_size_configured_) { |
1347 DampenOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); | 1347 DampenOldGenerationAllocationLimit(old_gen_size, gc_speed, mutator_speed); |
1348 } | 1348 } |
1349 | 1349 |
1350 { | 1350 { |
1351 GCCallbacksScope scope(this); | 1351 GCCallbacksScope scope(this); |
1352 if (scope.CheckReenter()) { | 1352 if (scope.CheckReenter()) { |
1353 AllowHeapAllocation allow_allocation; | 1353 AllowHeapAllocation allow_allocation; |
(...skipping 3064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4418 const double kGarbageThresholdAsFractionOfTotalMemory = 0.1; | 4418 const double kGarbageThresholdAsFractionOfTotalMemory = 0.1; |
4419 // This constant is the maximum response time in RAIL performance model. | 4419 // This constant is the maximum response time in RAIL performance model. |
4420 const double kMaxMemoryPressurePauseMs = 100; | 4420 const double kMaxMemoryPressurePauseMs = 100; |
4421 | 4421 |
4422 double start = MonotonicallyIncreasingTimeInMs(); | 4422 double start = MonotonicallyIncreasingTimeInMs(); |
4423 CollectAllGarbage(kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask, | 4423 CollectAllGarbage(kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask, |
4424 source, kGCCallbackFlagCollectAllAvailableGarbage); | 4424 source, kGCCallbackFlagCollectAllAvailableGarbage); |
4425 double end = MonotonicallyIncreasingTimeInMs(); | 4425 double end = MonotonicallyIncreasingTimeInMs(); |
4426 | 4426 |
4427 // Estimate how much memory we can free. | 4427 // Estimate how much memory we can free. |
4428 int64_t potential_garbage = (CommittedMemory() - SizeOfObjects()) + | 4428 int64_t potential_garbage = |
4429 amount_of_external_allocated_memory_; | 4429 (CommittedMemory() - SizeOfObjects()) + external_memory_; |
4430 // If we can potentially free large amount of memory, then start GC right | 4430 // If we can potentially free large amount of memory, then start GC right |
4431 // away instead of waiting for memory reducer. | 4431 // away instead of waiting for memory reducer. |
4432 if (potential_garbage >= kGarbageThresholdInBytes && | 4432 if (potential_garbage >= kGarbageThresholdInBytes && |
4433 potential_garbage >= | 4433 potential_garbage >= |
4434 CommittedMemory() * kGarbageThresholdAsFractionOfTotalMemory) { | 4434 CommittedMemory() * kGarbageThresholdAsFractionOfTotalMemory) { |
4435 // If we spent less than half of the time budget, then perform full GC | 4435 // If we spent less than half of the time budget, then perform full GC |
4436 // Otherwise, start incremental marking. | 4436 // Otherwise, start incremental marking. |
4437 if (end - start < kMaxMemoryPressurePauseMs / 2) { | 4437 if (end - start < kMaxMemoryPressurePauseMs / 2) { |
4438 CollectAllGarbage( | 4438 CollectAllGarbage( |
4439 kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask, source, | 4439 kReduceMemoryFootprintMask | kAbortIncrementalMarkingMask, source, |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5041 } | 5041 } |
5042 | 5042 |
5043 | 5043 |
5044 intptr_t Heap::PromotedSpaceSizeOfObjects() { | 5044 intptr_t Heap::PromotedSpaceSizeOfObjects() { |
5045 return old_space_->SizeOfObjects() + code_space_->SizeOfObjects() + | 5045 return old_space_->SizeOfObjects() + code_space_->SizeOfObjects() + |
5046 map_space_->SizeOfObjects() + lo_space_->SizeOfObjects(); | 5046 map_space_->SizeOfObjects() + lo_space_->SizeOfObjects(); |
5047 } | 5047 } |
5048 | 5048 |
5049 | 5049 |
5050 int64_t Heap::PromotedExternalMemorySize() { | 5050 int64_t Heap::PromotedExternalMemorySize() { |
5051 if (amount_of_external_allocated_memory_ <= | 5051 if (external_memory_ <= external_memory_at_last_mark_compact_) return 0; |
5052 amount_of_external_allocated_memory_at_last_global_gc_) | 5052 return external_memory_ - external_memory_at_last_mark_compact_; |
5053 return 0; | |
5054 return amount_of_external_allocated_memory_ - | |
5055 amount_of_external_allocated_memory_at_last_global_gc_; | |
5056 } | 5053 } |
5057 | 5054 |
5058 | 5055 |
5059 const double Heap::kMinHeapGrowingFactor = 1.1; | 5056 const double Heap::kMinHeapGrowingFactor = 1.1; |
5060 const double Heap::kMaxHeapGrowingFactor = 4.0; | 5057 const double Heap::kMaxHeapGrowingFactor = 4.0; |
5061 const double Heap::kMaxHeapGrowingFactorMemoryConstrained = 2.0; | 5058 const double Heap::kMaxHeapGrowingFactorMemoryConstrained = 2.0; |
5062 const double Heap::kMaxHeapGrowingFactorIdle = 1.5; | 5059 const double Heap::kMaxHeapGrowingFactorIdle = 1.5; |
5063 const double Heap::kTargetMutatorUtilization = 0.97; | 5060 const double Heap::kTargetMutatorUtilization = 0.97; |
5064 | 5061 |
5065 | 5062 |
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6375 } | 6372 } |
6376 | 6373 |
6377 | 6374 |
6378 // static | 6375 // static |
6379 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6376 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6380 return StaticVisitorBase::GetVisitorId(map); | 6377 return StaticVisitorBase::GetVisitorId(map); |
6381 } | 6378 } |
6382 | 6379 |
6383 } // namespace internal | 6380 } // namespace internal |
6384 } // namespace v8 | 6381 } // namespace v8 |
OLD | NEW |