8#define DUK__BITPACK_LETTER_LIMIT 26
9#define DUK__BITPACK_UNDERSCORE 26
10#define DUK__BITPACK_FF 27
11#define DUK__BITPACK_SWITCH1 29
12#define DUK__BITPACK_SWITCH 30
13#define DUK__BITPACK_SEVENBIT 31
15#if defined(DUK_USE_ROM_STRINGS)
17#define DUK__FIXED_HASH_SEED 0xabcd1234
78#if defined(DUK_USE_HSTRING_EXTDATA) && defined(DUK_USE_EXTSTR_FREE)
141#if defined(DUK_USE_REFERENCE_COUNTING)
157#if defined(DUK_USE_MARK_AND_SWEEP)
189#if defined(DUK_USE_REFERENCE_COUNTING)
192#if defined(DUK_USE_MARK_AND_SWEEP)
210 for (round_no = 0; ; round_no++) {
251 curr_limit = count_all * 2;
253 curr_limit = (curr_limit * 3) / 4;
255 DUK_D(
DUK_DPRINT(
"finalizer round %ld complete, %ld objects, tried to execute %ld finalizers, current limit is %ld",
256 (
long) round_no, (
long) count_all, (
long) count_finalized, (
long) curr_limit));
258 if (count_finalized == 0) {
259 DUK_D(
DUK_DPRINT(
"no more finalizable objects, forced finalization finished"));
262 if (count_finalized >= curr_limit) {
263 DUK_D(
DUK_DPRINT(
"finalizer count above limit, potentially runaway finalizer; skip remaining finalizers"));
275#if defined(DUK_USE_DEBUG)
276 duk_heap_dump_strtab(heap);
279#if defined(DUK_USE_DEBUGGER_SUPPORT)
286 duk_debug_do_detach(heap);
299#if defined(DUK_USE_MARK_AND_SWEEP)
312 DUK_D(
DUK_DPRINT(
"forced gc #3 in heap destruction (don't run finalizers)"));
326#if defined(DUK_USE_REFERENCE_COUNTING)
331#if defined(DUK_USE_MARK_AND_SWEEP)
332 DUK_D(
DUK_DPRINT(
"freeing mark-and-sweep finalize list of heap: %p", (
void *) heap));
350#if defined(DUK_USE_ROM_STRINGS)
352#if defined(DUK_USE_ASSERTIONS)
360#if defined(DUK_USE_ASSERTIONS)
361 for (i = 0; i <
sizeof(duk_rom_strings) /
sizeof(
const duk_hstring *); i++) {
364 h = duk_rom_strings[i];
393 for (j = 0; j < len; j++) {
418 tmp[j] = (duk_uint8_t) t;
454#if defined(DUK_USE_HEAPPTR16)
455 heap->strs16[i] = DUK_USE_HEAPPTR_ENC16(heap->
heap_udata, (
void *) h);
481#if defined(DUK_USE_ROM_STRINGS)
484#if defined(DUK_USE_HEAPPTR16)
485 thr->strs16 = heap->strs16;
509#if defined(DUK_USE_DEBUG)
510#define DUK__DUMPSZ(t) do { \
511 DUK_D(DUK_DPRINT("" #t "=%ld", (long) sizeof(t))); \
519#define DUK__DUMPLM_SIGNED_RAW(t,a,b) do { \
520 DUK_D(DUK_DPRINT(t "=[%ld,%ld]=[%lf,%lf]", \
521 (long) (a), (long) (b), \
522 (double) (a), (double) (b))); \
524#define DUK__DUMPLM_UNSIGNED_RAW(t,a,b) do { \
525 DUK_D(DUK_DPRINT(t "=[%lu,%lu]=[%lf,%lf]", \
526 (unsigned long) (a), (unsigned long) (b), \
527 (double) (a), (double) (b))); \
529#define DUK__DUMPLM_SIGNED(t) do { \
530 DUK__DUMPLM_SIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \
532#define DUK__DUMPLM_UNSIGNED(t) do { \
533 DUK__DUMPLM_UNSIGNED_RAW("DUK_" #t "_{MIN,MAX}", DUK_##t##_MIN, DUK_##t##_MAX); \
536DUK_LOCAL void duk__dump_type_sizes(
void) {
549 DUK__DUMPSZ(duk_uint8_t);
550 DUK__DUMPSZ(duk_int8_t);
551 DUK__DUMPSZ(duk_uint16_t);
552 DUK__DUMPSZ(duk_int16_t);
553 DUK__DUMPSZ(duk_uint32_t);
554 DUK__DUMPSZ(duk_int32_t);
555 DUK__DUMPSZ(duk_uint64_t);
556 DUK__DUMPSZ(duk_int64_t);
563#if defined(DUK_USE_64BIT_OPS)
564 DUK__DUMPSZ(duk_uint_least64_t);
565 DUK__DUMPSZ(duk_int_least64_t);
573#if defined(DUK_USE_64BIT_OPS)
574 DUK__DUMPSZ(duk_uint_fast64_t);
575 DUK__DUMPSZ(duk_int_fast64_t);
577 DUK__DUMPSZ(duk_uintptr_t);
578 DUK__DUMPSZ(duk_intptr_t);
622#if defined(DUK_USE_STRTAB_CHAIN)
629 DUK__DUMPSZ(duk_fixedbuffer);
642DUK_LOCAL void duk__dump_type_limits(
void) {
646 DUK__DUMPLM_SIGNED(INT8);
647 DUK__DUMPLM_UNSIGNED(UINT8);
648 DUK__DUMPLM_SIGNED(INT_FAST8);
649 DUK__DUMPLM_UNSIGNED(UINT_FAST8);
650 DUK__DUMPLM_SIGNED(INT_LEAST8);
651 DUK__DUMPLM_UNSIGNED(UINT_LEAST8);
652 DUK__DUMPLM_SIGNED(INT16);
653 DUK__DUMPLM_UNSIGNED(UINT16);
654 DUK__DUMPLM_SIGNED(INT_FAST16);
655 DUK__DUMPLM_UNSIGNED(UINT_FAST16);
656 DUK__DUMPLM_SIGNED(INT_LEAST16);
657 DUK__DUMPLM_UNSIGNED(UINT_LEAST16);
658 DUK__DUMPLM_SIGNED(INT32);
659 DUK__DUMPLM_UNSIGNED(UINT32);
660 DUK__DUMPLM_SIGNED(INT_FAST32);
661 DUK__DUMPLM_UNSIGNED(UINT_FAST32);
662 DUK__DUMPLM_SIGNED(INT_LEAST32);
663 DUK__DUMPLM_UNSIGNED(UINT_LEAST32);
664#if defined(DUK_USE_64BIT_OPS)
665 DUK__DUMPLM_SIGNED(INT64);
666 DUK__DUMPLM_UNSIGNED(UINT64);
667 DUK__DUMPLM_SIGNED(INT_FAST64);
668 DUK__DUMPLM_UNSIGNED(UINT_FAST64);
669 DUK__DUMPLM_SIGNED(INT_LEAST64);
670 DUK__DUMPLM_UNSIGNED(UINT_LEAST64);
672 DUK__DUMPLM_SIGNED(INTPTR);
673 DUK__DUMPLM_UNSIGNED(UINTPTR);
674 DUK__DUMPLM_SIGNED(INTMAX);
675 DUK__DUMPLM_UNSIGNED(UINTMAX);
678 DUK__DUMPLM_SIGNED(INT);
679 DUK__DUMPLM_UNSIGNED(UINT);
680 DUK__DUMPLM_SIGNED(INT_FAST);
681 DUK__DUMPLM_UNSIGNED(UINT_FAST);
682 DUK__DUMPLM_SIGNED(SMALL_INT);
683 DUK__DUMPLM_UNSIGNED(SMALL_UINT);
684 DUK__DUMPLM_SIGNED(SMALL_INT_FAST);
685 DUK__DUMPLM_UNSIGNED(SMALL_UINT_FAST);
688#undef DUK__DUMPLM_SIGNED_RAW
689#undef DUK__DUMPLM_UNSIGNED_RAW
690#undef DUK__DUMPLM_SIGNED
691#undef DUK__DUMPLM_UNSIGNED
693DUK_LOCAL void duk__dump_misc_options(
void) {
699#if defined(DUK_USE_PACKED_TVAL)
704#if defined(DUK_USE_VARIADIC_MACROS)
709#if defined(DUK_USE_INTEGER_LE)
711#elif defined(DUK_USE_INTEGER_ME)
713#elif defined(DUK_USE_INTEGER_BE)
718#if defined(DUK_USE_DOUBLE_LE)
720#elif defined(DUK_USE_DOUBLE_ME)
722#elif defined(DUK_USE_DOUBLE_BE)
747#if defined(DUK_USE_DEBUG)
748 duk__dump_misc_options();
749 duk__dump_type_sizes();
750 duk__dump_type_limits();
756#if defined(DUK_USE_SELF_TESTS)
758 duk_selftest_run_tests();
766#if defined(DUK_USE_COMPUTED_NAN)
776 volatile double dbl1 = 0.0;
777 volatile double dbl2 = 0.0;
778 duk_computed_nan = dbl1 / dbl2;
782#if defined(DUK_USE_COMPUTED_INFINITY)
785 volatile double dbl1 = 1.0;
786 volatile double dbl2 = 0.0;
787 duk_computed_infinity = dbl1 / dbl2;
809#if defined(DUK_USE_EXPLICIT_NULL_INIT)
812#if defined(DUK_USE_REFERENCE_COUNTING)
816#if defined(DUK_USE_MARK_AND_SWEEP)
822#if defined(DUK_USE_STRTAB_CHAIN)
824#elif defined(DUK_USE_STRTAB_PROBE)
825#if defined(DUK_USE_HEAPPTR16)
826 res->strtable16 = (duk_uint16_t *)
NULL;
831#if defined(DUK_USE_ROM_STRINGS)
834#if defined(DUK_USE_HEAPPTR16)
845#if defined(DUK_USE_DEBUGGER_SUPPORT)
846 res->dbg_read_cb =
NULL;
847 res->dbg_write_cb =
NULL;
848 res->dbg_peek_cb =
NULL;
849 res->dbg_read_flush_cb =
NULL;
850 res->dbg_write_flush_cb =
NULL;
851 res->dbg_request_cb =
NULL;
852 res->dbg_udata =
NULL;
853 res->dbg_step_thread =
NULL;
863#if defined(DUK_USE_HEAPPTR16)
865 res->heapptr_null16 = DUK_USE_HEAPPTR_ENC16(res->
heap_udata, (
void *)
NULL);
882#if defined(DUK_USE_ROM_STRINGS)
884 DUK_D(
DUK_DPRINT(
"using rom strings, force heap hash_seed to fixed value 0x%08lx", (
long) DUK__FIXED_HASH_SEED));
885 res->
hash_seed = (duk_uint32_t) DUK__FIXED_HASH_SEED;
887 res->
hash_seed = (duk_uint32_t) (duk_intptr_t) res;
888 res->
rnd_state = (duk_uint32_t) (duk_intptr_t) res;
889#if !defined(DUK_USE_STRHASH_DENSE)
894#if defined(DUK_USE_EXPLICIT_NULL_INIT)
902#if (DUK_STRTAB_INITIAL_SIZE < DUK_UTIL_MIN_HASH_PRIME)
903#error initial heap stringtable size is defined incorrectly
910#if defined(DUK_USE_STRTAB_CHAIN)
912#if defined(DUK_USE_EXPLICIT_NULL_INIT)
916#if defined(DUK_USE_HEAPPTR16)
917 res->
strtable[i].u.str16 = res->heapptr_null16;
930#if defined(DUK_USE_STRTAB_PROBE)
931#if defined(DUK_USE_HEAPPTR16)
933 if (!res->strtable16) {
943#if defined(DUK_USE_EXPLICIT_NULL_INIT)
948#if defined(DUK_USE_HEAPPTR16)
949 res->strtable16[i] = res->heapptr_null16;
956#if defined(DUK_USE_HEAPPTR16)
968#if defined(DUK_USE_EXPLICIT_NULL_INIT)
1036#undef DUK__BITPACK_LETTER_LIMIT
1037#undef DUK__BITPACK_UNDERSCORE
1038#undef DUK__BITPACK_FF
1039#undef DUK__BITPACK_SWITCH1
1040#undef DUK__BITPACK_SWITCH
1041#undef DUK__BITPACK_SEVENBIT
1042#undef DUK__FIXED_HASH_SEED
duk_uint16_t duk_uint_least16_t
#define DUK_UNREACHABLE()
duk_int32_t duk_int_fast32_t
unsigned int duk_small_uint_t
duk_uint32_t duk_uint_least32_t
duk_uint_t duk_ucodepoint_t
duk_uint_fast32_t duk_uint_fast_t
duk_int_fast32_t duk_int_fast_t
duk_int8_t duk_int_least8_t
#define DUK_USE_ARCH_STRING
duk_uint_fast16_t duk_small_uint_fast_t
#define DUK_USE_OS_STRING
#define DUK_USE_NATIVE_CALL_RECLIMIT
duk_uint8_t duk_uint_fast8_t
duk_int_t duk_codepoint_t
#define DUK_USE_COMPILER_STRING
duk_int_fast32_t duk_int_t
duk_int8_t duk_int_fast8_t
duk_int_fast16_t duk_small_int_fast_t
duk_int32_t duk_int_least32_t
duk_int16_t duk_int_fast16_t
duk_uint8_t duk_uint_least8_t
duk_uint_fast32_t duk_uint_t
duk_int16_t duk_int_least16_t
duk_uint32_t duk_uintmax_t
#define DUK_MEMZERO(p, n)
duk_small_int_t duk_bool_t
duk_uint32_t duk_uint_fast32_t
duk_uint16_t duk_uint_fast16_t
#define DUK_HEAP_HAS_FINALIZER_NORESCUE(heap)
DUK_INTERNAL const char * duk_str_unsupported
#define DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, x)
#define DUK_STRTAB_DELETED_MARKER(heap)
#define DUK_HSTRING_GET_DATA(x)
#define DUK_HEAPHDR_GET_TYPE(h)
#define DUK_HEAP_SET_FINALIZER_NORESCUE(heap)
#define DUK_STRIDX_LC_ARGUMENTS
#define DUK_STRDATA_MAX_STRLEN
#define DUK_HEAP_SET_MARKANDSWEEP_RUNNING(heap)
#define DUK_HOBJECT_GET_PROPS(heap, h)
#define DUK_HEAP_NUM_STRINGS
#define DUK_HOBJECT_CLASS_OBJECT
DUK_INTERNAL const duk_uint8_t duk_strings_data[1049]
#define DUK_STRIDX_START_RESERVED
#define DUK_HOBJECT_IS_COMPILEDFUNCTION(h)
#define DUK_HEAP_CLEAR_MARKANDSWEEP_RUNNING(heap)
#define DUK_STRDATA_DATA_LENGTH
DUK_INTERNAL_DECL void duk_hthread_create_builtin_objects(duk_hthread *thr)
#define DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, h, p)
#define DUK_HSTRING_GET_HASH(x)
#define DUK_FREE(heap, ptr)
#define DUK_ASSERT_DISABLE(x)
DUK_INTERNAL_DECL duk_hthread * duk_hthread_alloc(duk_heap *heap, duk_uint_t hobject_flags)
#define DUK_HOBJECT_CLASS_AS_FLAGS(v)
DUK_INTERNAL_DECL duk_hstring * duk_heap_string_intern(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen)
#define DUK_HSTRING_SET_EVAL_OR_ARGUMENTS(x)
#define DUK_HSTRING_HAS_EXTDATA(x)
#define DUK_HTHREAD_STATE_INACTIVE
#define DUK_HOBJECT_IS_THREAD(h)
#define DUK_LJ_TYPE_UNKNOWN
#define DUK_HSTRING_INCREF(thr, h)
#define DUK_HOBJECT_IS_NATIVEFUNCTION(h)
#define DUK_HTHREAD_INCREF(thr, h)
DUK_INTERNAL_DECL duk_bool_t duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags)
#define DUK_HEAPHDR_HAS_READONLY(h)
#define DUK_HSTRING_GET_BYTELEN(x)
DUK_INTERNAL_DECL duk_bool_t duk_hthread_init_stacks(duk_heap *heap, duk_hthread *thr)
#define DUK_STRTAB_CHAIN_SIZE
DUK_INTERNAL_DECL duk_bool_t duk_hobject_hasprop_raw(duk_hthread *thr, duk_hobject *obj, duk_hstring *key)
#define DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap)
#define DUK_STRTAB_INITIAL_SIZE
#define DUK_HOBJECT_CLASS_THREAD
#define DUK_STRIDX_START_STRICT_RESERVED
#define DUK_HSTRING_SET_STRICT_RESERVED_WORD(x)
#define DUK_HOBJECT_FLAG_THREAD
#define DUK_HEAPHDR_HAS_FINALIZED(h)
#define DUK_HSTRING_SET_RESERVED_WORD(x)
#define DUK_BIDX_THREAD_PROTOTYPE
#define DUK_HEAP_STRCACHE_SIZE
#define DUK_HOBJECT_FLAG_EXTENSIBLE
DUK_INTERNAL_DECL duk_uint32_t duk_heap_hashstring(duk_heap *heap, const duk_uint8_t *str, duk_size_t len)
#define DUK_HOBJECT_INCREF(thr, h)
#define DUK_STRIDX_END_RESERVED
DUK_INTERNAL void duk_heap_free_strtab(duk_heap *heap)
#define DUK_ASC_UNDERSCORE
#define DUK_TVAL_SET_UNDEFINED(tv)
#define DUK_HTHREAD_STRING_INT_FINALIZER(thr)
#define DUK_HEAPHDR_GET_NEXT(heap, h)
#define DUK_HBUFFER_HAS_EXTERNAL(x)
#define DUK_HBUFFER_HAS_DYNAMIC(x)
DUK_INTERNAL_DECL void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj)
DUK_INTERNAL_DECL duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits)
#define DUK_MS_FLAG_SKIP_FINALIZERS
DUK_INTERNAL_DECL duk_hobject * duk_hobject_alloc(duk_heap *heap, duk_uint_t hobject_flags)
void *(* duk_alloc_function)(void *udata, duk_size_t size)
void(* duk_fatal_function)(duk_context *ctx, duk_errcode_t code, const char *msg)
void(* duk_free_function)(void *udata, void *ptr)
void *(* duk_realloc_function)(void *udata, void *ptr, duk_size_t size)
DUK_INTERNAL void duk_heap_free(duk_heap *heap)
DUK_LOCAL void duk__free_run_finalizers(duk_heap *heap)
DUK_INTERNAL void duk_free_hobject_inner(duk_heap *heap, duk_hobject *h)
DUK_LOCAL void duk__free_stringtable(duk_heap *heap)
DUK_INTERNAL void duk_free_hstring_inner(duk_heap *heap, duk_hstring *h)
DUK_LOCAL duk_bool_t duk__init_heap_thread(duk_heap *heap)
DUK_LOCAL void duk__free_markandsweep_finalize_list(duk_heap *heap)
#define DUK__BITPACK_UNDERSCORE
DUK_LOCAL void duk__free_refzero_list(duk_heap *heap)
#define DUK__BITPACK_SWITCH
#define DUK__BITPACK_SEVENBIT
#define DUK__BITPACK_LETTER_LIMIT
DUK_LOCAL void duk__free_allocated(duk_heap *heap)
DUK_INTERNAL void duk_free_hbuffer_inner(duk_heap *heap, duk_hbuffer *h)
#define DUK__BITPACK_SWITCH1
DUK_LOCAL duk_bool_t duk__init_heap_strings(duk_heap *heap)
DUK_INTERNAL duk_heap * duk_heap_alloc(duk_alloc_function alloc_func, duk_realloc_function realloc_func, duk_free_function free_func, void *heap_udata, duk_fatal_function fatal_func)
DUK_INTERNAL void duk_heap_free_heaphdr_raw(duk_heap *heap, duk_heaphdr *hdr)
static void error(LoadState *S, const char *why)
duk_heaphdr * finalize_list
duk_heaphdr * refzero_list
duk_int_t call_recursion_limit
duk_hthread * curr_thread
duk_strcache strcache[DUK_HEAP_STRCACHE_SIZE]
duk_hthread * heap_thread
duk_fatal_function fatal_func
duk_realloc_function realloc_func
duk_hobject * heap_object
duk_free_function free_func
duk_hstring * strs[DUK_HEAP_NUM_STRINGS]
duk_int_t call_recursion_depth
duk_heaphdr * refzero_list_tail
duk_alloc_function alloc_func
duk_heaphdr * heap_allocated
duk_hobject * builtins[DUK_NUM_BUILTINS]
duk_activation * callstack