JS_GetGCParameter

Adjust performance parameters related to garbage collection.

Syntax

uint32_t
JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);

void
JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value);

uint32_t
JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key); // Added in SpiderMonkeySidebar 17

void
JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value); // Added in SpiderMonkeySidebar 17
Name Type Description
rt JSRuntime * The runtime to configure.
cx JSContext * The context to configure. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
key JSGCParamKey Specifies which garbage collection parameter to get or set.
value uint32_t (JS_SetGCParameter only) The value to assign to the parameter.
typedef enum JSGCParamKey {
    JSGC_MAX_BYTES,
    JSGC_MAX_MALLOC_BYTES,
    JSGC_MAX_NURSERY_BYTES,
    JSGC_BYTES,
    JSGC_NUMBER,
    JSGC_MODE,
    JSGC_UNUSED_CHUNKS,
    JSGC_TOTAL_CHUNKS,
    JSGC_SLICE_TIME_BUDGET,
    JSGC_MARK_STACK_LIMIT,
    JSGC_HIGH_FREQUENCY_TIME_LIMIT,
    JSGC_HIGH_FREQUENCY_LOW_LIMIT,
    JSGC_HIGH_FREQUENCY_HIGH_LIMIT,
    JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX,
    JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN,
    JSGC_LOW_FREQUENCY_HEAP_GROWTH,
    JSGC_DYNAMIC_HEAP_GROWTH,
    JSGC_DYNAMIC_MARK_SLICE,
    JSGC_ALLOCATION_THRESHOLD,
    JSGC_MIN_EMPTY_CHUNK_COUNT,
    JSGC_MAX_EMPTY_CHUNK_COUNT,
    JSGC_COMPACTION_ENABLED,
    JSGC_ALLOCATION_THRESHOLD_FACTOR,
    JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT,
    JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION,
    JSGC_PRETENURE_THRESHOLD,
    JSGC_PRETENURE_GROUP_THRESHOLD,
    JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION_PERCENT,
    JSGC_MIN_NURSERY_BYTES,
    JSGC_MIN_LAST_DITCH_GC_PERIOD,
} JSGCParamKey;
Value (C++/JS Shell) Description
JSGC_MAX_BYTES / "maxBytes" Maximum nominal heap before last ditch GC.
JSGC_MAX_MALLOC_BYTES / "maxMallocBytes" Number of JS_malloc bytes before last ditch GC.
JSGC_MAX_NURSERY_BYTES / "maxNurseryBytes" Maximum size the nursery may grow to, or 0 to disable generational GC.
JSGC_MIN_NURSERY_BYTES / "minNurseryBytes" Minimum size the nursery may shrink to.
JSGC_BYTES / "gcBytes" Amount of bytes allocated by the GC.
JSGC_NUMBER / "gcNumber" Number of times GC has been invoked. Includes both major and minor GC.
JSGC_MODE / "mode"

Select GC mode:

JSGC_MODE_GLOBAL (0)
The GC runs all objects are visited in a singleslice.
JSGC_MODE_ZONE (1)
The GC runs only the objects that belong to somezones are visited in a singleslice.
JSGC_MODE_INCREMENTAL (2)
The GC runs all objects are visited in multipleslices.
JSGC_MODE_ZONE_INCREMENTAL (3)
The GC runs only the objects that belong to somezones are visited in multipleslices.

This does not affect generational GC, see JSGC_MAX_NURSERY_BYTES

JSGC_UNUSED_CHUNKS / "unusedChunks" Number of cached empty GC chunks.
JSGC_TOTAL_CHUNKS / "totalChunks" Total number of allocated GC chunks.
JSGC_SLICE_TIME_BUDGET / "sliceTimeBudget" Max milliseconds to spend in an incremental GC slice. 0 for infinite.
JSGC_MARK_STACK_LIMIT / "markStackLimit" Maximum size the GC mark stack can grow to (units: entries).
JSGC_HIGH_FREQUENCY_TIME_LIMIT / "highFrequencyTimeLimit" GCs less than this far apart in time will be considered 'high-frequency GCs'.
JSGC_HIGH_FREQUENCY_LOW_LIMIT / "highFrequencyLowLimit"

Controls for dynamic heap growth. When the GC is in "high frequency" mode (see above) then, the heap will be allowed to grow between collections according to these four parameters. See ZoneHeapThreshold::computeZoneHeapGrowthFactorForHeapSize in GC.cpp for the details.

The first two parameters are in MB and the remaining two are in percentage of heap size.

JSGC_HIGH_FREQUENCY_HIGH_LIMIT / "highFrequencyHighLimit"
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX / "highFrequencyHeapGrowthMax"
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN / "highFrequencyHeapGrowthMin"
JSGC_LOW_FREQUENCY_HEAP_GROWTH / "lowFrequencyHeapGrowth" Heap growth percentage for low frequency GCs.
JSGC_DYNAMIC_HEAP_GROWTH / "dynamicHeapGrowth" If false, the heap growth percentage is fixed at 300%. If true, it is determined based on whether GCs are high- or low- frequency.
JSGC_DYNAMIC_MARK_SLICE / "dynamicMarkSlice" If true, high-frequency GCs will use a longer mark slice.
JSGC_ALLOCATION_THRESHOLD / "allocationThreshold" Lower limit after which we limit the heap growth. The heap will be collected if it is greater than: MAX(allocThreshold, lastSize) * thresholdFactor, This establishes allocThreshold as a baseline or default heap size.
JSGC_ALLOCATION_THRESHOLD_FACTOR / "allocationThresholdFactor"

These thresholds (as percentages) are compared with the zone threshold (above) to decide when to begin an incremental collection. JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT is used when a GC is already in progress for other zones and we may wish to avoid interrupting it.

Additionally if a zone expands beyond the threshold without this factor, then it will be collected non-incrementally

JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT / "allocationThresholdfactorAvoidInterrupt"
JSGC_MIN_EMPTY_CHUNK_COUNT / "minEmptyChunkCount" We try to keep at least this many unused chunks in the free chunk pool at all times, even after a shrinking GC.
JSGC_MAX_EMPTY_CHUNK_COUNT / "maxEmptyChunkCount" We never keep more than this many unused chunks in the free chunk pool.
JSGC_COMPACTION_ENABLED / "compactingEnabled" non-zero to enable compacting, zero to disable.
JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION / "nurseryFreeThresholdForIdleCollection" Collect the nursery in idle time if it has less than this many bytes of free space.
JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION_PERCENT / "nurseryFreeThresholdForIdleCollectionPercent" Collect the nursery in idle time if it has less than this percentage of capacity free (value from 0 - 99).
JSGC_PRETENURE_THRESHOLD / "pretenureThreshold" If this percentage of the nursery is tenured and the nursery is at least 4MB, then process object groups to look for pretenuring candidates.
JSGC_PRETENURE_GROUP_THRESHOLD / "pretenureGroupThreshold" If more than this number of objects in a given object group are tenured, then pretenruing will be enabled for new objects in this group.
JSGC_MIN_LAST_DITCH_GC_PERIOD / "minLastDitchGCPeriod" The minimum time to allow between triggering last ditch GCs in seconds.

Description

JS_GetGCParameter returns the current parameter of the garbage collection.

If successful, JS_GetGCParameter returns the current parameter.

JS_SetGCParameter ajusts the parameter of the garbage collection.

See Also