Commit aeb40684 authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Fix MemoryChunk::kHeaderSize computation and add some assertions.

R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/1302423007

Cr-Commit-Position: refs/heads/master@{#30630}
parent ccbb4ff0
...@@ -541,23 +541,38 @@ class MemoryChunk { ...@@ -541,23 +541,38 @@ class MemoryChunk {
static const intptr_t kSizeOffset = 0; static const intptr_t kSizeOffset = 0;
static const intptr_t kLiveBytesOffset = static const intptr_t kLiveBytesOffset =
kSizeOffset + kPointerSize + kPointerSize + kPointerSize + kPointerSize + kSizeOffset + kPointerSize // size_t size
kPointerSize + kPointerSize + kPointerSize + kPointerSize + kIntSize; + kIntptrSize // intptr_t flags_
+ kPointerSize // Address area_start_
+ kPointerSize // Address area_end_
+ 2 * kPointerSize // base::VirtualMemory reservation_
+ kPointerSize // Address owner_
+ kPointerSize // Heap* heap_
+ kIntSize; // int store_buffer_counter_
static const size_t kSlotsBufferOffset = kLiveBytesOffset + kIntSize;
static const size_t kSlotsBufferOffset =
kLiveBytesOffset + kIntSize; // int live_byte_count_
static const size_t kWriteBarrierCounterOffset = static const size_t kWriteBarrierCounterOffset =
kSlotsBufferOffset + kPointerSize + kPointerSize; kSlotsBufferOffset + kPointerSize // SlotsBuffer* slots_buffer_;
+ kPointerSize; // SkipList* skip_list_;
static const size_t kHeaderSize = kWriteBarrierCounterOffset +
kPointerSize + // write_barrier_counter_ static const size_t kMinHeaderSize =
kIntSize + // progress_bar_ kWriteBarrierCounterOffset +
kIntSize + // high_water_mark_ kIntptrSize // intptr_t write_barrier_counter_
kPointerSize + // mutex_ page lock + kIntSize // int progress_bar_
kPointerSize + // parallel_sweeping_ + kIntSize // int high_water_mark_
5 * kPointerSize + // free list statistics + kPointerSize // base::Mutex* mutex_
kPointerSize + // next_chunk_ + kPointerSize // base::AtomicWord parallel_sweeping_
kPointerSize; // prev_chunk_ + 5 * kIntSize // int free-list statistics
+ kPointerSize // base::AtomicWord next_chunk_
+ kPointerSize; // base::AtomicWord prev_chunk_
// We add some more space to the computed header size to amount for missing
// alignment requirements in our computation.
// Try to get kHeaderSize properly aligned on 32-bit and 64-bit machines.
static const size_t kHeaderSize = kMinHeaderSize + kIntSize;
static const int kBodyOffset = static const int kBodyOffset =
CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize); CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
...@@ -716,23 +731,21 @@ class MemoryChunk { ...@@ -716,23 +731,21 @@ class MemoryChunk {
int available_in_huge_free_list_; int available_in_huge_free_list_;
int non_available_small_blocks_; int non_available_small_blocks_;
static MemoryChunk* Initialize(Heap* heap, Address base, size_t size,
Address area_start, Address area_end,
Executability executable, Space* owner);
private:
// next_chunk_ holds a pointer of type MemoryChunk // next_chunk_ holds a pointer of type MemoryChunk
base::AtomicWord next_chunk_; base::AtomicWord next_chunk_;
// prev_chunk_ holds a pointer of type MemoryChunk // prev_chunk_ holds a pointer of type MemoryChunk
base::AtomicWord prev_chunk_; base::AtomicWord prev_chunk_;
static MemoryChunk* Initialize(Heap* heap, Address base, size_t size,
Address area_start, Address area_end,
Executability executable, Space* owner);
private:
friend class MemoryAllocator; friend class MemoryAllocator;
friend class MemoryChunkValidator;
}; };
STATIC_ASSERT(sizeof(MemoryChunk) <= MemoryChunk::kHeaderSize);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// A page is a memory chunk of a size 1MB. Large object pages may be larger. // A page is a memory chunk of a size 1MB. Large object pages may be larger.
// //
...@@ -841,9 +854,6 @@ class Page : public MemoryChunk { ...@@ -841,9 +854,6 @@ class Page : public MemoryChunk {
}; };
STATIC_ASSERT(sizeof(Page) <= MemoryChunk::kHeaderSize);
class LargePage : public MemoryChunk { class LargePage : public MemoryChunk {
public: public:
HeapObject* GetObject() { return HeapObject::FromAddress(area_start()); } HeapObject* GetObject() { return HeapObject::FromAddress(area_start()); }
...@@ -860,7 +870,6 @@ class LargePage : public MemoryChunk { ...@@ -860,7 +870,6 @@ class LargePage : public MemoryChunk {
friend class MemoryAllocator; friend class MemoryAllocator;
}; };
STATIC_ASSERT(sizeof(LargePage) <= MemoryChunk::kHeaderSize);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Space is the abstract superclass for all allocation spaces. // Space is the abstract superclass for all allocation spaces.
...@@ -914,6 +923,23 @@ class Space : public Malloced { ...@@ -914,6 +923,23 @@ class Space : public Malloced {
}; };
class MemoryChunkValidator {
// Computed offsets should match the compiler generated ones.
STATIC_ASSERT(MemoryChunk::kSizeOffset == offsetof(MemoryChunk, size_));
STATIC_ASSERT(MemoryChunk::kLiveBytesOffset ==
offsetof(MemoryChunk, live_byte_count_));
STATIC_ASSERT(MemoryChunk::kSlotsBufferOffset ==
offsetof(MemoryChunk, slots_buffer_));
STATIC_ASSERT(MemoryChunk::kWriteBarrierCounterOffset ==
offsetof(MemoryChunk, write_barrier_counter_));
// Validate our estimates on the header size.
STATIC_ASSERT(sizeof(MemoryChunk) <= MemoryChunk::kHeaderSize);
STATIC_ASSERT(sizeof(LargePage) <= MemoryChunk::kHeaderSize);
STATIC_ASSERT(sizeof(Page) <= MemoryChunk::kHeaderSize);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// All heap objects containing executable code (code objects) must be allocated // All heap objects containing executable code (code objects) must be allocated
// from a 2 GB range of memory, so that they can call each other using 32-bit // from a 2 GB range of memory, so that they can call each other using 32-bit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment