/usr/include/falcon/mempool.h is in falconpl-dev 0.9.6.9-git20120606-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | /*
FALCON - The Falcon Programming Language.
FILE: mempool.h
garbage basket class
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: Sun, 08 Feb 2009 16:08:50 +0100
-------------------------------------------------------------------
(C) Copyright 2009: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
#ifndef FALCON_MEMPOOL_H
#define FALCON_MEMPOOL_H
/** \file
Garbage basket holder.
*/
#include <falcon/setup.h>
#include <falcon/item.h>
#include <falcon/basealloc.h>
#include <falcon/mt.h>
#include <falcon/rampmode.h>
namespace Falcon {
class Garbageable;
class GarbageableBase;
class GarbageLock;
/** Storage pit for garbageable data.
Garbage items can be removed acting directly on them.
*/
#if 0
class FALCON_DYN_CLASS PoolRing: public BaseAlloc
{
Garbageable* m_head;
public:
PoolRing();
~PoolRing();
/**
Adds a garbageable item to this pool ring.
*/
void add( Garbageable * );
void transfer( PoolRing *target );
Garbageable *linearize();
};
#endif
/** 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:
- Allocating new memory or use recycled memory.
- Destroy memory or save block in the recycle bins for later use.
- Keep a track of all "live" object so that the garbage collector can detect unused memory,
and memory leaks can be detected.
*/
class FALCON_DYN_CLASS MemPool: public Runnable, public BaseAlloc
{
protected:
size_t m_thresholdNormal;
size_t m_thresholdActive;
/** Minimal generation.
Items marked with generations lower than this are killed.
*/
uint32 m_mingen;
/** Alive and possibly collectable items are stored in this ring. */
GarbageableBase *m_garbageRoot;
/** Newly created and unreclaimable items are stored in this ring. */
GarbageableBase *m_newRoot;
/** Used to block prevent the pool from grabbing new garbage. */
bool m_bNewReady;
/** The machine with the oldest generation loop checked out. */
VMachine *m_olderVM;
/** Ring of VMs */
VMachine *m_vmRing;
int32 m_vmCount;
/** List of VM in idle state and waiting to be inspected */
VMachine *m_vmIdle_head;
VMachine *m_vmIdle_tail;
// for gc
uint32 m_generation;
int32 m_allocatedItems;
uint32 m_allocatedMem;
SysThread *m_th;
bool m_bLive;
Event m_eRequest;
Mutex m_mtxa;
/** Mutex for newly created items ring.
- GarbageableBase::nextGarbage()
- GarbageableBase::prevGarbage()
- m_generation
- m_newRoot
- rollover()
\note This mutex is acquired once while inside m_mtx_vms.lock()
*/
mutable Mutex m_mtx_newitem;
/** Mutex for the VM ring structure.
- VMachine::m_nextVM
- VMachine::m_prevVM
- m_vmRing
- electOlderVM() -- call guard
- advanceGeneration()
*/
Mutex m_mtx_vms;
/** Mutex for the idle VM list structure.
Guards the linked list of VMs being in idle state.
- VMachine::m_idleNext
- VMachine::m_idlePrev
- m_vmIdle_head
- m_vmIdle_tail
*/
Mutex m_mtx_idlevm;
/** Guard for ramp modes. */
mutable Mutex m_mtx_ramp;
mutable Mutex m_mtx_gen;
RampMode* m_ramp[RAMP_MODE_COUNT];
RampMode* m_curRampMode;
int m_curRampID;
Mutex m_mtxRequest;
Event m_eGCPerformed;
bool m_bRequestSweep;
/** Mutex for locked items ring. */
Mutex m_mtx_lockitem;
/** Locked and non reclaimable items are stored in this ring. */
GarbageLock *m_lockRoot;
/** Generation at which locked items have been marked. *
*
*/
uint32 m_lockGen;
//==================================================
// Private functions
//==================================================
bool markVM( VMachine *vm );
void gcSweep();
/*
To reimplement this, we need to have anti-recursion checks on item, which are
currently being under consideration. However, I would prefer not to need to
have this functions back, as they were meant to be used when the memory
model wasn't complete.
In other words, I want items to be in garbage as soon as they are created,
and to exit when they are destroyed.
void removeFromGarbage( String *ptr );
void removeFromGarbage( Garbageable *ptr );
void storeForGarbageDeep( const Item &item );
void removeFromGarbageDeep( const Item &item );
*/
void clearRing( GarbageableBase *ringRoot );
void rollover();
void remark(uint32 mark);
void electOlderVM(); // to be called with m_mtx_vms locked
void promote( uint32 oldgen, uint32 curgen );
void advanceGeneration( VMachine* vm, uint32 oldGeneration );
void markLocked();
friend class GarbageLock;
void addGarbageLock( GarbageLock* lock );
void removeGarbageLock( GarbageLock* lock );
public:
enum constants {
MAX_GENERATION = 0xFFFFFFFE,
SWEEP_GENERATION = 0xFFFFFFFF
};
/** Builds a memory pool.
Initializes all element at 0 and set buffer sizes to the FALCON default.
*/
MemPool();
/** Destroys all the items.
Needless to say, this must be called outside any VM.
*/
virtual ~MemPool();
/** 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 registerVM( VMachine *vm );
/** Called before destruction of a VM.
Takes also care to disengage the VM from idle VM list.
*/
void unregisterVM( VMachine *vm );
/** 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 markItem( const Item &itm );
/** Returns the number of elements managed by this mempool. */
int32 allocatedItems() const;
/** Returns the current generation. */
uint32 generation() const { return m_generation; }
/*
void generation( uint32 i );
uint32 incgen();
*/
/** Stores a garbageable instance in the pool.
Called by the Garbageable constructor to ensure accounting of this item.
*/
void storeForGarbage( Garbageable *ptr );
virtual void* run();
/** Starts the parallel garbage collector. */
void start();
/** Stops the collector.
The function synchronously wait for the thread to exit and sets it to 0.
*/
void stop();
/** 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 safeArea();
/** Allows VM to proceed in checking newly allocated data.
\see safeArea()
*/
void unsafeArea();
/** 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 idleVM( VMachine *vm, bool bPrio = false );
/** Sets the normal threshold level. */
void thresholdNormal( size_t mem ) { m_thresholdNormal = mem; }
/** Sets the active threshold level. */
void thresholdActive( size_t mem ) { m_thresholdActive = mem; }
size_t thresholdNormal() const { return m_thresholdNormal; }
size_t thresholdActive() const { return m_thresholdActive; }
/** 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.
\param mode the mode to be set.
\return true if the mode can be set, false if it is an invalid value.
*/
bool rampMode( int mode );
int rampMode() const;
/** Alter the count of live items.
For internal use.
*/
void accountItems( int itemCount );
void performGC();
};
}
#endif
/* end of mempool.h */
|