Expand description
§bdwgc-alloc-sys
Rust bindings to the C API of bdwgc, the conservative garbage collector.
This crate builds bdwgc from its vendored source and links it statically. The bindings are generated from its headers at build time by bindgen, which requires libclang.
See the bdwgc-alloc crate for a GlobalAlloc implementation on top of these bindings.
§Install
cargo add bdwgc-alloc-sysBy default bdwgc is built with autotools. To build with cmake, enable the cmake feature:
cargo add bdwgc-alloc-sys --no-default-features --features cmake§License
Structs§
- GC_
prof_ stats_ s - Structure used to query the GC statistics (profiling information). More fields could be added in the future. To preserve compatibility new fields should be added only to the end, and no deprecated fields should be removed from.
- GC_
stack_ base - Structure representing the bottom (cold end) of a thread stack. On most platforms this contains just a single address.
- GC_
timeval_ s - A portable type definition of time with a nanosecond precision.
- __
sigset_ t
Constants§
- GC_
DUPLICATE - GC_
Event Type_ GC_ EVENT_ END - GC_
Event Type_ GC_ EVENT_ MARK_ END - GC_
Event Type_ GC_ EVENT_ MARK_ START - GC_
Event Type_ GC_ EVENT_ POST_ START_ WORLD - GC_
Event Type_ GC_ EVENT_ POST_ STOP_ WORLD - GC_
Event Type_ GC_ EVENT_ PRE_ START_ WORLD - GC_
Event Type_ GC_ EVENT_ PRE_ STOP_ WORLD - GC_
Event Type_ GC_ EVENT_ RECLAIM_ END - GC_
Event Type_ GC_ EVENT_ RECLAIM_ START - GC_
Event Type_ GC_ EVENT_ START - GC_
Event Type_ GC_ EVENT_ THREAD_ SUSPENDED - GC_
Event Type_ GC_ EVENT_ THREAD_ UNSUSPENDED - GC_
NOT_ FOUND - GC_
NO_ MEMORY - GC_
NO_ THREADS - GC_
PROTECTS_ NONE - GC_
PROTECTS_ POINTER_ HEAP - GC_
PROTECTS_ PTRFREE_ HEAP - GC_
PROTECTS_ STACK - GC_
PROTECTS_ STATIC_ DATA - GC_
SUCCESS - GC_
TIME_ UNLIMITED - GC_
TMP_ VERSION_ MAJOR - GC_
TMP_ VERSION_ MICRO - GC_
TMP_ VERSION_ MINOR - GC_
Toggle RefStatus_ GC_ TOGGLE_ REF_ DROP - GC_
Toggle RefStatus_ GC_ TOGGLE_ REF_ STRONG - GC_
Toggle RefStatus_ GC_ TOGGLE_ REF_ WEAK - GC_
UNIMPLEMENTED - GC_
VDB_ DEFAULT - GC_
VDB_ GWW - GC_
VDB_ MANUAL - GC_
VDB_ MPROTECT - GC_
VDB_ NONE - GC_
VDB_ PROC - GC_
VDB_ SOFT - GC_
VDB_ UFFDWP - GC_
VERSION_ MAJOR - GC_
VERSION_ MICRO - GC_
VERSION_ MINOR - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ FORWARDING - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ FREE - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ PADDING - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ UNMAPPED - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ USED - GC_
heap_ section_ type_ GC_ HEAP_ SECTION_ TYPE_ WHOLE_ SECT
Statics§
- GC_
all_ ⚠interior_ pointers - GC_
dont_ ⚠expand - Do not expand the heap unless explicitly requested or forced to. The setter and the getter are unsynchronized.
- GC_
dont_ ⚠gc - GC_
dont_ ⚠precollect - Do not collect as part of the collector initialization. Should be set only if the client wants a chance to manually initialize the root set before the first collection. Interferes with black-listing. Wizards only. The setter and the getter are unsynchronized (and no external locking is needed since the value is accessed at the collector initialization only).
- GC_
finalize_ ⚠on_ demand - If nonzero, finalizers will only be run in response to an explicit
GC_invoke_finalizers()call. The default is determined by whether theFINALIZE_ON_DEMANDmacro is defined when the collector is built. The setter and the getter are unsynchronized. - GC_
finalizer_ ⚠notifier - GC_
find_ ⚠leak - Turn on the find-leak mode (do not actually garbage collect, but simply
report inaccessible memory that was not deallocated with
GC_FREE()or friends). Initial value is determined byFIND_LEAKmacro. The value should not typically be modified after the collector initialization (and, thus, it does not use or need synchronization). The mode is supported only if the library has been compiled withoutNO_FIND_LEAKmacro defined. - GC_
free_ ⚠space_ divisor - We try to make sure that we allocate at least
N / GC_free_space_divisorbytes between collections, whereNis twice the number of traced bytes, plus the number of untraced bytes (i.e. bytes in the “atomic” objects), plus a rough estimate of the root set size.Napproximates GC tracing work per collection. The initial value is given byGC_FREE_SPACE_DIVISORmacro. Increasing its value will use less space but more collection time. Decreasing it will appreciably decrease total collection time at the expense of space. The setter and the getter are unsynchronized, soGC_call_with_alloc_lock()(GC_call_with_reader_lock()in case of the getter) is required to avoid data race (if the value is modified after the collector is put into the multi-threaded mode). In GC v7.1 and before, the setter returned the old value. - GC_
full_ ⚠freq - Number of partial collections between full collections. Matters only
if
GC_is_incremental_mode(). Full collections are also triggered if the collector detects a substantial increase in the number of the in-use heap blocks. Values in the tens are now perfectly reasonable. The setter and the getter are unsynchronized, soGC_call_with_alloc_lock()(GC_call_with_reader_lock()in case of the getter) is required to avoid data race (if the value is modified after the collector is put into the multi-threaded mode). - GC_
gc_ ⚠no - Counter incremented once per collection. Includes empty collections
at startup.
GC_get_gc_no()is unsynchronized, so it requiresGC_call_with_reader_lock()to avoid data race on multiprocessors. - GC_
is_ ⚠valid_ displacement_ print_ proc - GC_
is_ ⚠visible_ print_ proc - GC_
java_ ⚠finalization - Mark objects reachable from finalizable objects in a separate post-pass.
This makes it a bit safer to use non-topologically-ordered finalization.
Default value is determined by
JAVA_FINALIZATIONmacro. EnablesGC_register_finalizer_unreachable()to work correctly. The setter and the getter are unsynchronized. - GC_
max_ ⚠retries - The maximum number of collections attempted before reporting out of
memory after heap expansion fails. Initially 0. The setter and
getter are unsynchronized, so
GC_call_with_alloc_lock()(GC_call_with_reader_lock()in case of the getter) is required to avoid data race (if the value is modified after the collector is put into the multi-threaded mode). - GC_
no_ ⚠dls - Do not register dynamic library data segments automatically. Also, if set by the collector itself (during a collection), this means that such a registration is not supported. Wizards only. Should be set only if the client explicitly registers all roots. (In some environments like Microsoft Windows and Apple’s Darwin, this may also prevent registration of the main data segment as a part of the root set.) The setter and the getter are unsynchronized.
- GC_
non_ ⚠gc_ bytes - Bytes not considered candidates for collection. Used only to control
scheduling of collections. Updated by
GC_malloc_uncollectable(),GC_free()and friends. Wizards only. The setter and the getter are unsynchronized, soGC_call_with_alloc_lock()(GC_call_with_reader_lock()in case of the getter) is required to avoid data race (if the value is modified after the collector is put into the multi-threaded mode). - GC_
on_ ⚠heap_ resize - GC_
oom_ ⚠fn - GC_
parallel ⚠ - GC is parallelized for performance on multiprocessors.
Set to a nonzero value when client calls
GC_start_mark_threads()directly or starts the first non-main thread, provided the collector is built withPARALLEL_MARKmacro defined, and eitherGC_MARKERS(orGC_NPROCS) environment variable is set to a value bigger than 1, or multiple cores (processors) are available, or the client callsGC_set_markers_count()before the collector initialization. After setting,GC_parallelvalue is equal to the number of marker threads minus one (i.e. the number of existing parallel marker threads excluding the initiating one). - GC_
same_ ⚠obj_ print_ proc - GC_
stackbottom ⚠ - The cold end (bottom) of user stack. May be set in the client prior
to calling any
GC_routines. This avoids some overhead, and potentially some signals that can confuse debuggers. Otherwise the collector attempts to set it automatically. For multi-threaded code, this is the cold end of the stack for the primordial thread. For multi-threaded code, alteringGC_stackbottomvalue directly after the collector initialization has no effect. Portable clients should useGC_set_stackbottom(),GC_get_stack_base(),GC_call_with_gc_active()andGC_register_my_thread()instead. - GC_
time_ ⚠limit - If incremental collection is enabled, we try to terminate collections
after this many milliseconds (plus the amount of nanoseconds as given in
the latest
GC_set_time_limit_tv()call, if any). Not a hard time bound. Setting this variable toGC_TIME_UNLIMITEDessentially disables incremental collection (i.e. disables the “pause time exceeded” tests) while leaving generational collection enabled. The setter and the getter are unsynchronized, soGC_call_with_alloc_lock()(GC_call_with_reader_lock()in case of the getter) is required to avoid data race (if the value is modified after the collector is put into the multi-threaded mode). The setter does not update the value of the nanosecond part of the time limit (it is zero unless ever set byGC_set_time_limit_tv()call). - GC_
use_ ⚠entire_ heap - Causes the non-incremental collector to use the entire heap before collecting. This sometimes results in more large-block fragmentation, since very large blocks will tend to get broken up during each collection cycle. It is likely to result in a larger working set, but lower collection frequencies, and hence fewer instructions executed in the collector.
Functions§
- GC_
abort_ ⚠on_ oom - A portable way to abort the application because of not enough memory.
- GC_
add_ ⚠roots - Add a root segment. Wizards only. May merge adjacent or overlapping
segments if appropriate. Both segment start (
low_address) and end (high_address_plus_1) are not needed to be pointer-aligned.low_addressmust not be greater thanhigh_address_plus_1. - GC_
alloc_ ⚠lock - GC_
alloc_ ⚠unlock - GC_
allow_ ⚠register_ threads - Explicitly enable
GC_register_my_thread()invocation. Done implicitly if a GC thread-creation function is called (or implicit thread registration is activated, or the collector is compiled withGC_ALWAYS_MULTITHREADEDmacro defined). Otherwise, it must be called from the main (or any previously registered) thread between the collector initialization and the first explicit registering of a thread (it should be called as late as possible). Includes aGC_start_mark_threads()call. - GC_
atfork_ ⚠child - GC_
atfork_ ⚠parent - GC_
atfork_ ⚠prepare - Routines to handle POSIX
fork()manually (no-op if handled automatically).GC_atfork_prepare()should be called immediately beforefork();GC_atfork_parent()should be invoked just afterforkin the branch that corresponds to parent process (i.e.,forkresult is nonzero);GC_atfork_child()is to be called immediately in the child branch (i.e.,forkresult is 0). Note thatGC_atfork_child()call should, of course, precedeGC_start_mark_threads()call, if any. Note thatfork()could be called from an unregistered thread. - GC_base⚠
- Return a pointer to the base (lowest address) of an object given
a pointer to a location within the object. I.e., map an interior
pointer to the corresponding base pointer. Note that with debugging
allocation, this returns a pointer to the actual base of the object,
i.e. the debug information, not to the base of the user object.
Return
NULLifdisplaced_pointerdoes not point to within a valid object. Note that a deallocated object in the garbage collected heap may be considered valid, even if it has been deallocated withGC_free()or friends. - GC_
call_ ⚠with_ alloc_ lock - Execute given function with the allocator lock held (in the exclusive mode).
- GC_
call_ ⚠with_ gc_ active - Call a function switching to the “active” state of the collector for
the current thread (i.e. the user function is temporarily back
allowed to call any GC function and/or manipulate pointers to the
garbage-collected heap).
GC_call_with_gc_active()has the functionality opposite toGC_do_blocking()one. It is assumed that the collector is already initialized and the current thread is registered.fnmay toggle the collector thread’s state temporarily to “inactive” one by usingGC_do_blocking().GC_call_with_gc_active()often can be used to provide a sufficiently accurate stack bottom. Acquires the allocator lock in the reader mode (butfnis called not holding it). - GC_
call_ ⚠with_ reader_ lock - GC_
call_ ⚠with_ stack_ base - Call a function with a stack base structure corresponding to somewhere in
the
GC_call_with_stack_baseframe. This often can be used to provide a sufficiently accurate stack bottom. And we implement it everywhere. - GC_
change_ ⚠stubborn - GC_
clear_ ⚠exclusion_ table - Clear the number of entries in the exclusion table. Wizards only. Should be called typically with the allocator lock held, but no assertion about it by design.
- GC_
clear_ ⚠roots - Clear the set of root segments. Wizards only.
- GC_
collect_ ⚠a_ little - Perform some garbage collection work, if appropriate. Return 0 if there is no more work to be done (including the case when garbage collection is not appropriate). Typically performs an amount of work corresponding roughly to marking from one page. May do more work if further progress requires it, e.g. if incremental collection is disabled. It is reasonable to call this in a wait loop until it returns 0. If the garbage collection is disabled but the incremental collection is already ongoing, then perform marking anyway but not stopping the world (and without the reclaim phase).
- GC_
debug_ ⚠change_ stubborn - GC_
debug_ ⚠end_ stubborn_ change - GC_
debug_ ⚠free - GC_
debug_ ⚠freezero - GC_
debug_ ⚠malloc - Debugging (annotated) allocation.
GC_gcollect()will check objects allocated in this way for overwrites, etc. - GC_
debug_ ⚠malloc_ atomic - GC_
debug_ ⚠malloc_ atomic_ ignore_ off_ page - GC_
debug_ ⚠malloc_ atomic_ uncollectable - GC_
debug_ ⚠malloc_ ignore_ off_ page - GC_
debug_ ⚠malloc_ replacement - The functions that allocate objects with debug information (like the
above), but just fill in dummy file and line number information.
Thus they can serve as drop-in
malloc/realloc/reallocfreplacements. This can be useful for two reasons: - GC_
debug_ ⚠malloc_ stubborn - GC_
debug_ ⚠malloc_ uncollectable - GC_
debug_ ⚠malloc_ uncollectable_ replacement - GC_
debug_ ⚠ptr_ store_ and_ dirty - GC_
debug_ ⚠realloc - GC_
debug_ ⚠realloc_ replacement - GC_
debug_ ⚠reallocf - GC_
debug_ ⚠reallocf_ replacement - GC_
debug_ ⚠register_ displacement - GC_
debug_ ⚠register_ finalizer - GC_
debug_ ⚠register_ finalizer_ ignore_ self - GC_
debug_ ⚠register_ finalizer_ no_ order - GC_
debug_ ⚠register_ finalizer_ unreachable - GC_
debug_ ⚠strdup - GC_
debug_ ⚠strndup - GC_
debug_ ⚠toggleref_ add - GC_
deinit ⚠ - Perform the collector shutdown. (E.g. dispose critical sections on
Windows target.) A duplicate invocation is a no-op. In case of Windows,
typically, the client should also call
GC_win32_free_heap()before this function call. TODO: The collector reinitialization after shutdown might work in certain configurations, but not tested. - GC_
disable ⚠ - Disable garbage collection. Even
GC_gcollect()calls will be ineffective. - GC_
dlopen ⚠ - GC_
do_ ⚠blocking - Wrapper for functions that are likely to block (or, at least, do not
allocate garbage-collected memory and/or manipulate pointers to the
garbage-collected heap) for an appreciable length of time.
While
fnis running, the collector is said to be in the “inactive” state for the current thread (this means that the thread is not suspended and the thread’s stack frames “belonging” to the functions in the “inactive” state are not scanned during garbage collections). It is assumed that the collector is already initialized and the current thread is registered. It is allowed forfnto callGC_call_with_gc_active()(even recursively), thus temporarily toggling the collector’s state back to “active”. The latter technique might be used to make stack scanning more precise (i.e. scan only stack frames of functions that allocate garbage-collected memory and/or manipulate pointers to the garbage-collected heap). Acquires the allocator lock in the reader mode (butfnis called not holding it). - GC_dump⚠
- Explicitly dump the collector state. This is most often called from
the debugger, or by setting the
GC_DUMP_REGULARLYenvironment variable, but it may be useful to call it from client code during debugging. The current collection number is printed in the header of the dump. Acquires the allocator lock in the reader mode to avoid data race. Defined only if the library has been compiled withoutNO_DEBUGGINGmacro defined. - GC_
dump_ ⚠finalization - Dump information about every registered disappearing link and
finalizable object. Defined only if the library has been compiled
without
NO_DEBUGGINGmacro defined. - GC_
dump_ ⚠named - The same as
GC_dumpbut allows to specify the name of dump and does not acquire the allocator lock. Ifnameis non-NULL, it is printed to help identifying individual dumps. Otherwise the current collection number is used as the name. Defined only if the library has been compiled withoutNO_DEBUGGINGmacro defined. - GC_
dump_ ⚠regions - Dump information about each block of every GC memory section.
Defined only if the library has been compiled without
NO_DEBUGGINGmacro defined. - GC_
enable ⚠ - Try to re-enable garbage collection.
GC_disable()andGC_enable()calls could be nested. Garbage collection is enabled if the number of calls to both functions is equal. - GC_
enable_ ⚠incremental - Enable incremental/generational collection. Not advisable unless
dirty bits are available or most heap objects are pointer-free
(atomic) or immutable. Do not use in the find-leak mode.
Ignored if
GC_dont_gcis nonzero. Only the generational piece of this is functional ifGC_time_limitis set toGC_TIME_UNLIMITED. Causes thread-local variant ofGC_gcj_malloc()to revert to locked allocation. Must be called before any suchGC_gcj_malloc()calls. For best performance, should be called as early as possible. On some platforms, calling it later may have adverse effects. Safe to call before the collector initialization; it performs the latter if not done yet. - GC_
end_ ⚠stubborn_ change - Inform the collector that the object has been changed.
Only non-
NULLpointer stores into the object are considered to be changes. Matters only if the incremental collection is enabled in the manual VDB (virtual dirty bits) mode; otherwise the function does nothing. Should be followed typically byGC_reachable_here()called for each of the stored pointers. - GC_
exclude_ ⚠static_ roots - Inform the collector that a certain section of statically allocated
memory contains no pointers to garbage-collected memory. Thus it does
not need to be scanned. This is sometimes important if the application
maps large read/write files into the address space, which could be
mistaken for dynamic library data segments on some systems.
Both section start (
low_address) and end (high_address_plus_1) are not needed to be pointer-aligned. - GC_
expand_ ⚠hp - Increase the heap size explicitly. The performed increase is at
least
number_of_bytes. Does the collector initialization as well (if not yet). Returns 0 on failure, 1 on success. - GC_
finish_ ⚠and_ disable - Similar to
GC_disable()but finishes any ongoing collection first. - GC_
foreach_ ⚠heap_ section_ inner - Apply
fnto each heap section and each heap block inside. Similar toGC_apply_to_all_blocks(). Assumes the allocator lock is held at least in the reader mode, but no assertion about it by design. Defined only if the library has been compiled withoutNO_DEBUGGINGmacro defined. - GC_free⚠
- Explicitly deallocate an object. Dangerous if used incorrectly.
Requires a pointer to the base of an object. An object should not
be enabled for finalization (and it should not contain registered
disappearing links of any kind) when it is explicitly deallocated.
GC_free(0)is a no-op, as required by ANSI C forfree(). - GC_
free_ ⚠profiler_ hook - A symbol to be intercepted by heap profilers so that they can
accurately track allocations. Programs such as Valgrind
massifand KDE heaptrack do tracking of allocated objects by overriding common allocator methods (e.g.mallocandfree). However, because the collector does not work by calling standard allocation methods on objects that were reclaimed, we need a way to tell the profiler that an object has been freed. This function is not intended to be called by the client, it should be used for the interception purpose only. The collector calls this function internally whenever an object is freed. Defined only if the library has been compiled withVALGRIND_TRACKINGmacro defined. - GC_
freezero ⚠ - Similar to
GC_freebut also clears the object before deallocation. Guaranteed to clear the specified amount of bytes from the beginning of the deallocated object. It is safe to pass a value larger than the size of the object, e.g.~0could be passed to clear the entire object. - GC_
gcollect ⚠ - Explicitly trigger a full, world-stop collection.
- GC_
gcollect_ ⚠and_ unmap - Same as above but ignores the default
stop_funcsetting and tries to unmap as much memory as possible (regardless of the corresponding switch setting). The recommended usage: on receiving a system low-memory event; before retrying a system call failed because of the system is running out of resources. - GC_
general_ ⚠register_ disappearing_ link - A slight generalization of
GC_register_disappearing_link.*linkis cleared whenobjfirst becomes inaccessible. This can be used to implement weak pointers easily and safely. Typicallylinkwill point to a location (in a GC-allocated object or not) holding a disguised pointer toobj. (A pointer inside an “atomic” object is effectively disguised.) In this way, weak pointers are broken before any object reachable from them gets finalized. Eachlinkmay be registered only with oneobjvalue, i.e. all objects but the last one (linkregistered with) are ignored.linkmust be non-NULL(and be properly aligned).objmust be a pointer to the beginning of an object allocated byGC_mallocor friends. A link disappears when it is unregistered manually, or when*linkis cleared, or when the object containing thislinkis garbage collected. It is unsafe to explicitly deallocate the object containinglink. Explicit deallocation ofobjmay or may not causelinkto eventually be cleared. No-op in the find-leak mode. This function can be used to implement certain types of weak pointers. Note, however, this generally requires that the allocator lock is held, at least in the reader mode (e.g. usingGC_call_with_reader_lock()), when the disguised pointer is accessed. Otherwise a strong pointer could be recreated between the time the collector decides to reclaim the object and the link is cleared. ReturnsGC_SUCCESSif registration succeeded (a new link is registered),GC_DUPLICATEiflinkwas already registered (with some object),GC_NO_MEMORYif registration failed for lack of memory (andGC_oom_fndid not handle the problem),GC_UNIMPLEMENTEDifGC_find_leakis true. - GC_
get_ ⚠abort_ func - GC_
get_ ⚠actual_ vdb - An extended variant of
GC_is_incremental_mode()to return one ofGC_VDB_constants designating which VDB (virtual dirty bits) technique is used exactly. Does not acquire the allocator lock. - GC_
get_ ⚠all_ interior_ pointers - GC_
get_ ⚠allocd_ bytes_ per_ finalizer - GC_
get_ ⚠avg_ stopped_ mark_ time_ ns - Get the average time spent in all mark phases with the world stopped.
The average value is computed since the start of the performance
measurements (or right since the collector initialization if the
collector logging is enabled). The result is in nanoseconds.
The function acquires the allocator lock (in the reader mode) to avoid
data race. Defined only if the library has been compiled without
NO_CLOCKmacro defined. - GC_
get_ ⚠await_ finalize_ proc - GC_
get_ ⚠bytes_ since_ gc - Return the number of bytes allocated since the last collection.
This is an unsynchronized getter (see
GC_get_heap_sizecomment regarding thread-safety). - GC_
get_ ⚠disable_ automatic_ collection - GC_
get_ ⚠dont_ expand - GC_
get_ ⚠dont_ precollect - GC_
get_ ⚠expl_ freed_ bytes_ since_ gc - Return the number of explicitly deallocated bytes of memory since the recent collection. This is an unsynchronized getter.
- GC_
get_ ⚠finalize_ on_ demand - GC_
get_ ⚠finalizer_ notifier - GC_
get_ ⚠find_ leak - GC_
get_ ⚠force_ unmap_ on_ gcollect - GC_
get_ ⚠free_ bytes - Return a lower bound on the number of free bytes in the heap
(excluding the unmapped memory space). This is an unsynchronized
getter (see
GC_get_heap_sizecomment regarding thread-safety). - GC_
get_ ⚠free_ space_ divisor - GC_
get_ ⚠full_ freq - GC_
get_ ⚠full_ gc_ total_ ns_ frac - Get the fractional nanosecond part of the total time value returned by
GC_get_full_gc_total_time(). The result is always less than 1000000. In the multi-threaded mode, the client should useGC_call_with_reader_lock()to get a consistent total time value. Defined only if the library has been compiled withoutNO_CLOCKmacro defined. - GC_
get_ ⚠full_ gc_ total_ time - Get the total time of all full collections since the start of the
performance measurements. Includes time spent in the supplementary
actions like blacklists promotion, marks clearing, free lists
reconstruction and objects finalization. The measurement unit is a
millisecond. Note that the returned value wraps around on overflow.
The function does not use any synchronization. Defined only if the
library has been compiled without
NO_CLOCKmacro defined. - GC_
get_ ⚠gc_ no - GC_
get_ ⚠heap_ size - Return the number of bytes in the heap. Excludes collector private
data structures; excludes the unmapped memory (returned to the OS).
Includes empty blocks and fragmentation loss. Includes some pages
that were allocated but never written. This is an unsynchronized
getter, so it should be called typically with the allocator lock
held, at least in the reader mode, to avoid data race on
multiprocessors (the alternative way is to use
GC_get_prof_statsorGC_get_heap_usage_safeAPI calls instead). This getter remains lock-free (unsynchronized) for compatibility reason since some existing clients call it from a GC callback holding the allocator lock. (This API function and the following four ones below were made thread-safe in GC v7.2alpha1 and reverted back in v7.2alpha7 for the reason described.) - GC_
get_ ⚠heap_ usage_ safe - Return the heap usage information. This is a thread-safe (atomic)
alternative for the five above getters. (This function acquires
the allocator lock in the reader mode, thus preventing data race and
returning the consistent result.) Passing
NULLpointer is allowed for any argument. Returned (filled in) values are ofGC_wordtype. - GC_
get_ ⚠interrupt_ finalizers - GC_
get_ ⚠is_ valid_ displacement_ print_ proc - GC_
get_ ⚠is_ visible_ print_ proc - GC_
get_ ⚠java_ finalization - GC_
get_ ⚠manual_ vdb_ allowed - GC_
get_ ⚠max_ prior_ attempts - GC_
get_ ⚠max_ retries - GC_
get_ ⚠memory_ use - Return the total memory use (in bytes) by all allocated blocks.
The result is equal to
GC_get_heap_size() - GC_get_free_bytes(). Acquires the allocator lock in the reader mode. - GC_
get_ ⚠min_ bytes_ allocd - GC_
get_ ⚠mprotect_ vdb_ allowed - GC_
get_ ⚠my_ stackbottom - Fill in the GC_stack_base structure with the cold end (bottom) of
the stack of the current thread (or coroutine).
Unlike
GC_get_stack_base, it retrieves the value stored in the collector (which is initially set by the collector upon the thread is started or registered manually but it could be later updated by client usingGC_set_stackbottom). Returns the GC-internal non-NULLhandle of the thread which could be passed toGC_set_stackbottom()later. It is assumed that the collector is already initialized and the thread is registered. Acquires the allocator lock in the reader mode. - GC_
get_ ⚠no_ dls - GC_
get_ ⚠non_ gc_ bytes - GC_
get_ ⚠obtained_ from_ os_ bytes - Return the total number of bytes obtained from OS. Includes the unmapped memory. Never decreases. It is an unsynchronized getter.
- GC_
get_ ⚠on_ collection_ event - GC_
get_ ⚠on_ heap_ resize - GC_
get_ ⚠on_ os_ get_ mem - GC_
get_ ⚠on_ thread_ event - GC_
get_ ⚠oom_ fn - GC_
get_ ⚠pages_ executable - Returns nonzero value if the garbage collector is set to the
allocate-executable-memory mode. The mode could be changed by
GC_set_pages_executable(beforeGC_INIT()call) unless the former has no effect on the platform. Does not use or need synchronization. - GC_
get_ ⚠parallel - Return value of
GC_parallel. Does not acquire the allocator lock. - GC_
get_ ⚠prof_ stats - Atomically get the collector statistics (various global counters).
Clients should pass the size of the buffer (of
GC_prof_stats_stype) to fill in the values - this is for interoperability between different collector versions: an old client could have fewer fields, and vice versa, client could use newergc.hfile (with more entries declared in the structure) than that of the linked collector library; in the latter case, unsupported (unknown) fields are filled in with -1 (~0). Return the size (in bytes) of the filled in part of the structure (excluding all unknown fields, if any). - GC_
get_ ⚠prof_ stats_ unsafe - Same as
GC_get_prof_statsbut unsynchronized (i.e., not holding the allocator lock). Clients should call it usingGC_call_with_reader_lock()to avoid data race on multiprocessors. - GC_
get_ ⚠rate - GC_
get_ ⚠same_ obj_ print_ proc - GC_
get_ ⚠size_ map_ at - Get the element value (converted to bytes) at a given index of
GC_size_maptable which provides requested-to-actual allocation size mapping. Assumes the collector is initialized. Returns -1 (~0) if the index is out ofGC_size_maptable bounds. Does not use synchronization, thus clients should call it usingGC_call_with_reader_lock()typically to avoid data race on multiprocessors. - GC_
get_ ⚠sp_ corrector - GC_
get_ ⚠stack_ base - Attempt to fill in the
GC_stack_basestructure with the stack bottom for this thread. This appears to be required to implement anything like the JNI (Java Native Interface)AttachCurrentThreadin an environment in which new threads are not automatically registered with the collector. It is also unfortunately hard to implement well on many platforms. ReturnsGC_SUCCESSorGC_UNIMPLEMENTED. Acquires the allocator lock on some platforms. - GC_
get_ ⚠stop_ func - GC_
get_ ⚠stopped_ mark_ total_ time - Same as
GC_get_full_gc_total_timebut takes into account all mark phases with the world stopped and nothing else. - GC_
get_ ⚠supported_ vdbs - Get the list of available VDB (virtual dirty bits) techniques.
The returned value is a constant one, either
GC_VDB_NONE, or one or more of the aboveGC_VDB_constants, or’ed together. The result is not affected byGC_set_mprotect_vdb_allowed(). May be called before the collector is initialized. - GC_
get_ ⚠suspend_ signal - Return the signal number (which is a constant after the collector initialization) used by the collector to suspend threads on POSIX systems. Return -1 otherwise.
- GC_
get_ ⚠thr_ restart_ signal - Return the signal number (which is a constant after the collector initialization) used by the collector to restart (resume) threads on POSIX systems. Return -1 otherwise.
- GC_
get_ ⚠time_ limit - GC_
get_ ⚠time_ limit_ tv - GC_
get_ ⚠toggleref_ func - GC_
get_ ⚠total_ bytes - Return the total number of bytes allocated in this process.
Never decreases, except due to wrapping. This is an unsynchronized
getter (see
GC_get_heap_sizecomment regarding thread-safety). - GC_
get_ ⚠unmapped_ bytes - Return the size (in bytes) of the unmapped memory (which is returned
to the OS but could be remapped back by the collector later unless
the OS runs out of system/virtual memory). This is an unsynchronized
getter (see
GC_get_heap_sizecomment regarding thread-safety). - GC_
get_ ⚠version - Get the collector library version. The returned value is a constant
in the form:
((version_major << 16) | (version_minor << 8) | version_micro). - GC_
get_ ⚠warn_ proc - GC_
ignore_ ⚠warn_ proc GC_ignore_warn_procmay be used as an argument forGC_set_warn_proc()to suppress all warnings (unless statistics printing is turned on). This is recommended for production code (release).- GC_
incremental_ ⚠protection_ needs - Does incremental mode write-protect pages in a client-visible way?
Returns zero or more of the above
GC_PROTECTS_constants, or’ed together. The collector is assumed to be initialized before this call. The result is not affected byGC_set_manual_vdb_allowed(). Call ofGC_enable_incremental()may change the result toGC_PROTECTS_NONEif some VDB implementation chosen at runtime is not needing to write-protect the pages (thusGC_set_mprotect_vdb_allowed(0)might affect the result). - GC_init⚠
- Initialize the collector. Portable clients should call
GC_INIT()from the program’smain()instead. - GC_
invoke_ ⚠finalizers - Run finalizers for all objects that are ready to be finalized.
Return the number of finalizers that were run. Normally this is
also called implicitly during some allocations.
If
GC_finalize_on_demandis nonzero, it must be called explicitly. - GC_
is_ ⚠disabled - Return 1 (true) if the garbage collection is disabled (i.e., the
value of
GC_dont_gcis nonzero), 0 otherwise. Does not acquire the allocator lock. - GC_
is_ ⚠heap_ ptr - Return 1 (true) if the argument points to somewhere in the garbage
collected heap, 0 otherwise. Primary use is as a fast alternative to
GC_base_C()to check whether the given object is allocated by the collector or not. It is assumed that the collector is already initialized. - GC_
is_ ⚠incremental_ mode - Return 1 (true) if the incremental mode is on, 0 otherwise. Does not acquire the allocator lock.
- GC_
is_ ⚠init_ called - Return 1 (true) if the collector is initialized (or, at least, the initialization is in progress), 0 otherwise.
- GC_
is_ ⚠valid_ displacement - Check that if
pis a pointer to a heap page, then it points to a valid displacement within a heap object. If it is not, invokeGC_is_valid_displacement_print_proc(fail by default). Always returns the argument (p). Uninteresting in the all-interior-pointers mode. Note that we do not acquire the allocator lock, since nothing relevant about the header should change while we have a valid object pointer to the block. - GC_
is_ ⚠visible - Check that
pis visible to the collector as a possibly pointer containing location. If it is not, callGC_is_visible_print_proc(fail by default). Always returns the argument (p). May erroneously succeed in hard cases. The function is intended for debugging use with untyped allocations. (The idea is that it should be possible, though slow, to add such a call to all indirect pointer stores.) Currently almost useless for the multi-threaded worlds. - GC_
malloc ⚠ - General-purpose allocation functions, with roughly
malloccalling conventions. The atomic variants promise that no relevant pointers are contained in the object. The non-atomic variants guarantee that the new object is cleared.GC_malloc_uncollectable()allocates an object that is scanned for pointers to collectible objects, but is not itself collectible. The object is scanned even if it does not appear to be reachable.GC_malloc_uncollectable(),GC_free()(andGC_freezero()) called on the resulting object implicitly updateGC_non_gc_bytesappropriately. All these functions (GC_malloc,GC_malloc_atomic,GC_strdup,GC_strndup,GC_malloc_uncollectable) are guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
malloc_ ⚠atomic - GC_
malloc_ ⚠atomic_ ignore_ off_ page - GC_
malloc_ ⚠atomic_ uncollectable - Allocate
lbbytes of pointer-free, untraced, uncollectible data. This is normally roughly equivalent to the systemmalloc. But it may be useful ifmallocis redefined. The function (including its debug variant) is guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. Defined only if the library has been compiled withGC_ATOMIC_UNCOLLECTABLEmacro defined. - GC_
malloc_ ⚠ignore_ off_ page - Allocate an object of size
lbbytes. The client guarantees that as long as the object is live, it will be referenced by a pointer that points to somewhere within the first GC heap block (hblk) of the object. (This should normally be declaredvolatileto prevent the compiler from invalidating this assertion.) This function is only useful if a large array is being allocated. It reduces the chance of accidentally retaining such an array as a result of scanning an integer that happens to be an address inside the array. (Actually, it reduces the chance of the allocator not finding space for such an array, since it will try hard to avoid introducing such a false reference.) On a SunOS 4.x or Windows system this is recommended for arrays likely to be larger than 100 KB or so. For other systems, or if the collector is not configured to recognize all interior pointers, the threshold is normally much higher. These functions are guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
malloc_ ⚠many - This returns a list of objects with the link pointer located at the
beginning of each object. The use of such list can greatly reduce
lock contention problems, since the allocator lock can be acquired
and released many fewer times. Note that there is no “atomic”
variant of this function, as otherwise the links would not be seen
by the collector. If the argument (
lb) is zero, then it is treated as 1. The function is guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
malloc_ ⚠stubborn - GC_
malloc_ ⚠uncollectable - GC_
memalign ⚠ - The allocation function which guarantees the requested alignment of
the allocated memory object. The
alignargument should be nonzero and a power of two. It is guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
move_ ⚠disappearing_ link - Moves a
linkpreviously registered viaGC_general_register_disappearing_link(orGC_register_disappearing_link). Does not change the target object of the weak reference. Does not change contents of*new_link. May be called withnew_linkequal tolink(to check whetherlinkhas been registered). ReturnsGC_SUCCESSon success,GC_DUPLICATEif there is already another disappearing link at the new location (never returned ifnew_linkis equal tolink),GC_NOT_FOUNDif nolinkis registered at the original location. - GC_
move_ ⚠long_ link - Similar to
GC_move_disappearing_linkbut for alinkpreviously registered viaGC_register_long_link. - GC_
noop1 ⚠ - Make the argument of
GC_wordtype appear live to compiler. This could be used to prevent certain compiler false positive (FP) warnings and misoptimizations. Should be robust against the whole program analysis. - GC_
noop1_ ⚠ptr - Same as
GC_noop1()but for a pointer. - GC_
posix_ ⚠memalign - A function similar to
GC_memalignbut existing largely for redirection in the find-leak mode. Thealignargument should be nonzero and a power of two, but additionally the argument is required to be not less than size of a pointer. Note that the function does not change value of*memptrin case of failure (i.e. when the result is nonzero). It is guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
post_ ⚠incr - GC_
pre_ ⚠incr - Checked pointer pre- and post-increment operations. Note that the second
argument (
how_much) is in units of bytes, not multiples of the object size. This should either be invoked from a macro, or the call should be automatically generated. - GC_
pthread_ ⚠cancel - GC_
pthread_ ⚠create - GC_
pthread_ ⚠detach - GC_
pthread_ ⚠exit - GC_
pthread_ ⚠join - GC_
pthread_ ⚠sigmask - GC_
ptr_ ⚠store_ and_ dirty - GC_
pvalloc ⚠ - GC_
realloc ⚠ - For compatibility with C library. This is occasionally faster than
a
mallocfollowed by abcopy. But if you rely on that, either here or with the standard C library, your code is broken. Probably, it should not have been invented, but now we are stuck. The resulting object has the same kind as the original one. It is an error to have changes enabled for the original object. It does not change the contents of the object from its beginning to the minimum of old size andnew_size_in_bytes; the contents above in case of object size growth is initialized to zero (not guaranteed for atomic object type). The function follows ANSI conventions forNULLold_object(i.e., equivalent toGC_mallocregardless ofnew_size_in_bytes). Ifnew_size_in_bytesis zero (andold_objectis non-NULL), then the call is equivalent toGC_free(andNULLis returned). Ifold_objectis non-NULL, it must have been returned by an earlier call toGC_realloc,GC_mallocor friends. In case of the allocation failure,GC_realloc(and its debug variant) does not touch and does not free memory pointed byold_object. The logic ofGC_reallocfand its debug variant is different - they free memory pointed byold_objectif the allocation has failed. If the returned pointer is not the same asold_objectand both of them are non-NULL, thenold_objectis freed. Returns eitherNULL(in case of the allocation failure or zeronew_size_in_bytes) or pointer to the allocated memory. For a nonzeronew_size_in_bytes, the functions are guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
reallocf ⚠ - GC_
register_ ⚠altstack - Notify the collector about the stack and the alt-stack of the current
thread.
normstackandnormstack_sizeare used to determine the “normal” stack boundaries when a thread is suspended while it is on an alt-stack. Acquires the allocator lock in the reader mode. - GC_
register_ ⚠disappearing_ link - This routine may be used to break cycles between finalizable objects,
thus causing cyclic finalizable objects to be finalized in
the correct order. The standard use involves calling
GC_register_disappearing_link(&p), wherepis a pointer that is not followed by finalization code, and should not be considered in determining finalization order.linkshould point to a field of a heap-allocated object.*linkwill be cleared when the object is found to be inaccessible. This happens before any finalization code is invoked, and before any decisions about finalization order are made. This is useful in telling the finalizer that some pointers are not essential for proper finalization. This may avoid finalization cycles. Note that the object may be resurrected by another finalizer, and thus the clearing of*linkmay be visible to non-finalization code. There is an argument that an arbitrary action should be allowed here, instead of just clearing a pointer. But this causes problems if that action alters, or examines connectivity. ReturnsGC_DUPLICATEif givenlinkwas already registered,GC_SUCCESSif registration succeeded,GC_NO_MEMORYif it failed for lack of memory (andGC_oom_fndid not handle the problem). Only exists for backward compatibility, useGC_general_register_disappearing_link()instead. - GC_
register_ ⚠displacement - Add a displacement to the set of those considered valid by the
collector.
GC_register_displacement(offset)means that ifpwas returned byGC_malloc(), then(char *)p + offsetwill be considered to be a valid pointer top.offsetmust be less than the size of a heap block. (All pointers to the interior of objects from the stack are considered valid in any case. This applies to heap objects and static data.) Preferably, this should be called before any other GC procedures. Calling it later adds to the probability of excess memory retention. This is a no-op if the collector has recognition of arbitrary interior pointers enabled, which is the default (assuming the collector is built withALL_INTERIOR_POINTERSmacro defined). The debugging variant should be used if any debugging allocation is being done. - GC_
register_ ⚠finalizer - When
objis no longer accessible, invoke(*fn)(obj, cd). Ifaandbare inaccessible, andapoints tob(after disappearing links have been made to disappear), then onlyawill be finalized. (If this does not create any new pointers tob, thenbwill be finalized after the next collection.) Any finalizable object that is reachable from itself by following one or more pointers will not be finalized (or collected). Thus cycles involving finalizable objects should be avoided, or broken by disappearing links. All but the last finalizer registered for an object is ignored. No-op in the find-leak mode. Finalization may be removed by passing 0 asfn. Finalizers are implicitly unregistered when they are enqueued for finalization (i.e. become ready to be finalized). The old finalizer and client data are stored in*ofnand*ocd, respectively. (ofnand/orocdmay beNULL. The allocator lock is held while*ofnand*ocdare updated. In case of error (no memory to register new finalizer),*ofnand*ocdremain unchanged.)fnis never invoked on an accessible object, provided hidden pointers are converted to real pointers only if the allocator lock is held, at least in the reader mode, and such conversions are not performed by finalization routines. IfGC_register_finalizer()is aborted as a result of a signal, then the object may be left with no finalization, even if neither the old nor new finalizer wereNULL.objshould be the starting address of an object allocated byGC_mallocor friends.objmay also beNULLor point to something outside the collector heap (in this case,fnis ignored,*ofnand*ocdare set toNULL). Note that any garbage collectible object referenced bycdwill be considered accessible until the finalizer is invoked. - GC_
register_ ⚠finalizer_ ignore_ self - Another variant of
GC_register_finalizerbut ignoring self-cycles, i.e. pointers from a finalizable object to itself. There is a stylistic argument that this is wrong, but it is unavoidable for C++, since the compiler may silently introduce these. It is also benign in that specific case. And it helps if finalizable objects are split to avoid cycles. Note thatcdwill still be viewed as accessible, even if it refers to the object itself. - GC_
register_ ⚠finalizer_ no_ order - Another variant of
GC_register_finalizerwhich ignores all cycles. It should probably only be used by Java implementations. Note thatcdwill still be viewed as accessible, even if it refers to the object itself. - GC_
register_ ⚠finalizer_ unreachable - This is a special finalizer that is useful when an object’s finalizer
must be run when the object is known to be no longer reachable, not even
from other finalizable objects. It behaves like “normal” finalization,
except that the finalizer is not run while the object is reachable from
other objects specifying unordered finalization. Effectively it allows
an object referenced, possibly indirectly, from an unordered finalizable
object to override the unordered finalization request. This can be used
in combination with
GC_register_finalizer_no_orderso as to release resources that must not be released while an object can still be brought back to life by other finalizers. Only works ifGC_java_finalizationis set. Probably only of interest when implementing a language that requires unordered finalization (e.g. Java, C#). - GC_
register_ ⚠has_ static_ roots_ callback - Register a new callback (a user-supplied filter) to control the scanning of dynamic libraries. Replaces any previously registered callback. May be 0 (means no filtering). May be unused on some platforms (if the filtering is unimplemented or inappropriate).
- GC_
register_ ⚠long_ link - Similar to
GC_general_register_disappearing_linkbut*linkonly gets cleared whenobjbecomes truly inaccessible. An object becomes truly inaccessible when it can no longer be resurrected from its finalizer (e.g. by assigning itself to a pointer traceable from root). This can be used to implement “long” weak pointers easily and safely. - GC_
register_ ⚠my_ thread - Register the current thread, with the indicated stack bottom, as
a new thread whose stack(s) should be traced by the collector.
If it is not implicitly called by the collector, this must be called
before a thread can allocate garbage-collected memory, or assign
pointers to the garbage-collected heap. Once registered, a thread
will be stopped during garbage collections. This call must be
previously enabled (see
GC_allow_register_threads). This should never be called from the main thread, where it is always done implicitly. This is normally done implicitly ifGC_functions are called to create the thread, e.g. by includegc.hfile (which redefines some system functions) before calling the system thread creation function. Nonetheless, thread cleanup routines (e.g.,pthreadskey destructor) typically require manual thread registering (and unregistering) if pointers to GC-allocated objects are manipulated inside. It is also always done implicitly on Win32 platform ifGC_use_threads_discovery()is called at start-up. Except for the latter case, the explicit call is normally required for threads created by third-party libraries. A manually registered thread requires manual unregistering. ReturnsGC_SUCCESSon success,GC_DUPLICATEif already registered. - GC_
remove_ ⚠roots - Remove root segments located fully in the region. Wizards only.
- GC_
same_ ⚠obj - Check that
pandqpoint to the same object.GC_same_obj_print_procis called (fail by default) if they do not. Succeeds, as well, if neitherpnorqpoints to the heap. (May succeed also if bothpandqpoint to between heap objects.) Returns the first argument (p). (The returned value may be hard to use due to typing issues. But if we had a suitable preprocessor…) We assume this is somewhat performance critical (it should not be called by production code, of course, but it can easily make even debugging intolerably slow). - GC_
set_ ⚠abort_ func - GC_
set_ ⚠all_ interior_ pointers - GC_
set_ ⚠allocd_ bytes_ per_ finalizer - Set/get the minimum value of the ratio of allocated bytes since
garbage collection to the amount of finalizers created since that
collection (so value is greater than
GC_bytes_allocd / (GC_fo_entries - last_fo_entries)) which triggers the collection instead heap expansion. The value has no effect in the collector incremental mode. The default value is 10000 unlessGC_ALLOCD_BYTES_PER_FINALIZERmacro with a custom value is defined to build the collector. The default value might be not the right choice for clients where e.g. most objects have a finalizer. Zero value effectively disables taking amount of finalizers in the decision whether to collect or not. The functions do not use any synchronization. - GC_
set_ ⚠await_ finalize_ proc - GC_
set_ ⚠disable_ automatic_ collection - Control whether to disable algorithm deciding if a collection should be started when we allocated enough to amortize the collection. Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter) to avoid data race.
- GC_
set_ ⚠dont_ expand - GC_
set_ ⚠dont_ precollect - GC_
set_ ⚠finalize_ on_ demand - GC_
set_ ⚠finalizer_ notifier - GC_
set_ ⚠find_ leak - GC_
set_ ⚠force_ unmap_ on_ gcollect - The setter and the getter for switching “unmap as much as possible”
mode on(1) and off(0). Has no effect unless unmapping is turned on.
Initial value is controlled by
GC_FORCE_UNMAP_ON_GCOLLECTmacro. The setter and the getter are unsynchronized. - GC_
set_ ⚠free_ space_ divisor - GC_
set_ ⚠full_ freq - GC_
set_ ⚠handle_ fork - Overrides the default handle-fork mode. A nonzero value means GC
should install proper
pthread_atforkhandlers. Has effect only if called before the collector initialization. Clients should callGC_set_handle_fork()with nonzero argument if going to useforkwith the GC functions called in the child process. (Note that such client and at-fork handler activities are not fully POSIX-compliant.)GC_set_handle_fork()instructsGC_initto setup GC fork handlers usingpthread_atfork(), the latter might fail (or, even, absent on some targets) causingabortat the collector initialization. Issues with missing (or failed)pthread_atfork()could be avoided by invocation ofGC_set_handle_fork(-1)at application start-up and surrounding eachfork()with the relevantGC_atfork_prepare/GC_atfork_parent/GC_atfork_childcalls. - GC_
set_ ⚠interrupt_ finalizers - Set maximum amount of finalizers to run during a single invocation
of
GC_invoke_finalizers(). Zero means no limit. Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter). Note that invocation ofGC_finalize_all()resets the maximum amount value. - GC_
set_ ⚠is_ valid_ displacement_ print_ proc - GC_
set_ ⚠is_ visible_ print_ proc - GC_
set_ ⚠java_ finalization - GC_
set_ ⚠log_ fd - Change file descriptor of the collector log. Unavailable on some targets.
- GC_
set_ ⚠manual_ vdb_ allowed - Select whether to use the manual VDB (virtual dirty bits) mode for
the incremental collection. Has no effect if called after enabling
the incremental collection. The default value is off unless the
collector is compiled with
MANUAL_VDBmacro defined. The manual VDB mode should be used only if the client has the appropriateGC_END_STUBBORN_CHANGE()andGC_reachable_here()(or, alternatively,GC_PTR_STORE_AND_DIRTY()) calls (to ensure proper write barriers). The setter and the getter are not synchronized. - GC_
set_ ⚠markers_ count - Set the number of marker threads (including the initiating one)
to the desired value at start-up. Zero value means the collector
is to decide. If the correct nonzero value is passed, then
GC_parallelwill be set to the value minus one later. Has no effect if called after the collector initialization. Does not itself cause creation of the marker threads. Does not use any synchronization. - GC_
set_ ⚠max_ heap_ size - Limit the heap size to
nbytes. Useful when you are debugging, especially on systems that do not handle running out of memory well. A zeronmeans the heap is unbounded; this is the default. This setter function is unsynchronized (so it might requireGC_call_with_alloc_lockto avoid data race). - GC_
set_ ⚠max_ prior_ attempts - Set/get the maximum number of prior attempts at the world-stop marking. Not synchronized.
- GC_
set_ ⚠max_ retries - GC_
set_ ⚠min_ bytes_ allocd - The setter and the getter of the minimum value returned by the internal
min_bytes_allocd(). The value should not be zero; the default value is one. Not synchronized. - GC_
set_ ⚠mprotect_ vdb_ allowed - Select whether to allow usage of the
mprotect-based VDB (virtual dirty bits) mode for the incremental collection. The default value is on regardless of the availability of this VDB mode. Disallowing themprotect-based VDB might be useful for applications that usemprotect()and/orSIGSEGV/SIGBUSfor own needs or cannot deal with the related unintended system call failures. Has no effect if called after enabling the incremental collection (either explicitly or implicitly during the collector initialization). The setter and the getter are not synchronized. - GC_
set_ ⚠no_ dls - GC_
set_ ⚠non_ gc_ bytes - GC_
set_ ⚠on_ collection_ event - GC_
set_ ⚠on_ heap_ resize - GC_
set_ ⚠on_ os_ get_ mem - GC_
set_ ⚠on_ thread_ event - GC_
set_ ⚠oom_ fn - GC_
set_ ⚠pages_ executable - Set whether the garbage collector will allocate executable memory
pages or not. A nonzero argument instructs the collector to
allocate memory with the executable flag on. Must be called before
the collector is initialized. May have no effect on some platforms.
The default value is controlled by
NO_EXECUTE_PERMISSIONmacro (if present then the flag is off). Portable clients should haveGC_set_pages_executable(1)call (beforeGC_INIT()one) provided they are going to execute code on any of the GC-allocated memory objects. - GC_
set_ ⚠rate - Set/get the size in pages of units operated by
GC_collect_a_little(). The value should not be zero. Not synchronized. - GC_
set_ ⚠same_ obj_ print_ proc - GC_
set_ ⚠sp_ corrector - GC_
set_ ⚠stackbottom - Set the cool end of the user (coroutine) stack of the specified thread.
The GC thread handle (
gc_thread_handle) is either the one returned byGC_get_my_stackbottom()orNULL(the latter designates the current thread). The caller should hold the allocator lock (e.g. usingGC_call_with_reader_lock()withreleaseargument set to 1), the reader mode should be enough typically, at least for the collector itself (the client is responsible to avoid data race between this andGC_get_my_stackbottomfunctions if the client acquires the allocator lock in the reader mode). Also, the function could be used for settingGC_stackbottomvalue (the bottom of the primordial thread) before the collector is initialized (the allocator lock is not needed to be acquired at all in this case). - GC_
set_ ⚠stop_ func - Set/get the default
stop_func. The latter is used byGC_gcollect()and by implicitly triggered collections (except for the case when handling out of memory). Must not be 0. Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter) to avoid data race. - GC_
set_ ⚠suspend_ signal - Suggest the collector to use the specific signal to suspend threads. Has no effect after the collector initialization and on non-POSIX systems.
- GC_
set_ ⚠thr_ restart_ signal - Suggest the collector to use the specific signal to resume threads. Has no effect after the collector initialization and on non-POSIX systems. The same signal might be used for threads suspension and restart.
- GC_
set_ ⚠time_ limit - GC_
set_ ⚠time_ limit_ tv - Set/get the time limit of the incremental collections. This is
similar to
GC_set_time_limitandGC_get_time_limitbut the time is provided with the nanosecond precision. The value oftv_nsecpart should be less than a million. If the value oftv_mspart isGC_TIME_UNLIMITED, thentv_nsecpart is ignored. Initially, the value oftv_nsecpart of the time limit is zero. The functions do not use any synchronization. Defined only if the library has been compiled withoutNO_CLOCKmacro defined. - GC_
set_ ⚠toggleref_ func - Set (register) a callback that decides the state of a given object (by, probably, inspecting its native state). The argument may be 0 (means no callback). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter).
- GC_
set_ ⚠warn_ proc - GC_
should_ ⚠invoke_ finalizers - Returns a nonzero value (true) if
GC_invoke_finalizers()has something to do. (Useful if finalizers can only be called from some kind of “safe state” and getting into that safe state is expensive.) Does not use any synchronization. - GC_size⚠
- Given a pointer to the base of an object, return its size in bytes.
(For small objects this also happens to work from interior pointers,
but that should not be relied upon.) The returned size may be slightly
larger than the actual size of the object (the returned value may include
the size of the object debug header, an extra byte past end of the object,
etc.). The argument may be
NULL(causing 0 to be returned). - GC_
start_ ⚠incremental_ collection - Force start of incremental collection. Acquires the allocator lock. No-op unless the incremental mode is on.
- GC_
start_ ⚠mark_ threads - Start the parallel marker threads, if available. Useful, e.g.,
after POSIX
forkin a child process (provided not followed byexec()) or in single-threaded clients (provided it is OK for the client to perform marking in parallel). Acquires the allocator lock to avoid a race. - GC_
start_ ⚠performance_ measurement - Tell the collector to start various performance measurements.
Only the total time taken by full collections and the average time
spent in the world-stopped collections are calculated, as of now.
And, currently, there is no way to stop the measurements.
The function does not use any synchronization. Defined only if the
library has been compiled without
NO_CLOCKmacro defined. - GC_
start_ ⚠world_ external - GC_
stop_ ⚠world_ external - Stop/start the world explicitly. Not recommended for general use.
- GC_
strdup ⚠ - GC_
strndup ⚠ - GC_
thread_ ⚠is_ registered - Return 1 (true) if the calling (current) thread is registered with the garbage collector, 0 otherwise. Acquires the allocator lock in the reader mode. If the thread is finished (e.g. running in a destructor and not registered manually again), then it is considered as not registered.
- GC_
toggleref_ ⚠add - Register a given object for “toggle-refs” processing. It will be
stored internally and the “toggle-refs” callback will be invoked on
the object until the callback returns
GC_TOGGLE_REF_DROPor the object is collected. Ifis_strong, then the object is registered with a strong ref, a weak one otherwise.objshould be the starting address of an object allocated byGC_malloc(GC_debug_malloc) or friends. ReturnsGC_SUCCESSif registration succeeded (or no callback is registered yet),GC_NO_MEMORYif it failed for a lack of memory reason. - GC_
try_ ⚠to_ collect - GC_
unregister_ ⚠disappearing_ link - Undoes a registration by either
GC_register_disappearing_link()orGC_general_register_disappearing_link(). Returns 0 iflinkwas not actually registered (otherwise returns 1). - GC_
unregister_ ⚠long_ link - Similar to
GC_unregister_disappearing_linkbut forlinkregistration done byGC_register_long_link(). - GC_
unregister_ ⚠my_ thread - Unregister the current thread. Only an explicitly registered thread
(i.e. for which
GC_register_my_thread()returnsGC_SUCCESS) is allowed (and required) to call this function. (As a special exception, it is also allowed to once unregister the main thread.) The thread may no longer allocate garbage-collected memory or manipulate pointers to the garbage-collected heap after making this call. Specifically, if it wants to return or otherwise communicate a pointer to the garbage-collected heap to another thread, it must do this before callingGC_unregister_my_thread, most probably by saving it in a global data structure. Must not be called inside a GC callback function (except forGC_call_with_stack_base()one). Always returnsGC_SUCCESS. - GC_
valloc ⚠ - The allocation functions that guarantee the memory page alignment of
the returned object. Exist largely for redirection in the find-leak
mode. All these functions (
GC_pvalloc,GC_valloc) are guaranteed never to returnNULLunlessGC_oom_fn()returnsNULL. - GC_
win32_ ⚠free_ heap - win32s may not free all resources on process exit. This explicitly deallocates the heap. Defined only for Windows.
Type Aliases§
- GC_
Event Type - GC_PTR
- GC_
Toggle RefStatus - GC_
abort_ func - This is invoked on the collector fatal aborts (just before
OS-dependent
abort()orexit(1)is called). Must be non-NULL. The default one outputsmsgto the platformstderrprovidedmsgis non-NULL.msgisNULLif invoked beforeexit(1)otherwisemsgis non-NULL(i.e., if invoked beforeabort). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter). The setter does not changeGC_abort_funcif the library has been compiled withSMALL_CONFIGmacro defined. - GC_
await_ finalize_ proc - Finalizer callback support. Invoked by the collector (with the allocator lock held) for each unreachable object enqueued for finalization. Zero means no callback. The setter and the getter acquire the allocator lock too (in the reader mode in case of the getter).
- GC_
finalization_ proc - GC_
finalizer_ notifier_ proc - Invoked by the collector when there are objects to be finalized.
Invoked at most once per collection cycle. Never invoked unless
GC_finalize_on_demandis set. Typically this will notify a finalization thread, which will callGC_invoke_finalizers()in response. May be 0 (means no notifier). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter). - GC_
fn_ type - GC_
has_ static_ roots_ func - A filter function to control the scanning of dynamic libraries.
If implemented, called by the collector before registering a dynamic
library (discovered by the collector) section as a static data root
(called only as a last reason not to register). The filename
(
dlpi_name) of the library, the address and the length of the memory region (section) are passed. This routine should return a nonzero value if that region should be scanned. Always called with the allocator lock held. Depending on the platform, might be called with the world stopped. - GC_
heap_ section_ proc - GC_
heap_ section_ type - GC_
hidden_ pointer - GC_
on_ collection_ event_ proc - Invoked to indicate progress through the collection process. Not used for thread suspend/resume notifications. Called with the allocator lock held (or, even, the world stopped). May be 0 (means no notifier). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter).
- GC_
on_ heap_ resize_ proc - Invoked when the heap grows or shrinks. Called with the world stopped (and the allocator lock held). May be 0. Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter).
- GC_
on_ os_ get_ mem_ proc - Invoked when new memory space is obtained from the OS. Called with the
allocator lock held. If
spaceargument isNULL, this means a failure to the get the memory. The argument ofGC_set_on_os_get_mem()may be 0 (means no notifier). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter). - GC_
on_ thread_ event_ proc - Invoked when a thread is suspended or resumed during collection. Called with the allocator lock held (and the world stopped partially). May be 0 (means no notifier). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter).
- GC_
oom_ func - When there is insufficient memory to satisfy an allocation request,
we return
(*GC_oom_fn)(size). If it returns, it must return eitherNULLor a valid pointer to a previously allocated heap object. By default, this just returnsNULL. If it points to a function which never returnsNULL, probably by aborting the program instead, then invocations ofGC_MALLOC()and friends (that are additionally marked as “never returning NULL unless GC_oom_fn returns NULL”) do not need to be followed by code that checks for theNULLresult.GC_oom_fnmust not be 0. Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter) to avoid data race. - GC_
return_ addr_ t - GC_
same_ obj_ print_ proc_ t - GC_
signed_ word - GC_
sp_ corrector_ proc - Provide a verifier/modifier of the stack pointer when pushing the
thread stacks. This might be useful for a crude integration
with certain coroutine implementations.
*sp_ptris the captured stack pointer of the suspended thread withpthread_id(the latter is actually ofpthread_ttype). The functionality is unsupported on some targets (the getter always returns 0 in such a case). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter). The client function (if provided) is called with the allocator lock held and, might be, with the world stopped. - GC_
stack_ base_ func - GC_
stop_ func - Trigger a full world-stopped collection. Abort the collection if
and when
stop_func()returns a nonzero value.stop_func()will be called frequently, and should be reasonably fast. (stop_func()is called with the allocator lock held and the world might be stopped; it is not allowed forstop_func()to manipulate pointers to the garbage-collected heap or call most of GC functions.) This works even if no virtual dirty bits, and hence incremental collection is not available for the architecture. Collections can be aborted faster than normal pause times for incremental collection; however, aborted collections do no useful work; the next collection needs to start from the beginning.stop_funcmust not be 0.GC_try_to_collect()returns 0 if the collection was aborted (or the collections are disabled), 1 if it succeeded. - GC_
toggleref_ func - The callback is to decide (return) the new state of a given object. Invoked by the collector for all objects registered for “toggle-refs” processing. Invoked with the allocator lock held but the world is running.
- GC_
uintptr_ t - GC_
valid_ ptr_ print_ proc_ t - The functions called to report pointer checking errors. Called without the allocator lock held. The default behavior is to fail with the appropriate message which includes the pointers. The functions (variables) must not be 0. Both the setters and the getters are unsynchronized.
- GC_
warn_ proc GC_set_warn_proccan be used to redirect or filter warning messages.pmay not be aNULLpointer.msgis aprintfformat string (argmust match the format). Both the setter and the getter acquire the allocator lock (in the reader mode in case of the getter) to avoid data race. In GC v7.1 and before: the setter returned the value of oldwarn_proc. In GC v8.2.x and before:msgpointer type had noconstqualifier.- GC_word
- Define public
wordandsigned_wordto be unsigned and signed types of the size same as ofsize_t,ptrdiff_t, and of the address part of data pointers (likechar *andvoid *). - pthread_
t - sigset_
t