mirror of https://github.com/arendst/Tasmota.git
Berry ``debug.gcdebug()`` to enable GC debugging (#19936)
This commit is contained in:
parent
3207d542c1
commit
625b204cb2
|
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
||||||
## [13.2.0.2]
|
## [13.2.0.2]
|
||||||
### Added
|
### Added
|
||||||
- Scripter TCP client (#19914)
|
- Scripter TCP client (#19914)
|
||||||
|
- Berry ``debug.gcdebug()`` to enable GC debugging
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,19 @@ static int m_codedump(bvm *vm)
|
||||||
be_return_nil(vm);
|
be_return_nil(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int m_gcdebug(bvm *vm) {
|
||||||
|
int argc = be_top(vm);
|
||||||
|
if (argc >= 1 && be_isbool(vm, 1)) {
|
||||||
|
if (be_tobool(vm, 1)) {
|
||||||
|
comp_set_gc_debug(vm);
|
||||||
|
} else {
|
||||||
|
comp_clear_gc_debug(vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
be_pushbool(vm, comp_is_gc_debug(vm));
|
||||||
|
be_return(vm);
|
||||||
|
}
|
||||||
|
|
||||||
static int m_traceback(bvm *vm)
|
static int m_traceback(bvm *vm)
|
||||||
{
|
{
|
||||||
be_tracestack(vm);
|
be_tracestack(vm);
|
||||||
|
@ -223,6 +236,7 @@ be_native_module_attr_table(debug) {
|
||||||
be_native_module_function("varname", m_varname),
|
be_native_module_function("varname", m_varname),
|
||||||
be_native_module_function("upvname", m_upvname)
|
be_native_module_function("upvname", m_upvname)
|
||||||
#endif
|
#endif
|
||||||
|
be_native_module_function("gcdebug", m_gcdebug)
|
||||||
};
|
};
|
||||||
|
|
||||||
be_define_native_module(debug, NULL);
|
be_define_native_module(debug, NULL);
|
||||||
|
@ -242,6 +256,8 @@ module debug (scope: global, depend: BE_USE_DEBUG_MODULE) {
|
||||||
allocs, func(m_allocs)
|
allocs, func(m_allocs)
|
||||||
frees, func(m_frees)
|
frees, func(m_frees)
|
||||||
reallocs, func(m_reallocs)
|
reallocs, func(m_reallocs)
|
||||||
|
// GC debug mode
|
||||||
|
gcdebug, func(m_gcdebug)
|
||||||
}
|
}
|
||||||
@const_object_info_end */
|
@const_object_info_end */
|
||||||
#include "../generate/be_fixed_debug.h"
|
#include "../generate/be_fixed_debug.h"
|
||||||
|
|
|
@ -545,15 +545,9 @@ static void reset_fixedlist(bvm *vm)
|
||||||
|
|
||||||
void be_gc_auto(bvm *vm)
|
void be_gc_auto(bvm *vm)
|
||||||
{
|
{
|
||||||
#if BE_USE_DEBUG_GC
|
if (vm->gc.status & GC_PAUSE && (BE_USE_DEBUG_GC || vm->gc.usage > vm->gc.threshold || comp_is_gc_debug(vm))) {
|
||||||
if (vm->gc.status & GC_PAUSE) { /* force gc each time it's possible */
|
|
||||||
be_gc_collect(vm);
|
be_gc_collect(vm);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (vm->gc.status & GC_PAUSE && vm->gc.usage > vm->gc.threshold) {
|
|
||||||
be_gc_collect(vm);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t be_gc_memcount(bvm *vm)
|
size_t be_gc_memcount(bvm *vm)
|
||||||
|
|
|
@ -73,9 +73,9 @@ BERRY_API void* be_realloc(bvm *vm, void *ptr, size_t old_size, size_t new_size)
|
||||||
vm->counter_mem_free++;
|
vm->counter_mem_free++;
|
||||||
#endif
|
#endif
|
||||||
if (ptr == NULL) { return NULL; } /* safeguard */
|
if (ptr == NULL) { return NULL; } /* safeguard */
|
||||||
#if BE_USE_DEBUG_GC
|
if (BE_USE_DEBUG_GC || comp_is_gc_debug(vm)) {
|
||||||
memset(ptr, 0xFF, old_size); /* fill the structure with invalid pointers */
|
memset(ptr, 0xFF, old_size); /* fill the structure with invalid pointers */
|
||||||
#endif
|
}
|
||||||
free_from_pool(vm, ptr, old_size);
|
free_from_pool(vm, ptr, old_size);
|
||||||
break; /* early exit */
|
break; /* early exit */
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,13 +268,13 @@ void be_gcstrtab(bvm *vm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if BE_USE_DEBUG_GC == 0
|
if (BE_USE_DEBUG_GC || comp_is_gc_debug(vm)) {
|
||||||
|
resize(vm, tab->count + 4);
|
||||||
|
} else {
|
||||||
if (tab->count < size >> 2 && size > 8) {
|
if (tab->count < size >> 2 && size > 8) {
|
||||||
resize(vm, size >> 1);
|
resize(vm, size >> 1);
|
||||||
}
|
}
|
||||||
#else
|
}
|
||||||
resize(vm, tab->count + 4);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t be_strhash(const bstring *s)
|
uint32_t be_strhash(const bstring *s)
|
||||||
|
|
|
@ -18,10 +18,15 @@
|
||||||
#define comp_set_strict(vm) ((vm)->compopt |= (1<<COMP_STRICT))
|
#define comp_set_strict(vm) ((vm)->compopt |= (1<<COMP_STRICT))
|
||||||
#define comp_clear_strict(vm) ((vm)->compopt &= ~(1<<COMP_STRICT))
|
#define comp_clear_strict(vm) ((vm)->compopt &= ~(1<<COMP_STRICT))
|
||||||
|
|
||||||
|
#define comp_is_gc_debug(vm) ((vm)->compopt & (1<<COMP_GC_DEBUG))
|
||||||
|
#define comp_set_gc_debug(vm) ((vm)->compopt |= (1<<COMP_GC_DEBUG))
|
||||||
|
#define comp_clear_gc_debug(vm) ((vm)->compopt &= ~(1<<COMP_GC_DEBUG))
|
||||||
|
|
||||||
/* Compilation options */
|
/* Compilation options */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
COMP_NAMED_GBL = 0x00, /* compile with named globals */
|
COMP_NAMED_GBL = 0x00, /* compile with named globals */
|
||||||
COMP_STRICT = 0x01, /* compile with named globals */
|
COMP_STRICT = 0x01, /* compile with named globals */
|
||||||
|
COMP_GC_DEBUG = 0x02, /* compile with gc debug */
|
||||||
} compoptmask;
|
} compoptmask;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in New Issue