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

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

Issue 1853783002: [heap] Non-contiguous young generation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Hannes comment Created 4 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/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 "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/atomic-utils.h" 9 #include "src/atomic-utils.h"
10 #include "src/base/atomicops.h" 10 #include "src/base/atomicops.h"
11 #include "src/base/bits.h" 11 #include "src/base/bits.h"
12 #include "src/base/platform/mutex.h" 12 #include "src/base/platform/mutex.h"
13 #include "src/flags.h" 13 #include "src/flags.h"
14 #include "src/hashmap.h" 14 #include "src/hashmap.h"
15 #include "src/list.h" 15 #include "src/list.h"
16 #include "src/objects.h" 16 #include "src/objects.h"
17 #include "src/utils.h" 17 #include "src/utils.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 class AllocationInfo; 22 class AllocationInfo;
23 class AllocationObserver; 23 class AllocationObserver;
24 class CompactionSpace; 24 class CompactionSpace;
25 class CompactionSpaceCollection; 25 class CompactionSpaceCollection;
26 class FreeList; 26 class FreeList;
27 class Isolate; 27 class Isolate;
28 class MemoryAllocator; 28 class MemoryAllocator;
29 class MemoryChunk; 29 class MemoryChunk;
30 class NewSpacePage;
30 class Page; 31 class Page;
31 class PagedSpace; 32 class PagedSpace;
32 class SemiSpace; 33 class SemiSpace;
33 class SkipList; 34 class SkipList;
34 class SlotsBuffer; 35 class SlotsBuffer;
35 class SlotSet; 36 class SlotSet;
36 class TypedSlotSet; 37 class TypedSlotSet;
37 class Space; 38 class Space;
38 39
39 // ----------------------------------------------------------------------------- 40 // -----------------------------------------------------------------------------
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 1240
1240 // ---------------------------------------------------------------------------- 1241 // ----------------------------------------------------------------------------
1241 // A space acquires chunks of memory from the operating system. The memory 1242 // A space acquires chunks of memory from the operating system. The memory
1242 // allocator allocated and deallocates pages for the paged heap spaces and large 1243 // allocator allocated and deallocates pages for the paged heap spaces and large
1243 // pages for large object space. 1244 // pages for large object space.
1244 // 1245 //
1245 // Each space has to manage it's own pages. 1246 // Each space has to manage it's own pages.
1246 // 1247 //
1247 class MemoryAllocator { 1248 class MemoryAllocator {
1248 public: 1249 public:
1250 enum AllocationMode {
1251 kRegular,
1252 kPooled,
1253 };
1254
1249 explicit MemoryAllocator(Isolate* isolate); 1255 explicit MemoryAllocator(Isolate* isolate);
1250 1256
1251 // Initializes its internal bookkeeping structures. 1257 // Initializes its internal bookkeeping structures.
1252 // Max capacity of the total space and executable memory limit. 1258 // Max capacity of the total space and executable memory limit.
1253 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable); 1259 bool SetUp(intptr_t max_capacity, intptr_t capacity_executable);
1254 1260
1255 void TearDown(); 1261 void TearDown();
1256 1262
1257 Page* AllocatePage(intptr_t size, PagedSpace* owner, 1263 // Allocates either Page or NewSpacePage from the allocator. AllocationMode
1258 Executability executable); 1264 // is used to indicate whether pooled allocation, which only works for
1265 // MemoryChunk::kPageSize, should be tried first.
1266 template <typename PageType, MemoryAllocator::AllocationMode mode = kRegular,
1267 typename SpaceType>
1268 PageType* AllocatePage(intptr_t size, SpaceType* owner,
1269 Executability executable);
1259 1270
1260 LargePage* AllocateLargePage(intptr_t object_size, Space* owner, 1271 LargePage* AllocateLargePage(intptr_t object_size, Space* owner,
1261 Executability executable); 1272 Executability executable);
1262 1273
1263 // PreFree logically frees the object, i.e., it takes care of the size 1274 // PreFree logically frees the object, i.e., it takes care of the size
1264 // bookkeeping and calls the allocation callback. 1275 // bookkeeping and calls the allocation callback.
1265 void PreFreeMemory(MemoryChunk* chunk); 1276 void PreFreeMemory(MemoryChunk* chunk);
1266 1277
1267 // FreeMemory can be called concurrently when PreFree was executed before. 1278 // FreeMemory can be called concurrently when PreFree was executed before.
1268 void PerformFreeMemory(MemoryChunk* chunk); 1279 void PerformFreeMemory(MemoryChunk* chunk);
1269 1280
1270 // Free is a wrapper method, which calls PreFree and PerformFreeMemory 1281 // Free is a wrapper method. For kRegular AllocationMode it calls PreFree and
1271 // together. 1282 // PerformFreeMemory together. For kPooled it will dispatch to pooled free.
1283 template <MemoryAllocator::AllocationMode mode = kRegular>
1272 void Free(MemoryChunk* chunk); 1284 void Free(MemoryChunk* chunk);
1273 1285
1274 // Returns allocated spaces in bytes. 1286 // Returns allocated spaces in bytes.
1275 intptr_t Size() { return size_.Value(); } 1287 intptr_t Size() { return size_.Value(); }
1276 1288
1277 // Returns allocated executable spaces in bytes. 1289 // Returns allocated executable spaces in bytes.
1278 intptr_t SizeExecutable() { return size_executable_.Value(); } 1290 intptr_t SizeExecutable() { return size_executable_.Value(); }
1279 1291
1280 // Returns the maximum available bytes of heaps. 1292 // Returns the maximum available bytes of heaps.
1281 intptr_t Available() { 1293 intptr_t Available() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 Executability executable, Space* space); 1327 Executability executable, Space* space);
1316 1328
1317 Address ReserveAlignedMemory(size_t requested, size_t alignment, 1329 Address ReserveAlignedMemory(size_t requested, size_t alignment,
1318 base::VirtualMemory* controller); 1330 base::VirtualMemory* controller);
1319 Address AllocateAlignedMemory(size_t reserve_size, size_t commit_size, 1331 Address AllocateAlignedMemory(size_t reserve_size, size_t commit_size,
1320 size_t alignment, Executability executable, 1332 size_t alignment, Executability executable,
1321 base::VirtualMemory* controller); 1333 base::VirtualMemory* controller);
1322 1334
1323 bool CommitMemory(Address addr, size_t size, Executability executable); 1335 bool CommitMemory(Address addr, size_t size, Executability executable);
1324 1336
1325 void FreeNewSpaceMemory(Address addr, base::VirtualMemory* reservation,
1326 Executability executable);
1327 void FreeMemory(base::VirtualMemory* reservation, Executability executable); 1337 void FreeMemory(base::VirtualMemory* reservation, Executability executable);
1328 void FreeMemory(Address addr, size_t size, Executability executable); 1338 void FreeMemory(Address addr, size_t size, Executability executable);
1329 1339
1330 // Commit a contiguous block of memory from the initial chunk. Assumes that 1340 // Commit a contiguous block of memory from the initial chunk. Assumes that
1331 // the address is not NULL, the size is greater than zero, and that the 1341 // the address is not NULL, the size is greater than zero, and that the
1332 // block is contained in the initial chunk. Returns true if it succeeded 1342 // block is contained in the initial chunk. Returns true if it succeeded
1333 // and false otherwise. 1343 // and false otherwise.
1334 bool CommitBlock(Address start, size_t size, Executability executable); 1344 bool CommitBlock(Address start, size_t size, Executability executable);
1335 1345
1336 // Uncommit a contiguous block of memory [start..(start+size)[. 1346 // Uncommit a contiguous block of memory [start..(start+size)[.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 DCHECK_NE(LO_SPACE, space); 1379 DCHECK_NE(LO_SPACE, space);
1370 return (space == CODE_SPACE) ? CodePageAreaSize() 1380 return (space == CODE_SPACE) ? CodePageAreaSize()
1371 : Page::kAllocatableMemory; 1381 : Page::kAllocatableMemory;
1372 } 1382 }
1373 1383
1374 MUST_USE_RESULT bool CommitExecutableMemory(base::VirtualMemory* vm, 1384 MUST_USE_RESULT bool CommitExecutableMemory(base::VirtualMemory* vm,
1375 Address start, size_t commit_size, 1385 Address start, size_t commit_size,
1376 size_t reserved_size); 1386 size_t reserved_size);
1377 1387
1378 private: 1388 private:
1389 // See AllocatePage for public interface. Note that currently we only support
1390 // pools for NOT_EXECUTABLE pages of size MemoryChunk::kPageSize.
1391 template <typename SpaceType>
1392 MemoryChunk* AllocatePagePooled(SpaceType* owner);
1393
1394 // Free that chunk into the pool.
1395 void FreePooled(MemoryChunk* chunk);
1396
1379 Isolate* isolate_; 1397 Isolate* isolate_;
1380 1398
1381 // Maximum space size in bytes. 1399 // Maximum space size in bytes.
1382 intptr_t capacity_; 1400 intptr_t capacity_;
1383 // Maximum subset of capacity_ that can be executable 1401 // Maximum subset of capacity_ that can be executable
1384 intptr_t capacity_executable_; 1402 intptr_t capacity_executable_;
1385 1403
1386 // Allocated space size in bytes. 1404 // Allocated space size in bytes.
1387 AtomicNumber<intptr_t> size_; 1405 AtomicNumber<intptr_t> size_;
1388 // Allocated executable space size in bytes. 1406 // Allocated executable space size in bytes.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 // values only if they did not change in between. 1440 // values only if they did not change in between.
1423 void* ptr = nullptr; 1441 void* ptr = nullptr;
1424 do { 1442 do {
1425 ptr = lowest_ever_allocated_.Value(); 1443 ptr = lowest_ever_allocated_.Value();
1426 } while ((low < ptr) && !lowest_ever_allocated_.TrySetValue(ptr, low)); 1444 } while ((low < ptr) && !lowest_ever_allocated_.TrySetValue(ptr, low));
1427 do { 1445 do {
1428 ptr = highest_ever_allocated_.Value(); 1446 ptr = highest_ever_allocated_.Value();
1429 } while ((high > ptr) && !highest_ever_allocated_.TrySetValue(ptr, high)); 1447 } while ((high > ptr) && !highest_ever_allocated_.TrySetValue(ptr, high));
1430 } 1448 }
1431 1449
1450 List<MemoryChunk*> chunk_pool_;
1451
1432 DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator); 1452 DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator);
1433 }; 1453 };
1434 1454
1435 1455
1436 // ----------------------------------------------------------------------------- 1456 // -----------------------------------------------------------------------------
1437 // Interface for heap object iterator to be implemented by all object space 1457 // Interface for heap object iterator to be implemented by all object space
1438 // object iterators. 1458 // object iterators.
1439 // 1459 //
1440 // NOTE: The space specific object iterators also implements the own next() 1460 // NOTE: The space specific object iterators also implements the own next()
1441 // method which is used to avoid using virtual functions 1461 // method which is used to avoid using virtual functions
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 private: 2282 private:
2263 const char* name_; 2283 const char* name_;
2264 }; 2284 };
2265 2285
2266 2286
2267 enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 }; 2287 enum SemiSpaceId { kFromSpace = 0, kToSpace = 1 };
2268 2288
2269 2289
2270 class NewSpacePage : public MemoryChunk { 2290 class NewSpacePage : public MemoryChunk {
2271 public: 2291 public:
2292 static inline NewSpacePage* Initialize(Heap* heap, MemoryChunk* chunk,
2293 Executability executable,
2294 SemiSpace* owner);
2295
2272 static bool IsAtStart(Address addr) { 2296 static bool IsAtStart(Address addr) {
2273 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) == 2297 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) ==
2274 kObjectStartOffset; 2298 kObjectStartOffset;
2275 } 2299 }
2276 2300
2277 static bool IsAtEnd(Address addr) { 2301 static bool IsAtEnd(Address addr) {
2278 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) == 0; 2302 return (reinterpret_cast<intptr_t>(addr) & Page::kPageAlignmentMask) == 0;
2279 } 2303 }
2280 2304
2281 // Finds the NewSpacePage containing the given address. 2305 // Finds the NewSpacePage containing the given address.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 // GC related flags copied from from-space to to-space when 2343 // GC related flags copied from from-space to to-space when
2320 // flipping semispaces. 2344 // flipping semispaces.
2321 static const intptr_t kCopyOnFlipFlagsMask = 2345 static const intptr_t kCopyOnFlipFlagsMask =
2322 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) | 2346 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) |
2323 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING); 2347 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING);
2324 2348
2325 // Create a NewSpacePage object that is only used as anchor 2349 // Create a NewSpacePage object that is only used as anchor
2326 // for the doubly-linked list of real pages. 2350 // for the doubly-linked list of real pages.
2327 explicit NewSpacePage(SemiSpace* owner) { InitializeAsAnchor(owner); } 2351 explicit NewSpacePage(SemiSpace* owner) { InitializeAsAnchor(owner); }
2328 2352
2329 static NewSpacePage* Initialize(Heap* heap, Address start,
2330 SemiSpace* semi_space);
2331
2332 // Intialize a fake NewSpacePage used as sentinel at the ends 2353 // Intialize a fake NewSpacePage used as sentinel at the ends
2333 // of a doubly-linked list of real NewSpacePages. 2354 // of a doubly-linked list of real NewSpacePages.
2334 // Only uses the prev/next links, and sets flags to not be in new-space. 2355 // Only uses the prev/next links, and sets flags to not be in new-space.
2335 void InitializeAsAnchor(SemiSpace* owner); 2356 void InitializeAsAnchor(SemiSpace* owner);
2336 2357
2337 friend class SemiSpace; 2358 friend class SemiSpace;
2338 friend class SemiSpaceIterator; 2359 friend class SemiSpaceIterator;
2339 }; 2360 };
2340 2361
2341 2362
2342 // ----------------------------------------------------------------------------- 2363 // -----------------------------------------------------------------------------
2343 // SemiSpace in young generation 2364 // SemiSpace in young generation
2344 // 2365 //
2345 // A SemiSpace is a contiguous chunk of memory holding page-like memory chunks. 2366 // A SemiSpace is a contiguous chunk of memory holding page-like memory chunks.
2346 // The mark-compact collector uses the memory of the first page in the from 2367 // The mark-compact collector uses the memory of the first page in the from
2347 // space as a marking stack when tracing live objects. 2368 // space as a marking stack when tracing live objects.
2348 class SemiSpace : public Space { 2369 class SemiSpace : public Space {
2349 public: 2370 public:
2350 static void Swap(SemiSpace* from, SemiSpace* to); 2371 static void Swap(SemiSpace* from, SemiSpace* to);
2351 2372
2352 SemiSpace(Heap* heap, SemiSpaceId semispace) 2373 SemiSpace(Heap* heap, SemiSpaceId semispace)
2353 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), 2374 : Space(heap, NEW_SPACE, NOT_EXECUTABLE),
2354 current_capacity_(0), 2375 current_capacity_(0),
2355 maximum_capacity_(0), 2376 maximum_capacity_(0),
2356 minimum_capacity_(0), 2377 minimum_capacity_(0),
2357 start_(nullptr),
2358 age_mark_(nullptr), 2378 age_mark_(nullptr),
2359 committed_(false), 2379 committed_(false),
2360 id_(semispace), 2380 id_(semispace),
2361 anchor_(this), 2381 anchor_(this),
2362 current_page_(nullptr) {} 2382 current_page_(nullptr) {}
2363 2383
2364 inline bool Contains(HeapObject* o); 2384 inline bool Contains(HeapObject* o);
2365 inline bool Contains(Object* o); 2385 inline bool Contains(Object* o);
2366 inline bool ContainsSlow(Address a); 2386 inline bool ContainsSlow(Address a);
2367 2387
2368 // Creates a space in the young generation. The constructor does not 2388 void SetUp(int initial_capacity, int maximum_capacity);
2369 // allocate memory from the OS. 2389 void TearDown();
2370 void SetUp(Address start, int initial_capacity, int maximum_capacity); 2390 bool HasBeenSetUp() { return maximum_capacity_ != 0; }
2371 2391
2372 // Tear down the space. Heap memory was not allocated by the space, so it 2392 bool Commit();
2373 // is not deallocated here. 2393 bool Uncommit();
2374 void TearDown(); 2394 bool is_committed() { return committed_; }
2375 2395
2376 // True if the space has been set up but not torn down. 2396 // Grow the semispace to the new capacity. The new capacity requested must
2377 bool HasBeenSetUp() { return start_ != nullptr; } 2397 // be larger than the current capacity and less than the maximum capacity.
2378
2379 // Grow the semispace to the new capacity. The new capacity
2380 // requested must be larger than the current capacity and less than
2381 // the maximum capacity.
2382 bool GrowTo(int new_capacity); 2398 bool GrowTo(int new_capacity);
2383 2399
2384 // Shrinks the semispace to the new capacity. The new capacity 2400 // Shrinks the semispace to the new capacity. The new capacity requested
2385 // requested must be more than the amount of used memory in the 2401 // must be more than the amount of used memory in the semispace and less
2386 // semispace and less than the current capacity. 2402 // than the current capacity.
2387 bool ShrinkTo(int new_capacity); 2403 bool ShrinkTo(int new_capacity);
2388 2404
2389 // Returns the start address of the first page of the space. 2405 // Returns the start address of the first page of the space.
2390 Address space_start() { 2406 Address space_start() {
2391 DCHECK_NE(anchor_.next_page(), &anchor_); 2407 DCHECK_NE(anchor_.next_page(), anchor());
2392 return anchor_.next_page()->area_start(); 2408 return anchor_.next_page()->area_start();
2393 } 2409 }
2394 2410
2411 NewSpacePage* first_page() { return anchor_.next_page(); }
2412 NewSpacePage* current_page() { return current_page_; }
2413
2414 // Returns one past the end address of the space.
2415 Address space_end() { return anchor_.prev_page()->area_end(); }
2416
2395 // Returns the start address of the current page of the space. 2417 // Returns the start address of the current page of the space.
2396 Address page_low() { return current_page_->area_start(); } 2418 Address page_low() { return current_page_->area_start(); }
2397 2419
2398 // Returns one past the end address of the space.
2399 Address space_end() { return anchor_.prev_page()->area_end(); }
2400
2401 // Returns one past the end address of the current page of the space. 2420 // Returns one past the end address of the current page of the space.
2402 Address page_high() { return current_page_->area_end(); } 2421 Address page_high() { return current_page_->area_end(); }
2403 2422
2404 bool AdvancePage() { 2423 bool AdvancePage() {
2405 NewSpacePage* next_page = current_page_->next_page(); 2424 NewSpacePage* next_page = current_page_->next_page();
2406 if (next_page == anchor()) return false; 2425 if (next_page == anchor()) return false;
2407 current_page_ = next_page; 2426 current_page_ = next_page;
2408 return true; 2427 return true;
2409 } 2428 }
2410 2429
2411 // Resets the space to using the first page. 2430 // Resets the space to using the first page.
2412 void Reset(); 2431 void Reset();
2413 2432
2414 // Age mark accessors. 2433 // Age mark accessors.
2415 Address age_mark() { return age_mark_; } 2434 Address age_mark() { return age_mark_; }
2416 void set_age_mark(Address mark); 2435 void set_age_mark(Address mark);
2417 2436
2418 bool is_committed() { return committed_; } 2437 // Returns the current capacity of the semispace.
2419 bool Commit();
2420 bool Uncommit();
2421
2422 NewSpacePage* first_page() { return anchor_.next_page(); }
2423 NewSpacePage* current_page() { return current_page_; }
2424
2425 // Returns the current total capacity of the semispace.
2426 int current_capacity() { return current_capacity_; } 2438 int current_capacity() { return current_capacity_; }
2427 2439
2428 // Returns the maximum total capacity of the semispace. 2440 // Returns the maximum capacity of the semispace.
2429 int maximum_capacity() { return maximum_capacity_; } 2441 int maximum_capacity() { return maximum_capacity_; }
2430 2442
2431 // Returns the initial capacity of the semispace. 2443 // Returns the initial capacity of the semispace.
2432 int minimum_capacity() { return minimum_capacity_; } 2444 int minimum_capacity() { return minimum_capacity_; }
2433 2445
2434 SemiSpaceId id() { return id_; } 2446 SemiSpaceId id() { return id_; }
2435 2447
2436 // Approximate amount of physical memory committed for this space. 2448 // Approximate amount of physical memory committed for this space.
2437 size_t CommittedPhysicalMemory() override; 2449 size_t CommittedPhysicalMemory() override;
2438 2450
(...skipping 21 matching lines...) Expand all
2460 #else 2472 #else
2461 // Do nothing. 2473 // Do nothing.
2462 inline static void AssertValidRange(Address from, Address to) {} 2474 inline static void AssertValidRange(Address from, Address to) {}
2463 #endif 2475 #endif
2464 2476
2465 #ifdef VERIFY_HEAP 2477 #ifdef VERIFY_HEAP
2466 virtual void Verify(); 2478 virtual void Verify();
2467 #endif 2479 #endif
2468 2480
2469 private: 2481 private:
2470 NewSpacePage* anchor() { return &anchor_; } 2482 inline NewSpacePage* anchor() { return &anchor_; }
2471
2472 void set_current_capacity(int new_capacity) {
2473 current_capacity_ = new_capacity;
2474 }
2475 2483
2476 // Copies the flags into the masked positions on all pages in the space. 2484 // Copies the flags into the masked positions on all pages in the space.
2477 void FixPagesFlags(intptr_t flags, intptr_t flag_mask); 2485 void FixPagesFlags(intptr_t flags, intptr_t flag_mask);
2478 2486
2479 // The currently committed space capacity. 2487 // The currently committed space capacity.
2480 int current_capacity_; 2488 int current_capacity_;
2481 2489
2482 // The maximum capacity that can be used by this space. 2490 // The maximum capacity that can be used by this space.
2483 int maximum_capacity_; 2491 int maximum_capacity_;
2484 2492
2485 // The mimnimum capacity for the space. A space cannot shrink below this size. 2493 // The minimum capacity for the space. A space cannot shrink below this size.
2486 int minimum_capacity_; 2494 int minimum_capacity_;
2487 2495
2488 // The start address of the space.
2489 Address start_;
2490 // Used to govern object promotion during mark-compact collection. 2496 // Used to govern object promotion during mark-compact collection.
2491 Address age_mark_; 2497 Address age_mark_;
2492 2498
2493 bool committed_; 2499 bool committed_;
2494 SemiSpaceId id_; 2500 SemiSpaceId id_;
2495 2501
2496 NewSpacePage anchor_; 2502 NewSpacePage anchor_;
2497 NewSpacePage* current_page_; 2503 NewSpacePage* current_page_;
2498 2504
2499 friend class SemiSpaceIterator; 2505 friend class SemiSpaceIterator;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 2561
2556 2562
2557 // ----------------------------------------------------------------------------- 2563 // -----------------------------------------------------------------------------
2558 // The young generation space. 2564 // The young generation space.
2559 // 2565 //
2560 // The new space consists of a contiguous pair of semispaces. It simply 2566 // The new space consists of a contiguous pair of semispaces. It simply
2561 // forwards most functions to the appropriate semispace. 2567 // forwards most functions to the appropriate semispace.
2562 2568
2563 class NewSpace : public Space { 2569 class NewSpace : public Space {
2564 public: 2570 public:
2565 // Constructor.
2566 explicit NewSpace(Heap* heap) 2571 explicit NewSpace(Heap* heap)
2567 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), 2572 : Space(heap, NEW_SPACE, NOT_EXECUTABLE),
2568 to_space_(heap, kToSpace), 2573 to_space_(heap, kToSpace),
2569 from_space_(heap, kFromSpace), 2574 from_space_(heap, kFromSpace),
2570 reservation_(), 2575 reservation_(),
2571 top_on_previous_step_(0) {} 2576 pages_used_(0),
2577 top_on_previous_step_(0),
2578 allocated_histogram_(nullptr),
2579 promoted_histogram_(nullptr) {}
2572 2580
2573 inline bool Contains(HeapObject* o); 2581 inline bool Contains(HeapObject* o);
2574 inline bool ContainsSlow(Address a); 2582 inline bool ContainsSlow(Address a);
2575 inline bool Contains(Object* o); 2583 inline bool Contains(Object* o);
2576 2584
2577 // Sets up the new space using the given chunk. 2585 bool SetUp(int initial_semispace_capacity, int max_semispace_capacity);
2578 bool SetUp(int reserved_semispace_size_, int max_semi_space_size);
2579 2586
2580 // Tears down the space. Heap memory was not allocated by the space, so it 2587 // Tears down the space. Heap memory was not allocated by the space, so it
2581 // is not deallocated here. 2588 // is not deallocated here.
2582 void TearDown(); 2589 void TearDown();
2583 2590
2584 // True if the space has been set up but not torn down. 2591 // True if the space has been set up but not torn down.
2585 bool HasBeenSetUp() { 2592 bool HasBeenSetUp() {
2586 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp(); 2593 return to_space_.HasBeenSetUp() && from_space_.HasBeenSetUp();
2587 } 2594 }
2588 2595
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2631 return from_space_.MaximumCommittedMemory() + 2638 return from_space_.MaximumCommittedMemory() +
2632 to_space_.MaximumCommittedMemory(); 2639 to_space_.MaximumCommittedMemory();
2633 } 2640 }
2634 2641
2635 // Approximate amount of physical memory committed for this space. 2642 // Approximate amount of physical memory committed for this space.
2636 size_t CommittedPhysicalMemory() override; 2643 size_t CommittedPhysicalMemory() override;
2637 2644
2638 // Return the available bytes without growing. 2645 // Return the available bytes without growing.
2639 intptr_t Available() override { return Capacity() - Size(); } 2646 intptr_t Available() override { return Capacity() - Size(); }
2640 2647
2641 intptr_t PagesFromStart(Address addr) {
2642 return static_cast<intptr_t>(addr - bottom()) / Page::kPageSize;
2643 }
2644
2645 size_t AllocatedSinceLastGC() { 2648 size_t AllocatedSinceLastGC() {
2646 intptr_t allocated = top() - to_space_.age_mark(); 2649 bool seen_age_mark = false;
2647 if (allocated < 0) { 2650 Address age_mark = to_space_.age_mark();
2648 // Runtime has lowered the top below the age mark. 2651 NewSpacePage* current_page = to_space_.first_page();
2652 NewSpacePage* age_mark_page = NewSpacePage::FromAddress(age_mark);
2653 NewSpacePage* last_page = NewSpacePage::FromAddress(top() - kPointerSize);
2654 if (age_mark_page == last_page) {
2655 if (top() - age_mark >= 0) {
2656 return top() - age_mark;
2657 }
2658 // Top was reset at some point, invalidating this metric.
2649 return 0; 2659 return 0;
2650 } 2660 }
2651 // Correctly account for non-allocatable regions at the beginning of 2661 while (current_page != last_page) {
2652 // each page from the age_mark() to the top(). 2662 if (current_page == age_mark_page) {
2653 intptr_t pages = 2663 seen_age_mark = true;
2654 PagesFromStart(top()) - PagesFromStart(to_space_.age_mark()); 2664 break;
2655 allocated -= pages * (NewSpacePage::kObjectStartOffset); 2665 }
2656 DCHECK(0 <= allocated && allocated <= Size()); 2666 current_page = current_page->next_page();
2667 }
2668 if (!seen_age_mark) {
2669 // Top was reset at some point, invalidating this metric.
2670 return 0;
2671 }
2672 intptr_t allocated = age_mark_page->area_end() - age_mark;
2673 DCHECK_EQ(current_page, age_mark_page);
2674 current_page = age_mark_page->next_page();
2675 while (current_page != last_page) {
2676 allocated += NewSpacePage::kAllocatableMemory;
2677 current_page = current_page->next_page();
2678 }
2679 allocated += top() - current_page->area_start();
2680 DCHECK_LE(0, allocated);
2681 DCHECK_LE(allocated, Size());
2657 return static_cast<size_t>(allocated); 2682 return static_cast<size_t>(allocated);
2658 } 2683 }
2659 2684
2660 // Return the maximum capacity of a semispace. 2685 // Return the maximum capacity of a semispace.
2661 int MaximumCapacity() { 2686 int MaximumCapacity() {
2662 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity()); 2687 DCHECK(to_space_.maximum_capacity() == from_space_.maximum_capacity());
2663 return to_space_.maximum_capacity(); 2688 return to_space_.maximum_capacity();
2664 } 2689 }
2665 2690
2666 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); } 2691 bool IsAtMaximumCapacity() { return TotalCapacity() == MaximumCapacity(); }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 2823
2799 void PauseAllocationObservers() override; 2824 void PauseAllocationObservers() override;
2800 void ResumeAllocationObservers() override; 2825 void ResumeAllocationObservers() override;
2801 2826
2802 private: 2827 private:
2803 // Update allocation info to match the current to-space page. 2828 // Update allocation info to match the current to-space page.
2804 void UpdateAllocationInfo(); 2829 void UpdateAllocationInfo();
2805 2830
2806 base::Mutex mutex_; 2831 base::Mutex mutex_;
2807 2832
2808 Address chunk_base_;
2809 uintptr_t chunk_size_;
2810
2811 // The semispaces. 2833 // The semispaces.
2812 SemiSpace to_space_; 2834 SemiSpace to_space_;
2813 SemiSpace from_space_; 2835 SemiSpace from_space_;
2814 base::VirtualMemory reservation_; 2836 base::VirtualMemory reservation_;
2815 int pages_used_; 2837 int pages_used_;
2816 2838
2817 // Allocation pointer and limit for normal allocation and allocation during 2839 // Allocation pointer and limit for normal allocation and allocation during
2818 // mark-compact collection. 2840 // mark-compact collection.
2819 AllocationInfo allocation_info_; 2841 AllocationInfo allocation_info_;
2820 2842
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 count = 0; 3107 count = 0;
3086 } 3108 }
3087 // Must be small, since an iteration is used for lookup. 3109 // Must be small, since an iteration is used for lookup.
3088 static const int kMaxComments = 64; 3110 static const int kMaxComments = 64;
3089 }; 3111 };
3090 #endif 3112 #endif
3091 } // namespace internal 3113 } // namespace internal
3092 } // namespace v8 3114 } // namespace v8
3093 3115
3094 #endif // V8_HEAP_SPACES_H_ 3116 #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