Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / js / public / GCAPI.h
blob5773838e468a9673ba358921432bb7ff2e4c8beb
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * High-level interface to the JS garbage collector.
9 */
11 #ifndef js_GCAPI_h
12 #define js_GCAPI_h
14 #include "mozilla/TimeStamp.h"
15 #include "mozilla/Vector.h"
17 #include "js/CharacterEncoding.h" // JS::UTF8Chars
18 #include "js/GCAnnotations.h"
19 #include "js/shadow/Zone.h"
20 #include "js/SliceBudget.h"
21 #include "js/TypeDecls.h"
22 #include "js/UniquePtr.h"
23 #include "js/Utility.h"
25 class JS_PUBLIC_API JSTracer;
27 namespace js {
28 namespace gc {
29 class GCRuntime;
30 } // namespace gc
31 class JS_PUBLIC_API SliceBudget;
32 namespace gcstats {
33 struct Statistics;
34 } // namespace gcstats
35 } // namespace js
37 namespace JS {
39 // Options used when starting a GC.
40 enum class GCOptions : uint32_t {
41 // Normal GC invocation.
43 // Some objects that are unreachable from the program may still be alive after
44 // collection because of internal references
45 Normal = 0,
47 // A shrinking GC.
49 // Try to release as much memory as possible by clearing internal caches,
50 // aggressively discarding JIT code and decommitting unused chunks. This
51 // ensures all unreferenced objects are removed from the system.
53 // Finally, compact the GC heap.
54 Shrink = 1,
56 // A shutdown GC.
58 // This does more drastic cleanup as part of system shutdown, including:
59 // - clearing WeakRef kept object sets
60 // - not marking FinalizationRegistry roots
61 // - repeating collection if JS::NotifyGCRootsRemoved was called
62 // - skipping scheduling of various future work that won't be needed
64 // Note that this assumes that no JS will run after this point!
65 Shutdown = 2
68 } // namespace JS
70 typedef enum JSGCParamKey {
71 /**
72 * Maximum nominal heap before last ditch GC.
74 * Soft limit on the number of bytes we are allowed to allocate in the GC
75 * heap. Attempts to allocate gcthings over this limit will return null and
76 * subsequently invoke the standard OOM machinery, independent of available
77 * physical memory.
79 * Pref: javascript.options.mem.max
80 * Default: 0xffffffff
82 JSGC_MAX_BYTES = 0,
84 /**
85 * Maximum size of the generational GC nurseries.
87 * This will be rounded to the nearest gc::ChunkSize.
89 * Pref: javascript.options.mem.nursery.max_kb
90 * Default: JS::DefaultNurseryMaxBytes
92 JSGC_MAX_NURSERY_BYTES = 2,
94 /** Amount of bytes allocated by the GC. */
95 JSGC_BYTES = 3,
97 /** Number of times GC has been invoked. Includes both major and minor GC. */
98 JSGC_NUMBER = 4,
101 * Whether incremental GC is enabled. If not, GC will always run to
102 * completion.
104 * prefs: javascript.options.mem.gc_incremental.
105 * Default: false
107 JSGC_INCREMENTAL_GC_ENABLED = 5,
110 * Whether per-zone GC is enabled. If not, all zones are collected every time.
112 * prefs: javascript.options.mem.gc_per_zone
113 * Default: false
115 JSGC_PER_ZONE_GC_ENABLED = 6,
117 /** Number of cached empty GC chunks. */
118 JSGC_UNUSED_CHUNKS = 7,
120 /** Total number of allocated GC chunks. */
121 JSGC_TOTAL_CHUNKS = 8,
124 * Max milliseconds to spend in an incremental GC slice.
126 * A value of zero means there is no maximum.
128 * Pref: javascript.options.mem.gc_incremental_slice_ms
129 * Default: DefaultTimeBudgetMS.
131 JSGC_SLICE_TIME_BUDGET_MS = 9,
134 * The "do we collect?" decision depends on various parameters and can be
135 * summarised as:
137 * ZoneSize > Max(ThresholdBase, LastSize) * GrowthFactor * ThresholdFactor
139 * Where
140 * ZoneSize: Current size of this zone.
141 * LastSize: Heap size immediately after the most recent collection.
142 * ThresholdBase: The JSGC_ALLOCATION_THRESHOLD parameter
143 * GrowthFactor: A number above 1, calculated based on some of the
144 * following parameters.
145 * See computeZoneHeapGrowthFactorForHeapSize() in GC.cpp
146 * ThresholdFactor: 1.0 to trigger an incremental collections or between
147 * JSGC_SMALL_HEAP_INCREMENTAL_LIMIT and
148 * JSGC_LARGE_HEAP_INCREMENTAL_LIMIT to trigger a
149 * non-incremental collection.
151 * The RHS of the equation above is calculated and sets
152 * zone->gcHeapThreshold.bytes(). When gcHeapSize.bytes() exeeds
153 * gcHeapThreshold.bytes() for a zone, the zone may be scheduled for a GC.
157 * GCs less than this far apart in milliseconds will be considered
158 * 'high-frequency GCs'.
160 * Pref: javascript.options.mem.gc_high_frequency_time_limit_ms
161 * Default: HighFrequencyThreshold
163 JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11,
166 * Upper limit for classifying a heap as small (MB).
168 * Dynamic heap growth thresholds are based on whether the heap is small,
169 * medium or large. Heaps smaller than this size are classified as small;
170 * larger heaps are classified as medium or large.
172 * Pref: javascript.options.mem.gc_small_heap_size_max_mb
173 * Default: SmallHeapSizeMaxBytes
175 JSGC_SMALL_HEAP_SIZE_MAX = 12,
178 * Lower limit for classifying a heap as large (MB).
180 * Dynamic heap growth thresholds are based on whether the heap is small,
181 * medium or large. Heaps larger than this size are classified as large;
182 * smaller heaps are classified as small or medium.
184 * Pref: javascript.options.mem.gc_large_heap_size_min_mb
185 * Default: LargeHeapSizeMinBytes
187 JSGC_LARGE_HEAP_SIZE_MIN = 13,
190 * Heap growth factor for small heaps in the high-frequency GC state.
192 * Pref: javascript.options.mem.gc_high_frequency_small_heap_growth
193 * Default: HighFrequencySmallHeapGrowth
195 JSGC_HIGH_FREQUENCY_SMALL_HEAP_GROWTH = 14,
198 * Heap growth factor for large heaps in the high-frequency GC state.
200 * Pref: javascript.options.mem.gc_high_frequency_large_heap_growth
201 * Default: HighFrequencyLargeHeapGrowth
203 JSGC_HIGH_FREQUENCY_LARGE_HEAP_GROWTH = 15,
206 * Heap growth factor for low frequency GCs.
208 * This factor is applied regardless of the size of the heap when not in the
209 * high-frequency GC state.
211 * Pref: javascript.options.mem.gc_low_frequency_heap_growth
212 * Default: LowFrequencyHeapGrowth
214 JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16,
217 * Whether balanced heap limits are enabled.
219 * If this is set to true then heap limits are calculated in a way designed to
220 * balance memory usage optimally between many heaps.
222 * Otherwise, heap limits are set based on a linear multiple of the retained
223 * size after the last collection.
225 * Pref: javascript.options.mem.gc_balanced_heap_limits
226 * Default: BalancedHeapLimitsEnabled
228 JSGC_BALANCED_HEAP_LIMITS_ENABLED = 17,
231 * Heap growth parameter for balanced heap limit calculation.
233 * This parameter trades off GC time for memory usage. Smaller values result
234 * in lower memory use and larger values result in less time spent collecting.
236 * Heap limits are set to the heap's retained size plus some extra space. The
237 * extra space is calculated based on several factors but is scaled
238 * proportionally to this parameter.
240 * Pref: javascript.options.mem.gc_heap_growth_factor
241 * Default: HeapGrowthFactor
243 JSGC_HEAP_GROWTH_FACTOR = 18,
246 * Lower limit for collecting a zone (MB).
248 * Zones smaller than this size will not normally be collected.
250 * Pref: javascript.options.mem.gc_allocation_threshold_mb
251 * Default GCZoneAllocThresholdBase
253 JSGC_ALLOCATION_THRESHOLD = 19,
256 * We try to keep at least this many unused chunks in the free chunk pool at
257 * all times, even after a shrinking GC.
259 * Pref: javascript.options.mem.gc_min_empty_chunk_count
260 * Default: MinEmptyChunkCount
262 JSGC_MIN_EMPTY_CHUNK_COUNT = 21,
265 * We never keep more than this many unused chunks in the free chunk pool.
267 * Pref: javascript.options.mem.gc_max_empty_chunk_count
268 * Default: MaxEmptyChunkCount
270 JSGC_MAX_EMPTY_CHUNK_COUNT = 22,
273 * Whether compacting GC is enabled.
275 * Pref: javascript.options.mem.gc_compacting
276 * Default: CompactingEnabled
278 JSGC_COMPACTING_ENABLED = 23,
281 * Whether parallel marking is enabled.
283 * Pref: javascript.options.mem.gc_parallel_marking
284 * Default: ParallelMarkingEnabled
286 JSGC_PARALLEL_MARKING_ENABLED = 24,
289 * Limit of how far over the incremental trigger threshold we allow the heap
290 * to grow before finishing a collection non-incrementally, for small heaps.
292 * We trigger an incremental GC when a trigger threshold is reached but the
293 * collection may not be fast enough to keep up with the mutator. At some
294 * point we finish the collection non-incrementally.
296 * Default: SmallHeapIncrementalLimit
297 * Pref: javascript.options.mem.gc_small_heap_incremental_limit
299 JSGC_SMALL_HEAP_INCREMENTAL_LIMIT = 25,
302 * Limit of how far over the incremental trigger threshold we allow the heap
303 * to grow before finishing a collection non-incrementally, for large heaps.
305 * Default: LargeHeapIncrementalLimit
306 * Pref: javascript.options.mem.gc_large_heap_incremental_limit
308 JSGC_LARGE_HEAP_INCREMENTAL_LIMIT = 26,
311 * Free space bytes threshold for eager nursery collection.
313 * Default: NurseryChunkUsableSize / 4
314 * Pref: javascript.options.mem.nursery_eager_collection_threshold_kb
316 JSGC_NURSERY_EAGER_COLLECTION_THRESHOLD_KB = 27,
319 * Free space fraction threshold for eager nursery collection. This is a
320 * percentage (from 0 to 99).
322 * Default: 25
323 * Pref: javascript.options.mem.nursery_eager_collection_threshold_percent
325 JSGC_NURSERY_EAGER_COLLECTION_THRESHOLD_PERCENT = 30,
328 * Minimum size of the generational GC nurseries.
330 * This value will be rounded to the nearest Nursery::SubChunkStep if below
331 * gc::ChunkSize, otherwise it'll be rounded to the nearest gc::ChunkSize.
333 * Default: Nursery::SubChunkLimit
334 * Pref: javascript.options.mem.nursery.min_kb
336 JSGC_MIN_NURSERY_BYTES = 31,
339 * The minimum time to allow between triggering last ditch GCs in seconds.
341 * Default: 60 seconds
342 * Pref: None
344 JSGC_MIN_LAST_DITCH_GC_PERIOD = 32,
347 * The delay (in heapsize kilobytes) between slices of an incremental GC.
349 * Default: ZoneAllocDelayBytes
351 JSGC_ZONE_ALLOC_DELAY_KB = 33,
354 * The current size of the nursery.
356 * This parameter is read-only.
358 JSGC_NURSERY_BYTES = 34,
361 * Retained size base value for calculating malloc heap threshold.
363 * Default: MallocThresholdBase
365 JSGC_MALLOC_THRESHOLD_BASE = 35,
368 * Whether incremental weakmap marking is enabled.
370 * Pref: javascript.options.mem.incremental_weakmap
371 * Default: IncrementalWeakMarkEnabled
373 JSGC_INCREMENTAL_WEAKMAP_ENABLED = 37,
376 * The chunk size in bytes for this system.
378 * This parameter is read-only.
380 JSGC_CHUNK_BYTES = 38,
383 * The number of background threads to use for parallel GC work for each CPU
384 * core, expressed as an integer percentage.
386 * Pref: javascript.options.mem.gc_helper_thread_ratio
388 JSGC_HELPER_THREAD_RATIO = 39,
391 * The maximum number of background threads to use for parallel GC work.
393 * Pref: javascript.options.mem.gc_max_helper_threads
395 JSGC_MAX_HELPER_THREADS = 40,
398 * The number of background threads to use for parallel GC work.
400 * This parameter is read-only and is set based on the
401 * JSGC_HELPER_THREAD_RATIO and JSGC_MAX_HELPER_THREADS parameters.
403 JSGC_HELPER_THREAD_COUNT = 41,
406 * A number that is incremented on every major GC slice.
408 JSGC_MAJOR_GC_NUMBER = 44,
411 * A number that is incremented on every minor GC.
413 JSGC_MINOR_GC_NUMBER = 45,
416 * JS::MaybeRunNurseryCollection will collect the nursery if it hasn't been
417 * collected in this many milliseconds.
419 * Default: 5000
420 * Pref: javascript.options.mem.nursery_eager_collection_timeout_ms
422 JSGC_NURSERY_EAGER_COLLECTION_TIMEOUT_MS = 46,
425 * The system page size in KB.
427 * This parameter is read-only.
429 JSGC_SYSTEM_PAGE_SIZE_KB = 47,
432 * In an incremental GC, this determines the point at which to start
433 * increasing the slice budget and frequency of allocation triggered slices to
434 * try to avoid reaching the incremental limit and finishing the collection
435 * synchronously.
437 * The threshold is calculated by subtracting this value from the heap's
438 * incremental limit.
440 JSGC_URGENT_THRESHOLD_MB = 48,
443 * Set the number of threads to use for parallel marking, or zero to use the
444 * default.
446 * The actual number used is capped to the number of available helper threads.
448 * This is provided for testing purposes.
450 * Pref: None.
451 * Default: 0 (no effect).
453 JSGC_MARKING_THREAD_COUNT = 49,
456 * The heap size above which to use parallel marking.
458 * Pref: javascript.options.mem.gc_parallel_marking_threshold_mb
459 * Default: ParallelMarkingThresholdMB
461 JSGC_PARALLEL_MARKING_THRESHOLD_MB = 50,
464 * Whether the semispace nursery is enabled.
466 * Pref: javascript.options.mem.gc_experimental_semispace_nursery
467 * Default: SemispaceNurseryEnabled
469 JSGC_SEMISPACE_NURSERY_ENABLED = 51,
471 } JSGCParamKey;
474 * Generic trace operation that calls JS::TraceEdge on each traceable thing's
475 * location reachable from data.
477 typedef void (*JSTraceDataOp)(JSTracer* trc, void* data);
480 * Trace hook used to trace gray roots incrementally.
482 * This should return whether tracing is finished. It will be called repeatedly
483 * in subsequent GC slices until it returns true.
485 * While tracing this should check the budget and return false if it has been
486 * exceeded. When passed an unlimited budget it should always return true.
488 typedef bool (*JSGrayRootsTracer)(JSTracer* trc, js::SliceBudget& budget,
489 void* data);
491 typedef enum JSGCStatus { JSGC_BEGIN, JSGC_END } JSGCStatus;
493 typedef void (*JSObjectsTenuredCallback)(JSContext* cx, void* data);
495 typedef enum JSFinalizeStatus {
497 * Called when preparing to sweep a group of zones, before anything has been
498 * swept. The collector will not yield to the mutator before calling the
499 * callback with JSFINALIZE_GROUP_START status.
501 JSFINALIZE_GROUP_PREPARE,
504 * Called after preparing to sweep a group of zones. Weak references to
505 * unmarked things have been removed at this point, but no GC things have
506 * been swept. The collector may yield to the mutator after this point.
508 JSFINALIZE_GROUP_START,
511 * Called after sweeping a group of zones. All dead GC things have been
512 * swept at this point.
514 JSFINALIZE_GROUP_END,
517 * Called at the end of collection when everything has been swept.
519 JSFINALIZE_COLLECTION_END
520 } JSFinalizeStatus;
522 typedef void (*JSFinalizeCallback)(JS::GCContext* gcx, JSFinalizeStatus status,
523 void* data);
525 typedef void (*JSWeakPointerZonesCallback)(JSTracer* trc, void* data);
527 typedef void (*JSWeakPointerCompartmentCallback)(JSTracer* trc,
528 JS::Compartment* comp,
529 void* data);
532 * This is called to tell the embedding that a FinalizationRegistry object has
533 * cleanup work, and that the engine should be called back at an appropriate
534 * later time to perform this cleanup, by calling the function |doCleanup|.
536 * This callback must not do anything that could cause GC.
538 using JSHostCleanupFinalizationRegistryCallback =
539 void (*)(JSFunction* doCleanup, JSObject* incumbentGlobal, void* data);
542 * Each external string has a pointer to JSExternalStringCallbacks. Embedders
543 * can use this to implement custom finalization or memory reporting behavior.
545 struct JSExternalStringCallbacks {
547 * Finalizes external strings created by JS_NewExternalStringLatin1 or
548 * JS_NewExternalUCString. The finalizer can be called off the main
549 * thread.
551 virtual void finalize(JS::Latin1Char* chars) const = 0;
552 virtual void finalize(char16_t* chars) const = 0;
555 * Callback used by memory reporting to ask the embedder how much memory an
556 * external string is keeping alive. The embedder is expected to return a
557 * value that corresponds to the size of the allocation that will be released
558 * by the finalizer callback above.
560 * Implementations of this callback MUST NOT do anything that can cause GC.
562 virtual size_t sizeOfBuffer(const JS::Latin1Char* chars,
563 mozilla::MallocSizeOf mallocSizeOf) const = 0;
564 virtual size_t sizeOfBuffer(const char16_t* chars,
565 mozilla::MallocSizeOf mallocSizeOf) const = 0;
568 namespace JS {
570 #define GCREASONS(D) \
571 /* Reasons internal to the JS engine. */ \
572 D(API, 0) \
573 D(EAGER_ALLOC_TRIGGER, 1) \
574 D(DESTROY_RUNTIME, 2) \
575 D(ROOTS_REMOVED, 3) \
576 D(LAST_DITCH, 4) \
577 D(TOO_MUCH_MALLOC, 5) \
578 D(ALLOC_TRIGGER, 6) \
579 D(DEBUG_GC, 7) \
580 D(COMPARTMENT_REVIVED, 8) \
581 D(RESET, 9) \
582 D(OUT_OF_NURSERY, 10) \
583 D(EVICT_NURSERY, 11) \
584 D(SHARED_MEMORY_LIMIT, 13) \
585 D(EAGER_NURSERY_COLLECTION, 14) \
586 D(BG_TASK_FINISHED, 15) \
587 D(ABORT_GC, 16) \
588 D(FULL_WHOLE_CELL_BUFFER, 17) \
589 D(FULL_GENERIC_BUFFER, 18) \
590 D(FULL_VALUE_BUFFER, 19) \
591 D(FULL_CELL_PTR_OBJ_BUFFER, 20) \
592 D(FULL_SLOT_BUFFER, 21) \
593 D(FULL_SHAPE_BUFFER, 22) \
594 D(TOO_MUCH_WASM_MEMORY, 23) \
595 D(DISABLE_GENERATIONAL_GC, 24) \
596 D(FINISH_GC, 25) \
597 D(PREPARE_FOR_TRACING, 26) \
598 D(FULL_WASM_ANYREF_BUFFER, 27) \
599 D(FULL_CELL_PTR_STR_BUFFER, 28) \
600 D(TOO_MUCH_JIT_CODE, 29) \
601 D(FULL_CELL_PTR_BIGINT_BUFFER, 30) \
602 D(NURSERY_TRAILERS, 31) \
603 D(NURSERY_MALLOC_BUFFERS, 32) \
605 /* \
606 * Reasons from Firefox. \
608 * The JS engine attaches special meanings to some of these reasons. \
609 */ \
610 D(DOM_WINDOW_UTILS, FIRST_FIREFOX_REASON) \
611 D(COMPONENT_UTILS, 34) \
612 D(MEM_PRESSURE, 35) \
613 D(CC_FINISHED, 36) \
614 D(CC_FORCED, 37) \
615 D(LOAD_END, 38) \
616 D(UNUSED3, 39) \
617 D(PAGE_HIDE, 40) \
618 D(NSJSCONTEXT_DESTROY, 41) \
619 D(WORKER_SHUTDOWN, 42) \
620 D(SET_DOC_SHELL, 43) \
621 D(DOM_UTILS, 44) \
622 D(DOM_IPC, 45) \
623 D(DOM_WORKER, 46) \
624 D(INTER_SLICE_GC, 47) \
625 D(UNUSED1, 48) \
626 D(FULL_GC_TIMER, 49) \
627 D(SHUTDOWN_CC, 50) \
628 D(UNUSED2, 51) \
629 D(USER_INACTIVE, 52) \
630 D(XPCONNECT_SHUTDOWN, 53) \
631 D(DOCSHELL, 54) \
632 D(HTML_PARSER, 55) \
633 D(DOM_TESTUTILS, 56) \
634 D(PREPARE_FOR_PAGELOAD, 57) \
636 /* Reasons reserved for embeddings. */ \
637 D(RESERVED1, FIRST_RESERVED_REASON) \
638 D(RESERVED2, 91) \
639 D(RESERVED3, 92) \
640 D(RESERVED4, 93) \
641 D(RESERVED5, 94) \
642 D(RESERVED6, 95) \
643 D(RESERVED7, 96) \
644 D(RESERVED8, 97) \
645 D(RESERVED9, 98)
647 enum class GCReason {
648 FIRST_FIREFOX_REASON = 33,
649 FIRST_RESERVED_REASON = 90,
651 #define MAKE_REASON(name, val) name = val,
652 GCREASONS(MAKE_REASON)
653 #undef MAKE_REASON
654 NO_REASON,
655 NUM_REASONS,
658 * For telemetry, we want to keep a fixed max bucket size over time so we
659 * don't have to switch histograms. 100 is conservative; but the cost of extra
660 * buckets seems to be low while the cost of switching histograms is high.
662 NUM_TELEMETRY_REASONS = 100
666 * Get a statically allocated C string explaining the given GC reason.
668 extern JS_PUBLIC_API const char* ExplainGCReason(JS::GCReason reason);
671 * Return true if the GC reason is internal to the JS engine.
673 extern JS_PUBLIC_API bool InternalGCReason(JS::GCReason reason);
676 * Zone GC:
678 * SpiderMonkey's GC is capable of performing a collection on an arbitrary
679 * subset of the zones in the system. This allows an embedding to minimize
680 * collection time by only collecting zones that have run code recently,
681 * ignoring the parts of the heap that are unlikely to have changed.
683 * When triggering a GC using one of the functions below, it is first necessary
684 * to select the zones to be collected. To do this, you can call
685 * PrepareZoneForGC on each zone, or you can call PrepareForFullGC to select
686 * all zones. Failing to select any zone is an error.
690 * Schedule the given zone to be collected as part of the next GC.
692 extern JS_PUBLIC_API void PrepareZoneForGC(JSContext* cx, Zone* zone);
695 * Schedule all zones to be collected in the next GC.
697 extern JS_PUBLIC_API void PrepareForFullGC(JSContext* cx);
700 * When performing an incremental GC, the zones that were selected for the
701 * previous incremental slice must be selected in subsequent slices as well.
702 * This function selects those slices automatically.
704 extern JS_PUBLIC_API void PrepareForIncrementalGC(JSContext* cx);
707 * Returns true if any zone in the system has been scheduled for GC with one of
708 * the functions above or by the JS engine.
710 extern JS_PUBLIC_API bool IsGCScheduled(JSContext* cx);
713 * Undoes the effect of the Prepare methods above. The given zone will not be
714 * collected in the next GC.
716 extern JS_PUBLIC_API void SkipZoneForGC(JSContext* cx, Zone* zone);
719 * Non-Incremental GC:
721 * The following functions perform a non-incremental GC.
725 * Performs a non-incremental collection of all selected zones.
727 extern JS_PUBLIC_API void NonIncrementalGC(JSContext* cx, JS::GCOptions options,
728 GCReason reason);
731 * Incremental GC:
733 * Incremental GC divides the full mark-and-sweep collection into multiple
734 * slices, allowing client JavaScript code to run between each slice. This
735 * allows interactive apps to avoid long collection pauses. Incremental GC does
736 * not make collection take less time, it merely spreads that time out so that
737 * the pauses are less noticable.
739 * For a collection to be carried out incrementally the following conditions
740 * must be met:
741 * - The collection must be run by calling JS::IncrementalGC() rather than
742 * JS_GC().
743 * - The GC parameter JSGC_INCREMENTAL_GC_ENABLED must be true.
745 * Note: Even if incremental GC is enabled and working correctly,
746 * non-incremental collections can still happen when low on memory.
750 * Begin an incremental collection and perform one slice worth of work. When
751 * this function returns, the collection may not be complete.
752 * IncrementalGCSlice() must be called repeatedly until
753 * !IsIncrementalGCInProgress(cx).
755 * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or
756 * shorter than the requested interval.
758 extern JS_PUBLIC_API void StartIncrementalGC(JSContext* cx,
759 JS::GCOptions options,
760 GCReason reason,
761 const js::SliceBudget& budget);
764 * Perform a slice of an ongoing incremental collection. When this function
765 * returns, the collection may not be complete. It must be called repeatedly
766 * until !IsIncrementalGCInProgress(cx).
768 * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or
769 * shorter than the requested interval.
771 extern JS_PUBLIC_API void IncrementalGCSlice(JSContext* cx, GCReason reason,
772 const js::SliceBudget& budget);
775 * Return whether an incremental GC has work to do on the foreground thread and
776 * would make progress if a slice was run now. If this returns false then the GC
777 * is waiting for background threads to finish their work and a slice started
778 * now would return immediately.
780 extern JS_PUBLIC_API bool IncrementalGCHasForegroundWork(JSContext* cx);
783 * If IsIncrementalGCInProgress(cx), this call finishes the ongoing collection
784 * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(cx),
785 * this is equivalent to NonIncrementalGC. When this function returns,
786 * IsIncrementalGCInProgress(cx) will always be false.
788 extern JS_PUBLIC_API void FinishIncrementalGC(JSContext* cx, GCReason reason);
791 * If IsIncrementalGCInProgress(cx), this call aborts the ongoing collection and
792 * performs whatever work needs to be done to return the collector to its idle
793 * state. This may take an arbitrarily long time. When this function returns,
794 * IsIncrementalGCInProgress(cx) will always be false.
796 extern JS_PUBLIC_API void AbortIncrementalGC(JSContext* cx);
798 namespace dbg {
800 // The `JS::dbg::GarbageCollectionEvent` class is essentially a view of the
801 // `js::gcstats::Statistics` data without the uber implementation-specific bits.
802 // It should generally be palatable for web developers.
803 class GarbageCollectionEvent {
804 // The major GC number of the GC cycle this data pertains to.
805 uint64_t majorGCNumber_;
807 // Reference to a non-owned, statically allocated C string. This is a very
808 // short reason explaining why a GC was triggered.
809 const char* reason;
811 // Reference to a nullable, non-owned, statically allocated C string. If the
812 // collection was forced to be non-incremental, this is a short reason of
813 // why the GC could not perform an incremental collection.
814 const char* nonincrementalReason;
816 // Represents a single slice of a possibly multi-slice incremental garbage
817 // collection.
818 struct Collection {
819 mozilla::TimeStamp startTimestamp;
820 mozilla::TimeStamp endTimestamp;
823 // The set of garbage collection slices that made up this GC cycle.
824 mozilla::Vector<Collection> collections;
826 GarbageCollectionEvent(const GarbageCollectionEvent& rhs) = delete;
827 GarbageCollectionEvent& operator=(const GarbageCollectionEvent& rhs) = delete;
829 public:
830 explicit GarbageCollectionEvent(uint64_t majorGCNum)
831 : majorGCNumber_(majorGCNum),
832 reason(nullptr),
833 nonincrementalReason(nullptr),
834 collections() {}
836 using Ptr = js::UniquePtr<GarbageCollectionEvent>;
837 static Ptr Create(JSRuntime* rt, ::js::gcstats::Statistics& stats,
838 uint64_t majorGCNumber);
840 JSObject* toJSObject(JSContext* cx) const;
842 uint64_t majorGCNumber() const { return majorGCNumber_; }
845 } // namespace dbg
847 enum GCProgress {
849 * During GC, the GC is bracketed by GC_CYCLE_BEGIN/END callbacks. Each
850 * slice between those (whether an incremental or the sole non-incremental
851 * slice) is bracketed by GC_SLICE_BEGIN/GC_SLICE_END.
854 GC_CYCLE_BEGIN,
855 GC_SLICE_BEGIN,
856 GC_SLICE_END,
857 GC_CYCLE_END
860 struct JS_PUBLIC_API GCDescription {
861 bool isZone_;
862 bool isComplete_;
863 JS::GCOptions options_;
864 GCReason reason_;
866 GCDescription(bool isZone, bool isComplete, JS::GCOptions options,
867 GCReason reason)
868 : isZone_(isZone),
869 isComplete_(isComplete),
870 options_(options),
871 reason_(reason) {}
873 char16_t* formatSliceMessage(JSContext* cx) const;
874 char16_t* formatSummaryMessage(JSContext* cx) const;
876 mozilla::TimeStamp startTime(JSContext* cx) const;
877 mozilla::TimeStamp endTime(JSContext* cx) const;
878 mozilla::TimeStamp lastSliceStart(JSContext* cx) const;
879 mozilla::TimeStamp lastSliceEnd(JSContext* cx) const;
881 JS::UniqueChars sliceToJSONProfiler(JSContext* cx) const;
882 JS::UniqueChars formatJSONProfiler(JSContext* cx) const;
884 JS::dbg::GarbageCollectionEvent::Ptr toGCEvent(JSContext* cx) const;
887 extern JS_PUBLIC_API UniqueChars MinorGcToJSON(JSContext* cx);
889 typedef void (*GCSliceCallback)(JSContext* cx, GCProgress progress,
890 const GCDescription& desc);
893 * The GC slice callback is called at the beginning and end of each slice. This
894 * callback may be used for GC notifications as well as to perform additional
895 * marking.
897 extern JS_PUBLIC_API GCSliceCallback
898 SetGCSliceCallback(JSContext* cx, GCSliceCallback callback);
901 * Describes the progress of an observed nursery collection.
903 enum class GCNurseryProgress {
905 * The nursery collection is starting.
907 GC_NURSERY_COLLECTION_START,
909 * The nursery collection is ending.
911 GC_NURSERY_COLLECTION_END
915 * A nursery collection callback receives the progress of the nursery collection
916 * and the reason for the collection.
918 using GCNurseryCollectionCallback = void (*)(JSContext* cx,
919 GCNurseryProgress progress,
920 GCReason reason, void* data);
923 * Add and remove nursery collection callbacks for the given runtime. These will
924 * be called at the start and end of every nursery collection.
926 extern JS_PUBLIC_API bool AddGCNurseryCollectionCallback(
927 JSContext* cx, GCNurseryCollectionCallback callback, void* data);
928 extern JS_PUBLIC_API void RemoveGCNurseryCollectionCallback(
929 JSContext* cx, GCNurseryCollectionCallback callback, void* data);
931 typedef void (*DoCycleCollectionCallback)(JSContext* cx);
934 * The purge gray callback is called after any COMPARTMENT_REVIVED GC in which
935 * the majority of compartments have been marked gray.
937 extern JS_PUBLIC_API DoCycleCollectionCallback
938 SetDoCycleCollectionCallback(JSContext* cx, DoCycleCollectionCallback callback);
940 using CreateSliceBudgetCallback = js::SliceBudget (*)(JS::GCReason reason,
941 int64_t millis);
944 * Called when generating a GC slice budget. It allows the embedding to control
945 * the duration of slices and potentially check an interrupt flag as well. For
946 * internally triggered GCs, the given millis parameter is the JS engine's
947 * internal scheduling decision, which the embedding can choose to ignore.
948 * (Otherwise, it will be the value that was passed to eg
949 * JS::IncrementalGCSlice()).
951 extern JS_PUBLIC_API void SetCreateGCSliceBudgetCallback(
952 JSContext* cx, CreateSliceBudgetCallback cb);
955 * Incremental GC defaults to enabled, but may be disabled for testing or in
956 * embeddings that have not yet implemented barriers on their native classes.
957 * There is not currently a way to re-enable incremental GC once it has been
958 * disabled on the runtime.
960 extern JS_PUBLIC_API void DisableIncrementalGC(JSContext* cx);
963 * Returns true if incremental GC is enabled. Simply having incremental GC
964 * enabled is not sufficient to ensure incremental collections are happening.
965 * See the comment "Incremental GC" above for reasons why incremental GC may be
966 * suppressed. Inspection of the "nonincremental reason" field of the
967 * GCDescription returned by GCSliceCallback may help narrow down the cause if
968 * collections are not happening incrementally when expected.
970 extern JS_PUBLIC_API bool IsIncrementalGCEnabled(JSContext* cx);
973 * Returns true while an incremental GC is ongoing, both when actively
974 * collecting and between slices.
976 extern JS_PUBLIC_API bool IsIncrementalGCInProgress(JSContext* cx);
979 * Returns true while an incremental GC is ongoing, both when actively
980 * collecting and between slices.
982 extern JS_PUBLIC_API bool IsIncrementalGCInProgress(JSRuntime* rt);
985 * Returns true if the most recent GC ran incrementally.
987 extern JS_PUBLIC_API bool WasIncrementalGC(JSRuntime* rt);
990 * Generational GC:
994 * Ensure that generational GC is disabled within some scope.
996 * This evicts the nursery and discards JIT code so it is not a lightweight
997 * operation.
999 class JS_PUBLIC_API AutoDisableGenerationalGC {
1000 JSContext* cx;
1002 public:
1003 explicit AutoDisableGenerationalGC(JSContext* cx);
1004 ~AutoDisableGenerationalGC();
1008 * Returns true if generational allocation and collection is currently enabled
1009 * on the given runtime.
1011 extern JS_PUBLIC_API bool IsGenerationalGCEnabled(JSRuntime* rt);
1014 * Pass a subclass of this "abstract" class to callees to require that they
1015 * never GC. Subclasses can use assertions or the hazard analysis to ensure no
1016 * GC happens.
1018 class JS_PUBLIC_API AutoRequireNoGC {
1019 protected:
1020 AutoRequireNoGC() = default;
1021 ~AutoRequireNoGC() = default;
1025 * Diagnostic assert (see MOZ_DIAGNOSTIC_ASSERT) that GC cannot occur while this
1026 * class is live. This class does not disable the static rooting hazard
1027 * analysis.
1029 * This works by entering a GC unsafe region, which is checked on allocation and
1030 * on GC.
1032 class JS_PUBLIC_API AutoAssertNoGC : public AutoRequireNoGC {
1033 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
1034 protected:
1035 JSContext* cx_; // nullptr if inactive.
1037 public:
1038 // Nullptr here means get the context from TLS. It does not mean inactive
1039 // (though cx_ may end up nullptr, and thus inactive, if TLS has not yet been
1040 // initialized.)
1041 explicit AutoAssertNoGC(JSContext* cx = nullptr);
1042 AutoAssertNoGC(AutoAssertNoGC&& other) : cx_(other.cx_) {
1043 other.cx_ = nullptr;
1045 ~AutoAssertNoGC();
1047 void reset();
1048 #else
1049 public:
1050 explicit AutoAssertNoGC(JSContext* cx = nullptr) {}
1051 ~AutoAssertNoGC() {}
1053 void reset() {}
1054 #endif
1058 * Disable the static rooting hazard analysis in the live region and assert in
1059 * debug builds if any allocation that could potentially trigger a GC occurs
1060 * while this guard object is live. This is most useful to help the exact
1061 * rooting hazard analysis in complex regions, since it cannot understand
1062 * dataflow.
1064 * Note: GC behavior is unpredictable even when deterministic and is generally
1065 * non-deterministic in practice. The fact that this guard has not
1066 * asserted is not a guarantee that a GC cannot happen in the guarded
1067 * region. As a rule, anyone performing a GC unsafe action should
1068 * understand the GC properties of all code in that region and ensure
1069 * that the hazard analysis is correct for that code, rather than relying
1070 * on this class.
1072 #ifdef DEBUG
1073 class JS_PUBLIC_API AutoSuppressGCAnalysis : public AutoAssertNoGC {
1074 public:
1075 explicit AutoSuppressGCAnalysis(JSContext* cx = nullptr)
1076 : AutoAssertNoGC(cx) {}
1077 } JS_HAZ_GC_SUPPRESSED;
1078 #else
1079 class JS_PUBLIC_API AutoSuppressGCAnalysis : public AutoRequireNoGC {
1080 public:
1081 explicit AutoSuppressGCAnalysis(JSContext* cx = nullptr) {}
1082 } JS_HAZ_GC_SUPPRESSED;
1083 #endif
1086 * Assert that code is only ever called from a GC callback, disable the static
1087 * rooting hazard analysis and assert if any allocation that could potentially
1088 * trigger a GC occurs while this guard object is live.
1090 * This is useful to make the static analysis ignore code that runs in GC
1091 * callbacks.
1093 class JS_PUBLIC_API AutoAssertGCCallback : public AutoSuppressGCAnalysis {
1094 public:
1095 #ifdef DEBUG
1096 AutoAssertGCCallback();
1097 #else
1098 AutoAssertGCCallback() {}
1099 #endif
1103 * Place AutoCheckCannotGC in scopes that you believe can never GC. These
1104 * annotations will be verified both dynamically via AutoAssertNoGC, and
1105 * statically with the rooting hazard analysis (implemented by making the
1106 * analysis consider AutoCheckCannotGC to be a GC pointer, and therefore
1107 * complain if it is live across a GC call.) It is useful when dealing with
1108 * internal pointers to GC things where the GC thing itself may not be present
1109 * for the static analysis: e.g. acquiring inline chars from a JSString* on the
1110 * heap.
1112 * We only do the assertion checking in DEBUG builds.
1114 #ifdef DEBUG
1115 class JS_PUBLIC_API AutoCheckCannotGC : public AutoAssertNoGC {
1116 public:
1117 explicit AutoCheckCannotGC(JSContext* cx = nullptr) : AutoAssertNoGC(cx) {}
1118 # ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
1119 AutoCheckCannotGC(const AutoCheckCannotGC& other)
1120 : AutoCheckCannotGC(other.cx_) {}
1121 # else
1122 AutoCheckCannotGC(const AutoCheckCannotGC& other) : AutoCheckCannotGC() {}
1123 # endif
1124 AutoCheckCannotGC(AutoCheckCannotGC&& other)
1125 : AutoAssertNoGC(std::forward<AutoAssertNoGC>(other)) {}
1126 #else
1127 class JS_PUBLIC_API AutoCheckCannotGC : public AutoRequireNoGC {
1128 public:
1129 explicit AutoCheckCannotGC(JSContext* cx = nullptr) {}
1130 AutoCheckCannotGC(const AutoCheckCannotGC& other) : AutoCheckCannotGC() {}
1131 AutoCheckCannotGC(AutoCheckCannotGC&& other) : AutoCheckCannotGC() {}
1132 void reset() {}
1133 #endif
1134 } JS_HAZ_GC_INVALIDATED JS_HAZ_GC_REF;
1136 extern JS_PUBLIC_API void SetLowMemoryState(JSContext* cx, bool newState);
1139 * Internal to Firefox.
1141 extern JS_PUBLIC_API void NotifyGCRootsRemoved(JSContext* cx);
1143 } /* namespace JS */
1145 typedef void (*JSGCCallback)(JSContext* cx, JSGCStatus status,
1146 JS::GCReason reason, void* data);
1149 * Register externally maintained GC roots.
1151 * traceOp: the trace operation. For each root the implementation should call
1152 * JS::TraceEdge whenever the root contains a traceable thing.
1153 * data: the data argument to pass to each invocation of traceOp.
1155 extern JS_PUBLIC_API bool JS_AddExtraGCRootsTracer(JSContext* cx,
1156 JSTraceDataOp traceOp,
1157 void* data);
1159 /** Undo a call to JS_AddExtraGCRootsTracer. */
1160 extern JS_PUBLIC_API void JS_RemoveExtraGCRootsTracer(JSContext* cx,
1161 JSTraceDataOp traceOp,
1162 void* data);
1164 extern JS_PUBLIC_API void JS_GC(JSContext* cx,
1165 JS::GCReason reason = JS::GCReason::API);
1167 extern JS_PUBLIC_API void JS_MaybeGC(JSContext* cx);
1169 extern JS_PUBLIC_API void JS_SetGCCallback(JSContext* cx, JSGCCallback cb,
1170 void* data);
1172 extern JS_PUBLIC_API void JS_SetObjectsTenuredCallback(
1173 JSContext* cx, JSObjectsTenuredCallback cb, void* data);
1175 extern JS_PUBLIC_API bool JS_AddFinalizeCallback(JSContext* cx,
1176 JSFinalizeCallback cb,
1177 void* data);
1179 extern JS_PUBLIC_API void JS_RemoveFinalizeCallback(JSContext* cx,
1180 JSFinalizeCallback cb);
1183 * Weak pointers and garbage collection
1185 * Weak pointers are by their nature not marked as part of garbage collection,
1186 * but they may need to be updated in two cases after a GC:
1188 * 1) Their referent was found not to be live and is about to be finalized
1189 * 2) Their referent has been moved by a compacting GC
1191 * To handle this, any part of the system that maintain weak pointers to
1192 * JavaScript GC things must register a callback with
1193 * JS_(Add,Remove)WeakPointer{ZoneGroup,Compartment}Callback(). This callback
1194 * must then call JS_UpdateWeakPointerAfterGC() on all weak pointers it knows
1195 * about.
1197 * Since sweeping is incremental, we have several callbacks to avoid repeatedly
1198 * having to visit all embedder structures. The WeakPointerZonesCallback is
1199 * called once for each strongly connected group of zones, whereas the
1200 * WeakPointerCompartmentCallback is called once for each compartment that is
1201 * visited while sweeping. Structures that cannot contain references in more
1202 * than one compartment should sweep the relevant per-compartment structures
1203 * using the latter callback to minimizer per-slice overhead.
1205 * The argument to JS_UpdateWeakPointerAfterGC() is an in-out param. If the
1206 * referent is about to be finalized the pointer will be set to null. If the
1207 * referent has been moved then the pointer will be updated to point to the new
1208 * location.
1210 * The return value of JS_UpdateWeakPointerAfterGC() indicates whether the
1211 * referent is still alive. If the referent is is about to be finalized, this
1212 * will return false.
1214 * Callers of this method are responsible for updating any state that is
1215 * dependent on the object's address. For example, if the object's address is
1216 * used as a key in a hashtable, then the object must be removed and
1217 * re-inserted with the correct hash.
1220 extern JS_PUBLIC_API bool JS_AddWeakPointerZonesCallback(
1221 JSContext* cx, JSWeakPointerZonesCallback cb, void* data);
1223 extern JS_PUBLIC_API void JS_RemoveWeakPointerZonesCallback(
1224 JSContext* cx, JSWeakPointerZonesCallback cb);
1226 extern JS_PUBLIC_API bool JS_AddWeakPointerCompartmentCallback(
1227 JSContext* cx, JSWeakPointerCompartmentCallback cb, void* data);
1229 extern JS_PUBLIC_API void JS_RemoveWeakPointerCompartmentCallback(
1230 JSContext* cx, JSWeakPointerCompartmentCallback cb);
1232 namespace JS {
1233 template <typename T>
1234 class Heap;
1237 extern JS_PUBLIC_API bool JS_UpdateWeakPointerAfterGC(
1238 JSTracer* trc, JS::Heap<JSObject*>* objp);
1240 extern JS_PUBLIC_API bool JS_UpdateWeakPointerAfterGCUnbarriered(
1241 JSTracer* trc, JSObject** objp);
1243 extern JS_PUBLIC_API void JS_SetGCParameter(JSContext* cx, JSGCParamKey key,
1244 uint32_t value);
1246 extern JS_PUBLIC_API void JS_ResetGCParameter(JSContext* cx, JSGCParamKey key);
1248 extern JS_PUBLIC_API uint32_t JS_GetGCParameter(JSContext* cx,
1249 JSGCParamKey key);
1251 extern JS_PUBLIC_API void JS_SetGCParametersBasedOnAvailableMemory(
1252 JSContext* cx, uint32_t availMemMB);
1255 * Create a new JSString whose chars member refers to external memory, i.e.,
1256 * memory requiring application-specific finalization.
1258 extern JS_PUBLIC_API JSString* JS_NewExternalStringLatin1(
1259 JSContext* cx, const JS::Latin1Char* chars, size_t length,
1260 const JSExternalStringCallbacks* callbacks);
1261 extern JS_PUBLIC_API JSString* JS_NewExternalUCString(
1262 JSContext* cx, const char16_t* chars, size_t length,
1263 const JSExternalStringCallbacks* callbacks);
1266 * Create a new JSString whose chars member may refer to external memory.
1267 * If a new external string is allocated, |*allocatedExternal| is set to true.
1268 * Otherwise the returned string is either not an external string or an
1269 * external string allocated by a previous call and |*allocatedExternal| is set
1270 * to false. If |*allocatedExternal| is false, |fin| won't be called.
1272 extern JS_PUBLIC_API JSString* JS_NewMaybeExternalStringLatin1(
1273 JSContext* cx, const JS::Latin1Char* chars, size_t length,
1274 const JSExternalStringCallbacks* callbacks, bool* allocatedExternal);
1275 extern JS_PUBLIC_API JSString* JS_NewMaybeExternalUCString(
1276 JSContext* cx, const char16_t* chars, size_t length,
1277 const JSExternalStringCallbacks* callbacks, bool* allocatedExternal);
1280 * Similar to JS_NewMaybeExternalStringLatin1.
1282 * Create an external Latin1 string if the utf8 buffer contains only ASCII
1283 * chars, otherwise copy the chars into a non-external string.
1285 extern JS_PUBLIC_API JSString* JS_NewMaybeExternalStringUTF8(
1286 JSContext* cx, const JS::UTF8Chars& utf8,
1287 const JSExternalStringCallbacks* callbacks, bool* allocatedExternal);
1290 * Return the 'callbacks' arg passed to JS_NewExternalStringLatin1,
1291 * JS_NewExternalUCString, JS_NewMaybeExternalStringLatin1,
1292 * or JS_NewMaybeExternalUCString.
1294 extern JS_PUBLIC_API const JSExternalStringCallbacks*
1295 JS_GetExternalStringCallbacks(JSString* str);
1297 namespace JS {
1300 * Check whether the nursery should be eagerly collected, this is before it is
1301 * full.
1303 * The idea is that this can be called when the host environment has some idle
1304 * time which it can use to for GC activity.
1306 * Returns GCReason::NO_REASON to indicate no collection is desired.
1308 extern JS_PUBLIC_API GCReason WantEagerMinorGC(JSRuntime* rt);
1310 extern JS_PUBLIC_API GCReason WantEagerMajorGC(JSRuntime* rt);
1313 * Check whether the nursery should be eagerly collected as per WantEagerMajorGC
1314 * above, and if so run a collection.
1316 * The idea is that this can be called when the host environment has some idle
1317 * time which it can use to for GC activity.
1319 extern JS_PUBLIC_API void MaybeRunNurseryCollection(JSRuntime* rt,
1320 JS::GCReason reason);
1322 extern JS_PUBLIC_API void RunNurseryCollection(
1323 JSRuntime* rt, JS::GCReason reason,
1324 mozilla::TimeDuration aSinceLastMinorGC);
1326 extern JS_PUBLIC_API void SetHostCleanupFinalizationRegistryCallback(
1327 JSContext* cx, JSHostCleanupFinalizationRegistryCallback cb, void* data);
1330 * Clear kept alive objects in JS WeakRef.
1331 * https://tc39.es/proposal-weakrefs/#sec-clear-kept-objects
1333 extern JS_PUBLIC_API void ClearKeptObjects(JSContext* cx);
1335 inline JS_PUBLIC_API bool NeedGrayRootsForZone(Zone* zoneArg) {
1336 shadow::Zone* zone = shadow::Zone::from(zoneArg);
1337 return zone->isGCMarkingBlackAndGray() || zone->isGCCompacting();
1340 extern JS_PUBLIC_API bool AtomsZoneIsCollecting(JSRuntime* runtime);
1341 extern JS_PUBLIC_API bool IsAtomsZone(Zone* zone);
1343 } // namespace JS
1345 namespace js {
1346 namespace gc {
1349 * Create an object providing access to the garbage collector's internal notion
1350 * of the current state of memory (both GC heap memory and GCthing-controlled
1351 * malloc memory.
1353 extern JS_PUBLIC_API JSObject* NewMemoryInfoObject(JSContext* cx);
1356 * Return whether |obj| is a dead nursery object during a minor GC.
1358 JS_PUBLIC_API bool IsDeadNurseryObject(JSObject* obj);
1361 * Run the finalizer of a nursery-allocated JSObject that is known to be dead.
1363 * This is a dangerous operation - only use this if you know what you're doing!
1365 * This is used by the browser to implement nursery-allocated wrapper cached
1366 * wrappers.
1368 extern JS_PUBLIC_API void FinalizeDeadNurseryObject(JSContext* cx,
1369 JSObject* obj);
1371 } /* namespace gc */
1372 } /* namespace js */
1374 #ifdef JS_GC_ZEAL
1376 # define JS_DEFAULT_ZEAL_FREQ 100
1378 extern JS_PUBLIC_API void JS_GetGCZealBits(JSContext* cx, uint32_t* zealBits,
1379 uint32_t* frequency,
1380 uint32_t* nextScheduled);
1382 extern JS_PUBLIC_API void JS_SetGCZeal(JSContext* cx, uint8_t zeal,
1383 uint32_t frequency);
1385 extern JS_PUBLIC_API void JS_UnsetGCZeal(JSContext* cx, uint8_t zeal);
1387 extern JS_PUBLIC_API void JS_ScheduleGC(JSContext* cx, uint32_t count);
1389 #endif
1391 #endif /* js_GCAPI_h */