| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-08 16:05:55 -04:00
										 |  |  | static const cell free_list_count = 16; | 
					
						
							|  |  |  | static const cell block_size_increment = 32; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | struct heap_free_list { | 
					
						
							| 
									
										
										
										
											2009-05-08 16:05:55 -04:00
										 |  |  | 	free_heap_block *small_blocks[free_list_count]; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	free_heap_block *large_blocks; | 
					
						
							| 
									
										
										
										
											2009-05-02 11:17:05 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | struct heap { | 
					
						
							|  |  |  | 	segment *seg; | 
					
						
							|  |  |  | 	heap_free_list free; | 
					
						
							| 
									
										
										
										
											2009-05-02 11:17:05 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | typedef void (*heap_iterator)(heap_block *compiled); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void new_heap(heap *h, cell size); | 
					
						
							|  |  |  | void build_free_list(heap *h, cell size); | 
					
						
							|  |  |  | heap_block *heap_allot(heap *h, cell size); | 
					
						
							|  |  |  | void heap_free(heap *h, heap_block *block); | 
					
						
							|  |  |  | void mark_block(heap_block *block); | 
					
						
							|  |  |  | void unmark_marked(heap *heap); | 
					
						
							|  |  |  | void free_unmarked(heap *heap, heap_iterator iter); | 
					
						
							|  |  |  | void heap_usage(heap *h, cell *used, cell *total_free, cell *max_free); | 
					
						
							|  |  |  | cell heap_size(heap *h); | 
					
						
							| 
									
										
										
										
											2009-05-05 15:17:02 -04:00
										 |  |  | cell compute_heap_forwarding(heap *h, unordered_map<heap_block *,char *> &forwarding); | 
					
						
							|  |  |  | void compact_heap(heap *h, unordered_map<heap_block *,char *> &forwarding); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline static heap_block *next_block(heap *h, heap_block *block) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell next = ((cell)block + block->size); | 
					
						
							|  |  |  | 	if(next == h->seg->end) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		return (heap_block *)next; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static heap_block *first_block(heap *h) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return (heap_block *)h->seg->start; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | inline static heap_block *last_block(heap *h) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return (heap_block *)h->seg->end; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |