コード例 #1
0
ファイル: sqstate.cpp プロジェクト: elleryq/madedit
SQInteger SQSharedState::CollectGarbage(SQVM *vm)
{
	SQInteger n=0;
	SQCollectable *tchain=NULL;

	RunMark(vm,&tchain);

	SQCollectable *t = _gc_chain;
	SQCollectable *nx = NULL;
	while(t) {
		t->_uiRef++;
		t->Finalize();
		nx = t->_next;
		if(--t->_uiRef == 0)
			t->Release();
		t = nx;
		n++;
	}

	t = tchain;
	while(t) {
		t->UnMark();
		t = t->_next;
	}
	_gc_chain = tchain;
	
	return n;
}
コード例 #2
0
ファイル: sqstate.cpp プロジェクト: elleryq/madedit
SQInteger SQSharedState::ResurrectUnreachable(SQVM *vm)
{
	SQInteger n=0;
	SQCollectable *tchain=NULL;

	RunMark(vm,&tchain);

	SQCollectable *resurrected = _gc_chain;
	SQCollectable *t = resurrected;
	//SQCollectable *nx = NULL;

	_gc_chain = tchain;

	SQArray *ret = NULL;
	if(resurrected) {
		ret = SQArray::Create(this,0);
		SQCollectable *rlast = NULL;
		while(t) {
			rlast = t;
			SQObjectType type = t->GetType();
			if(type != OT_FUNCPROTO && type != OT_OUTER) {
				SQObject sqo;
				sqo._type = type;
				sqo._unVal.pRefCounted = t;
				ret->Append(sqo);
			}
			t = t->_next;
			n++;
		}

		assert(rlast->_next == NULL);
		rlast->_next = _gc_chain;
		if(_gc_chain)
		{
			_gc_chain->_prev = rlast;
		}
		_gc_chain = resurrected;
	}

	t = _gc_chain;
	while(t) {
		t->UnMark();
		t = t->_next;
	}

	if(ret) {
		SQObjectPtr temp = ret;
		vm->Push(temp);
	}
	else {
		vm->PushNull();
	}
	return n;
}
コード例 #3
0
ファイル: sqstate.cpp プロジェクト: Heartbroken/bikini
SQInteger SQSharedState::CollectGarbage(SQVM *vm)
{
	SQInteger n=0;
	SQCollectable *tchain=NULL;
	SQVM *vms = _thread(_root_vm);
	
	vms->Mark(&tchain);
	SQInteger x = _table(_thread(_root_vm)->_roottable)->CountUsed();
	_refs_table.Mark(&tchain);
	MarkObject(_registry,&tchain);
	MarkObject(_consts,&tchain);
	MarkObject(_metamethodsmap,&tchain);
	MarkObject(_table_default_delegate,&tchain);
	MarkObject(_array_default_delegate,&tchain);
	MarkObject(_string_default_delegate,&tchain);
	MarkObject(_number_default_delegate,&tchain);
	MarkObject(_generator_default_delegate,&tchain);
	MarkObject(_thread_default_delegate,&tchain);
	MarkObject(_closure_default_delegate,&tchain);
	MarkObject(_class_default_delegate,&tchain);
	MarkObject(_instance_default_delegate,&tchain);
	MarkObject(_weakref_default_delegate,&tchain);
	
	SQCollectable *t = _gc_chain;
	SQCollectable *nx = NULL;
	while(t) {
		t->_uiRef++;
		t->Finalize();
		nx = t->_next;
		if(--t->_uiRef == 0)
			t->Release();
		t = nx;
		n++;
	}

	t = tchain;
	while(t) {
		t->UnMark();
		t = t->_next;
	}
	_gc_chain = tchain;
	SQInteger z = _table(_thread(_root_vm)->_roottable)->CountUsed();
	assert(z == x);
	return n;
}