Falcon::MemPool Class Reference

Storage pit for garbageable data. More...

#include <mempool.h>

Inheritance diagram for Falcon::MemPool:

Inheritance graph
[legend]

List of all members.

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
RampModem_curRampMode
Event m_eGCPerformed
Event m_eRequest
GarbageableBasem_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.
GarbageLockm_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
GarbageableBasem_newRoot
 Newly created and unreclaimable items are stored in this ring.
VMachinem_olderVM
 The machine with the oldest generation loop checked out.
RampModem_ramp [RAMP_MODE_COUNT]
SysThreadm_th
size_t m_thresholdActive
size_t m_thresholdNormal
int32 m_vmCount
VMachinem_vmIdle_head
 List of VM in idle state and waiting to be inspected.
VMachinem_vmIdle_tail
VMachinem_vmRing
 Ring of VMs.

Friends

class GarbageLock


Detailed Description

Storage pit for garbageable data.

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:


Member Enumeration Documentation

Enumerator:
MAX_GENERATION 
SWEEP_GENERATION 


Constructor & Destructor Documentation

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.


Member Function Documentation

void Falcon::MemPool::accountItems ( int  itemCount  ) 

Alter the count of live items.

For internal use.

void Falcon::MemPool::addGarbageLock ( GarbageLock lock  )  [protected]

void Falcon::MemPool::advanceGeneration ( VMachine vm,
uint32  oldGeneration 
) [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 (  ) 

void Falcon::MemPool::promote ( uint32  oldgen,
uint32  curgen 
) [protected]

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:

  • RAMP_MODE_STRICT_ID
  • RAMP_MODE_LOOSE_ID
  • RAMP_MODE_SMOOTH_SLOW_ID
  • RAMP_MODE_SMOOTH_FAST_ID

Or RAMP_MODE_OFF to disable dynamic auto-adjust of collection levels.

Parameters:
mode the mode to be set.
Returns:
true if the mode can be set, false if it is an invalid value.

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 (  ) 

Allows VM to proceed in checking newly allocated data.

See also:
safeArea()


Friends And Related Function Documentation

friend class GarbageLock [friend]


Member Data Documentation

bool Falcon::MemPool::m_bLive [protected]

bool Falcon::MemPool::m_bNewReady [protected]

Used to block prevent the pool from grabbing new garbage.

Alive and possibly collectable items are stored in this ring.

Generation at which locked items have been marked.

*

Locked and non reclaimable items are stored in this ring.

Minimal generation.

Items marked with generations lower than this are killed.

Mutex Falcon::MemPool::m_mtx_gen [mutable, protected]

Mutex for the idle VM list structure.

Guards the linked list of VMs being in idle state.

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 for the VM ring structure.

Newly created and unreclaimable items are stored in this ring.

The machine with the oldest generation loop checked out.

RampMode* Falcon::MemPool::m_ramp[RAMP_MODE_COUNT] [protected]

List of VM in idle state and waiting to be inspected.

Ring of VMs.


The documentation for this class was generated from the following file:

Generated on Mon Oct 19 10:11:39 2009 for Falcon_Core by  doxygen 1.5.8