diff options
author | Pat Gavlin <pagavlin@microsoft.com> | 2016-04-13 12:55:47 -0700 |
---|---|---|
committer | Pat Gavlin <pagavlin@microsoft.com> | 2016-04-13 12:55:47 -0700 |
commit | 0c24ddaa1703805e472c6bf00cba1bcbc5d43e12 (patch) | |
tree | 6c0975ebff9044f38eb3a5bbf72d46f73155bd77 /src/gcinfo | |
parent | 8b91401398caffe63fe79d403e066ee55a8365f2 (diff) | |
download | coreclr-0c24ddaa1703805e472c6bf00cba1bcbc5d43e12.tar.gz coreclr-0c24ddaa1703805e472c6bf00cba1bcbc5d43e12.tar.bz2 coreclr-0c24ddaa1703805e472c6bf00cba1bcbc5d43e12.zip |
Refactor `MemoryBlockDesc`.
- Encapsulate link management into `MemoryBlockDescList`.
- Replace `MemoryBlockDesc` and its separately-allocated buffer
with a new type, `MemoryBlock`, that stores the link to the
next memory block with the buffer itself.
Diffstat (limited to 'src/gcinfo')
-rw-r--r-- | src/gcinfo/dbggcinfoencoder.cpp | 82 | ||||
-rw-r--r-- | src/gcinfo/gcinfoencoder.cpp | 64 |
2 files changed, 83 insertions, 63 deletions
diff --git a/src/gcinfo/dbggcinfoencoder.cpp b/src/gcinfo/dbggcinfoencoder.cpp index 7912c73f03..98480cf26d 100644 --- a/src/gcinfo/dbggcinfoencoder.cpp +++ b/src/gcinfo/dbggcinfoencoder.cpp @@ -43,46 +43,49 @@ void GcInfoEncoder::LifetimeTransitionAllocator::Free (void *context, void *pv) } -void BitStreamWriter::AllocMemoryBlock() +BitStreamWriter::MemoryBlockList::MemoryBlockList() + : m_head(nullptr), + m_tail(nullptr) { - _ASSERTE( IS_ALIGNED( m_MemoryBlockSize, sizeof( size_t ) ) ); - m_pCurrentSlot = (size_t*) m_pAllocator->Alloc( m_MemoryBlockSize ); - m_OutOfBlockSlot = m_pCurrentSlot + m_MemoryBlockSize / sizeof( size_t ); +} - MemoryBlockDesc* pMemBlockDesc = (MemoryBlockDesc*) m_pAllocator->Alloc( sizeof( MemoryBlockDesc ) ); - _ASSERTE( IS_ALIGNED( pMemBlockDesc, sizeof( void* ) ) ); +BitStreamWriter::MemoryBlock* BitStreamWriter::MemoryBlockList::AppendNew(IJitAllocator* allocator, size_t bytes) +{ + auto* memBlock = reinterpret_cast<MemoryBlock*>(allocator->Alloc(sizeof(MemoryBlock) + bytes)); + memBlock->m_next = nullptr; - pMemBlockDesc->Init(); - pMemBlockDesc->StartAddress = m_pCurrentSlot; - if (m_MemoryBlocksTail != NULL) + if (m_tail != nullptr) { - _ASSERTE(m_MemoryBlocksHead != NULL); - m_MemoryBlocksTail->m_Next = pMemBlockDesc; + _ASSERTE(m_head != nullptr); + m_tail->m_next = memBlock; } else { - _ASSERTE(m_MemoryBlocksHead == NULL); - m_MemoryBlocksHead = pMemBlockDesc; + _ASSERTE(m_head == nullptr); + m_head = memBlock; } - m_MemoryBlocksTail = pMemBlockDesc; - -#ifdef _DEBUG - m_MemoryBlocksCount++; -#endif + m_tail = memBlock; + return memBlock; } -GcInfoEncoder::GcInfoEncoder( - ICorJitInfo* pCorJitInfo, - CORINFO_METHOD_INFO* pMethodInfo, - IJitAllocator* pJitAllocator - ) - : m_HeaderInfoWriter( pJitAllocator ), -#if 0 -#ifdef PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED - m_PartiallyInterruptibleInfoWriter( pJitAllocator ), -#endif +void BitStreamWriter::MemoryBlockList::Dispose(IJitAllocator* allocator) +{ +#ifdef MUST_CALL_JITALLOCATOR_FREE + for (MemoryBlock* block = m_head, *next; block != nullptr; block = next) + { + next = block->m_next; + allocator->Free(block); + } + m_head = nullptr; + m_tail = nullptr; #endif +} + + +void BitStreamWriter::AllocMemoryBlock() +{ + _ASSERTE( IS_ALIGNED( m_MemoryBlockSize, sizeof( size_t ) ) ); m_FullyInterruptibleInfoWriter( pJitAllocator ), m_LifetimeTransitions( pJitAllocator ) { @@ -941,21 +944,21 @@ void BitStreamWriter::CopyTo( BYTE* buffer ) int i,c; BYTE* source = NULL; - MemoryBlockDesc* pMemBlockDesc = m_MemoryBlocks.GetHead(); + MemoryBlock* pMemBlock = m_MemoryBlocks.Head(); _ASSERTE( pMemBlockDesc != NULL ); - while (pMemBlockDesc->m_Next != NULL) + while (pMemBlock->Next() != NULL) { - source = (BYTE*) pMemBlockDesc->StartAddress; + source = (BYTE*) pMemBlock->Contents; // @TODO: use memcpy instead for( i = 0; i < m_MemoryBlockSize; i++ ) { *( buffer++ ) = *( source++ ); } - pMemBlockDesc = pMemBlockDesc->m_Next; + pMemBlock = pMemBlock->Next(); } - source = (BYTE*) pMemBlockDesc->StartAddress; + source = (BYTE*) pMemBlock->Contents; // The number of bytes to copy in the last block c = (int) ((BYTE*) ( m_pCurrentSlot + 1 ) - source - m_FreeBitsInCurrentSlot/8); _ASSERTE( c >= 0 ); @@ -969,18 +972,7 @@ void BitStreamWriter::CopyTo( BYTE* buffer ) void BitStreamWriter::Dispose() { -#ifdef MUST_CALL_JITALLOCATOR_FREE - for (MemoryBlockDes* block = m_MemoryBlocksHead, *next; block != NULL; block = next) - { - next = block->m_Next; - m_pAllocator->Free(block->StartAddress); - m_pAllocator->Free(block); - } - m_MemoryBlocksHead = NULL; - m_MemoryBlocksTail = NULL; - - m_pAllocator->Free( m_SlotMappings ); -#endif + m_MemoryBlocks.Dispose(m_pAllocator); } } diff --git a/src/gcinfo/gcinfoencoder.cpp b/src/gcinfo/gcinfoencoder.cpp index 88b79fbe6e..9fb37d37ef 100644 --- a/src/gcinfo/gcinfoencoder.cpp +++ b/src/gcinfo/gcinfoencoder.cpp @@ -900,6 +900,45 @@ int __cdecl CompareLifetimeTransitionsBySlot(const void* p1, const void* p2) } } +BitStreamWriter::MemoryBlockList::MemoryBlockList() + : m_head(nullptr), + m_tail(nullptr) +{ +} + +BitStreamWriter::MemoryBlock* BitStreamWriter::MemoryBlockList::AppendNew(IAllocator* allocator, size_t bytes) +{ + auto* memBlock = reinterpret_cast<MemoryBlock*>(allocator->Alloc(sizeof(MemoryBlock) + bytes)); + memBlock->m_next = nullptr; + + if (m_tail != nullptr) + { + _ASSERTE(m_head != nullptr); + m_tail->m_next = memBlock; + } + else + { + _ASSERTE(m_head == nullptr); + m_head = memBlock; + } + + m_tail = memBlock; + return memBlock; +} + +void BitStreamWriter::MemoryBlockList::Dispose(IAllocator* allocator) +{ +#ifdef MUST_CALL_JITALLOCATOR_FREE + for (MemoryBlock* block = m_head, *next; block != nullptr; block = next) + { + next = block->m_next; + allocator->Free(block); + } + m_head = nullptr; + m_tail = nullptr; +#endif +} + void BitStreamWriter::Write(BitArray& a, UINT32 count) { size_t* dataPtr = a.DataPtr(); @@ -2647,8 +2686,6 @@ BitStreamWriter::BitStreamWriter( IAllocator* pAllocator ) { m_pAllocator = pAllocator; m_BitCount = 0; - m_MemoryBlocksHead = NULL; - m_MemoryBlocksTail = NULL; #ifdef _DEBUG m_MemoryBlocksCount = 0; #endif @@ -2711,23 +2748,23 @@ void BitStreamWriter::CopyTo( BYTE* buffer ) int i,c; BYTE* source = NULL; - MemoryBlockDesc* pMemBlockDesc = m_MemoryBlocksHead; - if( pMemBlockDesc == NULL ) + MemoryBlock* pMemBlock = m_MemoryBlocks.Head(); + if( pMemBlock == NULL ) return; - while (pMemBlockDesc->m_Next != NULL) + while (pMemBlock->Next() != NULL) { - source = (BYTE*) pMemBlockDesc->StartAddress; + source = (BYTE*) pMemBlock->Contents; // @TODO: use memcpy instead for( i = 0; i < m_MemoryBlockSize; i++ ) { *( buffer++ ) = *( source++ ); } - pMemBlockDesc = pMemBlockDesc->m_Next; + pMemBlock = pMemBlock->Next(); } - source = (BYTE*) pMemBlockDesc->StartAddress; + source = (BYTE*) pMemBlock->Contents; // The number of bytes to copy in the last block c = (int) ((BYTE*) ( m_pCurrentSlot + 1 ) - source - m_FreeBitsInCurrentSlot/8); _ASSERTE( c >= 0 ); @@ -2741,16 +2778,7 @@ void BitStreamWriter::CopyTo( BYTE* buffer ) void BitStreamWriter::Dispose() { -#ifdef MUST_CALL_JITALLOCATOR_FREE - for (MemoryBlockDes* block = m_MemoryBlocksHead, *next; block != NULL; block = next) - { - next = block->m_Next; - m_pAllocator->Free(block->StartAddress); - m_pAllocator->Free(block); - } - m_MemoryBlocksHead = NULL; - m_MemoryBlocksTail = NULL; -#endif + m_MemoryBlocks.Dispose(m_pAllocator); } int BitStreamWriter::SizeofVarLengthUnsigned( size_t n, UINT32 base) |