| 
									
										
										
										
											2011-11-07 15:51:49 -05:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  | namespace factor { | 
					
						
							| 
									
										
										
										
											2011-11-07 15:51:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  | void safepoint_state::enqueue_fep(factor_vm* parent) volatile { | 
					
						
							|  |  |  |   if (parent->fep_p) | 
					
						
							|  |  |  |     fatal_error("Low-level debugger interrupted", 0); | 
					
						
							|  |  |  |   atomic::store(&fep_p, true); | 
					
						
							| 
									
										
										
										
											2015-08-26 10:56:55 -04:00
										 |  |  |   parent->code->set_safepoint_guard(true); | 
					
						
							| 
									
										
										
										
											2011-11-07 15:51:49 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 02:58:03 -04:00
										 |  |  | void safepoint_state::enqueue_samples(factor_vm* parent, | 
					
						
							|  |  |  |                                       cell samples, | 
					
						
							|  |  |  |                                       cell pc, | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  |                                       bool foreign_thread_p) volatile { | 
					
						
							| 
									
										
										
										
											2015-08-24 02:58:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!atomic::load(&parent->sampling_profiler_p)) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   atomic::fetch_add(&sample_counts.sample_count, samples); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (foreign_thread_p) | 
					
						
							|  |  |  |     atomic::fetch_add(&sample_counts.foreign_thread_sample_count, samples); | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if (atomic::load(&parent->current_gc_p)) | 
					
						
							|  |  |  |       atomic::fetch_add(&sample_counts.gc_sample_count, samples); | 
					
						
							|  |  |  |     if (atomic::load(&parent->current_jit_count) > 0) | 
					
						
							|  |  |  |       atomic::fetch_add(&sample_counts.jit_sample_count, samples); | 
					
						
							|  |  |  |     if (!parent->code->seg->in_segment_p(pc)) | 
					
						
							|  |  |  |       atomic::fetch_add(&sample_counts.foreign_sample_count, samples); | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-08-26 10:56:55 -04:00
										 |  |  |   parent->code->set_safepoint_guard(true); | 
					
						
							| 
									
										
										
										
											2011-11-07 15:51:49 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  | void safepoint_state::handle_safepoint(factor_vm* parent, cell pc) volatile { | 
					
						
							| 
									
										
										
										
											2015-08-24 02:58:03 -04:00
										 |  |  |   parent->code->set_safepoint_guard(false); | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  |   parent->faulting_p = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (atomic::load(&fep_p)) { | 
					
						
							|  |  |  |     if (atomic::load(&parent->sampling_profiler_p)) | 
					
						
							|  |  |  |       parent->end_sampling_profiler(); | 
					
						
							|  |  |  |     std::cout << "Interrupted\n"; | 
					
						
							|  |  |  |     parent->factorbug(); | 
					
						
							|  |  |  |     atomic::store(&fep_p, false); | 
					
						
							|  |  |  |   } else if (atomic::load(&parent->sampling_profiler_p)) { | 
					
						
							|  |  |  |     FACTOR_ASSERT(parent->code->seg->in_segment_p(pc)); | 
					
						
							|  |  |  |     code_block* block = parent->code->code_block_for_address(pc); | 
					
						
							| 
									
										
										
										
											2015-01-07 05:51:19 -05:00
										 |  |  |     bool prolog_p = block->entry_point() == pc; | 
					
						
							| 
									
										
										
										
											2013-05-11 22:27:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     parent->record_sample(prolog_p); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-07 15:51:49 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |