0x7CFE / llst

LLVM powered Little Smalltalk.
Other
93 stars 10 forks source link

Large allocation (like 4 MB) on a small heap causes allocation error #14

Closed 0x7CFE closed 9 years ago

0x7CFE commented 11 years ago

This happens due to incorrect condition in the BakerMemoryManager::allocate( ):

            // If even after collection there is too less space
            // we may try to expand the heap
            const uintptr_t distance = m_activeHeapPointer - m_activeHeapBase;
            if ((m_heapSize < m_maxHeapSize) && (distance < m_heapSize / 6))
               growHeap(requestedSize);

If requested size is larger than the total heap size allocation fails without growing the heap:

->Array new: 1000000
Could not allocate 4000008 bytes in heap
VM: memory manager failed to allocate 4000008 bytes
nil
->
kpp commented 10 years ago
->Array new: 350000
MM: Growing heap to 5308872

Program received signal SIGSEGV, Segmentation fault.
0x08066377 in SmalltalkVM::doPushBlock (this=0xffffc018, ec=...) at llst/src/vm.cpp:337
337     newBlock->stack    = newObject<TObjectArray>(stackSize/*, false*/);
(gdb) 

Code to reproduce the bug:

Array new: 1000000
Array new: 100000
Array new: 500000
Array new: 400000
Array new: 300000
Array new: 200000
Array new: 150000
Array new: 350000
Array new: 250000
Array new: 450000
Array new: 350000

or:

Array new: 1000
Array new: 10000
Array new: 100000
Array new: 150000
Array new: 250000
Array new: 350000

Affected: 5235d875c2f1c32682e (develop)

0x7CFE commented 9 years ago

Fixed in commit b0887193.