VM: simplify GC a bit, add GC_DEBUG compile-time flag
							parent
							
								
									dac5203e81
								
							
						
					
					
						commit
						087c962f75
					
				| 
						 | 
				
			
			@ -224,7 +224,8 @@ void mark_object_code_block(CELL scan)
 | 
			
		|||
	{
 | 
			
		||||
	case WORD_TYPE:
 | 
			
		||||
		word = (F_WORD *)scan;
 | 
			
		||||
		mark_code_block(word->code);
 | 
			
		||||
		if(word->code)
 | 
			
		||||
		  mark_code_block(word->code);
 | 
			
		||||
		if(word->profiling)
 | 
			
		||||
			mark_code_block(word->profiling);
 | 
			
		||||
		break;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -330,7 +330,7 @@ CELL copy_next_from_tenured(CELL scan)
 | 
			
		|||
 | 
			
		||||
void copy_reachable_objects(CELL scan, CELL *end)
 | 
			
		||||
{
 | 
			
		||||
	if(HAVE_NURSERY_P && collecting_gen == NURSERY)
 | 
			
		||||
	if(collecting_gen == NURSERY)
 | 
			
		||||
	{
 | 
			
		||||
		while(scan < *end)
 | 
			
		||||
			scan = copy_next_from_nursery(scan);
 | 
			
		||||
| 
						 | 
				
			
			@ -405,7 +405,7 @@ void end_gc(CELL gc_elapsed)
 | 
			
		|||
		if(collecting_gen != NURSERY)
 | 
			
		||||
			reset_generations(NURSERY,collecting_gen - 1);
 | 
			
		||||
	}
 | 
			
		||||
	else if(HAVE_NURSERY_P && collecting_gen == NURSERY)
 | 
			
		||||
	else if(collecting_gen == NURSERY)
 | 
			
		||||
	{
 | 
			
		||||
		nursery.here = nursery.start;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										20
									
								
								vm/data_gc.h
								
								
								
								
							
							
						
						
									
										20
									
								
								vm/data_gc.h
								
								
								
								
							| 
						 | 
				
			
			@ -58,7 +58,7 @@ INLINE bool should_copy(CELL untagged)
 | 
			
		|||
		return true;
 | 
			
		||||
	else if(HAVE_AGING_P && collecting_gen == AGING)
 | 
			
		||||
		return !in_zone(&data_heap->generations[TENURED],untagged);
 | 
			
		||||
	else if(HAVE_NURSERY_P && collecting_gen == NURSERY)
 | 
			
		||||
	else if(collecting_gen == NURSERY)
 | 
			
		||||
		return in_zone(&nursery,untagged);
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -78,15 +78,31 @@ allocation (which does not call GC because of possible roots in volatile
 | 
			
		|||
registers) does not run out of memory */
 | 
			
		||||
#define ALLOT_BUFFER_ZONE 1024
 | 
			
		||||
 | 
			
		||||
/* If this is defined, we GC every 100 allocations. This catches missing local roots */
 | 
			
		||||
#ifdef GC_DEBUG
 | 
			
		||||
static int count;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * It is up to the caller to fill in the object's fields in a meaningful
 | 
			
		||||
 * fashion!
 | 
			
		||||
 */
 | 
			
		||||
INLINE void *allot_object(CELL type, CELL a)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
#ifdef GC_DEBUG
 | 
			
		||||
 | 
			
		||||
	if(!gc_off)
 | 
			
		||||
	{
 | 
			
		||||
		if(count++ % 1000 == 0)
 | 
			
		||||
			gc();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	CELL *object;
 | 
			
		||||
 | 
			
		||||
	if(HAVE_NURSERY_P && nursery.size - ALLOT_BUFFER_ZONE > a)
 | 
			
		||||
	if(nursery.size - ALLOT_BUFFER_ZONE > a)
 | 
			
		||||
	{
 | 
			
		||||
		/* If there is insufficient room, collect the nursery */
 | 
			
		||||
		if(nursery.here + ALLOT_BUFFER_ZONE + a > nursery.end)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,7 +37,6 @@ F_DATA_HEAP *data_heap;
 | 
			
		|||
 | 
			
		||||
/* the 0th generation is where new objects are allocated. */
 | 
			
		||||
#define NURSERY 0
 | 
			
		||||
#define HAVE_NURSERY_P (data_heap->gen_count>1)
 | 
			
		||||
/* where objects hang around */
 | 
			
		||||
#define AGING (data_heap->gen_count-2)
 | 
			
		||||
#define HAVE_AGING_P (data_heap->gen_count>2)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue