| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
| 6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/base/atomicops.h" | 9 #include "src/base/atomicops.h" |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 // Constructor. | 2068 // Constructor. |
| 2069 SemiSpace(Heap* heap, SemiSpaceId semispace) | 2069 SemiSpace(Heap* heap, SemiSpaceId semispace) |
| 2070 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 2070 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| 2071 start_(NULL), | 2071 start_(NULL), |
| 2072 age_mark_(NULL), | 2072 age_mark_(NULL), |
| 2073 id_(semispace), | 2073 id_(semispace), |
| 2074 anchor_(this), | 2074 anchor_(this), |
| 2075 current_page_(NULL) {} | 2075 current_page_(NULL) {} |
| 2076 | 2076 |
| 2077 // Sets up the semispace using the given chunk. | 2077 // Sets up the semispace using the given chunk. |
| 2078 void SetUp(Address start, int initial_capacity, int maximum_capacity); | 2078 void SetUp(Address start, int initial_capacity, int target_capacity, |
| 2079 int maximum_capacity); |
| 2079 | 2080 |
| 2080 // Tear down the space. Heap memory was not allocated by the space, so it | 2081 // Tear down the space. Heap memory was not allocated by the space, so it |
| 2081 // is not deallocated here. | 2082 // is not deallocated here. |
| 2082 void TearDown(); | 2083 void TearDown(); |
| 2083 | 2084 |
| 2084 // True if the space has been set up but not torn down. | 2085 // True if the space has been set up but not torn down. |
| 2085 bool HasBeenSetUp() { return start_ != NULL; } | 2086 bool HasBeenSetUp() { return start_ != NULL; } |
| 2086 | 2087 |
| 2087 // Grow the semispace to the new capacity. The new capacity | 2088 // Grow the semispace to the new capacity. The new capacity |
| 2088 // requested must be larger than the current capacity and less than | 2089 // requested must be larger than the current capacity and less than |
| 2089 // the maximum capacity. | 2090 // the maximum capacity. |
| 2090 bool GrowTo(int new_capacity); | 2091 bool GrowTo(int new_capacity); |
| 2091 | 2092 |
| 2092 // Shrinks the semispace to the new capacity. The new capacity | 2093 // Shrinks the semispace to the new capacity. The new capacity |
| 2093 // requested must be more than the amount of used memory in the | 2094 // requested must be more than the amount of used memory in the |
| 2094 // semispace and less than the current capacity. | 2095 // semispace and less than the current capacity. |
| 2095 bool ShrinkTo(int new_capacity); | 2096 bool ShrinkTo(int new_capacity); |
| 2096 | 2097 |
| 2098 // Sets the total capacity. Only possible when the space is not committed. |
| 2099 bool SetTotalCapacity(int new_capacity); |
| 2100 |
| 2097 // Returns the start address of the first page of the space. | 2101 // Returns the start address of the first page of the space. |
| 2098 Address space_start() { | 2102 Address space_start() { |
| 2099 DCHECK(anchor_.next_page() != &anchor_); | 2103 DCHECK(anchor_.next_page() != &anchor_); |
| 2100 return anchor_.next_page()->area_start(); | 2104 return anchor_.next_page()->area_start(); |
| 2101 } | 2105 } |
| 2102 | 2106 |
| 2103 // Returns the start address of the current page of the space. | 2107 // Returns the start address of the current page of the space. |
| 2104 Address page_low() { return current_page_->area_start(); } | 2108 Address page_low() { return current_page_->area_start(); } |
| 2105 | 2109 |
| 2106 // Returns one past the end address of the space. | 2110 // Returns one past the end address of the space. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 // in the linked page order, or it must be earlier on the same page. | 2165 // in the linked page order, or it must be earlier on the same page. |
| 2162 static void AssertValidRange(Address from, Address to); | 2166 static void AssertValidRange(Address from, Address to); |
| 2163 #else | 2167 #else |
| 2164 // Do nothing. | 2168 // Do nothing. |
| 2165 inline static void AssertValidRange(Address from, Address to) {} | 2169 inline static void AssertValidRange(Address from, Address to) {} |
| 2166 #endif | 2170 #endif |
| 2167 | 2171 |
| 2168 // Returns the current total capacity of the semispace. | 2172 // Returns the current total capacity of the semispace. |
| 2169 int TotalCapacity() { return total_capacity_; } | 2173 int TotalCapacity() { return total_capacity_; } |
| 2170 | 2174 |
| 2175 // Returns the target for total capacity of the semispace. |
| 2176 int TargetCapacity() { return target_capacity_; } |
| 2177 |
| 2171 // Returns the maximum total capacity of the semispace. | 2178 // Returns the maximum total capacity of the semispace. |
| 2172 int MaximumTotalCapacity() { return maximum_total_capacity_; } | 2179 int MaximumTotalCapacity() { return maximum_total_capacity_; } |
| 2173 | 2180 |
| 2174 // Returns the initial capacity of the semispace. | 2181 // Returns the initial capacity of the semispace. |
| 2175 int InitialTotalCapacity() { return initial_total_capacity_; } | 2182 int InitialTotalCapacity() { return initial_total_capacity_; } |
| 2176 | 2183 |
| 2177 SemiSpaceId id() { return id_; } | 2184 SemiSpaceId id() { return id_; } |
| 2178 | 2185 |
| 2179 static void Swap(SemiSpace* from, SemiSpace* to); | 2186 static void Swap(SemiSpace* from, SemiSpace* to); |
| 2180 | 2187 |
| 2181 // Returns the maximum amount of memory ever committed by the semi space. | 2188 // Returns the maximum amount of memory ever committed by the semi space. |
| 2182 size_t MaximumCommittedMemory() { return maximum_committed_; } | 2189 size_t MaximumCommittedMemory() { return maximum_committed_; } |
| 2183 | 2190 |
| 2184 // Approximate amount of physical memory committed for this space. | 2191 // Approximate amount of physical memory committed for this space. |
| 2185 size_t CommittedPhysicalMemory(); | 2192 size_t CommittedPhysicalMemory(); |
| 2186 | 2193 |
| 2187 private: | 2194 private: |
| 2188 // Flips the semispace between being from-space and to-space. | 2195 // Flips the semispace between being from-space and to-space. |
| 2189 // Copies the flags into the masked positions on all pages in the space. | 2196 // Copies the flags into the masked positions on all pages in the space. |
| 2190 void FlipPages(intptr_t flags, intptr_t flag_mask); | 2197 void FlipPages(intptr_t flags, intptr_t flag_mask); |
| 2191 | 2198 |
| 2192 // Updates Capacity and MaximumCommitted based on new capacity. | 2199 // Updates Capacity and MaximumCommitted based on new capacity. |
| 2193 void SetCapacity(int new_capacity); | 2200 void SetCapacity(int new_capacity); |
| 2194 | 2201 |
| 2195 NewSpacePage* anchor() { return &anchor_; } | 2202 NewSpacePage* anchor() { return &anchor_; } |
| 2196 | 2203 |
| 2197 // The current and maximum total capacity of the space. | 2204 // The current and maximum total capacity of the space. |
| 2198 int total_capacity_; | 2205 int total_capacity_; |
| 2206 int target_capacity_; |
| 2199 int maximum_total_capacity_; | 2207 int maximum_total_capacity_; |
| 2200 int initial_total_capacity_; | 2208 int initial_total_capacity_; |
| 2201 | 2209 |
| 2202 intptr_t maximum_committed_; | 2210 intptr_t maximum_committed_; |
| 2203 | 2211 |
| 2204 // The start address of the space. | 2212 // The start address of the space. |
| 2205 Address start_; | 2213 Address start_; |
| 2206 // Used to govern object promotion during mark-compact collection. | 2214 // Used to govern object promotion during mark-compact collection. |
| 2207 Address age_mark_; | 2215 Address age_mark_; |
| 2208 | 2216 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp(); | 2342 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp(); |
| 2335 } | 2343 } |
| 2336 | 2344 |
| 2337 // Flip the pair of spaces. | 2345 // Flip the pair of spaces. |
| 2338 void Flip(); | 2346 void Flip(); |
| 2339 | 2347 |
| 2340 // Grow the capacity of the semispaces. Assumes that they are not at | 2348 // Grow the capacity of the semispaces. Assumes that they are not at |
| 2341 // their maximum capacity. | 2349 // their maximum capacity. |
| 2342 void Grow(); | 2350 void Grow(); |
| 2343 | 2351 |
| 2352 // Grow the capacity of the semispaces by one page. |
| 2353 bool GrowOnePage(); |
| 2354 |
| 2344 // Shrink the capacity of the semispaces. | 2355 // Shrink the capacity of the semispaces. |
| 2345 void Shrink(); | 2356 void Shrink(); |
| 2346 | 2357 |
| 2347 // True if the address or object lies in the address range of either | 2358 // True if the address or object lies in the address range of either |
| 2348 // semispace (not necessarily below the allocation pointer). | 2359 // semispace (not necessarily below the allocation pointer). |
| 2349 bool Contains(Address a) { | 2360 bool Contains(Address a) { |
| 2350 return (reinterpret_cast<uintptr_t>(a) & address_mask_) == | 2361 return (reinterpret_cast<uintptr_t>(a) & address_mask_) == |
| 2351 reinterpret_cast<uintptr_t>(start_); | 2362 reinterpret_cast<uintptr_t>(start_); |
| 2352 } | 2363 } |
| 2353 | 2364 |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2883 count = 0; | 2894 count = 0; |
| 2884 } | 2895 } |
| 2885 // Must be small, since an iteration is used for lookup. | 2896 // Must be small, since an iteration is used for lookup. |
| 2886 static const int kMaxComments = 64; | 2897 static const int kMaxComments = 64; |
| 2887 }; | 2898 }; |
| 2888 #endif | 2899 #endif |
| 2889 } | 2900 } |
| 2890 } // namespace v8::internal | 2901 } // namespace v8::internal |
| 2891 | 2902 |
| 2892 #endif // V8_HEAP_SPACES_H_ | 2903 #endif // V8_HEAP_SPACES_H_ |
| OLD | NEW |