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

Side by Side Diff: src/heap/spaces.h

Issue 2490523003: [heap] Use size_t for heap and space counters. (Closed)
Patch Set: more fixes Created 4 years, 1 month 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/heap/heap.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <unordered_set> 10 #include <unordered_set>
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 862
863 void AllocationStep(Address soon_object, int size); 863 void AllocationStep(Address soon_object, int size);
864 864
865 // Return the total amount committed memory for this space, i.e., allocatable 865 // Return the total amount committed memory for this space, i.e., allocatable
866 // memory and page headers. 866 // memory and page headers.
867 virtual size_t CommittedMemory() { return committed_; } 867 virtual size_t CommittedMemory() { return committed_; }
868 868
869 virtual size_t MaximumCommittedMemory() { return max_committed_; } 869 virtual size_t MaximumCommittedMemory() { return max_committed_; }
870 870
871 // Returns allocated size. 871 // Returns allocated size.
872 virtual intptr_t Size() = 0; 872 virtual size_t Size() = 0;
873 873
874 // Returns size of objects. Can differ from the allocated size 874 // Returns size of objects. Can differ from the allocated size
875 // (e.g. see LargeObjectSpace). 875 // (e.g. see LargeObjectSpace).
876 virtual intptr_t SizeOfObjects() { return Size(); } 876 virtual size_t SizeOfObjects() { return Size(); }
877 877
878 // Approximate amount of physical memory committed for this space. 878 // Approximate amount of physical memory committed for this space.
879 virtual size_t CommittedPhysicalMemory() = 0; 879 virtual size_t CommittedPhysicalMemory() = 0;
880 880
881 // Return the available bytes without growing. 881 // Return the available bytes without growing.
882 virtual intptr_t Available() = 0; 882 virtual size_t Available() = 0;
883 883
884 virtual int RoundSizeDownToObjectAlignment(int size) { 884 virtual int RoundSizeDownToObjectAlignment(int size) {
885 if (id_ == CODE_SPACE) { 885 if (id_ == CODE_SPACE) {
886 return RoundDown(size, kCodeAlignment); 886 return RoundDown(size, kCodeAlignment);
887 } else { 887 } else {
888 return RoundDown(size, kPointerSize); 888 return RoundDown(size, kPointerSize);
889 } 889 }
890 } 890 }
891 891
892 virtual std::unique_ptr<ObjectIterator> GetObjectIterator() = 0; 892 virtual std::unique_ptr<ObjectIterator> GetObjectIterator() = 0;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 static size_t PageAreaSize(AllocationSpace space) { 1206 static size_t PageAreaSize(AllocationSpace space) {
1207 DCHECK_NE(LO_SPACE, space); 1207 DCHECK_NE(LO_SPACE, space);
1208 return (space == CODE_SPACE) ? CodePageAreaSize() 1208 return (space == CODE_SPACE) ? CodePageAreaSize()
1209 : Page::kAllocatableMemory; 1209 : Page::kAllocatableMemory;
1210 } 1210 }
1211 1211
1212 explicit MemoryAllocator(Isolate* isolate); 1212 explicit MemoryAllocator(Isolate* isolate);
1213 1213
1214 // Initializes its internal bookkeeping structures. 1214 // Initializes its internal bookkeeping structures.
1215 // Max capacity of the total space and executable memory limit. 1215 // Max capacity of the total space and executable memory limit.
1216 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable, 1216 bool SetUp(size_t max_capacity, size_t capacity_executable,
1217 intptr_t code_range_size); 1217 size_t code_range_size);
1218 1218
1219 void TearDown(); 1219 void TearDown();
1220 1220
1221 // Allocates a Page from the allocator. AllocationMode is used to indicate 1221 // Allocates a Page from the allocator. AllocationMode is used to indicate
1222 // whether pooled allocation, which only works for MemoryChunk::kPageSize, 1222 // whether pooled allocation, which only works for MemoryChunk::kPageSize,
1223 // should be tried first. 1223 // should be tried first.
1224 template <MemoryAllocator::AllocationMode alloc_mode = kRegular, 1224 template <MemoryAllocator::AllocationMode alloc_mode = kRegular,
1225 typename SpaceType> 1225 typename SpaceType>
1226 Page* AllocatePage(size_t size, SpaceType* owner, Executability executable); 1226 Page* AllocatePage(size_t size, SpaceType* owner, Executability executable);
1227 1227
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 Object* FindObject(Address addr); 1920 Object* FindObject(Address addr);
1921 1921
1922 // During boot the free_space_map is created, and afterwards we may need 1922 // During boot the free_space_map is created, and afterwards we may need
1923 // to write it into the free list nodes that were already created. 1923 // to write it into the free list nodes that were already created.
1924 void RepairFreeListsAfterDeserialization(); 1924 void RepairFreeListsAfterDeserialization();
1925 1925
1926 // Prepares for a mark-compact GC. 1926 // Prepares for a mark-compact GC.
1927 void PrepareForMarkCompact(); 1927 void PrepareForMarkCompact();
1928 1928
1929 // Current capacity without growing (Size() + Available()). 1929 // Current capacity without growing (Size() + Available()).
1930 intptr_t Capacity() { return accounting_stats_.Capacity(); } 1930 size_t Capacity() { return accounting_stats_.Capacity(); }
1931 1931
1932 // Approximate amount of physical memory committed for this space. 1932 // Approximate amount of physical memory committed for this space.
1933 size_t CommittedPhysicalMemory() override; 1933 size_t CommittedPhysicalMemory() override;
1934 1934
1935 void ResetFreeListStatistics(); 1935 void ResetFreeListStatistics();
1936 1936
1937 // Sets the capacity, the available space and the wasted space to zero. 1937 // Sets the capacity, the available space and the wasted space to zero.
1938 // The stats are rebuilt during sweeping by adding each page to the 1938 // The stats are rebuilt during sweeping by adding each page to the
1939 // capacity and the size when it is encountered. As free spaces are 1939 // capacity and the size when it is encountered. As free spaces are
1940 // discovered during the sweeping they are subtracted from the size and added 1940 // discovered during the sweeping they are subtracted from the size and added
1941 // to the available and wasted totals. 1941 // to the available and wasted totals.
1942 void ClearStats() { 1942 void ClearStats() {
1943 accounting_stats_.ClearSize(); 1943 accounting_stats_.ClearSize();
1944 free_list_.ResetStats(); 1944 free_list_.ResetStats();
1945 ResetFreeListStatistics(); 1945 ResetFreeListStatistics();
1946 } 1946 }
1947 1947
1948 // Available bytes without growing. These are the bytes on the free list. 1948 // Available bytes without growing. These are the bytes on the free list.
1949 // The bytes in the linear allocation area are not included in this total 1949 // The bytes in the linear allocation area are not included in this total
1950 // because updating the stats would slow down allocation. New pages are 1950 // because updating the stats would slow down allocation. New pages are
1951 // immediately added to the free list so they show up here. 1951 // immediately added to the free list so they show up here.
1952 intptr_t Available() override { return free_list_.Available(); } 1952 size_t Available() override { return free_list_.Available(); }
1953 1953
1954 // Allocated bytes in this space. Garbage bytes that were not found due to 1954 // Allocated bytes in this space. Garbage bytes that were not found due to
1955 // concurrent sweeping are counted as being allocated! The bytes in the 1955 // concurrent sweeping are counted as being allocated! The bytes in the
1956 // current linear allocation area (between top and limit) are also counted 1956 // current linear allocation area (between top and limit) are also counted
1957 // here. 1957 // here.
1958 intptr_t Size() override { return accounting_stats_.Size(); } 1958 size_t Size() override { return accounting_stats_.Size(); }
1959 1959
1960 // As size, but the bytes in lazily swept pages are estimated and the bytes 1960 // As size, but the bytes in lazily swept pages are estimated and the bytes
1961 // in the current linear allocation area are not included. 1961 // in the current linear allocation area are not included.
1962 intptr_t SizeOfObjects() override; 1962 size_t SizeOfObjects() override;
1963 1963
1964 // Wasted bytes in this space. These are just the bytes that were thrown away 1964 // Wasted bytes in this space. These are just the bytes that were thrown away
1965 // due to being too small to use for allocation. 1965 // due to being too small to use for allocation.
1966 virtual intptr_t Waste() { return free_list_.wasted_bytes(); } 1966 virtual size_t Waste() { return free_list_.wasted_bytes(); }
1967 1967
1968 // Returns the allocation pointer in this space. 1968 // Returns the allocation pointer in this space.
1969 Address top() { return allocation_info_.top(); } 1969 Address top() { return allocation_info_.top(); }
1970 Address limit() { return allocation_info_.limit(); } 1970 Address limit() { return allocation_info_.limit(); }
1971 1971
1972 // The allocation top address. 1972 // The allocation top address.
1973 Address* allocation_top_address() { return allocation_info_.top_address(); } 1973 Address* allocation_top_address() { return allocation_info_.top_address(); }
1974 1974
1975 // The allocation limit address. 1975 // The allocation limit address.
1976 Address* allocation_limit_address() { 1976 Address* allocation_limit_address() {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 committed_(false), 2183 committed_(false),
2184 id_(semispace), 2184 id_(semispace),
2185 anchor_(this), 2185 anchor_(this),
2186 current_page_(nullptr), 2186 current_page_(nullptr),
2187 pages_used_(0) {} 2187 pages_used_(0) {}
2188 2188
2189 inline bool Contains(HeapObject* o); 2189 inline bool Contains(HeapObject* o);
2190 inline bool Contains(Object* o); 2190 inline bool Contains(Object* o);
2191 inline bool ContainsSlow(Address a); 2191 inline bool ContainsSlow(Address a);
2192 2192
2193 void SetUp(int initial_capacity, int maximum_capacity); 2193 void SetUp(size_t initial_capacity, size_t maximum_capacity);
2194 void TearDown(); 2194 void TearDown();
2195 bool HasBeenSetUp() { return maximum_capacity_ != 0; } 2195 bool HasBeenSetUp() { return maximum_capacity_ != 0; }
2196 2196
2197 bool Commit(); 2197 bool Commit();
2198 bool Uncommit(); 2198 bool Uncommit();
2199 bool is_committed() { return committed_; } 2199 bool is_committed() { return committed_; }
2200 2200
2201 // Grow the semispace to the new capacity. The new capacity requested must 2201 // Grow the semispace to the new capacity. The new capacity requested must
2202 // be larger than the current capacity and less than the maximum capacity. 2202 // be larger than the current capacity and less than the maximum capacity.
2203 bool GrowTo(int new_capacity); 2203 bool GrowTo(size_t new_capacity);
2204 2204
2205 // Shrinks the semispace to the new capacity. The new capacity requested 2205 // Shrinks the semispace to the new capacity. The new capacity requested
2206 // must be more than the amount of used memory in the semispace and less 2206 // must be more than the amount of used memory in the semispace and less
2207 // than the current capacity. 2207 // than the current capacity.
2208 bool ShrinkTo(int new_capacity); 2208 bool ShrinkTo(size_t new_capacity);
2209 2209
2210 bool EnsureCurrentCapacity(); 2210 bool EnsureCurrentCapacity();
2211 2211
2212 // Returns the start address of the first page of the space. 2212 // Returns the start address of the first page of the space.
2213 Address space_start() { 2213 Address space_start() {
2214 DCHECK_NE(anchor_.next_page(), anchor()); 2214 DCHECK_NE(anchor_.next_page(), anchor());
2215 return anchor_.next_page()->area_start(); 2215 return anchor_.next_page()->area_start();
2216 } 2216 }
2217 2217
2218 Page* first_page() { return anchor_.next_page(); } 2218 Page* first_page() { return anchor_.next_page(); }
(...skipping 27 matching lines...) Expand all
2246 void Reset(); 2246 void Reset();
2247 2247
2248 void RemovePage(Page* page); 2248 void RemovePage(Page* page);
2249 void PrependPage(Page* page); 2249 void PrependPage(Page* page);
2250 2250
2251 // Age mark accessors. 2251 // Age mark accessors.
2252 Address age_mark() { return age_mark_; } 2252 Address age_mark() { return age_mark_; }
2253 void set_age_mark(Address mark); 2253 void set_age_mark(Address mark);
2254 2254
2255 // Returns the current capacity of the semispace. 2255 // Returns the current capacity of the semispace.
2256 int current_capacity() { return current_capacity_; } 2256 size_t current_capacity() { return current_capacity_; }
2257 2257
2258 // Returns the maximum capacity of the semispace. 2258 // Returns the maximum capacity of the semispace.
2259 int maximum_capacity() { return maximum_capacity_; } 2259 size_t maximum_capacity() { return maximum_capacity_; }
2260 2260
2261 // Returns the initial capacity of the semispace. 2261 // Returns the initial capacity of the semispace.
2262 int minimum_capacity() { return minimum_capacity_; } 2262 size_t minimum_capacity() { return minimum_capacity_; }
2263 2263
2264 SemiSpaceId id() { return id_; } 2264 SemiSpaceId id() { return id_; }
2265 2265
2266 // Approximate amount of physical memory committed for this space. 2266 // Approximate amount of physical memory committed for this space.
2267 size_t CommittedPhysicalMemory() override; 2267 size_t CommittedPhysicalMemory() override;
2268 2268
2269 // If we don't have these here then SemiSpace will be abstract. However 2269 // If we don't have these here then SemiSpace will be abstract. However
2270 // they should never be called: 2270 // they should never be called:
2271 2271
2272 intptr_t Size() override { 2272 size_t Size() override {
2273 UNREACHABLE(); 2273 UNREACHABLE();
2274 return 0; 2274 return 0;
2275 } 2275 }
2276 2276
2277 intptr_t SizeOfObjects() override { return Size(); } 2277 size_t SizeOfObjects() override { return Size(); }
2278 2278
2279 intptr_t Available() override { 2279 size_t Available() override {
2280 UNREACHABLE(); 2280 UNREACHABLE();
2281 return 0; 2281 return 0;
2282 } 2282 }
2283 2283
2284 iterator begin() { return iterator(anchor_.next_page()); } 2284 iterator begin() { return iterator(anchor_.next_page()); }
2285 iterator end() { return iterator(anchor()); } 2285 iterator end() { return iterator(anchor()); }
2286 2286
2287 std::unique_ptr<ObjectIterator> GetObjectIterator() override; 2287 std::unique_ptr<ObjectIterator> GetObjectIterator() override;
2288 2288
2289 #ifdef DEBUG 2289 #ifdef DEBUG
2290 void Print() override; 2290 void Print() override;
2291 // Validate a range of of addresses in a SemiSpace. 2291 // Validate a range of of addresses in a SemiSpace.
2292 // The "from" address must be on a page prior to the "to" address, 2292 // The "from" address must be on a page prior to the "to" address,
2293 // in the linked page order, or it must be earlier on the same page. 2293 // in the linked page order, or it must be earlier on the same page.
2294 static void AssertValidRange(Address from, Address to); 2294 static void AssertValidRange(Address from, Address to);
2295 #else 2295 #else
2296 // Do nothing. 2296 // Do nothing.
2297 inline static void AssertValidRange(Address from, Address to) {} 2297 inline static void AssertValidRange(Address from, Address to) {}
2298 #endif 2298 #endif
2299 2299
2300 #ifdef VERIFY_HEAP 2300 #ifdef VERIFY_HEAP
2301 virtual void Verify(); 2301 virtual void Verify();
2302 #endif 2302 #endif
2303 2303
2304 private: 2304 private:
2305 void RewindPages(Page* start, int num_pages); 2305 void RewindPages(Page* start, int num_pages);
2306 2306
2307 inline Page* anchor() { return &anchor_; } 2307 inline Page* anchor() { return &anchor_; }
2308 inline int max_pages() { return current_capacity_ / Page::kPageSize; } 2308 inline int max_pages() {
2309 return static_cast<int>(current_capacity_ / Page::kPageSize);
2310 }
2309 2311
2310 // Copies the flags into the masked positions on all pages in the space. 2312 // Copies the flags into the masked positions on all pages in the space.
2311 void FixPagesFlags(intptr_t flags, intptr_t flag_mask); 2313 void FixPagesFlags(intptr_t flags, intptr_t flag_mask);
2312 2314
2313 // The currently committed space capacity. 2315 // The currently committed space capacity.
2314 int current_capacity_; 2316 size_t current_capacity_;
2315 2317
2316 // The maximum capacity that can be used by this space. A space cannot grow 2318 // The maximum capacity that can be used by this space. A space cannot grow
2317 // beyond that size. 2319 // beyond that size.
2318 int maximum_capacity_; 2320 size_t maximum_capacity_;
2319 2321
2320 // The minimum capacity for the space. A space cannot shrink below this size. 2322 // The minimum capacity for the space. A space cannot shrink below this size.
2321 int minimum_capacity_; 2323 size_t minimum_capacity_;
2322 2324
2323 // Used to govern object promotion during mark-compact collection. 2325 // Used to govern object promotion during mark-compact collection.
2324 Address age_mark_; 2326 Address age_mark_;
2325 2327
2326 bool committed_; 2328 bool committed_;
2327 SemiSpaceId id_; 2329 SemiSpaceId id_;
2328 2330
2329 Page anchor_; 2331 Page anchor_;
2330 Page* current_page_; 2332 Page* current_page_;
2331 int pages_used_; 2333 int pages_used_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 from_space_(heap, kFromSpace), 2374 from_space_(heap, kFromSpace),
2373 reservation_(), 2375 reservation_(),
2374 top_on_previous_step_(0), 2376 top_on_previous_step_(0),
2375 allocated_histogram_(nullptr), 2377 allocated_histogram_(nullptr),
2376 promoted_histogram_(nullptr) {} 2378 promoted_histogram_(nullptr) {}
2377 2379
2378 inline bool Contains(HeapObject* o); 2380 inline bool Contains(HeapObject* o);
2379 inline bool ContainsSlow(Address a); 2381 inline bool ContainsSlow(Address a);
2380 inline bool Contains(Object* o); 2382 inline bool Contains(Object* o);
2381 2383
2382 bool SetUp(int initial_semispace_capacity, int max_semispace_capacity); 2384 bool SetUp(size_t initial_semispace_capacity, size_t max_semispace_capacity);
2383 2385
2384 // Tears down the space. Heap memory was not allocated by the space, so it 2386 // Tears down the space. Heap memory was not allocated by the space, so it
2385 // is not deallocated here. 2387 // is not deallocated here.
2386 void TearDown(); 2388 void TearDown();
2387 2389
2388 // True if the space has been set up but not torn down. 2390 // True if the space has been set up but not torn down.
2389 bool HasBeenSetUp() { 2391 bool HasBeenSetUp() {
2390 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp(); 2392 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp();
2391 } 2393 }
2392 2394
2393 // Flip the pair of spaces. 2395 // Flip the pair of spaces.
2394 void Flip(); 2396 void Flip();
2395 2397
2396 // Grow the capacity of the semispaces. Assumes that they are not at 2398 // Grow the capacity of the semispaces. Assumes that they are not at
2397 // their maximum capacity. 2399 // their maximum capacity.
2398 void Grow(); 2400 void Grow();
2399 2401
2400 // Shrink the capacity of the semispaces. 2402 // Shrink the capacity of the semispaces.
2401 void Shrink(); 2403 void Shrink();
2402 2404
2403 // Return the allocated bytes in the active semispace. 2405 // Return the allocated bytes in the active semispace.
2404 intptr_t Size() override { 2406 size_t Size() override {
2407 DCHECK_GE(top(), to_space_.page_low());
2405 return to_space_.pages_used() * Page::kAllocatableMemory + 2408 return to_space_.pages_used() * Page::kAllocatableMemory +
2406 static_cast<int>(top() - to_space_.page_low()); 2409 static_cast<size_t>(top() - to_space_.page_low());
2407 } 2410 }
2408 2411
2409 intptr_t SizeOfObjects() override { return Size(); } 2412 size_t SizeOfObjects() override { return Size(); }
2410 2413
2411 // Return the allocatable capacity of a semispace. 2414 // Return the allocatable capacity of a semispace.
2412 intptr_t Capacity() { 2415 size_t Capacity() {
2413 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); 2416 SLOW_DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
2414 return (to_space_.current_capacity() / Page::kPageSize) * 2417 return (to_space_.current_capacity() / Page::kPageSize) *
2415 Page::kAllocatableMemory; 2418 Page::kAllocatableMemory;
2416 } 2419 }
2417 2420
2418 // Return the current size of a semispace, allocatable and non-allocatable 2421 // Return the current size of a semispace, allocatable and non-allocatable
2419 // memory. 2422 // memory.
2420 intptr_t TotalCapacity() { 2423 size_t TotalCapacity() {
2421 DCHECK(to_space_.current_capacity() == from_space_.current_capacity()); 2424 DCHECK(to_space_.current_capacity() == from_space_.current_capacity());
2422 return to_space_.current_capacity(); 2425 return to_space_.current_capacity();
2423 } 2426 }
2424 2427
2425 // Committed memory for NewSpace is the committed memory of both semi-spaces 2428 // Committed memory for NewSpace is the committed memory of both semi-spaces
2426 // combined. 2429 // combined.
2427 size_t CommittedMemory() override { 2430 size_t CommittedMemory() override {
2428 return from_space_.CommittedMemory() + to_space_.CommittedMemory(); 2431 return from_space_.CommittedMemory() + to_space_.CommittedMemory();
2429 } 2432 }
2430 2433
2431 size_t MaximumCommittedMemory() override { 2434 size_t MaximumCommittedMemory() override {
2432 return from_space_.MaximumCommittedMemory() + 2435 return from_space_.MaximumCommittedMemory() +
2433 to_space_.MaximumCommittedMemory(); 2436 to_space_.MaximumCommittedMemory();
2434 } 2437 }
2435 2438
2436 // Approximate amount of physical memory committed for this space. 2439 // Approximate amount of physical memory committed for this space.
2437 size_t CommittedPhysicalMemory() override; 2440 size_t CommittedPhysicalMemory() override;
2438 2441
2439 // Return the available bytes without growing. 2442 // Return the available bytes without growing.
2440 intptr_t Available() override { return Capacity() - Size(); } 2443 size_t Available() override {
2444 DCHECK_GE(Capacity(), Size());
2445 return Capacity() - Size();
2446 }
2441 2447
2442 size_t AllocatedSinceLastGC() { 2448 size_t AllocatedSinceLastGC() {
2443 bool seen_age_mark = false; 2449 bool seen_age_mark = false;
2444 Address age_mark = to_space_.age_mark(); 2450 Address age_mark = to_space_.age_mark();
2445 Page* current_page = to_space_.first_page(); 2451 Page* current_page = to_space_.first_page();
2446 Page* age_mark_page = Page::FromAddress(age_mark); 2452 Page* age_mark_page = Page::FromAddress(age_mark);
2447 Page* last_page = Page::FromAddress(top() - kPointerSize); 2453 Page* last_page = Page::FromAddress(top() - kPointerSize);
2448 if (age_mark_page == last_page) { 2454 if (age_mark_page == last_page) {
2449 if (top() - age_mark >= 0) { 2455 if (top() - age_mark >= 0) {
2450 return top() - age_mark; 2456 return top() - age_mark;
2451 } 2457 }
2452 // Top was reset at some point, invalidating this metric. 2458 // Top was reset at some point, invalidating this metric.
2453 return 0; 2459 return 0;
2454 } 2460 }
2455 while (current_page != last_page) { 2461 while (current_page != last_page) {
2456 if (current_page == age_mark_page) { 2462 if (current_page == age_mark_page) {
2457 seen_age_mark = true; 2463 seen_age_mark = true;
2458 break; 2464 break;
2459 } 2465 }
2460 current_page = current_page->next_page(); 2466 current_page = current_page->next_page();
2461 } 2467 }
2462 if (!seen_age_mark) { 2468 if (!seen_age_mark) {
2463 // Top was reset at some point, invalidating this metric. 2469 // Top was reset at some point, invalidating this metric.
2464 return 0; 2470 return 0;
2465 } 2471 }
2466 intptr_t allocated = age_mark_page->area_end() - age_mark; 2472 DCHECK_GE(age_mark_page->area_end(), age_mark);
2473 size_t allocated = age_mark_page->area_end() - age_mark;
2467 DCHECK_EQ(current_page, age_mark_page); 2474 DCHECK_EQ(current_page, age_mark_page);
2468 current_page = age_mark_page->next_page(); 2475 current_page = age_mark_page->next_page();
2469 while (current_page != last_page) { 2476 while (current_page != last_page) {
2470 allocated += Page::kAllocatableMemory; 2477 allocated += Page::kAllocatableMemory;
2471 current_page = current_page->next_page(); 2478 current_page = current_page->next_page();
2472 } 2479 }
2480 DCHECK_GE(top(), current_page->area_start());
2473 allocated += top() - current_page->area_start(); 2481 allocated += top() - current_page->area_start();
2474 DCHECK_LE(0, allocated);
2475 DCHECK_LE(allocated, Size()); 2482 DCHECK_LE(allocated, Size());
2476 return static_cast<size_t>(allocated); 2483 return allocated;
2477 } 2484 }
2478 2485
2479 void MovePageFromSpaceToSpace(Page* page) { 2486 void MovePageFromSpaceToSpace(Page* page) {
2480 DCHECK(page->InFromSpace()); 2487 DCHECK(page->InFromSpace());
2481 from_space_.RemovePage(page); 2488 from_space_.RemovePage(page);
2482 to_space_.PrependPage(page); 2489 to_space_.PrependPage(page);
2483 } 2490 }
2484 2491
2485 bool Rebalance(); 2492 bool Rebalance();
2486 2493
2487 // Return the maximum capacity of a semispace. 2494 // Return the maximum capacity of a semispace.
2488 int MaximumCapacity() { 2495 size_t MaximumCapacity() {
2489 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity()); 2496 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity());
2490 return to_space_.maximum_capacity(); 2497 return to_space_.maximum_capacity();
2491 } 2498 }
2492 2499
2493 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); } 2500 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); }
2494 2501
2495 // Returns the initial capacity of a semispace. 2502 // Returns the initial capacity of a semispace.
2496 int InitialTotalCapacity() { 2503 size_t InitialTotalCapacity() {
2497 DCHECK(to_space_.minimum_capacity() == from_space_.minimum_capacity()); 2504 DCHECK(to_space_.minimum_capacity() == from_space_.minimum_capacity());
2498 return to_space_.minimum_capacity(); 2505 return to_space_.minimum_capacity();
2499 } 2506 }
2500 2507
2501 // Return the address of the allocation pointer in the active semispace. 2508 // Return the address of the allocation pointer in the active semispace.
2502 Address top() { 2509 Address top() {
2503 DCHECK(to_space_.current_page()->ContainsLimit(allocation_info_.top())); 2510 DCHECK(to_space_.current_page()->ContainsLimit(allocation_info_.top()));
2504 return allocation_info_.top(); 2511 return allocation_info_.top();
2505 } 2512 }
2506 2513
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 2785
2779 LargeObjectSpace(Heap* heap, AllocationSpace id); 2786 LargeObjectSpace(Heap* heap, AllocationSpace id);
2780 virtual ~LargeObjectSpace(); 2787 virtual ~LargeObjectSpace();
2781 2788
2782 // Initializes internal data structures. 2789 // Initializes internal data structures.
2783 bool SetUp(); 2790 bool SetUp();
2784 2791
2785 // Releases internal resources, frees objects in this space. 2792 // Releases internal resources, frees objects in this space.
2786 void TearDown(); 2793 void TearDown();
2787 2794
2788 static intptr_t ObjectSizeFor(intptr_t chunk_size) { 2795 static size_t ObjectSizeFor(size_t chunk_size) {
2789 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0; 2796 if (chunk_size <= (Page::kPageSize + Page::kObjectStartOffset)) return 0;
2790 return chunk_size - Page::kPageSize - Page::kObjectStartOffset; 2797 return chunk_size - Page::kPageSize - Page::kObjectStartOffset;
2791 } 2798 }
2792 2799
2793 // Shared implementation of AllocateRaw, AllocateRawCode and 2800 // Shared implementation of AllocateRaw, AllocateRawCode and
2794 // AllocateRawFixedArray. 2801 // AllocateRawFixedArray.
2795 MUST_USE_RESULT AllocationResult 2802 MUST_USE_RESULT AllocationResult
2796 AllocateRaw(int object_size, Executability executable); 2803 AllocateRaw(int object_size, Executability executable);
2797 2804
2798 // Available bytes for objects in this space. 2805 // Available bytes for objects in this space.
2799 inline intptr_t Available() override; 2806 inline size_t Available() override;
2800 2807
2801 intptr_t Size() override { return size_; } 2808 size_t Size() override { return size_; }
2802 2809
2803 intptr_t SizeOfObjects() override { return objects_size_; } 2810 size_t SizeOfObjects() override { return objects_size_; }
2804 2811
2805 // Approximate amount of physical memory committed for this space. 2812 // Approximate amount of physical memory committed for this space.
2806 size_t CommittedPhysicalMemory() override; 2813 size_t CommittedPhysicalMemory() override;
2807 2814
2808 int PageCount() { return page_count_; } 2815 int PageCount() { return page_count_; }
2809 2816
2810 // Finds an object for a given address, returns a Smi if it is not found. 2817 // Finds an object for a given address, returns a Smi if it is not found.
2811 // The function iterates through all objects in this space, may be slow. 2818 // The function iterates through all objects in this space, may be slow.
2812 Object* FindObject(Address a); 2819 Object* FindObject(Address a);
2813 2820
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2851 #endif 2858 #endif
2852 2859
2853 #ifdef DEBUG 2860 #ifdef DEBUG
2854 void Print() override; 2861 void Print() override;
2855 void ReportStatistics(); 2862 void ReportStatistics();
2856 #endif 2863 #endif
2857 2864
2858 private: 2865 private:
2859 // The head of the linked list of large object chunks. 2866 // The head of the linked list of large object chunks.
2860 LargePage* first_page_; 2867 LargePage* first_page_;
2861 intptr_t size_; // allocated bytes 2868 size_t size_; // allocated bytes
2862 int page_count_; // number of chunks 2869 int page_count_; // number of chunks
2863 intptr_t objects_size_; // size of objects 2870 size_t objects_size_; // size of objects
2864 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them 2871 // Map MemoryChunk::kAlignment-aligned chunks to large pages covering them
2865 base::HashMap chunk_map_; 2872 base::HashMap chunk_map_;
2866 2873
2867 friend class LargeObjectIterator; 2874 friend class LargeObjectIterator;
2868 }; 2875 };
2869 2876
2870 2877
2871 class LargeObjectIterator : public ObjectIterator { 2878 class LargeObjectIterator : public ObjectIterator {
2872 public: 2879 public:
2873 explicit LargeObjectIterator(LargeObjectSpace* space); 2880 explicit LargeObjectIterator(LargeObjectSpace* space);
(...skipping 26 matching lines...) Expand all
2900 PageIterator old_iterator_; 2907 PageIterator old_iterator_;
2901 PageIterator code_iterator_; 2908 PageIterator code_iterator_;
2902 PageIterator map_iterator_; 2909 PageIterator map_iterator_;
2903 LargePageIterator lo_iterator_; 2910 LargePageIterator lo_iterator_;
2904 }; 2911 };
2905 2912
2906 } // namespace internal 2913 } // namespace internal
2907 } // namespace v8 2914 } // namespace v8
2908 2915
2909 #endif // V8_HEAP_SPACES_H_ 2916 #endif // V8_HEAP_SPACES_H_
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698