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

Side by Side Diff: src/spaces.h

Issue 7027030: Changes that anticipate making semispaces contain more than one page. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 356 }
357 inline void set_scan_on_scavenge(bool scan); 357 inline void set_scan_on_scavenge(bool scan);
358 358
359 int store_buffer_counter() { return store_buffer_counter_; } 359 int store_buffer_counter() { return store_buffer_counter_; }
360 void set_store_buffer_counter(int counter) { 360 void set_store_buffer_counter(int counter) {
361 store_buffer_counter_ = counter; 361 store_buffer_counter_ = counter;
362 } 362 }
363 363
364 Address body() { return address() + kObjectStartOffset; } 364 Address body() { return address() + kObjectStartOffset; }
365 365
366 Address body_limit() { return address() + size(); }
367
366 int body_size() { return size() - kObjectStartOffset; } 368 int body_size() { return size() - kObjectStartOffset; }
367 369
368 bool Contains(Address addr) { 370 bool Contains(Address addr) {
369 return addr >= body() && addr < address() + size(); 371 return addr >= body() && addr < address() + size();
370 } 372 }
371 373
372 enum MemoryChunkFlags { 374 enum MemoryChunkFlags {
373 IS_EXECUTABLE, 375 IS_EXECUTABLE,
374 WAS_SWEPT_CONSERVATIVELY, 376 WAS_SWEPT_CONSERVATIVELY,
375 CONTAINS_ONLY_DATA, 377 CONTAINS_ONLY_DATA,
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 }; 1470 };
1469 #endif 1471 #endif
1470 1472
1471 1473
1472 enum SemiSpaceId { 1474 enum SemiSpaceId {
1473 kFromSpace = 0, 1475 kFromSpace = 0,
1474 kToSpace = 1 1476 kToSpace = 1
1475 }; 1477 };
1476 1478
1477 1479
1480 class SemiSpace;
1481
1482
1478 class NewSpacePage : public MemoryChunk { 1483 class NewSpacePage : public MemoryChunk {
1479 public: 1484 public:
1480 // GC related flags copied from from-space to to-space when 1485 // GC related flags copied from from-space to to-space when
1481 // flipping semispaces. 1486 // flipping semispaces.
1482 static const intptr_t kCopyOnFlipFlagsMask = 1487 static const intptr_t kCopyOnFlipFlagsMask =
1483 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) | 1488 (1 << MemoryChunk::POINTERS_TO_HERE_ARE_INTERESTING) |
1484 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING) | 1489 (1 << MemoryChunk::POINTERS_FROM_HERE_ARE_INTERESTING) |
1485 (1 << MemoryChunk::SCAN_ON_SCAVENGE); 1490 (1 << MemoryChunk::SCAN_ON_SCAVENGE);
1486 1491
1487 inline NewSpacePage* next_page() const { 1492 inline NewSpacePage* next_page() const {
1488 return static_cast<NewSpacePage*>(next_chunk()); 1493 return static_cast<NewSpacePage*>(next_chunk());
1489 } 1494 }
1490 1495
1491 inline void set_next_page(NewSpacePage* page) { 1496 inline void set_next_page(NewSpacePage* page) {
1492 set_next_chunk(page); 1497 set_next_chunk(page);
1493 } 1498 }
1499
1500 inline NewSpacePage* prev_page() const {
1501 return static_cast<NewSpacePage*>(prev_chunk());
1502 }
1503
1504 inline void set_prev_page(NewSpacePage* page) {
1505 set_prev_chunk(page);
1506 }
1507
1508 SemiSpace* semi_space() {
1509 return reinterpret_cast<SemiSpace*>(owner());
1510 }
1511
1494 private: 1512 private:
1513 NewSpacePage(SemiSpace* owner) {
1514 InitializeAsAnchor(owner);
1515 }
1516
1495 // Finds the NewSpacePage containg the given address. 1517 // Finds the NewSpacePage containg the given address.
1496 static NewSpacePage* FromAddress(Address address_in_page) { 1518 static NewSpacePage* FromAddress(Address address_in_page) {
1497 Address page_start = 1519 Address page_start =
1498 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & 1520 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) &
1499 ~Page::kPageAlignmentMask); 1521 ~Page::kPageAlignmentMask);
1500 return reinterpret_cast<NewSpacePage*>(page_start); 1522 return reinterpret_cast<NewSpacePage*>(page_start);
1501 } 1523 }
1502 1524
1503 static NewSpacePage* Initialize(Heap* heap, 1525 static NewSpacePage* Initialize(Heap* heap,
1504 Address start, 1526 Address start,
1505 SemiSpaceId semispace); 1527 SemiSpace* semi_space);
1528
1529 // Intialize a fake NewSpacePage used as sentinel at the ends
1530 // of a doubly-linked list of real NewSpacePages.
1531 // Only uses the prev/next links.
1532 void InitializeAsAnchor(SemiSpace* owner);
1506 1533
1507 friend class SemiSpace; 1534 friend class SemiSpace;
1508 friend class SemiSpaceIterator; 1535 friend class SemiSpaceIterator;
1509 }; 1536 };
1510 1537
1511 1538
1512 // ----------------------------------------------------------------------------- 1539 // -----------------------------------------------------------------------------
1513 // SemiSpace in young generation 1540 // SemiSpace in young generation
1514 // 1541 //
1515 // A semispace is a contiguous chunk of memory holding page-like memory 1542 // A semispace is a contiguous chunk of memory holding page-like memory
1516 // chunks. The mark-compact collector uses the memory of the first page in 1543 // chunks. The mark-compact collector uses the memory of the first page in
1517 // the from space as a marking stack when tracing live objects. 1544 // the from space as a marking stack when tracing live objects.
1518 1545
1519 class SemiSpace : public Space { 1546 class SemiSpace : public Space {
1520 public: 1547 public:
1521 // Constructor. 1548 // Constructor.
1522 SemiSpace(Heap* heap, SemiSpaceId semispace) 1549 SemiSpace(Heap* heap, SemiSpaceId semispace)
1523 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), 1550 : Space(heap, NEW_SPACE, NOT_EXECUTABLE),
1524 start_(NULL), 1551 start_(NULL),
1525 age_mark_(NULL), 1552 age_mark_(NULL),
1526 id_(semispace) { } 1553 id_(semispace),
1554 anchor_(this),
1555 current_page_(NULL) { }
1527 1556
1528 // Sets up the semispace using the given chunk. 1557 // Sets up the semispace using the given chunk.
1529 bool Setup(Address start, int initial_capacity, int maximum_capacity); 1558 bool Setup(Address start, int initial_capacity, int maximum_capacity);
1530 1559
1531 // Tear down the space. Heap memory was not allocated by the space, so it 1560 // Tear down the space. Heap memory was not allocated by the space, so it
1532 // is not deallocated here. 1561 // is not deallocated here.
1533 void TearDown(); 1562 void TearDown();
1534 1563
1535 // True if the space has been set up but not torn down. 1564 // True if the space has been set up but not torn down.
1536 bool HasBeenSetup() { return start_ != NULL; } 1565 bool HasBeenSetup() { return start_ != NULL; }
1537 1566
1538 // Grow the size of the semispace by committing extra virtual memory. 1567 // Grow the size of the semispace by committing extra virtual memory.
1539 // Assumes that the caller has checked that the semispace has not reached 1568 // Assumes that the caller has checked that the semispace has not reached
1540 // its maximum capacity (and thus there is space available in the reserved 1569 // its maximum capacity (and thus there is space available in the reserved
1541 // address range to grow). 1570 // address range to grow).
1542 bool Grow(); 1571 bool Grow();
1543 1572
1544 // Grow the semispace to the new capacity. The new capacity 1573 // Grow the semispace to the new capacity. The new capacity
1545 // requested must be larger than the current capacity. 1574 // requested must be larger than the current capacity.
1546 bool GrowTo(int new_capacity); 1575 bool GrowTo(int new_capacity);
1547 1576
1548 // Shrinks the semispace to the new capacity. The new capacity 1577 // Shrinks the semispace to the new capacity. The new capacity
1549 // requested must be more than the amount of used memory in the 1578 // requested must be more than the amount of used memory in the
1550 // semispace and less than the current capacity. 1579 // semispace and less than the current capacity.
1551 bool ShrinkTo(int new_capacity); 1580 bool ShrinkTo(int new_capacity);
1552 1581
1553 // Flips the semispace between being from-space and to-space. 1582 // Returns the start address of the first page of the space.
1554 // Copies the flags into the masked positions on all pages in the space. 1583 Address low() {
1555 void Flip(intptr_t flags, intptr_t flag_mask); 1584 ASSERT(anchor_.next_page() != &anchor_);
1585 return anchor_.next_page()->body();
1586 }
1556 1587
1557 // Returns the start address of the space. 1588 // Returns the start address of the current page of the space.
1558 Address low() { 1589 Address page_low() {
1559 return NewSpacePage::FromAddress(start_)->body(); 1590 ASSERT(anchor_.next_page() != &anchor_);
1591 return current_page_->body();
1560 } 1592 }
1561 1593
1562 // Returns one past the end address of the space. 1594 // Returns one past the end address of the space.
1563 Address high() { 1595 Address high() {
1564 // TODO(gc): Change when there is more than one page. 1596 // TODO(gc): Change when there is more than one page.
1565 return current_page_->body() + current_page_->body_size(); 1597 return current_page_->body_limit();
1566 } 1598 }
1567 1599
1600 // Resets the space to using the first page.
1601 void Reset();
1602
1568 // Age mark accessors. 1603 // Age mark accessors.
1569 Address age_mark() { return age_mark_; } 1604 Address age_mark() { return age_mark_; }
1570 void set_age_mark(Address mark) { age_mark_ = mark; } 1605 void set_age_mark(Address mark) { age_mark_ = mark; }
1571 1606
1572 // The offset of an address from the beginning of the space. 1607 // The offset of an address from the beginning of the space.
1573 int SpaceOffsetForAddress(Address addr) { 1608 int SpaceOffsetForAddress(Address addr) {
1574 return static_cast<int>(addr - low()); 1609 return static_cast<int>(addr - low());
1575 } 1610 }
1576 1611
1577 // If we don't have these here then SemiSpace will be abstract. However 1612 // If we don't have these here then SemiSpace will be abstract. However
(...skipping 28 matching lines...) Expand all
1606 1641
1607 // Returns the current capacity of the semi space. 1642 // Returns the current capacity of the semi space.
1608 int Capacity() { return capacity_; } 1643 int Capacity() { return capacity_; }
1609 1644
1610 // Returns the maximum capacity of the semi space. 1645 // Returns the maximum capacity of the semi space.
1611 int MaximumCapacity() { return maximum_capacity_; } 1646 int MaximumCapacity() { return maximum_capacity_; }
1612 1647
1613 // Returns the initial capacity of the semi space. 1648 // Returns the initial capacity of the semi space.
1614 int InitialCapacity() { return initial_capacity_; } 1649 int InitialCapacity() { return initial_capacity_; }
1615 1650
1651 SemiSpaceId id() { return id_; }
1652
1653 static void Swap(SemiSpace* from, SemiSpace* to);
1654
1616 private: 1655 private:
1656 // Flips the semispace between being from-space and to-space.
1657 // Copies the flags into the masked positions on all pages in the space.
1658 void FlipPages(intptr_t flags, intptr_t flag_mask);
1659
1617 // The current and maximum capacity of the space. 1660 // The current and maximum capacity of the space.
1618 int capacity_; 1661 int capacity_;
1619 int maximum_capacity_; 1662 int maximum_capacity_;
1620 int initial_capacity_; 1663 int initial_capacity_;
1621 1664
1622 // The start address of the space. 1665 // The start address of the space.
1623 Address start_; 1666 Address start_;
1624 // Used to govern object promotion during mark-compact collection. 1667 // Used to govern object promotion during mark-compact collection.
1625 Address age_mark_; 1668 Address age_mark_;
1626 1669
1627 // Masks and comparison values to test for containment in this semispace. 1670 // Masks and comparison values to test for containment in this semispace.
1628 uintptr_t address_mask_; 1671 uintptr_t address_mask_;
1629 uintptr_t object_mask_; 1672 uintptr_t object_mask_;
1630 uintptr_t object_expected_; 1673 uintptr_t object_expected_;
1631 1674
1632 bool committed_; 1675 bool committed_;
1633 SemiSpaceId id_; 1676 SemiSpaceId id_;
1634 1677
1678 NewSpacePage anchor_;
1635 NewSpacePage* current_page_; 1679 NewSpacePage* current_page_;
1636 1680
1637 public: 1681 public:
1638 TRACK_MEMORY("SemiSpace") 1682 TRACK_MEMORY("SemiSpace")
1639 }; 1683 };
1640 1684
1641 1685
1642 // A SemiSpaceIterator is an ObjectIterator that iterates over the active 1686 // A SemiSpaceIterator is an ObjectIterator that iterates over the active
1643 // semispace of the heap's new space. It iterates over the objects in the 1687 // semispace of the heap's new space. It iterates over the objects in the
1644 // semispace from a given start address (defaulting to the bottom of the 1688 // semispace from a given start address (defaulting to the bottom of the
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 } 2371 }
2328 // Must be small, since an iteration is used for lookup. 2372 // Must be small, since an iteration is used for lookup.
2329 static const int kMaxComments = 64; 2373 static const int kMaxComments = 64;
2330 }; 2374 };
2331 #endif 2375 #endif
2332 2376
2333 2377
2334 } } // namespace v8::internal 2378 } } // namespace v8::internal
2335 2379
2336 #endif // V8_SPACES_H_ 2380 #endif // V8_SPACES_H_
OLDNEW
« no previous file with comments | « no previous file | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698