Fix the CopiedBlock offset alignment in a cross platform fashion
authormhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Feb 2012 08:07:44 +0000 (08:07 +0000)
committermhahnenberg@apple.com <mhahnenberg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 25 Feb 2012 08:07:44 +0000 (08:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79556

Reviewed by Filip Pizlo.

Replaced m_payload with a payload() method that calculates the offset
of the payload with the proper alignment. This change allows us to
avoid alignment-related issues in a cross-platform manner.

* heap/CopiedAllocator.h:
(JSC::CopiedAllocator::currentUtilization):
* heap/CopiedBlock.h:
(JSC::CopiedBlock::CopiedBlock):
(JSC::CopiedBlock::payload):
(CopiedBlock):
* heap/CopiedSpace.cpp:
(JSC::CopiedSpace::doneFillingBlock):
* heap/CopiedSpaceInlineMethods.h:
(JSC::CopiedSpace::borrowBlock):
(JSC::CopiedSpace::allocateFromBlock):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108888 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/CopiedAllocator.h
Source/JavaScriptCore/heap/CopiedBlock.h
Source/JavaScriptCore/heap/CopiedSpace.cpp
Source/JavaScriptCore/heap/CopiedSpaceInlineMethods.h

index 080e9e1..b21c871 100644 (file)
@@ -1,3 +1,26 @@
+2012-02-25  Mark Hahnenberg  <mhahnenberg@apple.com>
+
+        Fix the CopiedBlock offset alignment in a cross platform fashion
+        https://bugs.webkit.org/show_bug.cgi?id=79556
+
+        Reviewed by Filip Pizlo.
+
+        Replaced m_payload with a payload() method that calculates the offset
+        of the payload with the proper alignment. This change allows us to 
+        avoid alignment-related issues in a cross-platform manner.
+
+        * heap/CopiedAllocator.h:
+        (JSC::CopiedAllocator::currentUtilization):
+        * heap/CopiedBlock.h:
+        (JSC::CopiedBlock::CopiedBlock):
+        (JSC::CopiedBlock::payload):
+        (CopiedBlock):
+        * heap/CopiedSpace.cpp:
+        (JSC::CopiedSpace::doneFillingBlock):
+        * heap/CopiedSpaceInlineMethods.h:
+        (JSC::CopiedSpace::borrowBlock):
+        (JSC::CopiedSpace::allocateFromBlock):
+
 2012-02-24  Michael Saboff  <msaboff@apple.com>
 
         Unreviewed, Windows build fix.  Changed signature in export to match
index c5ba50d..5585b08 100644 (file)
@@ -93,7 +93,7 @@ inline void CopiedAllocator::resetCurrentBlock(CopiedBlock* newBlock)
 
 inline size_t CopiedAllocator::currentUtilization()
 {
-    return static_cast<size_t>(m_currentOffset - m_currentBlock->m_payload);
+    return static_cast<size_t>(m_currentOffset - m_currentBlock->payload());
 }
 
 inline void CopiedAllocator::resetLastAllocation(void* ptr)
index a57c115..1b86cc1 100644 (file)
@@ -40,26 +40,31 @@ class CopiedBlock : public HeapBlock {
 public:
     CopiedBlock(PageAllocationAligned& allocation)
         : HeapBlock(allocation)
-        , m_offset(m_payload)
+        , m_offset(payload())
         , m_isPinned(false)
     {
-        ASSERT(is8ByteAligned(static_cast<void*>(m_payload)));
+        ASSERT(is8ByteAligned(static_cast<void*>(m_offset)));
 #if USE(JSVALUE64)
-        memset(static_cast<void*>(m_payload), 0, static_cast<size_t>((reinterpret_cast<char*>(this) + allocation.size()) - m_payload));
+        char* offset = static_cast<char*>(m_offset);
+        memset(static_cast<void*>(offset), 0, static_cast<size_t>((reinterpret_cast<char*>(this) + allocation.size()) - offset));
 #else
         JSValue emptyValue;
         JSValue* limit = reinterpret_cast<JSValue*>(reinterpret_cast<char*>(this) + allocation.size());
-        for (JSValue* currentValue = reinterpret_cast<JSValue*>(m_payload); currentValue < limit; currentValue++)
+        for (JSValue* currentValue = reinterpret_cast<JSValue*>(m_offset); currentValue < limit; currentValue++)
             *currentValue = emptyValue;
 #endif
     }
 
+    char* payload()
+    {
+        return reinterpret_cast<char*>(this) + ((sizeof(CopiedBlock) + 7) & ~7);
+    }
+
 private:
     void* m_offset;
     uintptr_t m_isPinned;
     uintptr_t m_padding;
     uintptr_t m_dummy;
-    char m_payload[1];
 };
 
 } // namespace JSC
index 3310d2c..c847012 100644 (file)
@@ -153,7 +153,7 @@ void CopiedSpace::doneFillingBlock(CopiedBlock* block)
     ASSERT(block->m_offset < reinterpret_cast<char*>(block) + HeapBlock::s_blockSize);
     ASSERT(m_inCopyingPhase);
 
-    if (block->m_offset == block->m_payload) {
+    if (block->m_offset == block->payload()) {
         recycleBlock(block);
         return;
     }
@@ -167,7 +167,7 @@ void CopiedSpace::doneFillingBlock(CopiedBlock* block)
 
     {
         MutexLocker locker(m_memoryStatsLock);
-        m_totalMemoryUtilized += static_cast<size_t>(static_cast<char*>(block->m_offset) - block->m_payload);
+        m_totalMemoryUtilized += static_cast<size_t>(static_cast<char*>(block->m_offset) - block->payload());
     }
 
     {
index 9a1f63c..0b1b38d 100644 (file)
@@ -92,7 +92,7 @@ inline CheckedBoolean CopiedSpace::borrowBlock(CopiedBlock** outBlock)
     MutexLocker locker(m_loanedBlocksLock);
     m_numberOfLoanedBlocks++;
 
-    ASSERT(block->m_offset == block->m_payload);
+    ASSERT(block->m_offset == block->payload());
     *outBlock = block;
     return true;
 }
@@ -151,9 +151,9 @@ inline void* CopiedSpace::allocateFromBlock(CopiedBlock* block, size_t bytes)
     ASSERT(is8ByteAligned(block->m_offset));
     
     void* ptr = block->m_offset;
-    ASSERT(block->m_offset >= block->m_payload && block->m_offset < reinterpret_cast<char*>(block) + HeapBlock::s_blockSize);
+    ASSERT(block->m_offset >= block->payload() && block->m_offset < reinterpret_cast<char*>(block) + HeapBlock::s_blockSize);
     block->m_offset = static_cast<void*>((static_cast<char*>(ptr) + bytes));
-    ASSERT(block->m_offset >= block->m_payload && block->m_offset < reinterpret_cast<char*>(block) + HeapBlock::s_blockSize);
+    ASSERT(block->m_offset >= block->payload() && block->m_offset < reinterpret_cast<char*>(block) + HeapBlock::s_blockSize);
 
     ASSERT(is8ByteAligned(ptr));
     return ptr;