7#ifdef DUK_USE_MARK_AND_SWEEP
99 DUK_D(
DUK_DPRINT(
"duk_hcompiledfunction 'data' is NULL, skipping marking"));
113 while (tv < t->valstack_top) {
123#ifdef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
151#if defined(DUK_USE_ROM_OBJECTS)
165 DUK_D(
DUK_DPRINT(
"mark-and-sweep recursion limit reached, marking as temproot: %p", (
void *) h));
221#if defined(DUK_USE_DEBUGGER_SUPPORT)
222 for (i = 0; i < heap->dbg_breakpoint_count; i++) {
239#ifdef DUK_USE_REFERENCE_COUNTING
296 "finalized -> mark as finalizable "
297 "and treat as a reachability root: %p",
301 count_finalizable ++;
307 if (count_finalizable == 0) {
311 DUK_DD(
DUK_DDPRINT(
"marked %ld heap objects as finalizable, now mark them reachable",
312 (
long) count_finalizable));
344 count_finalize_list++;
349 if (count_finalize_list > 0) {
350 DUK_D(
DUK_DPRINT(
"marked %ld objects on the finalize_list as reachable (previous finalizer run skipped)",
351 (
long) count_finalize_list));
399 DUK_DD(
DUK_DDPRINT(
"recursion limit reached, doing heap scan to continue from temproots"));
417#ifdef DUK_USE_REFERENCE_COUNTING
430 DUK_DD(
DUK_DDPRINT(
"temproot mark heap scan processed %ld temp roots", (
long) count));
444#ifdef DUK_USE_REFERENCE_COUNTING
453 (
void *) heap, (
void *) thr));
468 DUK_DDD(
DUK_DDDPRINT(
"unreachable object, refcount finalize before sweeping: %p", (
void *) hdr));
481#ifdef DUK_USE_REFERENCE_COUNTING
528#if defined(DUK_USE_STRTAB_CHAIN)
531#if defined(DUK_USE_HEAPPTR16)
533 duk_uint16_t h16 = *slot;
535 duk_uint16_t null16 = heap->heapptr_null16;
548#if defined(DUK_USE_REFERENCE_COUNTING)
576#if defined(DUK_USE_REFERENCE_COUNTING)
599#if defined(DUK_USE_HEAPPTR16)
616#if defined(DUK_USE_HEAPPTR16)
617 duk__sweep_string_chain16(heap, &e->
u.str16, &count_keep, &count_free);
619 duk__sweep_string_chain(heap, &e->
u.
str, &count_keep, &count_free);
622#if defined(DUK_USE_HEAPPTR16)
623 lst = (duk_uint16_t *) DUK_USE_HEAPPTR_DEC16(heap->
heap_udata, e->
u.strlist16);
627 for (j = 0, n = e->
listlen; j < n; j++) {
628#if defined(DUK_USE_HEAPPTR16)
629 duk__sweep_string_chain16(heap, lst + j, &count_keep, &count_free);
631 duk__sweep_string_chain(heap, lst + j, &count_keep, &count_free);
637 DUK_D(
DUK_DPRINT(
"mark-and-sweep sweep stringtable: %ld freed, %ld kept",
638 (
long) count_free, (
long) count_keep));
639 *out_count_keep = count_keep;
643#if defined(DUK_USE_STRTAB_PROBE)
654 for (i = 0; i < heap->
st_size; i++) {
655#if defined(DUK_USE_HEAPPTR16)
672#if defined(DUK_USE_REFERENCE_COUNTING)
690#if defined(DUK_USE_HEAPPTR16)
691 heap->strtable16[i] = heap->heapptr_deleted16;
706 DUK_D(
DUK_DPRINT(
"mark-and-sweep sweep stringtable: %ld freed, %ld kept",
707 (
long) count_free, (
long) count_keep));
709 *out_count_keep = count_keep;
758 DUK_DDD(
DUK_DDDPRINT(
"object has finalizer, move to finalization work list: %p", (
void *) curr));
760#ifdef DUK_USE_DOUBLE_LINKED_HEAP
785 DUK_DD(
DUK_DDPRINT(
"object rescued during mark-and-sweep finalization: %p", (
void *) curr));
803#ifdef DUK_USE_DOUBLE_LINKED_HEAP
827#if defined(DUK_USE_REFERENCE_COUNTING)
865 DUK_D(
DUK_DPRINT(
"mark-and-sweep sweep objects (non-string): %ld freed, %ld kept, %ld rescued, %ld queued for finalization",
866 (
long) count_free, (
long) count_keep, (
long) count_rescue, (
long) count_finalize));
868 *out_count_keep = count_keep;
912 DUK_D(
DUK_DPRINT(
"skip finalizers flag set, queue object to heap_allocated without finalizing"));
930 DUK_D(
DUK_DPRINT(
"mark-and-sweep finalize objects: %ld finalizers called", (
long) count));
989 (*p_count_compact)++;
990 (*p_count_bytes_saved) += (
duk_size_t) (old_size - new_size);
1018#ifdef DUK_USE_REFERENCE_COUNTING
1024#ifdef DUK_USE_REFERENCE_COUNTING
1030 DUK_D(
DUK_DPRINT(
"mark-and-sweep compact objects: %ld checked, %ld compaction attempts, %ld bytes saved by compaction",
1031 (
long) count_check, (
long) count_compact, (
long) count_bytes_saved));
1039#ifdef DUK_USE_ASSERTIONS
1052#ifdef DUK_USE_REFERENCE_COUNTING
1064#ifdef DUK_USE_REFERENCE_COUNTING
1101#if defined(DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE)
1130 DUK_D(
DUK_DPRINT(
"call recursion depth reached, avoid fake mark-and-sweep torture finalizer"));
1155#ifdef DUK_USE_VOLUNTARY_GC
1173#ifdef DUK_USE_VOLUNTARY_GC
1183#if defined(DUK_USE_DEBUGGER_SUPPORT)
1184 if (DUK_HEAP_IS_PAUSED(heap)) {
1195 DUK_D(
DUK_DPRINT(
"garbage collect (mark-and-sweep) starting, requested flags: 0x%08lx, effective flags: 0x%08lx",
1204#ifdef DUK_USE_ASSERTIONS
1208 duk__assert_heaphdr_flags(heap);
1209#ifdef DUK_USE_REFERENCE_COUNTING
1213 duk__assert_valid_refcounts(heap);
1240#ifdef DUK_USE_REFERENCE_COUNTING
1265#ifdef DUK_USE_REFERENCE_COUNTING
1269#if defined(DUK_USE_STRTAB_CHAIN)
1270 duk__sweep_stringtable_chain(heap, &count_keep_str);
1271#elif defined(DUK_USE_STRTAB_PROBE)
1274#error internal error, invalid strtab options
1276#ifdef DUK_USE_REFERENCE_COUNTING
1317#if defined(DUK_USE_MS_STRINGTABLE_RESIZE)
1322 DUK_D(
DUK_DPRINT(
"stringtable resize skipped because DUK_MS_FLAG_NO_STRINGTABLE_RESIZE is set"));
1353#if defined(DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE)
1360 DUK_D(
DUK_DPRINT(
"skip mark-and-sweep torture finalizer, DUK_MS_FLAG_NO_FINALIZERS is set"));
1362 DUK_D(
DUK_DPRINT(
"skip mark-and-sweep torture finalizer, thread not yet viable"));
1365 duk__markandsweep_torture_finalizer(thr);
1370 DUK_D(
DUK_DPRINT(
"finalizer run skipped because DUK_MS_FLAG_NO_FINALIZERS is set"));
1385#ifdef DUK_USE_ASSERTIONS
1389 duk__assert_heaphdr_flags(heap);
1390#ifdef DUK_USE_REFERENCE_COUNTING
1394 duk__assert_valid_refcounts(heap);
1402#ifdef DUK_USE_VOLUNTARY_GC
1403 tmp = (count_keep_obj + count_keep_str) / 256;
1407 DUK_D(
DUK_DPRINT(
"garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, trigger reset to %ld",
1410 DUK_D(
DUK_DPRINT(
"garbage collect (mark-and-sweep) finished: %ld objects kept, %ld strings kept, no voluntary trigger",
1411 (
long) count_keep_obj, (
long) count_keep_str));
#define DUK_UNREACHABLE()
unsigned int duk_small_uint_t
duk_small_int_t duk_ret_t
#define DUK_USE_MARK_AND_SWEEP_RECLIMIT
duk_int_fast32_t duk_int_t
duk_small_int_t duk_bool_t
duk_uint32_t duk_uint_fast32_t
#define DUK_MS_FLAG_EMERGENCY
#define DUK_HEAPHDR_CLEAR_FINALIZED(h)
#define DUK_MS_FLAG_NO_OBJECT_COMPACTION
#define DUK_STRTAB_DELETED_MARKER(heap)
#define DUK_HEAPHDR_SET_REACHABLE(h)
#define DUK_HOBJECT_A_GET_VALUE_PTR(heap, h, i)
#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_BASE(heap, h)
#define DUK_HEAPHDR_SET_TEMPROOT(h)
#define DUK_HEAP_HAS_MARKANDSWEEP_RECLIMIT_REACHED(heap)
#define DUK_HEAPHDR_GET_TYPE(h)
#define DUK_HOBJECT_GET_PROTOTYPE(heap, h)
#define DUK_HEAP_CLEAR_MARKANDSWEEP_RECLIMIT_REACHED(heap)
#define DUK_HOBJECT_P_COMPUTE_SIZE(n_ent, n_arr, n_hash)
#define DUK_HEAPHDR_SET_NEXT(heap, h, val)
#define DUK_HEAP_SET_MARKANDSWEEP_RUNNING(heap)
#define DUK_HOBJECT_GET_ENEXT(h)
#define DUK_HEAP_NUM_STRINGS
#define DUK_HEAPHDR_SET_PREV(heap, h, val)
#define DUK_HEAPHDR_SET_FINALIZABLE(h)
#define DUK_HOBJECT_IS_COMPILEDFUNCTION(h)
#define DUK_HEAPHDR_CLEAR_FINALIZABLE(h)
#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, hdr)
#define DUK_HEAP_CLEAR_MARKANDSWEEP_RUNNING(heap)
DUK_EXTERNAL void duk_require_stack(duk_context *ctx, duk_idx_t extra)
#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_BASE(heap, h)
#define DUK_HOBJECT_E_GET_KEY(heap, h, i)
#define DUK_HOBJECT_GET_ASIZE(h)
DUK_INTERNAL_DECL void duk_hobject_compact_props(duk_hthread *thr, duk_hobject *obj)
#define DUK_FREE(heap, ptr)
#define DUK_HEAPHDR_HAS_TEMPROOT(h)
DUK_INTERNAL_DECL void duk_free_hstring_inner(duk_heap *heap, duk_hstring *h)
DUK_EXTERNAL duk_idx_t duk_push_c_function(duk_context *ctx, duk_c_function func, duk_int_t nargs)
#define DUK_MS_FLAG_NO_FINALIZERS
#define DUK_HEAPHDR_HAS_REACHABLE(h)
#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD
#define DUK_HEAPHDR_GET_REFCOUNT(h)
#define DUK_HOBJECT_IS_THREAD(h)
#define DUK_HOBJECT_IS_NATIVEFUNCTION(h)
#define DUK_HCOMPILEDFUNCTION_GET_FUNCS_END(heap, h)
#define DUK_HOBJECT_GET_HSIZE(h)
#define DUK_HEAPHDR_HAS_READONLY(h)
#define DUK_HOBJECT_IS_BUFFEROBJECT(h)
#define DUK_STRTAB_CHAIN_SIZE
#define DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap)
DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key)
#define DUK_HOBJECT_E_SLOT_IS_ACCESSOR(heap, h, i)
#define DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap)
#define DUK_TVAL_IS_HEAP_ALLOCATED(tv)
#define DUK_MS_FLAG_NO_STRINGTABLE_RESIZE
#define DUK_HOBJECT_E_GET_VALUE_PTR(heap, h, i)
DUK_EXTERNAL duk_int_t duk_safe_call(duk_context *ctx, duk_safe_call_function func, duk_idx_t nargs, duk_idx_t nrets)
#define DUK_HEAPHDR_HAS_FINALIZED(h)
#define DUK_HEAP_GET_STRING(heap, idx)
DUK_INTERNAL_DECL void duk_heaphdr_refcount_finalize(duk_hthread *thr, duk_heaphdr *hdr)
#define DUK_HEAPHDR_CLEAR_REACHABLE(h)
#define DUK_HCOMPILEDFUNCTION_GET_DATA(heap, h)
#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP
#define DUK_ACT_GET_FUNC(act)
DUK_EXTERNAL void duk_pop(duk_context *ctx)
DUK_INTERNAL_DECL duk_hobject * duk_get_hobject(duk_context *ctx, duk_idx_t index)
DUK_INTERNAL_DECL void duk_push_hobject(duk_context *ctx, duk_hobject *h)
#define DUK_TVAL_GET_HEAPHDR(tv)
DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h)
#define DUK_CALLSTACK_GROW_STEP
#define DUK_HOBJECT_GET_ESIZE(h)
#define DUK_HEAPHDR_HAS_FINALIZABLE(h)
DUK_INTERNAL_DECL void duk_heap_force_strtab_resize(duk_heap *heap)
#define DUK_HTHREAD_STRING_INT_FINALIZER(thr)
#define DUK_HEAPHDR_GET_NEXT(heap, h)
#define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT
DUK_INTERNAL_DECL void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj)
DUK_EXTERNAL duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs)
#define DUK_MS_FLAG_SKIP_FINALIZERS
#define DUK_HCOMPILEDFUNCTION_GET_CONSTS_END(heap, h)
#define DUK_ASSERT_HEAPHDR_LINKS(heap, h)
DUK_INTERNAL_DECL void duk_heap_free_heaphdr_raw(duk_heap *heap, duk_heaphdr *hdr)
#define DUK_HEAPHDR_CLEAR_TEMPROOT(h)
DUK_LOCAL void duk__clear_refzero_list_flags(duk_heap *heap)
DUK_LOCAL void duk__mark_temproots_by_heap_scan(duk_heap *heap)
DUK_LOCAL_DECL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h)
DUK_LOCAL void duk__handle_temproot(duk_heap *heap, duk_heaphdr *hdr)
DUK_LOCAL void duk__mark_hstring(duk_heap *heap, duk_hstring *h)
DUK_LOCAL void duk__finalize_refcounts(duk_heap *heap)
DUK_LOCAL void duk__sweep_heap(duk_heap *heap, duk_int_t flags, duk_size_t *out_count_keep)
DUK_LOCAL int duk__protected_compact_object(duk_context *ctx)
DUK_LOCAL void duk__run_object_finalizers(duk_heap *heap, duk_small_uint_t flags)
DUK_INTERNAL duk_bool_t duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags)
DUK_LOCAL void duk__mark_roots_heap(duk_heap *heap)
DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start)
DUK_LOCAL void duk__mark_finalizable(duk_heap *heap)
DUK_LOCAL void duk__mark_finalize_list(duk_heap *heap)
DUK_LOCAL void duk__mark_refzero_list(duk_heap *heap)
DUK_LOCAL void duk__mark_hobject(duk_heap *heap, duk_hobject *h)
DUK_LOCAL_DECL void duk__mark_tval(duk_heap *heap, duk_tval *tv)
DUK_LOCAL void duk__clear_finalize_list_flags(duk_heap *heap)
DUK_LOCAL void duk__compact_objects(duk_heap *heap)
DUK_LOCAL void duk__sweep_stringtable_probe(duk_heap *heap, duk_size_t *out_count_keep)
DUK_LOCAL duk_hthread * duk__get_temp_hthread(duk_heap *heap)
duk_heaphdr * finalize_list
duk_heaphdr * refzero_list
duk_int_t call_recursion_limit
duk_int_t mark_and_sweep_trigger_counter
duk_hthread * curr_thread
duk_hthread * heap_thread
duk_int_t mark_and_sweep_recursion_depth
duk_small_uint_t mark_and_sweep_base_flags
duk_hobject * heap_object
duk_int_t call_recursion_depth
duk_heaphdr * heap_allocated
duk_hobject * builtins[DUK_NUM_BUILTINS]
duk_size_t catchstack_top
duk_size_t callstack_size
duk_activation * callstack
union duk_strtab_entry::@21 u