Chromium Code Reviews| Index: src/spaces.h |
| diff --git a/src/spaces.h b/src/spaces.h |
| index c7f6f693a4dc627595f82dc641094ea3cf2f16b1..d04bf794da5774909a93f76601117367422673dc 100644 |
| --- a/src/spaces.h |
| +++ b/src/spaces.h |
| @@ -1497,8 +1497,7 @@ class FreeListNode: public HeapObject { |
| inline void Zap(); |
| - static inline FreeListNode* cast(MaybeObject* maybe) { |
| - ASSERT(!maybe->IsFailure()); |
| + static inline FreeListNode* cast(Object* maybe) { |
|
Hannes Payer (out of office)
2014/04/30 07:07:07
maybe -> object
|
| return reinterpret_cast<FreeListNode*>(maybe); |
| } |
| @@ -1670,6 +1669,47 @@ class FreeList { |
| }; |
| +class AllocationResult { |
| + public: |
| + // Implicit constructor from Object*. |
| + AllocationResult(Object* object) : object_(object), // NOLINT |
| + retry_space_(INVALID_SPACE) { } |
| + |
| + AllocationResult() : object_(NULL), |
| + retry_space_(INVALID_SPACE) { } |
| + |
| + static inline AllocationResult Retry(AllocationSpace space = NEW_SPACE) { |
| + return AllocationResult(space); |
| + } |
| + |
| + inline bool IsRetry() { return retry_space_ != INVALID_SPACE; } |
| + |
| + template <typename T> |
| + bool To(T** obj) { |
| + if (IsRetry()) return false; |
| + *obj = T::cast(object_); |
| + return true; |
| + } |
| + |
| + Object* ToObjectChecked() { |
| + CHECK(!IsRetry()); |
| + return object_; |
| + } |
| + |
| + AllocationSpace RetrySpace() { |
| + ASSERT(IsRetry()); |
| + return retry_space_; |
| + } |
| + |
| + private: |
| + explicit AllocationResult(AllocationSpace space) : object_(NULL), |
| + retry_space_(space) { } |
| + |
| + Object* object_; |
| + AllocationSpace retry_space_; |
| +}; |
| + |
| + |
| class PagedSpace : public Space { |
| public: |
| // Creates a space with a maximum capacity, and an id. |
| @@ -1790,7 +1830,7 @@ class PagedSpace : public Space { |
| // Allocate the requested number of bytes in the space if possible, return a |
| // failure object if not. |
| - MUST_USE_RESULT inline MaybeObject* AllocateRaw(int size_in_bytes); |
| + MUST_USE_RESULT inline AllocationResult AllocateRaw(int size_in_bytes); |
| // Give a block of memory to the space's free list. It might be added to |
| // the free list or accounted as waste. |
| @@ -2516,7 +2556,7 @@ class NewSpace : public Space { |
| return allocation_info_.limit_address(); |
| } |
| - MUST_USE_RESULT INLINE(MaybeObject* AllocateRaw(int size_in_bytes)); |
| + MUST_USE_RESULT INLINE(AllocationResult AllocateRaw(int size_in_bytes)); |
| // Reset the allocation pointer to the beginning of the active semispace. |
| void ResetAllocationInfo(); |
| @@ -2633,7 +2673,7 @@ class NewSpace : public Space { |
| HistogramInfo* allocated_histogram_; |
| HistogramInfo* promoted_histogram_; |
| - MUST_USE_RESULT MaybeObject* SlowAllocateRaw(int size_in_bytes); |
| + MUST_USE_RESULT AllocationResult SlowAllocateRaw(int size_in_bytes); |
| friend class SemiSpaceIterator; |
| @@ -2788,8 +2828,8 @@ class LargeObjectSpace : public Space { |
| // Shared implementation of AllocateRaw, AllocateRawCode and |
| // AllocateRawFixedArray. |
| - MUST_USE_RESULT MaybeObject* AllocateRaw(int object_size, |
| - Executability executable); |
| + MUST_USE_RESULT AllocationResult AllocateRaw(int object_size, |
| + Executability executable); |
| // Available bytes for objects in this space. |
| inline intptr_t Available(); |