mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
inline gc check
This commit is contained in:
parent
4fa7106f2c
commit
3cae7e6809
@ -63,6 +63,7 @@ struct ManagedHeap{
|
|||||||
|
|
||||||
int sweep();
|
int sweep();
|
||||||
void _auto_collect();
|
void _auto_collect();
|
||||||
|
bool _should_auto_collect() const { return gc_counter >= gc_threshold; }
|
||||||
int collect();
|
int collect();
|
||||||
void mark();
|
void mark();
|
||||||
~ManagedHeap();
|
~ManagedHeap();
|
||||||
|
@ -82,7 +82,7 @@ __NEXT_STEP:;
|
|||||||
DISPATCH();
|
DISPATCH();
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
TARGET(LOAD_CONST)
|
TARGET(LOAD_CONST)
|
||||||
heap._auto_collect();
|
if(heap._should_auto_collect()) heap._auto_collect();
|
||||||
PUSH(co_consts[byte.arg]);
|
PUSH(co_consts[byte.arg]);
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
TARGET(LOAD_NONE) PUSH(None); DISPATCH();
|
TARGET(LOAD_NONE) PUSH(None); DISPATCH();
|
||||||
@ -105,13 +105,13 @@ __NEXT_STEP:;
|
|||||||
TARGET(LOAD_NULL) PUSH(PY_NULL); DISPATCH();
|
TARGET(LOAD_NULL) PUSH(PY_NULL); DISPATCH();
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
TARGET(LOAD_FAST) {
|
TARGET(LOAD_FAST) {
|
||||||
heap._auto_collect();
|
if(heap._should_auto_collect()) heap._auto_collect();
|
||||||
_0 = frame->_locals[byte.arg];
|
_0 = frame->_locals[byte.arg];
|
||||||
if(_0 == PY_NULL) vm->UnboundLocalError(co->varnames[byte.arg]);
|
if(_0 == PY_NULL) vm->UnboundLocalError(co->varnames[byte.arg]);
|
||||||
PUSH(_0);
|
PUSH(_0);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(LOAD_NAME) {
|
TARGET(LOAD_NAME) {
|
||||||
heap._auto_collect();
|
if(heap._should_auto_collect()) heap._auto_collect();
|
||||||
_name = StrName(byte.arg);
|
_name = StrName(byte.arg);
|
||||||
PyObject** slot = frame->_locals.try_get_name(_name);
|
PyObject** slot = frame->_locals.try_get_name(_name);
|
||||||
if(slot != nullptr) {
|
if(slot != nullptr) {
|
||||||
@ -128,7 +128,7 @@ __NEXT_STEP:;
|
|||||||
vm->NameError(_name);
|
vm->NameError(_name);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(LOAD_NONLOCAL) {
|
TARGET(LOAD_NONLOCAL) {
|
||||||
heap._auto_collect();
|
if(heap._should_auto_collect()) heap._auto_collect();
|
||||||
_name = StrName(byte.arg);
|
_name = StrName(byte.arg);
|
||||||
_0 = frame->f_closure_try_get(_name);
|
_0 = frame->f_closure_try_get(_name);
|
||||||
if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
|
if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
|
||||||
@ -139,7 +139,7 @@ __NEXT_STEP:;
|
|||||||
vm->NameError(_name);
|
vm->NameError(_name);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(LOAD_GLOBAL)
|
TARGET(LOAD_GLOBAL)
|
||||||
heap._auto_collect();
|
if(heap._should_auto_collect()) heap._auto_collect();
|
||||||
_name = StrName(byte.arg);
|
_name = StrName(byte.arg);
|
||||||
_0 = frame->f_globals().try_get_likely_found(_name);
|
_0 = frame->f_globals().try_get_likely_found(_name);
|
||||||
if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
|
if(_0 != nullptr) { PUSH(_0); DISPATCH(); }
|
||||||
|
@ -33,7 +33,6 @@ namespace pkpy{
|
|||||||
void ManagedHeap::_auto_collect(){
|
void ManagedHeap::_auto_collect(){
|
||||||
#if !PK_DEBUG_NO_AUTO_GC
|
#if !PK_DEBUG_NO_AUTO_GC
|
||||||
if(_gc_lock_counter > 0) return;
|
if(_gc_lock_counter > 0) return;
|
||||||
if(gc_counter < gc_threshold) return;
|
|
||||||
gc_counter = 0;
|
gc_counter = 0;
|
||||||
collect();
|
collect();
|
||||||
gc_threshold = gen.size() * 2;
|
gc_threshold = gen.size() * 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user