Reviewers: Michael Starzinger,

https://codereview.chromium.org/1302423007/diff/1/src/heap/spaces.h
File src/heap/spaces.h (left):

https://codereview.chromium.org/1302423007/diff/1/src/heap/spaces.h#oldcode558
src/heap/spaces.h:558: 5 * kPointerSize +  // free list statistics
5 * kPointerSize implicitly included the memory that was needed to
amount for alignment requirements. (Maybe the author new this, maybe
not.)

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

[email protected]

Please review this at https://codereview.chromium.org/1302423007/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+46, -21 lines):
  M src/heap/spaces.h


Index: src/heap/spaces.h
diff --git a/src/heap/spaces.h b/src/heap/spaces.h
index de82164a1332be17c00c5f2c9e239a4284a1e1cb..25c1211329229536ac8ac6ec58288cb03b3c888a 100644
--- a/src/heap/spaces.h
+++ b/src/heap/spaces.h
@@ -541,23 +541,37 @@ 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 +
+      kPointerSize     // 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.
+  static const size_t kHeaderSize = kMinHeaderSize + kPointerSize;

   static const int kBodyOffset =
       CODE_POINTER_ALIGN(kHeaderSize + Bitmap::kSize);
@@ -727,12 +741,10 @@ class MemoryChunk {
   base::AtomicWord prev_chunk_;

   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 +853,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 +869,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 +922,23 @@ class Space : public Malloced {
 };


+class MemoryChunkValidator {
+  // Computed offsets should match the compiler generates 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


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to