diff --git a/src-input/duk_heap.h b/src-input/duk_heap.h index f619895f..d0c71c2e 100644 --- a/src-input/duk_heap.h +++ b/src-input/duk_heap.h @@ -131,6 +131,13 @@ #define DUK_HEAP_MARK_AND_SWEEP_TRIGGER_SKIP 256L #endif +/* GC torture. */ +#if defined(DUK_USE_GC_TORTURE) +#define DUK_GC_TORTURE(heap) do { duk_heap_mark_and_sweep((heap), 0); } while (0) +#else +#define DUK_GC_TORTURE(heap) do { } while (0) +#endif + /* Stringcache is used for speeding up char-offset-to-byte-offset * translations for non-ASCII strings. */ diff --git a/src-input/duk_heap_refcount.c b/src-input/duk_heap_refcount.c index 2b40a1bd..6303566f 100644 --- a/src-input/duk_heap_refcount.c +++ b/src-input/duk_heap_refcount.c @@ -728,6 +728,11 @@ DUK_INTERNAL void duk_heaphdr_decref(duk_hthread *thr, duk_heaphdr *h) { DUK__DECREF_ASSERTS(); DUK__DECREF_SHARED(); duk_heaphdr_refzero(thr, h); + + /* Forced mark-and-sweep when GC torture enabled; this could happen + * on any DECREF (but not DECREF_NORZ). + */ + DUK_GC_TORTURE(thr->heap); } DUK_INTERNAL void duk_heaphdr_decref_norz(duk_hthread *thr, duk_heaphdr *h) { DUK__DECREF_ASSERTS(); diff --git a/src-input/duk_hobject_props.c b/src-input/duk_hobject_props.c index 70efc97a..aa8dc1af 100644 --- a/src-input/duk_hobject_props.c +++ b/src-input/duk_hobject_props.c @@ -1,5 +1,5 @@ /* - * Hobject property set/get functionality. + * duk_hobject property access functionality. * * This is very central functionality for size, performance, and compliance. * It is also rather intricate; see hobject-algorithms.rst for discussion on @@ -40,10 +40,6 @@ * might be more appropriate. */ -/* - * XXX: duk_uint_fast32_t should probably be used in many places here. - */ - #include "duk_internal.h" /* @@ -699,7 +695,7 @@ DUK_INTERNAL void duk_hobject_realloc_props(duk_hthread *thr, (void *) new_a, (void *) new_h)); /* - * Migrate array to start of entries if requested. + * Migrate array part to start of entries if requested. * * Note: from an enumeration perspective the order of entry keys matters. * Array keys should appear wherever they appeared before the array abandon diff --git a/src-input/duk_js_executor.c b/src-input/duk_js_executor.c index 2966f8bc..17e40747 100644 --- a/src-input/duk_js_executor.c +++ b/src-input/duk_js_executor.c @@ -1439,6 +1439,8 @@ duk_small_uint_t duk__handle_longjmp(duk_hthread *thr, DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value1); /* side effects */ DUK_TVAL_SET_UNDEFINED_UPDREF(thr, &thr->heap->lj.value2); /* side effects */ + DUK_GC_TORTURE(thr->heap); + just_return: return retval; @@ -2351,6 +2353,8 @@ DUK_INTERNAL void duk_js_execute_bytecode(duk_hthread *exec_thr) { DUK_ASSERT(DUK_ACT_GET_FUNC(exec_thr->callstack_curr) != NULL); DUK_ASSERT(DUK_HOBJECT_IS_COMPFUNC(DUK_ACT_GET_FUNC(exec_thr->callstack_curr))); + DUK_GC_TORTURE(exec_thr->heap); + entry_thread = exec_thr; heap = entry_thread->heap; entry_callstack_top = entry_thread->callstack_top; @@ -2481,6 +2485,8 @@ DUK_LOCAL DUK_NOINLINE DUK_HOT void duk__js_execute_bytecode_inner(duk_hthread * #endif #endif + DUK_GC_TORTURE(entry_thread->heap); + /* * Restart execution by reloading thread state. *