| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | #include "master.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							|  |  |  | F_COMPILED *compile_profiling_stub(F_WORD *word) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	CELL literals = allot_array_1(tag_object(word)); | 
					
						
							|  |  |  | 	REGISTER_ROOT(literals); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F_ARRAY *quadruple = untag_object(userenv[JIT_PROFILING]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL code = array_nth(quadruple,0); | 
					
						
							|  |  |  | 	REGISTER_ROOT(code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL rel_type = allot_cell(to_fixnum(array_nth(quadruple,2)) | 
					
						
							|  |  |  | 		| (to_fixnum(array_nth(quadruple,1)) << 8)); | 
					
						
							| 
									
										
										
										
											2008-01-09 01:33:40 -05:00
										 |  |  | 	CELL rel_offset = array_nth(quadruple,3) * compiled_code_format(); | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CELL relocation = allot_array_2(rel_type,rel_offset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UNREGISTER_ROOT(code); | 
					
						
							|  |  |  | 	UNREGISTER_ROOT(literals); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return add_compiled_block( | 
					
						
							|  |  |  | 		WORD_TYPE, | 
					
						
							|  |  |  | 		untag_object(code), | 
					
						
							|  |  |  | 		NULL, /* no labels */ | 
					
						
							|  |  |  | 		untag_object(relocation), | 
					
						
							|  |  |  | 		untag_object(literals)); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							|  |  |  | void update_word_xt(F_WORD *word) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* If we just enabled the profiler, reset call count */ | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	if(profiling_p) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2007-12-29 12:44:01 -05:00
										 |  |  | 		word->counter = tag_fixnum(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 		if(!word->profiling) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			REGISTER_UNTAGGED(word); | 
					
						
							|  |  |  | 			F_COMPILED *profiling = compile_profiling_stub(word); | 
					
						
							|  |  |  | 			UNREGISTER_UNTAGGED(word); | 
					
						
							|  |  |  | 			word->profiling = profiling; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		word->xt = (XT)(word->profiling + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-12-29 12:44:01 -05:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 		word->xt = (XT)(word->code + 1); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void set_profiling(bool profiling) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	if(profiling == profiling_p) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	profiling_p = profiling; | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	/* Push everything to tenured space so that we can heap scan,
 | 
					
						
							|  |  |  | 	also code GC so that we can allocate profiling blocks if | 
					
						
							|  |  |  | 	necessary */ | 
					
						
							|  |  |  | 	code_gc(); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-26 17:14:33 -05:00
										 |  |  | 	/* Update word XTs and saved callstack objects */ | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 	begin_scan(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL obj; | 
					
						
							|  |  |  | 	while((obj = next_object()) != F) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if(type_of(obj) == WORD_TYPE) | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 			update_word_xt(untag_object(obj)); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gc_off = false; /* end heap scan */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-26 17:14:33 -05:00
										 |  |  | 	/* Update XTs in code heap */ | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 	iterate_code_heap(relocate_code_block); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DEFINE_PRIMITIVE(profiling) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	set_profiling(to_boolean(dpop())); | 
					
						
							|  |  |  | } |