#include <mempool.h>
Public Types | |
enum | constants { MAX_GENERATION = 0xFFFFFFFE, SWEEP_GENERATION = 0xFFFFFFFF } |
Public Member Functions | |
void | accountItems (int itemCount) |
Alter the count of live items. | |
int32 | allocatedItems () const |
Returns the number of elements managed by this mempool. | |
uint32 | generation () const |
Returns the current generation. | |
void | idleVM (VMachine *vm, bool bPrio=false) |
Declares the given VM idle. | |
void | markItem (const Item &itm) |
Marks an item during a GC Loop. | |
MemPool () | |
Builds a memory pool. | |
void | performGC () |
int | rampMode () const |
bool | rampMode (int mode) |
Sets the algorithm used to dynamically configure the collection levels. | |
void | registerVM (VMachine *vm) |
Called upon creation of a new VM. | |
virtual void * | run () |
void | safeArea () |
Turns the GC safe allocation mode on. | |
void | start () |
Starts the parallel garbage collector. | |
void | stop () |
Stops the collector. | |
void | storeForGarbage (Garbageable *ptr) |
Stores a garbageable instance in the pool. | |
size_t | thresholdActive () const |
void | thresholdActive (size_t mem) |
Sets the active threshold level. | |
size_t | thresholdNormal () const |
void | thresholdNormal (size_t mem) |
Sets the normal threshold level. | |
void | unregisterVM (VMachine *vm) |
Called before destruction of a VM. | |
void | unsafeArea () |
Allows VM to proceed in checking newly allocated data. | |
virtual | ~MemPool () |
Destroys all the items. | |
Protected Member Functions | |
void | addGarbageLock (GarbageLock *lock) |
void | advanceGeneration (VMachine *vm, uint32 oldGeneration) |
void | clearRing (GarbageableBase *ringRoot) |
void | electOlderVM () |
void | gcSweep () |
void | markLocked () |
bool | markVM (VMachine *vm) |
void | promote (uint32 oldgen, uint32 curgen) |
void | remark (uint32 mark) |
void | removeGarbageLock (GarbageLock *lock) |
void | rollover () |
Protected Attributes | |
int32 | m_allocatedItems |
uint32 | m_allocatedMem |
bool | m_bLive |
bool | m_bNewReady |
Used to block prevent the pool from grabbing new garbage. | |
bool | m_bRequestSweep |
int | m_curRampID |
RampMode * | m_curRampMode |
Event | m_eGCPerformed |
Event | m_eRequest |
GarbageableBase * | m_garbageRoot |
Alive and possibly collectable items are stored in this ring. | |
uint32 | m_generation |
uint32 | m_lockGen |
Generation at which locked items have been marked. | |
GarbageLock * | m_lockRoot |
Locked and non reclaimable items are stored in this ring. | |
uint32 | m_mingen |
Minimal generation. | |
Mutex | m_mtx_gen |
Mutex | m_mtx_idlevm |
Mutex for the idle VM list structure. | |
Mutex | m_mtx_lockitem |
Mutex for locked items ring. | |
Mutex | m_mtx_newitem |
Mutex for newly created items ring. | |
Mutex | m_mtx_ramp |
Guard for ramp modes. | |
Mutex | m_mtx_vms |
Mutex for the VM ring structure. | |
Mutex | m_mtxa |
Mutex | m_mtxRequest |
GarbageableBase * | m_newRoot |
Newly created and unreclaimable items are stored in this ring. | |
VMachine * | m_olderVM |
The machine with the oldest generation loop checked out. | |
RampMode * | m_ramp [RAMP_MODE_COUNT] |
SysThread * | m_th |
size_t | m_thresholdActive |
size_t | m_thresholdNormal |
int32 | m_vmCount |
VMachine * | m_vmIdle_head |
List of VM in idle state and waiting to be inspected. | |
VMachine * | m_vmIdle_tail |
VMachine * | m_vmRing |
Ring of VMs. | |
Friends | |
class | GarbageLock |
Garbage items can be removed acting directly on them. Falcon Memory pool The garbage basket is the Falcon standard memory allocator. It provides newly created objects and memory chunks and saves them for later recycle. The garbage collector moves unused items and memory chunks to the basket holder. Is then responsibility of the holder to decide what to do about them.
The memory pool is responsible for:
Falcon::MemPool::MemPool | ( | ) |
Builds a memory pool.
Initializes all element at 0 and set buffer sizes to the FALCON default.
virtual Falcon::MemPool::~MemPool | ( | ) | [virtual] |
Destroys all the items.
Needless to say, this must be called outside any VM.
void Falcon::MemPool::accountItems | ( | int | itemCount | ) |
Alter the count of live items.
For internal use.
void Falcon::MemPool::addGarbageLock | ( | GarbageLock * | lock | ) | [protected] |
int32 Falcon::MemPool::allocatedItems | ( | ) | const |
Returns the number of elements managed by this mempool.
void Falcon::MemPool::clearRing | ( | GarbageableBase * | ringRoot | ) | [protected] |
void Falcon::MemPool::electOlderVM | ( | ) | [protected] |
void Falcon::MemPool::gcSweep | ( | ) | [protected] |
uint32 Falcon::MemPool::generation | ( | ) | const [inline] |
Returns the current generation.
void Falcon::MemPool::idleVM | ( | VMachine * | vm, | |
bool | bPrio = false | |||
) |
Declares the given VM idle.
The VM may be sent to the the main memory pool garbage collector mark loop if it is found outdated and in need of a new marking.
Set prio = true if the VM requests a priority GC. In that case, the VM must present itself non-idle, and the idle-ship is taken implicitly by the GC. The VM is notified with m_eGCPerformed being set after the complete loop is performed.
void Falcon::MemPool::markItem | ( | const Item & | itm | ) |
Marks an item during a GC Loop.
This method should be called only from inside GC mark callbacks of class having some GC hook.
void Falcon::MemPool::markLocked | ( | ) | [protected] |
bool Falcon::MemPool::markVM | ( | VMachine * | vm | ) | [protected] |
void Falcon::MemPool::performGC | ( | ) |
int Falcon::MemPool::rampMode | ( | ) | const |
bool Falcon::MemPool::rampMode | ( | int | mode | ) |
Sets the algorithm used to dynamically configure the collection levels.
Can be one of:
Or RAMP_MODE_OFF to disable dynamic auto-adjust of collection levels.
mode | the mode to be set. |
void Falcon::MemPool::registerVM | ( | VMachine * | vm | ) |
Called upon creation of a new VM.
This sets the current generation of the VM so that it is unique among the currently living VMs.
void Falcon::MemPool::remark | ( | uint32 | mark | ) | [protected] |
void Falcon::MemPool::removeGarbageLock | ( | GarbageLock * | lock | ) | [protected] |
void Falcon::MemPool::rollover | ( | ) | [protected] |
virtual void* Falcon::MemPool::run | ( | ) | [virtual] |
Implements Falcon::Runnable.
void Falcon::MemPool::safeArea | ( | ) |
Turns the GC safe allocation mode on.
In case an "core" class object (like CoreObject, CoreDict, CoreArray, CoreString and so on) needs to be declared in a place where it cannot be granted that there is a working virtual machine, it is necessary to ask the Garbage Collector not to try to collect newly allocated data.
When core data is allocated inside a running VM, the GC ensures that the data cannot be ripped away before it reaches a safe area in a virtual machine; but modules or embedding applications may will to allocate garbage sensible data without any chance to control the idle status of the running virtual machines.
To inform the GC about this fact, the safeArea(); / unsafeArea() functions are provided.
Data should be assigned to a virtual machine or alternatively garbage locked before unsafeArea() is called to allow the Garbage Collector to proceed normally.
void Falcon::MemPool::start | ( | ) |
Starts the parallel garbage collector.
void Falcon::MemPool::stop | ( | ) |
Stops the collector.
The function synchronously wait for the thread to exit and sets it to 0.
void Falcon::MemPool::storeForGarbage | ( | Garbageable * | ptr | ) |
Stores a garbageable instance in the pool.
Called by the Garbageable constructor to ensure accounting of this item.
size_t Falcon::MemPool::thresholdActive | ( | ) | const [inline] |
void Falcon::MemPool::thresholdActive | ( | size_t | mem | ) | [inline] |
Sets the active threshold level.
size_t Falcon::MemPool::thresholdNormal | ( | ) | const [inline] |
void Falcon::MemPool::thresholdNormal | ( | size_t | mem | ) | [inline] |
Sets the normal threshold level.
void Falcon::MemPool::unregisterVM | ( | VMachine * | vm | ) |
Called before destruction of a VM.
Takes also care to disengage the VM from idle VM list.
void Falcon::MemPool::unsafeArea | ( | ) |
friend class GarbageLock [friend] |
int32 Falcon::MemPool::m_allocatedItems [protected] |
uint32 Falcon::MemPool::m_allocatedMem [protected] |
bool Falcon::MemPool::m_bLive [protected] |
bool Falcon::MemPool::m_bNewReady [protected] |
Used to block prevent the pool from grabbing new garbage.
bool Falcon::MemPool::m_bRequestSweep [protected] |
int Falcon::MemPool::m_curRampID [protected] |
RampMode* Falcon::MemPool::m_curRampMode [protected] |
Event Falcon::MemPool::m_eGCPerformed [protected] |
Event Falcon::MemPool::m_eRequest [protected] |
GarbageableBase* Falcon::MemPool::m_garbageRoot [protected] |
Alive and possibly collectable items are stored in this ring.
uint32 Falcon::MemPool::m_generation [protected] |
uint32 Falcon::MemPool::m_lockGen [protected] |
Generation at which locked items have been marked.
*
GarbageLock* Falcon::MemPool::m_lockRoot [protected] |
Locked and non reclaimable items are stored in this ring.
uint32 Falcon::MemPool::m_mingen [protected] |
Minimal generation.
Items marked with generations lower than this are killed.
Mutex Falcon::MemPool::m_mtx_gen [mutable, protected] |
Mutex Falcon::MemPool::m_mtx_idlevm [protected] |
Mutex for the idle VM list structure.
Guards the linked list of VMs being in idle state.
Mutex Falcon::MemPool::m_mtx_lockitem [protected] |
Mutex for locked items ring.
Mutex Falcon::MemPool::m_mtx_newitem [mutable, protected] |
Mutex for newly created items ring.
Mutex Falcon::MemPool::m_mtx_ramp [mutable, protected] |
Guard for ramp modes.
Mutex Falcon::MemPool::m_mtx_vms [protected] |
Mutex for the VM ring structure.
Mutex Falcon::MemPool::m_mtxa [protected] |
Mutex Falcon::MemPool::m_mtxRequest [protected] |
GarbageableBase* Falcon::MemPool::m_newRoot [protected] |
Newly created and unreclaimable items are stored in this ring.
VMachine* Falcon::MemPool::m_olderVM [protected] |
The machine with the oldest generation loop checked out.
RampMode* Falcon::MemPool::m_ramp[RAMP_MODE_COUNT] [protected] |
SysThread* Falcon::MemPool::m_th [protected] |
size_t Falcon::MemPool::m_thresholdActive [protected] |
size_t Falcon::MemPool::m_thresholdNormal [protected] |
int32 Falcon::MemPool::m_vmCount [protected] |
VMachine* Falcon::MemPool::m_vmIdle_head [protected] |
List of VM in idle state and waiting to be inspected.
VMachine* Falcon::MemPool::m_vmIdle_tail [protected] |
VMachine* Falcon::MemPool::m_vmRing [protected] |
Ring of VMs.