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

Unified Diff: src/heap/spaces.h

Issue 1302423007: [heap] Fix MemoryChunk::kHeaderSize computation and add some assertions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/spaces.h
diff --git a/src/heap/spaces.h b/src/heap/spaces.h
index de82164a1332be17c00c5f2c9e239a4284a1e1cb..b11f926fde3cf373b1144b0dc67ebc5f859c0a02 100644
--- a/src/heap/spaces.h
+++ b/src/heap/spaces.h
@@ -541,23 +541,38 @@ class MemoryChunk {
static const intptr_t kSizeOffset = 0;
static const intptr_t kLiveBytesOffset =
- kSizeOffset + kPointerSize + kPointerSize + kPointerSize + kPointerSize +
- kPointerSize + kPointerSize + kPointerSize + kPointerSize + kIntSize;
+ kSizeOffset + kPointerSize // size_t size
+ + 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 =
- kSlotsBufferOffset + kPointerSize + kPointerSize;
-
- static const size_t kHeaderSize = kWriteBarrierCounterOffset +
- kPointerSize + // write_barrier_counter_
- kIntSize + // progress_bar_
- kIntSize + // high_water_mark_
- kPointerSize + // mutex_ page lock
- kPointerSize + // parallel_sweeping_
- 5 * kPointerSize + // free list statistics
- kPointerSize + // next_chunk_
- kPointerSize; // prev_chunk_
+ kSlotsBufferOffset + kPointerSize // SlotsBuffer* slots_buffer_;
+ + kPointerSize; // SkipList* skip_list_;
+
+ static const size_t kMinHeaderSize =
+ kWriteBarrierCounterOffset +
+ kIntptrSize // intptr_t write_barrier_counter_
+ + kIntSize // int progress_bar_
+ + kIntSize // int high_water_mark_
+ + kPointerSize // base::Mutex* mutex_
+ + kPointerSize // base::AtomicWord parallel_sweeping_
+ + 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 =
CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
@@ -716,23 +731,21 @@ class MemoryChunk {
int available_in_huge_free_list_;
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
base::AtomicWord next_chunk_;
// prev_chunk_ holds a pointer of type MemoryChunk
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 MemoryChunkValidator;
};
-STATIC_ASSERT(sizeof(MemoryChunk) <= MemoryChunk::kHeaderSize);
-
-
// -----------------------------------------------------------------------------
// A page is a memory chunk of a size 1MB. Large object pages may be larger.
//
@@ -841,9 +854,6 @@ class Page : public MemoryChunk {
};
-STATIC_ASSERT(sizeof(Page) <= MemoryChunk::kHeaderSize);
-
-
class LargePage : public MemoryChunk {
public:
HeapObject* GetObject() { return HeapObject::FromAddress(area_start()); }
@@ -860,7 +870,6 @@ class LargePage : public MemoryChunk {
friend class MemoryAllocator;
};
-STATIC_ASSERT(sizeof(LargePage) <= MemoryChunk::kHeaderSize);
// ----------------------------------------------------------------------------
// Space is the abstract superclass for all allocation spaces.
@@ -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
// from a 2 GB range of memory, so that they can call each other using 32-bit
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698