Source/JavaScriptCore/ChangeLog

112012-03-23 Mark Hahnenberg <mhahnenberg@apple.com>
22
 3 tryReallocate could break the zero-ed memory invariant of CopiedBlocks
 4 https://bugs.webkit.org/show_bug.cgi?id=82087
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Removing this optimization turned out to be ~1% regression on kraken, so I simply
 9 undid the modification to the current block if we fail.
 10
 11 * heap/CopiedSpace.cpp:
 12 (JSC::CopiedSpace::tryReallocate): Undid the reset in the CopiedAllocator if we fail
 13 to reallocate from the current block.
 14
 152012-03-23 Mark Hahnenberg <mhahnenberg@apple.com>
 16
317 Simplify memory usage tracking in CopiedSpace
418 https://bugs.webkit.org/show_bug.cgi?id=80705
519

Source/JavaScriptCore/heap/CopiedAllocator.h

@@public:
3939 bool wasLastAllocation(void*, size_t);
4040 void startedCopying();
4141 void resetCurrentBlock(CopiedBlock*);
42  void resetLastAllocation(void*);
4342 size_t currentCapacity();
4443
4544private:

@@inline size_t CopiedAllocator::currentCapacity()
9796 return m_currentBlock->capacity();
9897}
9998
100 inline void CopiedAllocator::resetLastAllocation(void* ptr)
101 {
102  m_currentOffset = static_cast<char*>(ptr);
103 }
104 
10599} // namespace JSC
106100
107101#endif

Source/JavaScriptCore/heap/CopiedSpace.cpp

@@CheckedBoolean CopiedSpace::tryReallocate(void** ptr, size_t oldSize, size_t new
100100 return tryReallocateOversize(ptr, oldSize, newSize);
101101
102102 if (m_allocator.wasLastAllocation(oldPtr, oldSize)) {
103  m_allocator.resetLastAllocation(oldPtr);
104  if (m_allocator.fitsInCurrentBlock(newSize))
105  return m_allocator.allocate(newSize);
 103 size_t delta = newSize - oldSize;
 104 if (m_allocator.fitsInCurrentBlock(delta)) {
 105 (void)m_allocator.allocate(delta);
 106 return true;
 107 }
106108 }
107109
108110 void* result = 0;