Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 } | 369 } |
| 370 | 370 |
| 371 enum MemoryChunkFlags { | 371 enum MemoryChunkFlags { |
| 372 IS_EXECUTABLE, | 372 IS_EXECUTABLE, |
| 373 WAS_SWEPT_CONSERVATIVELY, | 373 WAS_SWEPT_CONSERVATIVELY, |
| 374 CONTAINS_ONLY_DATA, | 374 CONTAINS_ONLY_DATA, |
| 375 POINTERS_TO_HERE_ARE_INTERESTING, | 375 POINTERS_TO_HERE_ARE_INTERESTING, |
| 376 POINTERS_FROM_HERE_ARE_INTERESTING, | 376 POINTERS_FROM_HERE_ARE_INTERESTING, |
| 377 SCAN_ON_SCAVENGE, | 377 SCAN_ON_SCAVENGE, |
| 378 IN_NEW_SPACE, | 378 IN_NEW_SPACE, |
| 379 IN_TO_SPACE, // Only used if IN_NEW_SPACE is set. | |
|
Erik Corry
2011/05/24 11:25:50
Instead of a TO_SPACE flag and a FROM_SPACE flag I
Lasse Reichstein
2011/05/24 12:29:03
Done.
| |
| 379 NUM_MEMORY_CHUNK_FLAGS | 380 NUM_MEMORY_CHUNK_FLAGS |
| 380 }; | 381 }; |
| 381 | 382 |
| 382 void SetFlag(int flag) { | 383 void SetFlag(int flag) { |
| 383 flags_ |= 1 << flag; | 384 flags_ |= (1 << flag); |
| 384 } | 385 } |
| 385 | 386 |
| 386 void ClearFlag(int flag) { | 387 void ClearFlag(int flag) { |
| 387 flags_ &= ~(1 << flag); | 388 flags_ &= ~(1 << flag); |
| 388 } | 389 } |
| 389 | 390 |
| 391 void SetFlagTo(int flag, bool value) { | |
| 392 if (value) { | |
| 393 SetFlag(flag); | |
| 394 } else { | |
| 395 ClearFlag(flag); | |
| 396 } | |
| 397 } | |
| 398 | |
| 390 bool IsFlagSet(int flag) { | 399 bool IsFlagSet(int flag) { |
| 391 return (flags_ & (1 << flag)) != 0; | 400 return (flags_ & (1 << flag)) != 0; |
| 392 } | 401 } |
| 393 | 402 |
| 394 void CopyFlagsFrom(MemoryChunk* chunk) { | 403 // Set or clear multiple flags at a time. The flags in the mask |
| 395 flags_ = chunk->flags_; | 404 // are set to the value in "flags", the rest retain the current value |
| 405 // in flags_. | |
| 406 void SetFlags(intptr_t flags, intptr_t mask) { | |
| 407 flags_ = (flags_ & ~mask) | (flags & mask); | |
| 396 } | 408 } |
| 397 | 409 |
| 410 // Return all current flags. | |
| 411 intptr_t GetFlags() { return flags_; } | |
| 412 | |
| 398 static const intptr_t kAlignment = (1 << kPageSizeBits); | 413 static const intptr_t kAlignment = (1 << kPageSizeBits); |
| 399 | 414 |
| 400 static const intptr_t kAlignmentMask = kAlignment - 1; | 415 static const intptr_t kAlignmentMask = kAlignment - 1; |
| 401 | 416 |
| 402 static const size_t kHeaderSize = kPointerSize + kPointerSize + kPointerSize + | 417 static const size_t kHeaderSize = kPointerSize + kPointerSize + kPointerSize + |
| 403 kPointerSize + kPointerSize + kPointerSize + kPointerSize + kPointerSize; | 418 kPointerSize + kPointerSize + kPointerSize + kPointerSize + kPointerSize; |
| 404 | 419 |
| 405 static const int kBodyOffset = | 420 static const int kBodyOffset = |
| 406 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); | 421 CODE_POINTER_ALIGN(MAP_POINTER_ALIGN(kHeaderSize + Bitmap::kSize)); |
| 407 | 422 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 419 } | 434 } |
| 420 | 435 |
| 421 bool ContainsOnlyData() { | 436 bool ContainsOnlyData() { |
| 422 return IsFlagSet(CONTAINS_ONLY_DATA); | 437 return IsFlagSet(CONTAINS_ONLY_DATA); |
| 423 } | 438 } |
| 424 | 439 |
| 425 bool InNewSpace() { | 440 bool InNewSpace() { |
| 426 return IsFlagSet(IN_NEW_SPACE); | 441 return IsFlagSet(IN_NEW_SPACE); |
| 427 } | 442 } |
| 428 | 443 |
| 444 bool InToSpace() { | |
| 445 intptr_t mask = ((1 << IN_NEW_SPACE) | (1 << IN_TO_SPACE)); | |
| 446 return (flags_ & mask) == mask; | |
| 447 } | |
| 448 | |
| 449 bool InFromSpace() { | |
| 450 intptr_t mask = ((1 << IN_NEW_SPACE) | (1 << IN_TO_SPACE)); | |
| 451 return (flags_ & mask) == (1 << IN_NEW_SPACE) ; | |
| 452 } | |
| 453 | |
| 429 // --------------------------------------------------------------------- | 454 // --------------------------------------------------------------------- |
| 430 // Markbits support | 455 // Markbits support |
| 431 | 456 |
| 432 inline Bitmap* markbits() { | 457 inline Bitmap* markbits() { |
| 433 return Bitmap::FromAddress(address() + kHeaderSize); | 458 return Bitmap::FromAddress(address() + kHeaderSize); |
| 434 } | 459 } |
| 435 | 460 |
| 436 void PrintMarkbits() { markbits()->Print(); } | 461 void PrintMarkbits() { markbits()->Print(); } |
| 437 | 462 |
| 438 inline uint32_t AddressToMarkbitIndex(Address addr) { | 463 inline uint32_t AddressToMarkbitIndex(Address addr) { |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 | 1463 |
| 1439 const char* name() { return name_; } | 1464 const char* name() { return name_; } |
| 1440 void set_name(const char* name) { name_ = name; } | 1465 void set_name(const char* name) { name_ = name; } |
| 1441 | 1466 |
| 1442 private: | 1467 private: |
| 1443 const char* name_; | 1468 const char* name_; |
| 1444 }; | 1469 }; |
| 1445 #endif | 1470 #endif |
| 1446 | 1471 |
| 1447 | 1472 |
| 1473 enum SemiSpaceId { | |
| 1474 kFromSpace = 0, | |
| 1475 kToSpace = 1 | |
| 1476 }; | |
| 1477 | |
| 1478 | |
| 1448 class NewSpacePage : public MemoryChunk { | 1479 class NewSpacePage : public MemoryChunk { |
| 1449 public: | 1480 public: |
| 1450 inline NewSpacePage* next_page() const { | 1481 inline NewSpacePage* next_page() const { |
| 1451 return static_cast<NewSpacePage*>(next_chunk()); | 1482 return static_cast<NewSpacePage*>(next_chunk()); |
| 1452 } | 1483 } |
| 1453 | 1484 |
| 1454 inline void set_next_page(NewSpacePage* page) { | 1485 inline void set_next_page(NewSpacePage* page) { |
| 1455 set_next_chunk(page); | 1486 set_next_chunk(page); |
| 1456 } | 1487 } |
| 1457 private: | 1488 private: |
| 1458 // Finds the NewSpacePage containg the given address. | 1489 // Finds the NewSpacePage containg the given address. |
| 1459 static NewSpacePage* FromAddress(Address address_in_page) { | 1490 static NewSpacePage* FromAddress(Address address_in_page) { |
| 1460 Address page_start = | 1491 Address page_start = |
| 1461 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & | 1492 reinterpret_cast<Address>(reinterpret_cast<uintptr_t>(address_in_page) & |
| 1462 ~Page::kPageAlignmentMask); | 1493 ~Page::kPageAlignmentMask); |
| 1463 return reinterpret_cast<NewSpacePage*>(page_start); | 1494 return reinterpret_cast<NewSpacePage*>(page_start); |
| 1464 } | 1495 } |
| 1465 | 1496 |
| 1466 static NewSpacePage* Initialize(Heap* heap, Address start); | 1497 static NewSpacePage* Initialize(Heap* heap, |
| 1498 Address start, | |
| 1499 SemiSpaceId semispace); | |
| 1467 | 1500 |
| 1468 friend class SemiSpace; | 1501 friend class SemiSpace; |
| 1469 friend class SemiSpaceIterator; | 1502 friend class SemiSpaceIterator; |
| 1470 }; | 1503 }; |
| 1471 | 1504 |
| 1472 | 1505 |
| 1473 // ----------------------------------------------------------------------------- | 1506 // ----------------------------------------------------------------------------- |
| 1474 // SemiSpace in young generation | 1507 // SemiSpace in young generation |
| 1475 // | 1508 // |
| 1476 // A semispace is a contiguous chunk of memory holding page-like memory | 1509 // A semispace is a contiguous chunk of memory holding page-like memory |
| 1477 // chunks. The mark-compact collector uses the memory of the first page in | 1510 // chunks. The mark-compact collector uses the memory of the first page in |
| 1478 // the from space as a marking stack when tracing live objects. | 1511 // the from space as a marking stack when tracing live objects. |
| 1479 | 1512 |
| 1480 class SemiSpace : public Space { | 1513 class SemiSpace : public Space { |
| 1481 public: | 1514 public: |
| 1482 // Constructor. | 1515 // Constructor. |
| 1483 explicit SemiSpace(Heap* heap) : Space(heap, NEW_SPACE, NOT_EXECUTABLE) { | 1516 SemiSpace(Heap* heap, SemiSpaceId semispace) |
| 1484 start_ = NULL; | 1517 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| 1485 age_mark_ = NULL; | 1518 start_(NULL), |
| 1486 } | 1519 age_mark_(NULL), |
| 1520 is_to_space_(semispace != kFromSpace) { } | |
| 1487 | 1521 |
| 1488 // Sets up the semispace using the given chunk. | 1522 // Sets up the semispace using the given chunk. |
| 1489 bool Setup(Address start, int initial_capacity, int maximum_capacity); | 1523 bool Setup(Address start, int initial_capacity, int maximum_capacity); |
| 1490 | 1524 |
| 1491 // Tear down the space. Heap memory was not allocated by the space, so it | 1525 // Tear down the space. Heap memory was not allocated by the space, so it |
| 1492 // is not deallocated here. | 1526 // is not deallocated here. |
| 1493 void TearDown(); | 1527 void TearDown(); |
| 1494 | 1528 |
| 1495 // True if the space has been set up but not torn down. | 1529 // True if the space has been set up but not torn down. |
| 1496 bool HasBeenSetup() { return start_ != NULL; } | 1530 bool HasBeenSetup() { return start_ != NULL; } |
| 1497 | 1531 |
| 1498 // Grow the size of the semispace by committing extra virtual memory. | 1532 // Grow the size of the semispace by committing extra virtual memory. |
| 1499 // Assumes that the caller has checked that the semispace has not reached | 1533 // Assumes that the caller has checked that the semispace has not reached |
| 1500 // its maximum capacity (and thus there is space available in the reserved | 1534 // its maximum capacity (and thus there is space available in the reserved |
| 1501 // address range to grow). | 1535 // address range to grow). |
| 1502 bool Grow(); | 1536 bool Grow(); |
| 1503 | 1537 |
| 1504 // Grow the semispace to the new capacity. The new capacity | 1538 // Grow the semispace to the new capacity. The new capacity |
| 1505 // requested must be larger than the current capacity. | 1539 // requested must be larger than the current capacity. |
| 1506 bool GrowTo(int new_capacity); | 1540 bool GrowTo(int new_capacity); |
| 1507 | 1541 |
| 1508 // Shrinks the semispace to the new capacity. The new capacity | 1542 // Shrinks the semispace to the new capacity. The new capacity |
| 1509 // requested must be more than the amount of used memory in the | 1543 // requested must be more than the amount of used memory in the |
| 1510 // semispace and less than the current capacity. | 1544 // semispace and less than the current capacity. |
| 1511 bool ShrinkTo(int new_capacity); | 1545 bool ShrinkTo(int new_capacity); |
| 1512 | 1546 |
| 1547 // Flips the semispace between being from-space and to-space. | |
| 1548 // Copies the flags into the masked positions on all pages in the space. | |
| 1549 void Flip(intptr_t flags, intptr_t flag_mask); | |
| 1550 | |
| 1513 // Returns the start address of the space. | 1551 // Returns the start address of the space. |
| 1514 Address low() { | 1552 Address low() { |
| 1515 return NewSpacePage::FromAddress(start_)->body(); | 1553 return NewSpacePage::FromAddress(start_)->body(); |
| 1516 } | 1554 } |
| 1517 | 1555 |
| 1518 // Returns one past the end address of the space. | 1556 // Returns one past the end address of the space. |
| 1519 Address high() { | 1557 Address high() { |
| 1520 // TODO(gc): Change when there is more than one page. | 1558 // TODO(gc): Change when there is more than one page. |
| 1521 return current_page_->body() + current_page_->body_size(); | 1559 return current_page_->body() + current_page_->body_size(); |
| 1522 } | 1560 } |
| 1523 | 1561 |
| 1524 // Age mark accessors. | 1562 // Age mark accessors. |
| 1525 Address age_mark() { return age_mark_; } | 1563 Address age_mark() { return age_mark_; } |
| 1526 void set_age_mark(Address mark) { age_mark_ = mark; } | 1564 void set_age_mark(Address mark) { age_mark_ = mark; } |
| 1527 | 1565 |
| 1528 // True if the address is in the address range of this semispace (not | |
| 1529 // necessarily below the allocation pointer). | |
| 1530 bool Contains(Address a) { | |
| 1531 return (reinterpret_cast<uintptr_t>(a) & address_mask_) | |
| 1532 == reinterpret_cast<uintptr_t>(start_); | |
| 1533 } | |
| 1534 | |
| 1535 // True if the object is a heap object in the address range of this | |
| 1536 // semispace (not necessarily below the allocation pointer). | |
| 1537 bool Contains(Object* o) { | |
| 1538 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; | |
| 1539 } | |
| 1540 | |
| 1541 // The offset of an address from the beginning of the space. | 1566 // The offset of an address from the beginning of the space. |
| 1542 int SpaceOffsetForAddress(Address addr) { | 1567 int SpaceOffsetForAddress(Address addr) { |
| 1543 return static_cast<int>(addr - low()); | 1568 return static_cast<int>(addr - low()); |
| 1544 } | 1569 } |
| 1545 | 1570 |
| 1546 // If we don't have these here then SemiSpace will be abstract. However | 1571 // If we don't have these here then SemiSpace will be abstract. However |
| 1547 // they should never be called. | 1572 // they should never be called. |
| 1548 virtual intptr_t Size() { | 1573 virtual intptr_t Size() { |
| 1549 UNREACHABLE(); | 1574 UNREACHABLE(); |
| 1550 return 0; | 1575 return 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1592 Address start_; | 1617 Address start_; |
| 1593 // Used to govern object promotion during mark-compact collection. | 1618 // Used to govern object promotion during mark-compact collection. |
| 1594 Address age_mark_; | 1619 Address age_mark_; |
| 1595 | 1620 |
| 1596 // Masks and comparison values to test for containment in this semispace. | 1621 // Masks and comparison values to test for containment in this semispace. |
| 1597 uintptr_t address_mask_; | 1622 uintptr_t address_mask_; |
| 1598 uintptr_t object_mask_; | 1623 uintptr_t object_mask_; |
| 1599 uintptr_t object_expected_; | 1624 uintptr_t object_expected_; |
| 1600 | 1625 |
| 1601 bool committed_; | 1626 bool committed_; |
| 1627 bool is_to_space_; | |
|
Erik Corry
2011/05/24 11:25:50
This should be a SemiSpaceId instead of a bool
Lasse Reichstein
2011/05/24 12:29:03
Done.
| |
| 1602 | 1628 |
| 1603 NewSpacePage* current_page_; | 1629 NewSpacePage* current_page_; |
| 1604 | 1630 |
| 1605 public: | 1631 public: |
| 1606 TRACK_MEMORY("SemiSpace") | 1632 TRACK_MEMORY("SemiSpace") |
| 1607 }; | 1633 }; |
| 1608 | 1634 |
| 1609 | 1635 |
| 1610 // A SemiSpaceIterator is an ObjectIterator that iterates over the active | 1636 // A SemiSpaceIterator is an ObjectIterator that iterates over the active |
| 1611 // semispace of the heap's new space. It iterates over the objects in the | 1637 // semispace of the heap's new space. It iterates over the objects in the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 // The young generation space. | 1686 // The young generation space. |
| 1661 // | 1687 // |
| 1662 // The new space consists of a contiguous pair of semispaces. It simply | 1688 // The new space consists of a contiguous pair of semispaces. It simply |
| 1663 // forwards most functions to the appropriate semispace. | 1689 // forwards most functions to the appropriate semispace. |
| 1664 | 1690 |
| 1665 class NewSpace : public Space { | 1691 class NewSpace : public Space { |
| 1666 public: | 1692 public: |
| 1667 // Constructor. | 1693 // Constructor. |
| 1668 explicit NewSpace(Heap* heap) | 1694 explicit NewSpace(Heap* heap) |
| 1669 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), | 1695 : Space(heap, NEW_SPACE, NOT_EXECUTABLE), |
| 1670 to_space_(heap), | 1696 to_space_(heap, kToSpace), |
| 1671 from_space_(heap) {} | 1697 from_space_(heap, kFromSpace) {} |
| 1672 | 1698 |
| 1673 // Sets up the new space using the given chunk. | 1699 // Sets up the new space using the given chunk. |
| 1674 bool Setup(int max_semispace_size); | 1700 bool Setup(int max_semispace_size); |
| 1675 | 1701 |
| 1676 // Tears down the space. Heap memory was not allocated by the space, so it | 1702 // Tears down the space. Heap memory was not allocated by the space, so it |
| 1677 // is not deallocated here. | 1703 // is not deallocated here. |
| 1678 void TearDown(); | 1704 void TearDown(); |
| 1679 | 1705 |
| 1680 // True if the space has been set up but not torn down. | 1706 // True if the space has been set up but not torn down. |
| 1681 bool HasBeenSetup() { | 1707 bool HasBeenSetup() { |
| 1682 return to_space_.HasBeenSetup() && from_space_.HasBeenSetup(); | 1708 return to_space_.HasBeenSetup() && from_space_.HasBeenSetup(); |
| 1683 } | 1709 } |
| 1684 | 1710 |
| 1685 // Flip the pair of spaces. | 1711 // Flip the pair of spaces. |
| 1686 void Flip(); | 1712 void Flip(); |
| 1687 | 1713 |
| 1688 // Grow the capacity of the semispaces. Assumes that they are not at | 1714 // Grow the capacity of the semispaces. Assumes that they are not at |
| 1689 // their maximum capacity. | 1715 // their maximum capacity. |
| 1690 void Grow(); | 1716 void Grow(); |
| 1691 | 1717 |
| 1692 // Shrink the capacity of the semispaces. | 1718 // Shrink the capacity of the semispaces. |
| 1693 void Shrink(); | 1719 void Shrink(); |
| 1694 | 1720 |
| 1695 // True if the address or object lies in the address range of either | 1721 // True if the address or object lies in the address range of either |
| 1696 // semispace (not necessarily below the allocation pointer). | 1722 // semispace (not necessarily below the allocation pointer). |
| 1697 bool Contains(Address a) { | 1723 bool Contains(Address a) { |
| 1724 // TODO(gc): Replace by PageContains when we stop passing | |
| 1725 // pointers to non-paged space. | |
| 1698 return (reinterpret_cast<uintptr_t>(a) & address_mask_) | 1726 return (reinterpret_cast<uintptr_t>(a) & address_mask_) |
| 1699 == reinterpret_cast<uintptr_t>(start_); | 1727 == reinterpret_cast<uintptr_t>(start_); |
| 1700 } | 1728 } |
| 1701 | 1729 |
| 1702 // True if the address or object lies on a NewSpacePage. | 1730 // True if the address or object lies on a NewSpacePage. |
| 1703 // Must be a pointer into a heap page, and if it's a large object | 1731 // Must be a pointer into a heap page, and if it's a large object |
| 1704 // page, it must be a pointer into the beginning of it. | 1732 // page, it must be a pointer into the beginning of it. |
| 1705 // TODO(gc): When every call to Contains is converted to PageContains, | 1733 // TODO(gc): When every call to Contains is converted to PageContains, |
| 1706 // remove Contains and rename PageContains to Contains. | 1734 // remove Contains and rename PageContains to Contains. |
| 1707 bool PageContains(Address a) { | 1735 bool PageContains(Address a) { |
| 1708 if ((reinterpret_cast<intptr_t>(a) & ~kHeapObjectTagMask) == | 1736 MemoryChunk* page = MemoryChunk::FromAddress(a); |
| 1709 static_cast<intptr_t>(0)) { | 1737 // Tagged zero-page pointers are not real heap pointers. |
| 1710 // Tagged zero-page pointers are not real heap pointers. | 1738 // TODO(gc): Remove when we no longer have tagged zero-page |
| 1711 // TODO(gc): Remove when we no longer have tagged zero-page | 1739 // pointers intermingled with real heap object pointers. |
| 1712 // pointers intermingled with real heap object pointers. | 1740 if (!page->is_valid()) return false; |
| 1713 return false; | 1741 return page->InNewSpace(); |
| 1714 } | |
| 1715 return MemoryChunk::FromAddress(a)->InNewSpace(); | |
| 1716 } | 1742 } |
| 1717 | 1743 |
| 1718 bool Contains(Object* o) { | 1744 bool Contains(Object* o) { |
| 1719 return (reinterpret_cast<uintptr_t>(o) & object_mask_) == object_expected_; | |
| 1720 } | |
| 1721 | |
| 1722 bool PageContains(Object* o) { | |
| 1723 if (o->IsSmi()) return false; | 1745 if (o->IsSmi()) return false; |
| 1724 if ((reinterpret_cast<uintptr_t>(o) & ~kHeapObjectTagMask) == | |
| 1725 static_cast<uintptr_t>(0)) { | |
| 1726 // Tagged zero-page pointers are not real heap pointers. | |
| 1727 // TODO(gc): Remove when we no longer have tagged zero-page | |
| 1728 // pointers intermingled with real heap object pointers. | |
| 1729 return false; | |
| 1730 } | |
| 1731 Address a = HeapObject::cast(o)->address(); | 1746 Address a = HeapObject::cast(o)->address(); |
| 1732 return MemoryChunk::FromAddress(a)->InNewSpace(); | 1747 MemoryChunk* page = MemoryChunk::FromAddress(a); |
| 1748 if (!page->is_valid()) return false; | |
| 1749 return page->InNewSpace(); | |
| 1733 } | 1750 } |
| 1734 | 1751 |
| 1735 // Return the allocated bytes in the active semispace. | 1752 // Return the allocated bytes in the active semispace. |
| 1736 virtual intptr_t Size() { return static_cast<int>(top() - bottom()); } | 1753 virtual intptr_t Size() { return static_cast<int>(top() - bottom()); } |
| 1737 // The same, but returning an int. We have to have the one that returns | 1754 // The same, but returning an int. We have to have the one that returns |
| 1738 // intptr_t because it is inherited, but if we know we are dealing with the | 1755 // intptr_t because it is inherited, but if we know we are dealing with the |
| 1739 // new space, which can't get as big as the other spaces then this is useful: | 1756 // new space, which can't get as big as the other spaces then this is useful: |
| 1740 int SizeAsInt() { return static_cast<int>(Size()); } | 1757 int SizeAsInt() { return static_cast<int>(Size()); } |
| 1741 | 1758 |
| 1742 // Return the current capacity of a semispace. | 1759 // Return the current capacity of a semispace. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1825 Address ToSpaceHigh() { return to_space_.high(); } | 1842 Address ToSpaceHigh() { return to_space_.high(); } |
| 1826 | 1843 |
| 1827 // Offsets from the beginning of the semispaces. | 1844 // Offsets from the beginning of the semispaces. |
| 1828 int ToSpaceOffsetForAddress(Address a) { | 1845 int ToSpaceOffsetForAddress(Address a) { |
| 1829 return to_space_.SpaceOffsetForAddress(a); | 1846 return to_space_.SpaceOffsetForAddress(a); |
| 1830 } | 1847 } |
| 1831 int FromSpaceOffsetForAddress(Address a) { | 1848 int FromSpaceOffsetForAddress(Address a) { |
| 1832 return from_space_.SpaceOffsetForAddress(a); | 1849 return from_space_.SpaceOffsetForAddress(a); |
| 1833 } | 1850 } |
| 1834 | 1851 |
| 1852 inline bool ToSpaceContains(Address address) { | |
| 1853 MemoryChunk* page = MemoryChunk::FromAddress(address); | |
|
Erik Corry
2011/05/24 11:25:50
assert it is a new space page and the same in From
Lasse Reichstein
2011/05/24 12:29:03
Are we sure it is a new-space address?
This also w
| |
| 1854 return page->is_valid() && page->InToSpace(); | |
| 1855 } | |
| 1856 | |
| 1857 inline bool FromSpaceContains(Address address) { | |
| 1858 MemoryChunk* page = MemoryChunk::FromAddress(address); | |
| 1859 return page->is_valid() && page->InFromSpace(); | |
| 1860 } | |
| 1861 | |
| 1835 // True if the object is a heap object in the address range of the | 1862 // True if the object is a heap object in the address range of the |
| 1836 // respective semispace (not necessarily below the allocation pointer of the | 1863 // respective semispace (not necessarily below the allocation pointer of the |
| 1837 // semispace). | 1864 // semispace). |
| 1838 bool ToSpaceContains(Object* o) { return to_space_.Contains(o); } | 1865 bool ToSpaceContains(Object* o) { |
| 1839 bool FromSpaceContains(Object* o) { return from_space_.Contains(o); } | 1866 if (o->IsSmi()) return false; |
| 1867 HeapObject* heap_object = HeapObject::cast(o); | |
| 1868 return ToSpaceContains(heap_object->address()); | |
| 1869 } | |
| 1840 | 1870 |
| 1841 bool ToSpaceContains(Address a) { return to_space_.Contains(a); } | 1871 bool FromSpaceContains(Object* o) { |
| 1842 bool FromSpaceContains(Address a) { return from_space_.Contains(a); } | 1872 if (o->IsSmi()) return false; |
| 1873 HeapObject* heap_object = HeapObject::cast(o); | |
| 1874 return FromSpaceContains(heap_object->address()); | |
| 1875 } | |
| 1843 | 1876 |
| 1844 virtual bool ReserveSpace(int bytes); | 1877 virtual bool ReserveSpace(int bytes); |
| 1845 | 1878 |
| 1846 // Resizes a sequential string which must be the most recent thing that was | 1879 // Resizes a sequential string which must be the most recent thing that was |
| 1847 // allocated in new space. | 1880 // allocated in new space. |
| 1848 template <typename StringType> | 1881 template <typename StringType> |
| 1849 inline void ShrinkStringAtAllocationBoundary(String* string, int len); | 1882 inline void ShrinkStringAtAllocationBoundary(String* string, int len); |
| 1850 | 1883 |
| 1851 #ifdef ENABLE_HEAP_PROTECTION | 1884 #ifdef ENABLE_HEAP_PROTECTION |
| 1852 // Protect/unprotect the space by marking it read-only/writable. | 1885 // Protect/unprotect the space by marking it read-only/writable. |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2288 } | 2321 } |
| 2289 // Must be small, since an iteration is used for lookup. | 2322 // Must be small, since an iteration is used for lookup. |
| 2290 static const int kMaxComments = 64; | 2323 static const int kMaxComments = 64; |
| 2291 }; | 2324 }; |
| 2292 #endif | 2325 #endif |
| 2293 | 2326 |
| 2294 | 2327 |
| 2295 } } // namespace v8::internal | 2328 } } // namespace v8::internal |
| 2296 | 2329 |
| 2297 #endif // V8_SPACES_H_ | 2330 #endif // V8_SPACES_H_ |
| OLD | NEW |