Felix now has first stage support for a new gc configuration.
This is a part of a critical revamping which makes functional
programming in Felix feasible.

Previously, functional code using the machine stack for function
return addresses could allocate heap storage, but not call the 
collector. This is because Felix has no way to locate the machine stack
or analyse its contents.

Things are changing!

First, Judy Array supported GC now allows identifying which pointers
belong to the gc, so if only we could locate the machine stack we 
could use the whole stack as a root in the style of a conservative
collector.

Next, an algorithm has been implemented which can convert 
Felix functions into procedures, eliminating the need for
all but transient machine stack use, except in callbacks.
The callback problem may be solved later with a callback server
(using pthreads and a bidirectional link from the callback 
issuing thread to the callback service thread).

Now, I have changed operator new() so there is a flag saying
if collection is allowed. This flag should be set to false
if there might be pointers to Felix heap on the machine stack.
This may be the case if the execution engine is running a
function modelled as a C function or C++ class with an apply() method,
or a procedure using stack_call protocol.

However, if the model is a heaped procedure, there is no machine
stack (rather, no Felix pointers on the machine stack), and so it
is safe to run the collector without missing any roots.

In that case the operator new flag should be set to true.
The following environment variables control gc operation
whilst using the standard driver:

[FLX_DEBUG] Debug enabled for dynamic link program
[FLX_DEBUG_ALLOCATIONS] Allocation debug enabled
[FLX_DEBUG_COLLECTIONS] Collection debug enabled
[FLX_DEBUG_DRIVER] Driver debug enabled
[FLX_FINALISE] Finalisation Disabled
[FLX_GC_FREQ] call gc every 1000 iterations
[FLX_MIN_MEM] call gc only if more than 10000000 heap used
[FLX_MAX_MEM] terminate if more than 18446744073709551615 heap used
[FLX_FREE_FACTOR] reset gc trigger 110.00% use after collection


FLX_GC_FREQ is the frequency with which possible calls to the
collector actually check if a collection is required. The default
is 1000 so that the maximum overhead is 0.1% of calls.

FLX_MIN_MEM is an absolute threshhold of heap allocated
memory under which the collector is never called. 
It is specified in Meg (bug in the display above!). 
The default is 10 Meg.

FLX_MAX_MEM is the absolute threshhold above which Felix will
chuck an out of memory exception. The default is all of your
address space (no limit). Again, specified in Meg.

NOTE CHANGED BEHAVIOUR: Felix throws an exception on out of
memory, either due to malloc() failure OR exceeding the bound,
rather than abort()ing your process.

FLX_FREE_FACTOR is a floating point number explained now,
defaulting to 1.1.

Initially, a value called 'threshhold' is set to FLX_MIN_MEM.
When allowed and memory use exceeds threshhold, the collector is called.
After collection, the threshhold is reset to

        max ( FLX_MIN_MEM, FLX_FREE_FACTOR * allocated)

where allocated is the actual amount of memory allocated.
The free factor must be greater than 1. The idea is that
after collection, if you have say 1G memory use, and the
free factor is 1.1, then the collector will be called again
when usage increases to 1.1G. If at that point your
usage shrinks to 0.5G, then the collector will next be
called at 0.55G.

There is one exception: if the allocator fails, the collector
is called once to try to free up some memory. Note, this
ONLY occurs if the operator new() flag permits it
(out of memory error is better than corruption from trashing live
objects).


* This algorithm is CRUDE.
* As of this commit, flxg does not allow any collection!

The last * will be repaired next so the mechanism can be tested.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to