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 #ifndef V8_HEAP_HEAP_H_ | 5 #ifndef V8_HEAP_HEAP_H_ |
6 #define V8_HEAP_HEAP_H_ | 6 #define V8_HEAP_HEAP_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 return old_pointer_space_->allocation_limit_address(); | 685 return old_pointer_space_->allocation_limit_address(); |
686 } | 686 } |
687 | 687 |
688 Address* OldDataSpaceAllocationTopAddress() { | 688 Address* OldDataSpaceAllocationTopAddress() { |
689 return old_data_space_->allocation_top_address(); | 689 return old_data_space_->allocation_top_address(); |
690 } | 690 } |
691 Address* OldDataSpaceAllocationLimitAddress() { | 691 Address* OldDataSpaceAllocationLimitAddress() { |
692 return old_data_space_->allocation_limit_address(); | 692 return old_data_space_->allocation_limit_address(); |
693 } | 693 } |
694 | 694 |
695 // TODO(hpayer): There is still a missmatch between capacity and actual | 695 // TODO(hpayer): There is still a mismatch between capacity and actual |
696 // committed memory size. | 696 // committed memory size. |
697 bool CanExpandOldGeneration(int size) { | 697 bool CanExpandOldGeneration(int size) { |
698 return (CommittedOldGenerationMemory() + size) < MaxOldGenerationSize(); | 698 return (CommittedOldGenerationMemory() + size) < MaxOldGenerationSize(); |
699 } | 699 } |
700 | 700 |
701 // Returns a deep copy of the JavaScript object. | 701 // Returns a deep copy of the JavaScript object. |
702 // Properties and elements are copied too. | 702 // Properties and elements are copied too. |
703 // Optionally takes an AllocationSite to be appended in an AllocationMemento. | 703 // Optionally takes an AllocationSite to be appended in an AllocationMemento. |
704 MUST_USE_RESULT AllocationResult | 704 MUST_USE_RESULT AllocationResult |
705 CopyJSObject(JSObject* source, AllocationSite* site = NULL); | 705 CopyJSObject(JSObject* source, AllocationSite* site = NULL); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 int64_t total = PromotedSpaceSizeOfObjects() + PromotedExternalMemorySize(); | 1083 int64_t total = PromotedSpaceSizeOfObjects() + PromotedExternalMemorySize(); |
1084 if (total > kMaxInt) return static_cast<intptr_t>(kMaxInt); | 1084 if (total > kMaxInt) return static_cast<intptr_t>(kMaxInt); |
1085 if (total < 0) return 0; | 1085 if (total < 0) return 0; |
1086 return static_cast<intptr_t>(total); | 1086 return static_cast<intptr_t>(total); |
1087 } | 1087 } |
1088 | 1088 |
1089 inline intptr_t OldGenerationSpaceAvailable() { | 1089 inline intptr_t OldGenerationSpaceAvailable() { |
1090 return old_generation_allocation_limit_ - PromotedTotalSize(); | 1090 return old_generation_allocation_limit_ - PromotedTotalSize(); |
1091 } | 1091 } |
1092 | 1092 |
1093 inline intptr_t OldGenerationCapacityAvailable() { | |
1094 return max_old_generation_size_ - PromotedTotalSize(); | |
1095 } | |
1096 | |
1097 static const intptr_t kMinimumOldGenerationAllocationLimit = | 1093 static const intptr_t kMinimumOldGenerationAllocationLimit = |
1098 8 * (Page::kPageSize > MB ? Page::kPageSize : MB); | 1094 8 * (Page::kPageSize > MB ? Page::kPageSize : MB); |
1099 | 1095 |
1100 static const int kInitalOldGenerationLimitFactor = 2; | 1096 static const int kInitalOldGenerationLimitFactor = 2; |
1101 | 1097 |
| 1098 static const intptr_t kDefaultMaxOldGenSize = 700ul * (kPointerSize / 4) * MB; |
| 1099 |
1102 #if V8_OS_ANDROID | 1100 #if V8_OS_ANDROID |
1103 // Don't apply pointer multiplier on Android since it has no swap space and | 1101 // Don't apply pointer multiplier on Android since it has no swap space and |
1104 // should instead adapt it's heap size based on available physical memory. | 1102 // should instead adapt it's heap size based on available physical memory. |
1105 static const int kPointerMultiplier = 1; | 1103 static const int kPointerMultiplier = 1; |
1106 #else | 1104 #else |
1107 static const int kPointerMultiplier = i::kPointerSize / 4; | 1105 static const int kPointerMultiplier = i::kPointerSize / 4; |
1108 #endif | 1106 #endif |
1109 | 1107 |
1110 // The new space size has to be a power of 2. Sizes are in MB. | 1108 // The new space size has to be a power of 2. Sizes are in MB. |
1111 static const int kMaxSemiSpaceSizeLowMemoryDevice = 1 * kPointerMultiplier; | 1109 static const int kMaxSemiSpaceSizeLowMemoryDevice = 1 * kPointerMultiplier; |
(...skipping 12 matching lines...) Expand all Loading... |
1124 // The executable size has to be a multiple of Page::kPageSize. | 1122 // The executable size has to be a multiple of Page::kPageSize. |
1125 // Sizes are in MB. | 1123 // Sizes are in MB. |
1126 static const int kMaxExecutableSizeLowMemoryDevice = 96 * kPointerMultiplier; | 1124 static const int kMaxExecutableSizeLowMemoryDevice = 96 * kPointerMultiplier; |
1127 static const int kMaxExecutableSizeMediumMemoryDevice = | 1125 static const int kMaxExecutableSizeMediumMemoryDevice = |
1128 192 * kPointerMultiplier; | 1126 192 * kPointerMultiplier; |
1129 static const int kMaxExecutableSizeHighMemoryDevice = | 1127 static const int kMaxExecutableSizeHighMemoryDevice = |
1130 256 * kPointerMultiplier; | 1128 256 * kPointerMultiplier; |
1131 static const int kMaxExecutableSizeHugeMemoryDevice = | 1129 static const int kMaxExecutableSizeHugeMemoryDevice = |
1132 256 * kPointerMultiplier; | 1130 256 * kPointerMultiplier; |
1133 | 1131 |
1134 intptr_t OldGenerationAllocationLimit(intptr_t old_gen_size, | 1132 void SetOldGenerationAllocationLimit(intptr_t old_gen_size, |
1135 int freed_global_handles); | 1133 int freed_global_handles, |
| 1134 bool weak_callbacks_completed); |
1136 | 1135 |
1137 // Indicates whether inline bump-pointer allocation has been disabled. | 1136 // Indicates whether inline bump-pointer allocation has been disabled. |
1138 bool inline_allocation_disabled() { return inline_allocation_disabled_; } | 1137 bool inline_allocation_disabled() { return inline_allocation_disabled_; } |
1139 | 1138 |
1140 // Switch whether inline bump-pointer allocation should be used. | 1139 // Switch whether inline bump-pointer allocation should be used. |
1141 void EnableInlineAllocation(); | 1140 void EnableInlineAllocation(); |
1142 void DisableInlineAllocation(); | 1141 void DisableInlineAllocation(); |
1143 | 1142 |
1144 // Implements the corresponding V8 API function. | 1143 // Implements the corresponding V8 API function. |
1145 bool IdleNotification(double deadline_in_seconds); | 1144 bool IdleNotification(double deadline_in_seconds); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 survived_since_last_expansion_ += survived; | 1237 survived_since_last_expansion_ += survived; |
1239 } | 1238 } |
1240 | 1239 |
1241 inline bool NextGCIsLikelyToBeFull() { | 1240 inline bool NextGCIsLikelyToBeFull() { |
1242 if (FLAG_gc_global) return true; | 1241 if (FLAG_gc_global) return true; |
1243 | 1242 |
1244 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true; | 1243 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true; |
1245 | 1244 |
1246 intptr_t adjusted_allocation_limit = | 1245 intptr_t adjusted_allocation_limit = |
1247 old_generation_allocation_limit_ - new_space_.Capacity(); | 1246 old_generation_allocation_limit_ - new_space_.Capacity(); |
| 1247 intptr_t adjusted_committed_limit = |
| 1248 old_generation_committed_memory_limit_ - new_space_.Capacity(); |
1248 | 1249 |
1249 if (PromotedTotalSize() >= adjusted_allocation_limit) return true; | 1250 if (PromotedTotalSize() >= adjusted_allocation_limit) { |
| 1251 if (FLAG_trace_gc_verbose) { |
| 1252 PrintF("Next GC likely to be full: We are at %" V8_PTR_PREFIX |
| 1253 "dMbytes out of %" V8_PTR_PREFIX "dMbytes\n", |
| 1254 PromotedTotalSize() >> 20, |
| 1255 old_generation_allocation_limit_ >> 20); |
| 1256 } |
| 1257 return true; |
| 1258 } |
| 1259 |
| 1260 if (CommittedOldGenerationMemory() >= adjusted_committed_limit) { |
| 1261 if (FLAG_trace_gc_verbose) { |
| 1262 PrintF("Next GC likely to be full: We are at %" V8_PTR_PREFIX |
| 1263 "dMbytes committed out of %" V8_PTR_PREFIX "dMbytes\n", |
| 1264 CommittedOldGenerationMemory() >> 20, |
| 1265 old_generation_committed_memory_limit_ >> 20); |
| 1266 } |
| 1267 return true; |
| 1268 } |
1250 | 1269 |
1251 return false; | 1270 return false; |
1252 } | 1271 } |
1253 | 1272 |
1254 void UpdateNewSpaceReferencesInExternalStringTable( | 1273 void UpdateNewSpaceReferencesInExternalStringTable( |
1255 ExternalStringTableUpdaterCallback updater_func); | 1274 ExternalStringTableUpdaterCallback updater_func); |
1256 | 1275 |
1257 void UpdateReferencesInExternalStringTable( | 1276 void UpdateReferencesInExternalStringTable( |
1258 ExternalStringTableUpdaterCallback updater_func); | 1277 ExternalStringTableUpdaterCallback updater_func); |
1259 | 1278 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 #ifdef DEBUG | 1657 #ifdef DEBUG |
1639 // If the --gc-interval flag is set to a positive value, this | 1658 // If the --gc-interval flag is set to a positive value, this |
1640 // variable holds the value indicating the number of allocations | 1659 // variable holds the value indicating the number of allocations |
1641 // remain until the next failure and garbage collection. | 1660 // remain until the next failure and garbage collection. |
1642 int allocation_timeout_; | 1661 int allocation_timeout_; |
1643 #endif // DEBUG | 1662 #endif // DEBUG |
1644 | 1663 |
1645 // Limit that triggers a global GC on the next (normally caused) GC. This | 1664 // Limit that triggers a global GC on the next (normally caused) GC. This |
1646 // is checked when we have already decided to do a GC to help determine | 1665 // is checked when we have already decided to do a GC to help determine |
1647 // which collector to invoke, before expanding a paged space in the old | 1666 // which collector to invoke, before expanding a paged space in the old |
1648 // generation and on every allocation in large object space. | 1667 // generation and on every allocation in large object space. This only |
| 1668 // measures objects, so it may be underreporting if we have fragmentation. |
1649 intptr_t old_generation_allocation_limit_; | 1669 intptr_t old_generation_allocation_limit_; |
1650 | 1670 |
| 1671 // As above, but counts pages, not objects, so is more likely to trigger |
| 1672 // when we have fragmentation. |
| 1673 intptr_t old_generation_committed_memory_limit_; |
| 1674 |
1651 // Indicates that an allocation has failed in the old generation since the | 1675 // Indicates that an allocation has failed in the old generation since the |
1652 // last GC. | 1676 // last GC. |
1653 bool old_gen_exhausted_; | 1677 bool old_gen_exhausted_; |
1654 | 1678 |
1655 // Indicates that inline bump-pointer allocation has been globally disabled | 1679 // Indicates that inline bump-pointer allocation has been globally disabled |
1656 // for all spaces. This is used to disable allocations in generated code. | 1680 // for all spaces. This is used to disable allocations in generated code. |
1657 bool inline_allocation_disabled_; | 1681 bool inline_allocation_disabled_; |
1658 | 1682 |
1659 // Weak list heads, threaded through the objects. | 1683 // Weak list heads, threaded through the objects. |
1660 // List heads are initialized lazily and contain the undefined_value at start. | 1684 // List heads are initialized lazily and contain the undefined_value at start. |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2073 void ConfigureInitialOldGenerationSize(); | 2097 void ConfigureInitialOldGenerationSize(); |
2074 | 2098 |
2075 void SelectScavengingVisitorsTable(); | 2099 void SelectScavengingVisitorsTable(); |
2076 | 2100 |
2077 void IdleMarkCompact(const char* message); | 2101 void IdleMarkCompact(const char* message); |
2078 | 2102 |
2079 bool TryFinalizeIdleIncrementalMarking( | 2103 bool TryFinalizeIdleIncrementalMarking( |
2080 double idle_time_in_ms, size_t size_of_objects, | 2104 double idle_time_in_ms, size_t size_of_objects, |
2081 size_t mark_compact_speed_in_bytes_per_ms); | 2105 size_t mark_compact_speed_in_bytes_per_ms); |
2082 | 2106 |
2083 bool WorthActivatingIncrementalMarking(); | |
2084 | |
2085 void ClearObjectStats(bool clear_last_time_stats = false); | 2107 void ClearObjectStats(bool clear_last_time_stats = false); |
2086 | 2108 |
2087 inline void UpdateAllocationsHash(HeapObject* object); | 2109 inline void UpdateAllocationsHash(HeapObject* object); |
2088 inline void UpdateAllocationsHash(uint32_t value); | 2110 inline void UpdateAllocationsHash(uint32_t value); |
2089 inline void PrintAlloctionsHash(); | 2111 inline void PrintAlloctionsHash(); |
2090 | 2112 |
2091 // Object counts and used memory by InstanceType | 2113 // Object counts and used memory by InstanceType |
2092 size_t object_counts_[OBJECT_STATS_COUNT]; | 2114 size_t object_counts_[OBJECT_STATS_COUNT]; |
2093 size_t object_counts_last_time_[OBJECT_STATS_COUNT]; | 2115 size_t object_counts_last_time_[OBJECT_STATS_COUNT]; |
2094 size_t object_sizes_[OBJECT_STATS_COUNT]; | 2116 size_t object_sizes_[OBJECT_STATS_COUNT]; |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2650 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2629 | 2651 |
2630 private: | 2652 private: |
2631 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2653 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2632 }; | 2654 }; |
2633 #endif // DEBUG | 2655 #endif // DEBUG |
2634 } | 2656 } |
2635 } // namespace v8::internal | 2657 } // namespace v8::internal |
2636 | 2658 |
2637 #endif // V8_HEAP_HEAP_H_ | 2659 #endif // V8_HEAP_HEAP_H_ |
OLD | NEW |