OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_SPACES_H_ | 5 #ifndef V8_HEAP_SPACES_H_ |
6 #define V8_HEAP_SPACES_H_ | 6 #define V8_HEAP_SPACES_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/base/atomicops.h" | 9 #include "src/base/atomicops.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 FreeListCategory huge_list_; | 1601 FreeListCategory huge_list_; |
1602 | 1602 |
1603 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); | 1603 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeList); |
1604 }; | 1604 }; |
1605 | 1605 |
1606 | 1606 |
1607 class AllocationResult { | 1607 class AllocationResult { |
1608 public: | 1608 public: |
1609 // Implicit constructor from Object*. | 1609 // Implicit constructor from Object*. |
1610 AllocationResult(Object* object) // NOLINT | 1610 AllocationResult(Object* object) // NOLINT |
1611 : object_(object), | 1611 : object_(object) { |
1612 retry_space_(INVALID_SPACE) {} | 1612 // AllocationResults can't return Smis, which are used to represent |
| 1613 // failure and the space to retry in. |
| 1614 CHECK(!object->IsSmi()); |
| 1615 } |
1613 | 1616 |
1614 AllocationResult() : object_(NULL), retry_space_(INVALID_SPACE) {} | 1617 AllocationResult() : object_(Smi::FromInt(NEW_SPACE)) {} |
1615 | 1618 |
1616 static inline AllocationResult Retry(AllocationSpace space = NEW_SPACE) { | 1619 static inline AllocationResult Retry(AllocationSpace space = NEW_SPACE) { |
1617 return AllocationResult(space); | 1620 return AllocationResult(space); |
1618 } | 1621 } |
1619 | 1622 |
1620 inline bool IsRetry() { return retry_space_ != INVALID_SPACE; } | 1623 inline bool IsRetry() { return object_->IsSmi(); } |
1621 | 1624 |
1622 template <typename T> | 1625 template <typename T> |
1623 bool To(T** obj) { | 1626 bool To(T** obj) { |
1624 if (IsRetry()) return false; | 1627 if (IsRetry()) return false; |
1625 *obj = T::cast(object_); | 1628 *obj = T::cast(object_); |
1626 return true; | 1629 return true; |
1627 } | 1630 } |
1628 | 1631 |
1629 Object* ToObjectChecked() { | 1632 Object* ToObjectChecked() { |
1630 CHECK(!IsRetry()); | 1633 CHECK(!IsRetry()); |
1631 return object_; | 1634 return object_; |
1632 } | 1635 } |
1633 | 1636 |
1634 AllocationSpace RetrySpace() { | 1637 AllocationSpace RetrySpace() { |
1635 DCHECK(IsRetry()); | 1638 DCHECK(IsRetry()); |
1636 return retry_space_; | 1639 return static_cast<AllocationSpace>(Smi::cast(object_)->value()); |
1637 } | 1640 } |
1638 | 1641 |
1639 private: | 1642 private: |
1640 explicit AllocationResult(AllocationSpace space) | 1643 explicit AllocationResult(AllocationSpace space) |
1641 : object_(NULL), retry_space_(space) {} | 1644 : object_(Smi::FromInt(static_cast<int>(space))) {} |
1642 | 1645 |
1643 Object* object_; | 1646 Object* object_; |
1644 AllocationSpace retry_space_; | |
1645 }; | 1647 }; |
1646 | 1648 |
1647 | 1649 |
| 1650 STATIC_ASSERT(sizeof(AllocationResult) == kPointerSize); |
| 1651 |
| 1652 |
1648 class PagedSpace : public Space { | 1653 class PagedSpace : public Space { |
1649 public: | 1654 public: |
1650 // Creates a space with a maximum capacity, and an id. | 1655 // Creates a space with a maximum capacity, and an id. |
1651 PagedSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id, | 1656 PagedSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id, |
1652 Executability executable); | 1657 Executability executable); |
1653 | 1658 |
1654 virtual ~PagedSpace() {} | 1659 virtual ~PagedSpace() {} |
1655 | 1660 |
1656 // Set up the space using the given address range of virtual memory (from | 1661 // Set up the space using the given address range of virtual memory (from |
1657 // the memory allocator's initial chunk) if possible. If the block of | 1662 // the memory allocator's initial chunk) if possible. If the block of |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2894 count = 0; | 2899 count = 0; |
2895 } | 2900 } |
2896 // Must be small, since an iteration is used for lookup. | 2901 // Must be small, since an iteration is used for lookup. |
2897 static const int kMaxComments = 64; | 2902 static const int kMaxComments = 64; |
2898 }; | 2903 }; |
2899 #endif | 2904 #endif |
2900 } | 2905 } |
2901 } // namespace v8::internal | 2906 } // namespace v8::internal |
2902 | 2907 |
2903 #endif // V8_HEAP_SPACES_H_ | 2908 #endif // V8_HEAP_SPACES_H_ |
OLD | NEW |