Renamed variables, fixed code to work with latest changes in main

This commit is contained in:
karurochari 2024-06-10 07:49:30 +00:00
parent f722d5c440
commit b0e977cee7
2 changed files with 15 additions and 21 deletions

View file

@ -237,9 +237,9 @@ struct JSRuntime {
struct list_head tmp_obj_list; /* used during GC */
JSGCPhaseEnum gc_phase : 8;
size_t malloc_gc_threshold;
BOOL malloc_gc_fix_threshold : 8;
BOOL (*malloc_gc_before_callback)();
void (*malloc_gc_after_callback)();
BOOL fix_malloc_gc_threshold : 8;
BOOL (*gc_before_callback)(); /* Callback before the gc event takes place */
void (*gc_after_callback)(); /* Callback after the gc event takes place */
#ifdef DUMP_LEAKS
struct list_head string_list; /* list of JSString.link */
#endif
@ -1365,18 +1365,18 @@ static void js_trigger_gc(JSRuntime *rt, size_t size)
(uint64_t)rt->malloc_state.malloc_size);
}
#endif
//To ensure JS_RunGC cannot be executed again within callbacks.
//To ensure JS_RunGC cannot be executed again within callbacks, disable and restore it after.
size_t tmp_threshold = rt->malloc_gc_threshold;
rt->malloc_gc_threshold=-1;
if((rt->malloc_gc_before_callback == NULL) || rt->malloc_gc_before_callback()){
if((rt->gc_before_callback == NULL) || rt->gc_before_callback()){
JS_RunGC(rt);
if(rt->malloc_gc_after_callback != NULL)rt->malloc_gc_after_callback();
if(rt->gc_after_callback != NULL)rt->gc_after_callback();
}
rt->malloc_gc_threshold=tmp_threshold;
if(rt->malloc_gc_fix_threshold == FALSE) {
if(rt->fix_malloc_gc_threshold == FALSE) {
rt->malloc_gc_threshold = rt->malloc_state.malloc_size +
(rt->malloc_state.malloc_size >> 1);
}
@ -1646,9 +1646,9 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
rt->malloc_state = ms;
rt->malloc_gc_threshold = 256 * 1024;
rt->malloc_gc_fix_threshold = FALSE;
rt->malloc_gc_after_callback = NULL;
rt->malloc_gc_before_callback = NULL;
rt->fix_malloc_gc_threshold = FALSE;
rt->gc_after_callback = NULL;
rt->gc_before_callback = NULL;
bf_context_init(&rt->bf_ctx, js_bf_realloc, rt);
@ -1796,25 +1796,20 @@ void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold)
rt->malloc_gc_threshold = gc_threshold;
}
size_t JS_GetGCThreshold(JSRuntime *rt)
{
return rt->malloc_gc_threshold;
}
void JS_SetGCThresholdFixed(JSRuntime *rt, BOOL fix)
{
rt->malloc_gc_fix_threshold = fix;
rt->fix_malloc_gc_threshold = fix;
}
void JS_SetGCBeforeCallback(JSRuntime *rt, BOOL(*fn)())
{
rt->malloc_gc_before_callback = fn;
rt->gc_before_callback = fn;
}
void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)())
{
rt->malloc_gc_after_callback = fn;
rt->gc_after_callback = fn;
}
#define malloc(s) malloc_is_forbidden(s)

View file

@ -307,10 +307,9 @@ JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit);
JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags);
JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt);
JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);
JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt);
JS_EXTERN void JS_SetGCThresholdFixed(JSRuntime *rt, JS_BOOL fixed);
JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, JS_BOOL(*fn)());
JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)());
JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, JS_BOOL(*cb)());
JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*cb)());
/* use 0 to disable maximum stack size check */
JS_EXTERN void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size);
/* should be called when changing thread to update the stack top value