本文整理汇总了C++中DUK_DDPRINT函数的典型用法代码示例。如果您正苦于以下问题:C++ DUK_DDPRINT函数的具体用法?C++ DUK_DDPRINT怎么用?C++ DUK_DDPRINT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DUK_DDPRINT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: duk_bi_object_constructor_seal_freeze_shared
DUK_INTERNAL duk_ret_t duk_bi_object_constructor_seal_freeze_shared(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_hobject *h;
duk_bool_t is_freeze;
DUK_ASSERT_TOP(ctx, 1);
is_freeze = (duk_bool_t) duk_get_current_magic(ctx);
if (duk_is_buffer(ctx, 0)) {
/* Plain buffer: already sealed, but not frozen (and can't be frozen
* because index properties can't be made non-writable.
*/
if (is_freeze) {
goto fail_cannot_freeze;
}
return 1;
} else if (duk_is_lightfunc(ctx, 0)) {
/* Lightfunc: already sealed and frozen, success. */
return 1;
}
#if 0
/* Seal/freeze are quite rare in practice so it'd be nice to get the
* correct behavior simply via automatic promotion (at the cost of some
* memory churn). However, the promoted objects don't behave the same,
* e.g. promoted lightfuncs are extensible.
*/
h = duk_require_hobject_promote_mask(ctx, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER);
#endif
h = duk_get_hobject(ctx, 0);
if (h == NULL) {
/* ES2015 Sections 19.1.2.5, 19.1.2.17 */
return 1;
}
if (is_freeze && DUK_HOBJECT_IS_BUFOBJ(h)) {
/* Buffer objects cannot be frozen because there's no internal
* support for making virtual array indices non-writable.
*/
DUK_DD(DUK_DDPRINT("cannot freeze a buffer object"));
goto fail_cannot_freeze;
}
duk_hobject_object_seal_freeze_helper(thr, h, is_freeze);
/* Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
*/
duk_hobject_compact_props(thr, h);
return 1;
fail_cannot_freeze:
DUK_DCERROR_TYPE_INVALID_ARGS(thr); /* XXX: proper error message */
}
示例2: duk__mark_refzero_list
DUK_LOCAL void duk__mark_refzero_list(duk_heap *heap) {
duk_heaphdr *hdr;
DUK_DD(DUK_DDPRINT("duk__mark_refzero_list: %p", (void *) heap));
hdr = heap->refzero_list;
while (hdr) {
duk__mark_heaphdr(heap, hdr);
hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr);
}
}
示例3: duk__run_voluntary_gc
DUK_LOCAL void duk__run_voluntary_gc(duk_heap *heap) {
if (DUK_HEAP_HAS_MARKANDSWEEP_RUNNING(heap)) {
DUK_DD(DUK_DDPRINT("mark-and-sweep in progress -> skip voluntary mark-and-sweep now"));
} else {
duk_small_uint_t flags;
duk_bool_t rc;
DUK_D(DUK_DPRINT("triggering voluntary mark-and-sweep"));
flags = 0;
rc = duk_heap_mark_and_sweep(heap, flags);
DUK_UNREF(rc);
}
}
示例4: duk__refcount_fake_finalizer
DUK_LOCAL duk_ret_t duk__refcount_fake_finalizer(duk_context *ctx) {
DUK_UNREF(ctx);
DUK_D(DUK_DPRINT("fake refcount torture finalizer executed"));
#if 0
DUK_DD(DUK_DDPRINT("fake torture finalizer for: %!T", duk_get_tval(ctx, 0)));
#endif
/* Require a lot of stack to force a value stack grow/shrink. */
duk_require_stack(ctx, 100000);
/* XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
*/
return 0;
}
示例5: duk__clear_refzero_list_flags
DUK_LOCAL void duk__clear_refzero_list_flags(duk_heap *heap) {
duk_heaphdr *hdr;
DUK_DD(DUK_DDPRINT("duk__clear_refzero_list_flags: %p", (void *) heap));
hdr = heap->refzero_list;
while (hdr) {
DUK_HEAPHDR_CLEAR_REACHABLE(hdr);
DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(hdr));
/* DUK_HEAPHDR_HAS_FINALIZED may or may not be set. */
DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr));
hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr);
}
}
示例6: duk__clear_finalize_list_flags
DUK_LOCAL void duk__clear_finalize_list_flags(duk_heap *heap) {
duk_heaphdr *hdr;
DUK_DD(DUK_DDPRINT("duk__clear_finalize_list_flags: %p", (void *) heap));
hdr = heap->finalize_list;
while (hdr) {
DUK_HEAPHDR_CLEAR_REACHABLE(hdr);
DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(hdr));
DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(hdr));
DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(hdr));
hdr = DUK_HEAPHDR_GET_NEXT(heap, hdr);
}
}
示例7: duk__compact_object_list
DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start, duk_size_t *p_count_check, duk_size_t *p_count_compact, duk_size_t *p_count_bytes_saved) {
#else
DUK_LOCAL void duk__compact_object_list(duk_heap *heap, duk_hthread *thr, duk_heaphdr *start) {
#endif
duk_heaphdr *curr;
#if defined(DUK_USE_DEBUG)
duk_size_t old_size, new_size;
#endif
duk_hobject *obj;
DUK_UNREF(heap);
curr = start;
while (curr) {
DUK_DDD(DUK_DDDPRINT("mark-and-sweep compact: %p", (void *) curr));
if (DUK_HEAPHDR_GET_TYPE(curr) != DUK_HTYPE_OBJECT) {
goto next;
}
obj = (duk_hobject *) curr;
#if defined(DUK_USE_DEBUG)
old_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj),
DUK_HOBJECT_GET_ASIZE(obj),
DUK_HOBJECT_GET_HSIZE(obj));
#endif
DUK_DD(DUK_DDPRINT("compact object: %p", (void *) obj));
duk_push_hobject((duk_context *) thr, obj);
/* XXX: disable error handlers for duration of compaction? */
duk_safe_call((duk_context *) thr, duk__protected_compact_object, NULL, 1, 0);
#if defined(DUK_USE_DEBUG)
new_size = DUK_HOBJECT_P_COMPUTE_SIZE(DUK_HOBJECT_GET_ESIZE(obj),
DUK_HOBJECT_GET_ASIZE(obj),
DUK_HOBJECT_GET_HSIZE(obj));
#endif
#if defined(DUK_USE_DEBUG)
(*p_count_compact)++;
(*p_count_bytes_saved) += (duk_size_t) (old_size - new_size);
#endif
next:
curr = DUK_HEAPHDR_GET_NEXT(heap, curr);
#if defined(DUK_USE_DEBUG)
(*p_count_check)++;
#endif
}
}
示例8: duk__sweep_stringtable_chain
DUK_LOCAL void duk__sweep_stringtable_chain(duk_heap *heap, duk_size_t *out_count_keep) {
duk_strtab_entry *e;
duk_uint_fast32_t i;
duk_size_t count_free = 0;
duk_size_t count_keep = 0;
duk_size_t j, n;
#if defined(DUK_USE_HEAPPTR16)
duk_uint16_t *lst;
#else
duk_hstring **lst;
#endif
DUK_DD(DUK_DDPRINT("duk__sweep_stringtable: %p", (void *) heap));
/* Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
*/
for (i = 0; i < DUK_STRTAB_CHAIN_SIZE; i++) {
e = heap->strtable + i;
if (e->listlen == 0) {
#if defined(DUK_USE_HEAPPTR16)
duk__sweep_string_chain16(heap, &e->u.str16, &count_keep, &count_free);
#else
duk__sweep_string_chain(heap, &e->u.str, &count_keep, &count_free);
#endif
} else {
#if defined(DUK_USE_HEAPPTR16)
lst = (duk_uint16_t *) DUK_USE_HEAPPTR_DEC16(heap->heap_udata, e->u.strlist16);
#else
lst = e->u.strlist;
#endif
for (j = 0, n = e->listlen; j < n; j++) {
#if defined(DUK_USE_HEAPPTR16)
duk__sweep_string_chain16(heap, lst + j, &count_keep, &count_free);
#else
duk__sweep_string_chain(heap, lst + j, &count_keep, &count_free);
#endif
}
}
}
DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %ld freed, %ld kept",
(long) count_free, (long) count_keep));
*out_count_keep = count_keep;
}
示例9: duk__run_object_finalizers
static void duk__run_object_finalizers(duk_heap *heap) {
duk_heaphdr *curr;
duk_heaphdr *next;
#ifdef DUK_USE_DEBUG
int count = 0;
#endif
duk_hthread *thr;
DUK_DD(DUK_DDPRINT("duk__run_object_finalizers: %p", (void *) heap));
thr = duk__get_temp_hthread(heap);
DUK_ASSERT(thr != NULL);
curr = heap->finalize_list;
while (curr) {
DUK_DDD(DUK_DDDPRINT("mark-and-sweep finalize: %p", (void *) curr));
DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(curr) == DUK_HTYPE_OBJECT); /* only objects have finalizers */
DUK_ASSERT(!DUK_HEAPHDR_HAS_REACHABLE(curr)); /* flags have been already cleared */
DUK_ASSERT(!DUK_HEAPHDR_HAS_TEMPROOT(curr));
DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZABLE(curr));
DUK_ASSERT(!DUK_HEAPHDR_HAS_FINALIZED(curr));
/* run the finalizer */
duk_hobject_run_finalizer(thr, (duk_hobject *) curr); /* must never longjmp */
/* mark FINALIZED, for next mark-and-sweep (will collect unless has become reachable;
* prevent running finalizer again if reachable)
*/
DUK_HEAPHDR_SET_FINALIZED(curr);
/* queue back to heap_allocated */
next = DUK_HEAPHDR_GET_NEXT(curr);
DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap, curr);
curr = next;
#ifdef DUK_USE_DEBUG
count++;
#endif
}
/* finalize_list will always be processed completely */
heap->finalize_list = NULL;
#ifdef DUK_USE_DEBUG
DUK_D(DUK_DPRINT("mark-and-sweep finalize objects: %d finalizers called", count));
#endif
}
示例10: duk_heap_strcache_string_remove
DUK_INTERNAL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h) {
duk_small_int_t i;
for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) {
duk_strcache *c = heap->strcache + i;
if (c->h == h) {
DUK_DD(DUK_DDPRINT("deleting weak strcache reference to hstring %p from heap %p",
(void *) h, (void *) heap));
c->h = NULL;
/* XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
*/
}
}
}
示例11: DUK_ASSERT
DUK_LOCAL duk_hstring *duk__do_lookup(duk_heap *heap, const duk_uint8_t *str, duk_uint32_t blen, duk_uint32_t *out_strhash) {
duk_hstring *res;
DUK_ASSERT(out_strhash);
*out_strhash = duk_heap_hashstring(heap, str, (duk_size_t) blen);
#if defined(DUK_USE_ROM_STRINGS)
{
duk_small_uint_t i;
/* XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
*/
for (i = 0; i < (duk_small_uint_t) (sizeof(duk_rom_strings) / sizeof(duk_hstring *)); i++) {
duk_hstring *romstr;
romstr = (duk_hstring *) duk_rom_strings[i];
if (blen == DUK_HSTRING_GET_BYTELEN(romstr) &&
DUK_MEMCMP(str, (void *) DUK_HSTRING_GET_DATA(romstr), blen) == 0) {
DUK_DD(DUK_DDPRINT("intern check: rom string: %!O, computed hash 0x%08lx, rom hash 0x%08lx",
romstr, (unsigned long) *out_strhash, (unsigned long) DUK_HSTRING_GET_HASH(romstr)));
DUK_ASSERT(*out_strhash == DUK_HSTRING_GET_HASH(romstr));
*out_strhash = DUK_HSTRING_GET_HASH(romstr);
return romstr;
}
}
}
#endif /* DUK_USE_ROM_STRINGS */
#if defined(DUK_USE_STRTAB_CHAIN)
res = duk__find_matching_string_chain(heap, str, blen, *out_strhash);
#elif defined(DUK_USE_STRTAB_PROBE)
res = duk__find_matching_string_probe(heap,
#if defined(DUK_USE_HEAPPTR16)
heap->strtable16,
#else
heap->strtable,
#endif
heap->st_size,
str,
blen,
*out_strhash);
#else
#error internal error, invalid strtab options
#endif
return res;
}
示例12: duk__check_voluntary_gc
DUK_LOCAL DUK_INLINE void duk__check_voluntary_gc(duk_heap *heap) {
if (DUK_UNLIKELY(--(heap)->ms_trigger_counter < 0)) {
#if defined(DUK_USE_DEBUG)
if (heap->ms_prevent_count == 0) {
DUK_D(DUK_DPRINT("triggering voluntary mark-and-sweep"));
} else {
DUK_DD(DUK_DDPRINT("gc blocked -> skip voluntary mark-and-sweep now"));
}
#endif
/* Prevention checks in the call target handle cases where
* voluntary GC is not allowed. The voluntary GC trigger
* counter is only rewritten if mark-and-sweep actually runs.
*/
duk_heap_mark_and_sweep(heap, DUK_MS_FLAG_VOLUNTARY /*flags*/);
}
}
示例13: duk__mark_roots_heap
static void duk__mark_roots_heap(duk_heap *heap) {
int i;
DUK_DD(DUK_DDPRINT("duk__mark_roots_heap: %p", (void *) heap));
duk__mark_heaphdr(heap, (duk_heaphdr *) heap->heap_thread);
duk__mark_heaphdr(heap, (duk_heaphdr *) heap->heap_object);
duk__mark_heaphdr(heap, (duk_heaphdr *) heap->log_buffer);
for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) {
duk_hstring *h = heap->strs[i];
duk__mark_heaphdr(heap, (duk_heaphdr *) h);
}
duk__mark_tval(heap, &heap->lj.value1);
duk__mark_tval(heap, &heap->lj.value2);
}
示例14: duk_err_longjmp
DUK_INTERNAL void duk_err_longjmp(duk_hthread *thr) {
DUK_ASSERT(thr != NULL);
DUK_DD(DUK_DDPRINT("longjmp error: type=%d iserror=%d value1=%!T value2=%!T",
(int) thr->heap->lj.type, (int) thr->heap->lj.iserror,
&thr->heap->lj.value1, &thr->heap->lj.value2));
#if !defined(DUK_USE_CPP_EXCEPTIONS)
/* If we don't have a jmpbuf_ptr, there is little we can do except
* cause a fatal error. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
*/
if (!thr->heap->lj.jmpbuf_ptr) {
DUK_D(DUK_DPRINT("uncaught error: type=%d iserror=%d value1=%!T value2=%!T",
(int) thr->heap->lj.type, (int) thr->heap->lj.iserror,
&thr->heap->lj.value1, &thr->heap->lj.value2));
#if defined(DUK_USE_PREFER_SIZE)
duk__uncaught_minimal(thr);
#else
duk__uncaught_error_aware(thr);
#endif
DUK_UNREACHABLE();
}
#endif /* DUK_USE_CPP_EXCEPTIONS */
#if defined(DUK_USE_CPP_EXCEPTIONS)
{
duk_internal_exception exc; /* dummy */
throw exc;
}
#else /* DUK_USE_CPP_EXCEPTIONS */
DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb);
#endif /* DUK_USE_CPP_EXCEPTIONS */
DUK_UNREACHABLE();
}
示例15: duk_heap_dump_strtab
DUK_INTERNAL void duk_heap_dump_strtab(duk_heap *heap) {
duk_uint32_t i;
duk_hstring *h;
DUK_ASSERT(heap != NULL);
#if defined(DUK_USE_HEAPPTR16)
DUK_ASSERT(heap->strtable16 != NULL);
#else
DUK_ASSERT(heap->strtable != NULL);
#endif
for (i = 0; i < heap->st_size; i++) {
#if defined(DUK_USE_HEAPPTR16)
h = (duk_hstring *) DUK_USE_HEAPPTR_DEC16(heap->strtable16[i]);
#else
h = heap->strtable[i];
#endif
DUK_DD(DUK_DDPRINT("[%03d] -> %p", (int) i, (void *) h));
}
}