Jelajahi Sumber

Fixed the GC fixes, removed redundant bbmemory files.

Mark Sibly 7 tahun lalu
induk
melakukan
e727fc3481

+ 0 - 1
modules/monkey/monkey.monkey2

@@ -7,7 +7,6 @@ Namespace monkey
 
 
 #Import "native/bbtypes.cpp"
 #Import "native/bbtypes.cpp"
 #Import "native/bbassert.cpp"
 #Import "native/bbassert.cpp"
-#Import "native/bbmemory.cpp"
 #Import "native/bbstring.cpp"
 #Import "native/bbstring.cpp"
 #Import "native/bbfunction.cpp"
 #Import "native/bbfunction.cpp"
 #Import "native/bbarray.cpp"
 #Import "native/bbarray.cpp"

+ 7 - 3
modules/monkey/native/bbfunction.h

@@ -3,9 +3,13 @@
 #define BB_FUNCTION_H
 #define BB_FUNCTION_H
 
 
 #include "bbtypes.h"
 #include "bbtypes.h"
-//#include "bbgc.h"
 #include "bbdebug.h"
 #include "bbdebug.h"
 
 
+namespace bbGC{
+	void *malloc( size_t size );
+	void free( void *p );
+}
+
 template<class T> class bbFunction;
 template<class T> class bbFunction;
 
 
 template<class R,class...A> struct bbFunction<R(A...)>{
 template<class R,class...A> struct bbFunction<R(A...)>{
@@ -53,11 +57,11 @@ template<class R,class...A> struct bbFunction<R(A...)>{
 		}
 		}
 		
 		
 		void *operator new( size_t size ){
 		void *operator new( size_t size ){
-			return bbMalloc( size );
+			return bbGC::malloc( size );
 		}
 		}
 		
 		
 		void operator delete( void *p ){
 		void operator delete( void *p ){
-			bbFree( p );
+			bbGC::free( p );
 		}
 		}
 	};
 	};
 	
 	

+ 19 - 15
modules/monkey/native/bbgc.cpp

