| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | #include "master.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2009-01-24 21:13:17 -05:00
										 |  |  | F_CODE_BLOCK *compile_profiling_stub(F_WORD *word) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-19 21:03:07 -04:00
										 |  |  | 	CELL literals = allot_array_2(tag_object(word),tag_object(word)); | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	REGISTER_ROOT(literals); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F_ARRAY *quadruple = untag_object(userenv[JIT_PROFILING]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL code = array_nth(quadruple,0); | 
					
						
							|  |  |  | 	REGISTER_ROOT(code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-20 00:21:32 -04:00
										 |  |  | 	F_REL rel = (to_fixnum(array_nth(quadruple,1)) << 24) | 
					
						
							| 
									
										
										
										
											2009-03-19 21:03:07 -04:00
										 |  |  | 		| (to_fixnum(array_nth(quadruple,2)) << 28) | 
					
						
							|  |  |  | 		| (to_fixnum(array_nth(quadruple,3)) * compiled_code_format()); | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-20 00:21:32 -04:00
										 |  |  | 	F_BYTE_ARRAY *relocation = allot_byte_array(sizeof(F_REL)); | 
					
						
							|  |  |  | 	memcpy(relocation + 1,&rel,sizeof(F_REL)); | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	UNREGISTER_ROOT(code); | 
					
						
							|  |  |  | 	UNREGISTER_ROOT(literals); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-19 04:45:37 -04:00
										 |  |  | 	return add_code_block( | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 		WORD_TYPE, | 
					
						
							|  |  |  | 		untag_object(code), | 
					
						
							|  |  |  | 		NULL, /* no labels */ | 
					
						
							| 
									
										
										
										
											2008-05-30 15:10:18 -04:00
										 |  |  | 		tag_object(relocation), | 
					
						
							| 
									
										
										
										
											2009-01-24 18:01:01 -05:00
										 |  |  | 		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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 	if(profiling_p) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if(!word->profiling) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			REGISTER_UNTAGGED(word); | 
					
						
							| 
									
										
										
										
											2009-01-24 21:13:17 -05:00
										 |  |  | 			F_CODE_BLOCK *profiling = compile_profiling_stub(word); | 
					
						
							| 
									
										
										
										
											2008-01-02 19:36:36 -05:00
										 |  |  | 			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-04-05 05:01:46 -04:00
										 |  |  | 	/* Push everything to tenured space so that we can heap scan
 | 
					
						
							|  |  |  | 	and allocate profiling blocks if necessary */ | 
					
						
							|  |  |  | 	gc(); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-05 09:27:07 -04:00
										 |  |  | 	CELL words = find_all_words(); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-05 09:27:07 -04:00
										 |  |  | 	REGISTER_ROOT(words); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL i; | 
					
						
							|  |  |  | 	CELL length = array_capacity(untag_object(words)); | 
					
						
							|  |  |  | 	for(i = 0; i < length; i++) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-04-05 09:27:07 -04:00
										 |  |  | 		F_WORD *word = untag_word(array_nth(untag_array(words),i)); | 
					
						
							| 
									
										
										
										
											2008-07-05 23:19:16 -04:00
										 |  |  | 		if(profiling) | 
					
						
							|  |  |  | 			word->counter = tag_fixnum(0); | 
					
						
							| 
									
										
										
										
											2008-04-05 09:27:07 -04:00
										 |  |  | 		update_word_xt(word); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-05 09:27:07 -04:00
										 |  |  | 	UNREGISTER_ROOT(words); | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 04:20:34 -05:00
										 |  |  | void primitive_profiling(void) | 
					
						
							| 
									
										
										
										
											2007-10-28 04:33:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	set_profiling(to_boolean(dpop())); | 
					
						
							|  |  |  | } |