Browse Source

More GC tweaks; removed bbinit files.

Mark Sibly 8 years ago
parent
commit
077da38765

+ 0 - 1
modules/monkey/monkey.monkey2

@@ -11,7 +11,6 @@ Namespace monkey
 #Import "gc.monkey2"
 #Import "gc.monkey2"
 
 
 #Import "native/bbtypes.cpp"
 #Import "native/bbtypes.cpp"
-#Import "native/bbinit.cpp"
 #Import "native/bbassert.cpp"
 #Import "native/bbassert.cpp"
 #Import "native/bbmemory.cpp"
 #Import "native/bbmemory.cpp"
 #Import "native/bbstring.cpp"
 #Import "native/bbstring.cpp"

+ 21 - 13
modules/monkey/native/bbgc.cpp

@@ -12,8 +12,8 @@ namespace bbGC{
 
 
 	size_t trigger=4*1024*1024;
 	size_t trigger=4*1024*1024;
 
 
-	int suspended;
-
+	int suspended=1;
+	
 	int markedBit;
 	int markedBit;
 	int unmarkedBit;
 	int unmarkedBit;
 
 
@@ -46,6 +46,7 @@ namespace bbGC{
 	bool inited;
 	bool inited;
 	
 	
 	void init(){
 	void init(){
+
 		if( inited ) return;
 		if( inited ) return;
 		inited=true;
 		inited=true;
 
 
@@ -62,6 +63,8 @@ namespace bbGC{
 		fibers=new bbGCFiber;
 		fibers=new bbGCFiber;
 		
 		
 		currentFiber=fibers;
 		currentFiber=fibers;
+		
+		suspended=0;
 	}
 	}
 	
 	
 	void setTrigger( size_t size ){
 	void setTrigger( size_t size ){
@@ -194,9 +197,6 @@ namespace bbGC{
 	}
 	}
 
 
 	void sweep(){
 	void sweep(){
-	
-//		puts( "bbGC::sweep()" );fflush( stdout );
-	
 		markRetained();
 		markRetained();
 		
 		
 		markFibers();
 		markFibers();
@@ -214,16 +214,16 @@ namespace bbGC{
 			//clear unmarked
 			//clear unmarked
 			unmarkedList->succ=unmarkedList->pred=unmarkedList;
 			unmarkedList->succ=unmarkedList->pred=unmarkedList;
 		}
 		}
-		
+
+		//swap mark/unmarked lists		
 		std::swap( markedList,unmarkedList );
 		std::swap( markedList,unmarkedList );
 		std::swap( markedBit,unmarkedBit );
 		std::swap( markedBit,unmarkedBit );
-		
 		unmarkedBytes=markedBytes;
 		unmarkedBytes=markedBytes;
-
 		markedBytes=0;
 		markedBytes=0;
-		
+
+		//start new sweep phase
 		allocedBytes=0;
 		allocedBytes=0;
-		
+
 		markRoots();
 		markRoots();
 	}
 	}
 	
 	
@@ -255,8 +255,6 @@ namespace bbGC{
 	
 	
 	void *malloc( size_t size ){
 	void *malloc( size_t size ){
 	
 	
-//		if( !inited ){ printf( "GC not inited!\n" );fflush( stdout ); }
-	
 		size=(size+sizeof(size_t)+7)&~7;
 		size=(size+sizeof(size_t)+7)&~7;
 		
 		
 		if( size<256 && pools[size>>3] ){
 		if( size<256 && pools[size>>3] ){
@@ -269,7 +267,7 @@ namespace bbGC{
 		}
 		}
 		
 		
 		if( !suspended ){
 		if( !suspended ){
-			
+
 			if( allocedBytes+size>=trigger ){
 			if( allocedBytes+size>=trigger ){
 				
 				
 				sweep();
 				sweep();
@@ -340,4 +338,14 @@ namespace bbGC{
 		
 		
 		return p;
 		return p;
 	}
 	}
+	
+	void collect(){
+	
+		if( !inited ) return;
+	
+		sweep();
+		
+		reclaim();
+	}
 }
 }
+

+ 0 - 12
modules/monkey/native/bbinit.cpp

@@ -1,12 +0,0 @@
-
-#include "bbinit.h"
-
-#include <stdio.h>
-
-bbInit *bbInit::first;
-
-bbInit::bbInit( const char *ident,void(*init)() ):info( info ),init( init ){
-//	printf( "Registering initializer '%s'\n",info );fflush( stdout );
-	succ=first;
-	first=this;
-}

+ 0 - 17
modules/monkey/native/bbinit.h

@@ -1,17 +0,0 @@
-
-#ifndef BB_INIT_H
-#define BB_INIT_H
-
-//Simple list of stuff to get inited before main is run
-
-struct bbInit{
-	bbInit *succ;
-	const char *info;
-	void (*init)();
-	
-	static bbInit *first;
-	
-	bbInit( const char *info,void(*init)() );
-};
-
-#endif

+ 3 - 12
modules/monkey/native/bbmonkey.cpp

@@ -51,23 +51,14 @@ int main( int argc,char **argv ){
 
 
 #endif
 #endif
 
 
+	bbGC::init();
+	bbDB::init();
+
 	bb_argc=argc;
 	bb_argc=argc;
 	bb_argv=argv;
 	bb_argv=argv;
 	
 	
 	try{
 	try{
 	
 	
-		bbGC::init();
-		
-		bbDB::init();
-
-		{		
-			bbDBFrame( "_void()","" );
-			
-			for( bbInit *init=bbInit::first;init;init=init->succ ){
-				init->init();
-			}
-		}
-		
 		bbMain();
 		bbMain();
 	
 	
 	}catch( bbThrowable *t ){
 	}catch( bbThrowable *t ){

+ 0 - 1
modules/monkey/native/bbmonkey.h

@@ -3,7 +3,6 @@
 #define BB_MONKEY_H
 #define BB_MONKEY_H
 
 
 #include "bbstd.h"
 #include "bbstd.h"
-#include "bbinit.h"
 #include "bbtypes.h"
 #include "bbtypes.h"
 #include "bbassert.h"
 #include "bbassert.h"
 #include "bbmemory.h"
 #include "bbmemory.h"

+ 7 - 7
modules/monkey/native/bbstring.cpp

@@ -114,7 +114,7 @@ namespace{
 
 
 bbString::Rep *bbString::Rep::alloc( int length ){
 bbString::Rep *bbString::Rep::alloc( int length ){
 	if( !length ) return &_nullRep;
 	if( !length ) return &_nullRep;
-	Rep *rep=(Rep*)bbMalloc( sizeof(Rep)+length*sizeof(bbChar) );
+	Rep *rep=(Rep*)bbGC::malloc( sizeof(Rep)+length*sizeof(bbChar) );
 	rep->refs=1;
 	rep->refs=1;
 	rep->length=length;
 	rep->length=length;
 	return rep;
 	return rep;
@@ -273,8 +273,8 @@ const char *bbString::c_str()const{
 	
 	
 	int sz=utf8Length()+1;
 	int sz=utf8Length()+1;
 	if( sz>_sz ){
 	if( sz>_sz ){
-		free( _tmp );
-		_tmp=(char*)malloc( _sz=sz );
+		::free( _tmp );
+		_tmp=(char*)::malloc( _sz=sz );
 	}
 	}
 	toCString( _tmp,sz );
 	toCString( _tmp,sz );
 	return _tmp;
 	return _tmp;
@@ -571,12 +571,12 @@ bbString::operator double()const{
 
 
 bbCString::bbCString( const bbString &str ){
 bbCString::bbCString( const bbString &str ){
 	int size=str.utf8Length()+1;
 	int size=str.utf8Length()+1;
-	_data=(char*)bbMalloc( size );
+	_data=(char*)bbGC::malloc( size );
 	str.toCString( _data,size );
 	str.toCString( _data,size );
 }
 }
 
 
 bbCString::~bbCString(){
 bbCString::~bbCString(){
-	bbFree( _data );
+	bbGC::free( _data );
 }
 }
 
 
 bbCString::operator char*()const{
 bbCString::operator char*()const{
@@ -595,12 +595,12 @@ bbCString::operator unsigned char*()const{
 
 
 bbWString::bbWString( const bbString &str ){
 bbWString::bbWString( const bbString &str ){
 	int size=(str.length()+1)*sizeof(wchar_t);
 	int size=(str.length()+1)*sizeof(wchar_t);
-	_data=(wchar_t*)bbMalloc( size );
+	_data=(wchar_t*)bbGC::malloc( size );
 	str.toWString( _data,size );
 	str.toWString( _data,size );
 }
 }
 
 
 bbWString::~bbWString(){
 bbWString::~bbWString(){
-	bbFree( _data );
+	bbGC::free( _data );
 }
 }
 
 
 bbWString::operator wchar_t*()const{
 bbWString::operator wchar_t*()const{

+ 1 - 9
modules/monkey/native/bbstring.h

@@ -20,15 +20,7 @@ class bbString{
 		int length;
 		int length;
 		bbChar data[0];
 		bbChar data[0];
 		
 		
-//		Rep():refs( $80000000 ),length( 0 ){
-//		}
-		
-//		Rep( int length ):refs( 1 ),length( length ){
-//		}
-		
 		static Rep *alloc( int length );
 		static Rep *alloc( int length );
-//			return new( bbGC::malloc( sizeof( Rep )+length*sizeof( bbChar ) ) ) Rep( length );
-//		}
 		
 		
 		template<class C> static Rep *create( const C *p,int length ){
 		template<class C> static Rep *create( const C *p,int length ){
 			Rep *rep=alloc( length );
 			Rep *rep=alloc( length );
@@ -53,7 +45,7 @@ class bbString{
 	}
 	}
 	
 	
 	void release(){
 	void release(){
-		if( !--_rep->refs && _rep!=&_nullRep ) bbFree( _rep );
+		if( !--_rep->refs && _rep!=&_nullRep ) bbGC::free( _rep );
 	}
 	}
 	
 	
 	bbString( Rep *rep ):_rep( rep ){
 	bbString( Rep *rep ):_rep( rep ){