@@ -1,4 +1,3 @@
-
 #include "bbgc.h"
 #include "bbgc.h"
 
 
 namespace bbDB{
 namespace bbDB{
@@ -241,15 +240,13 @@ namespace bbGC{
 		printf( "Warning! bbGC::release() - node not found!\n" );
 		printf( "Warning! bbGC::release() - node not found!\n" );
 	}
 	}
 	
 	
-	//need to return 8 byte aligned memory!
-	//
 	void *malloc( size_t size ){
 	void *malloc( size_t size ){
 	
 	
-//		size=(size+sizeof(size_t)+7)&~7;
-		size=( size+8+7 ) & ~7;
+		size=(size+8+7) & ~7;
 		
 		
 		memused+=size;
 		memused+=size;
 		
 		
+		
 		if( !suspended ){
 		if( !suspended ){
 
 
 			if( allocedBytes+size>=trigger ){
 			if( allocedBytes+size>=trigger ){
@@ -294,13 +291,10 @@ namespace bbGC{
 		}
 		}
 		
 		
 		allocedBytes+=size;
 		allocedBytes+=size;
-		
 		size_t *q=(size_t*)p;
 		size_t *q=(size_t*)p;
-		
 		if( sizeof(size_t)==4 ) ++q;
 		if( sizeof(size_t)==4 ) ++q;
-
 		*q++=size;
 		*q++=size;
-		
+
 		return q;
 		return q;
 	}
 	}
 	
 	
@@ -315,15 +309,13 @@ namespace bbGC{
 	
 	
 		if( !p ) return;
 		if( !p ) return;
 		
 		
-		size_t *q=(size_t*)p-1;
-		
-		size_t size=*q;
-		
+		size_t *q=(size_t*)p;
+		size_t size=*--q;
 		if( sizeof(size_t)==4 ) --q;
 		if( sizeof(size_t)==4 ) --q;
 		
 		
-#ifndef NDEBUG
+		#ifndef NDEBUG
 		memset( q,0xa5,size );
 		memset( q,0xa5,size );
-#endif
+		#endif
 		
 		
 		memused-=size;
 		memused-=size;
 		
 		
@@ -335,7 +327,19 @@ namespace bbGC{
 			::free( q );
 			::free( q );
 		}
 		}
 	}
 	}
+/*
+	bbGCNode *alloc( size_t size ){
 
 
+		bbGCNode *p=(bbGCNode*)bbGC::malloc( size );
+		
+		*((void**)p)=(void*)0xcafebabe;
+		
+		p->state=0;
+		p->flags=0;
+		
+		return p;
+	}
+*/	
 	void collect(){
 	void collect(){
 	
 	
 		if( !inited ) return;
 		if( !inited ) return;

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

@@ -4,7 +4,6 @@
 
 
 #include "bbstd.h"
 #include "bbstd.h"
 #include "bbtypes.h"
 #include "bbtypes.h"
-#include "bbmemory.h"
 #include "bbfunction.h"
 #include "bbfunction.h"
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG

+ 0 - 74
modules/monkey/native/bbmemory.cpp

@@ -1,74 +0,0 @@
-
-#include "bbmemory.h"
-
-#include <cstring>
-
-namespace{
-
-	void *pools[32];
-	
-	unsigned char *poolBuf;
-	size_t poolBufSize;
-}
-
-size_t bbMallocedBytes;
-
-void *bbMalloc( size_t size ){
-
-	size=(size+sizeof( size_t )+7)&~7;
-	
-	void *p;
-	
-	if( size<256 ){
-		if( pools[size>>3] ){
-			p=pools[size>>3];
-			pools[size>>3]=*(void**)p;
-		}else{
-			if( size>poolBufSize ){
-				if( poolBufSize ){
-					*(void**)poolBuf=pools[poolBufSize>>3];
-					pools[poolBufSize>>3]=poolBuf;
-				}
-				poolBufSize=65536;
-				poolBuf=(unsigned char*)::malloc( poolBufSize );
-			}
-			p=poolBuf;
-			poolBuf+=size;
-			poolBufSize-=size;
-		}
-	}else{
-		p=::malloc( size );
-	}
-	
-	bbMallocedBytes+=size;
-
-	size_t *q=(size_t*)p;
-	*q++=size;
-	return q;
-}
-
-size_t bbMallocSize( void *p ){
-
-	if( p ) return *((size_t*)p-1);
-	
-	return 0;
-}
-
-void bbFree( void *p ){
-
-	if( !p ) return;
-	
-	size_t *q=(size_t*)p-1;
-	
-	size_t size=*q;
-	
-	bbMallocedBytes-=size;
-
-	if( size<256 ){
-		*(void**)q=pools[size>>3];
-		pools[size>>3]=q;
-	}else{
-		::free( q );
-	}
-
-}

+ 0 - 15
modules/monkey/native/bbmemory.h

@@ -1,15 +0,0 @@
-
-#ifndef BB_MEMORY_H
-#define BB_MEMORY_H
-
-#include "bbtypes.h"
-
-extern size_t bbMallocedBytes;
-
-void *bbMalloc( size_t size );
-
-size_t bbMallocSize( void *p );
-
-void bbFree( void *p );
-
-#endif

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

@@ -5,7 +5,6 @@
 #include "bbstd.h"
 #include "bbstd.h"
 #include "bbtypes.h"
 #include "bbtypes.h"
 #include "bbassert.h"
 #include "bbassert.h"
-#include "bbmemory.h"
 #include "bbstring.h"
 #include "bbstring.h"
 #include "bbdebug.h"
 #include "bbdebug.h"
 #include "bbgc.h"
 #include "bbgc.h"

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

@@ -598,7 +598,7 @@ bbCString::bbCString( const bbString &str ){
 }
 }
 
 
 bbCString::~bbCString(){
 bbCString::~bbCString(){
-	bbFree( _data );
+	bbGC::free( _data );
 }
 }
 
 
 bbCString::operator char*()const{
 bbCString::operator char*()const{
@@ -622,7 +622,7 @@ bbWString::bbWString( const bbString &str ){
 }
 }
 
 
 bbWString::~bbWString(){
 bbWString::~bbWString(){
-	bbFree( _data );
+	bbGC::free( _data );
 }
 }
 
 
 bbWString::operator wchar_t*()const{
 bbWString::operator wchar_t*()const{

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

@@ -4,7 +4,6 @@
 
 
 #include "bbtypes.h"
 #include "bbtypes.h"
 #include "bbassert.h"
 #include "bbassert.h"
-#include "bbmemory.h"
 
 
 namespace bbGC{
 namespace bbGC{
 	void *malloc( size_t size );
 	void *malloc( size_t size );