mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
mark_sweep test passed on pikaui
This commit is contained in:
parent
2a633d0a63
commit
28fc4b9403
@ -1807,8 +1807,8 @@ void obj_dump(PikaObj* self) {
|
||||
#if !PIKA_KERNAL_DEBUG_ENABLE
|
||||
return;
|
||||
#else
|
||||
pika_platform_printf("[%s]", self->name);
|
||||
pika_platform_printf("\t\t@%p", self);
|
||||
pika_platform_printf("[\033[32m%s\033[0m]", self->name);
|
||||
pika_platform_printf(" \033[36m@%p\033[0m", self);
|
||||
pika_platform_printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
@ -1826,8 +1826,8 @@ uint32_t pikaGC_markSweepOnce(PikaGC* gc) {
|
||||
obj = obj->gcNext;
|
||||
}
|
||||
if (count > 0) {
|
||||
pikaGC_markDump();
|
||||
pikaGC_printFreeList();
|
||||
// pikaGC_markDump();
|
||||
// pikaGC_printFreeList();
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
obj_GC(freeList[i]);
|
||||
}
|
||||
@ -1901,7 +1901,7 @@ void pikaGC_mark(void) {
|
||||
|
||||
int _pikaGC_markDumpHandler(PikaGC* gc) {
|
||||
for (uint32_t i = 0; i < gc->markDeepth - 1; i++) {
|
||||
pika_platform_printf(" ");
|
||||
pika_platform_printf(" |");
|
||||
}
|
||||
if (gc->markDeepth != 1) {
|
||||
pika_platform_printf("- ");
|
||||
@ -1910,13 +1910,6 @@ int _pikaGC_markDumpHandler(PikaGC* gc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pikaGC_markDump(void) {
|
||||
PikaGC gc = {0};
|
||||
pika_platform_printf("========= PIKA GC DUMP =========\r\n");
|
||||
gc.onMarkObj = _pikaGC_markDumpHandler;
|
||||
_pikaGC_mark(&gc);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
PIKA_BOOL obj_checkAlive(PikaObj* self) {
|
||||
@ -1959,6 +1952,9 @@ uint32_t pikaGC_markSweep(void) {
|
||||
while (pikaGC_markSweepOnce(&gc) != 0) {
|
||||
count++;
|
||||
};
|
||||
if (count > 0) {
|
||||
// pikaGC_markDump();
|
||||
}
|
||||
/* update gc state */
|
||||
g_PikaObjState.objCntLastGC = g_PikaObjState.objCnt;
|
||||
pikaGC_unlock();
|
||||
@ -1966,6 +1962,20 @@ uint32_t pikaGC_markSweep(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void pikaGC_markDump(void) {
|
||||
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
||||
return;
|
||||
#else
|
||||
PikaGC gc = {0};
|
||||
pika_platform_printf(
|
||||
"\033[31m"
|
||||
"========= PIKA GC DUMP =========\r\n"
|
||||
"\033[0m");
|
||||
gc.onMarkObj = _pikaGC_markDumpHandler;
|
||||
_pikaGC_mark(&gc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pikaGC_checkThreshold(void) {
|
||||
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
||||
return;
|
||||
|
19
src/PikaVM.c
19
src/PikaVM.c
@ -451,11 +451,9 @@ static int32_t VMState_getAddrOffsetOfContinue(VMState* vm) {
|
||||
static void VMState_delLReg(VMState* vm, uint8_t index) {
|
||||
PikaObj* obj = vm->lreg[index];
|
||||
if (NULL != obj) {
|
||||
obj_refcntDec(obj);
|
||||
obj_enableGC(obj);
|
||||
vm->lreg[index] = NULL;
|
||||
if (0 == obj_refcntNow(obj)) {
|
||||
obj_deinit(obj);
|
||||
}
|
||||
obj_GC(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1604,8 +1602,10 @@ static Arg* VM_instruction_handler_RET(PikaObj* self,
|
||||
Arg* arg_ret_reg) {
|
||||
/* exit jmp signal */
|
||||
vm->jmp = VM_JMP_EXIT;
|
||||
Arg* return_arg = stack_popArg_alloc(&(vm->stack));
|
||||
method_returnArg(vm->locals->list, return_arg);
|
||||
Arg* aReturn = stack_popArg_alloc(&(vm->stack));
|
||||
/* set gc root to avoid gc */
|
||||
arg_setObjFlag(aReturn, OBJ_FLAG_GC_ROOT);
|
||||
method_returnArg(vm->locals->list, aReturn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2909,18 +2909,19 @@ static Arg* VM_instruction_handler_DEL(PikaObj* self,
|
||||
if (_checkLReg(data)) {
|
||||
uint8_t reg_index = _getLRegIndex(data);
|
||||
VMState_delLReg(vm, reg_index);
|
||||
return NULL;
|
||||
goto __exit;
|
||||
}
|
||||
if (obj_isArgExist(vm->locals, data)) {
|
||||
obj_removeArg(vm->locals, data);
|
||||
return NULL;
|
||||
goto __exit;
|
||||
}
|
||||
if (obj_isArgExist(vm->globals, data)) {
|
||||
obj_removeArg(vm->globals, data);
|
||||
return NULL;
|
||||
goto __exit;
|
||||
}
|
||||
VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
pika_platform_printf("NameError: name '%s' is not defined\n", data);
|
||||
__exit:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "test_common.h"
|
||||
TEST_START
|
||||
#if !PIKA_NANO_ENABLE && 0
|
||||
|
||||
#if PIKA_GC_MARK_SWEEP_ENABLE
|
||||
|
||||
TEST(pikaui, page) {
|
||||
/* init */
|
||||
|
@ -44,7 +44,8 @@ class Widget:
|
||||
|
||||
def _set_perent(self, parent):
|
||||
# use weakref to avoid circular reference
|
||||
self.parent = weakref.ref(parent)
|
||||
# self.parent = weakref.ref(parent)
|
||||
self.parent = parent
|
||||
|
||||
def update(self):
|
||||
if self.needbuild:
|
||||
|
@ -59,18 +59,17 @@ class Page2(ui.Page):
|
||||
|
||||
|
||||
app = ui.App()
|
||||
page1 = Page1()
|
||||
page1.add(page1.build())
|
||||
app.pageManager.enter(Page2())
|
||||
app.timer.cb(0)
|
||||
# mem.now()
|
||||
# app.pageManager.enter(Page2())
|
||||
# app.timer.cb(0)
|
||||
# mem.now()
|
||||
# app.pageManager.back()
|
||||
# app.timer.cb(0)
|
||||
# mem.now()
|
||||
mem.now()
|
||||
app.pageManager.enter(Page2())
|
||||
app.timer.cb(0)
|
||||
mem.now()
|
||||
app.pageManager.back()
|
||||
app.timer.cb(0)
|
||||
mem.now()
|
||||
|
||||
gcdump()
|
||||
|
||||
# for i in range(100):
|
||||
# app.pageManager.enter(Page2())
|
||||
|
Loading…
x
Reference in New Issue
Block a user