vm: sample pc on windows

db4
Joe Groff 2011-11-02 21:18:31 -07:00
parent 1833beea52
commit 2d87b68a56
5 changed files with 28 additions and 8 deletions

View File

@ -212,9 +212,10 @@ void factor_vm::start_standalone_factor(int argc, vm_char **argv)
factor_vm *new_factor_vm()
{
factor_vm *newvm = new factor_vm();
THREADHANDLE thread = thread_id();
factor_vm *newvm = new factor_vm(thread);
register_vm_with_thread(newvm);
thread_vms[thread_id()] = newvm;
thread_vms[thread] = newvm;
return newvm;
}

View File

@ -320,13 +320,28 @@ void factor_vm::sampler_thread_loop()
assert(ok);
new_counter.QuadPart *= samples_per_second;
cell samples = 0;
while (new_counter.QuadPart - counter.QuadPart > units_per_second.QuadPart) {
// We would have to suspend the thread to sample the PC
while (new_counter.QuadPart - counter.QuadPart > units_per_second.QuadPart)
{
++samples;
counter.QuadPart += units_per_second.QuadPart;
}
if (samples > 0)
enqueue_safepoint_sample(samples, 0, false);
{
DWORD suscount = SuspendThread(thread);
assert(suscount == 0);
CONTEXT context;
memset((void*)&context, 0, sizeof(CONTEXT));
context.ContextFlags = CONTEXT_CONTROL;
BOOL context_ok = GetThreadContext(thread, &context);
assert(context_ok);
suscount = ResumeThread(thread);
assert(suscount == 1);
enqueue_safepoint_sample(samples, context.EIP, false);
}
}
}

View File

@ -164,7 +164,7 @@ void factor_vm::enqueue_safepoint_sample(cell samples, cell pc, bool foreign_thr
atomic::add(&safepoint_sample_counts.gc_sample_count, samples);
if (atomic::load(&current_jit_count) > 0)
atomic::add(&safepoint_sample_counts.jit_sample_count, samples);
if (pc != 0 && !code->seg->in_segment_p(pc))
if (!code->seg->in_segment_p(pc))
atomic::add(&safepoint_sample_counts.foreign_sample_count, samples);
}
code->guard_safepoint();

View File

@ -3,8 +3,9 @@
namespace factor
{
factor_vm::factor_vm() :
factor_vm::factor_vm(THREADHANDLE thread) :
nursery(0,0),
thread(thread),
callback_id(0),
c_to_factor_func(NULL),
counting_profiler_p(false),

View File

@ -36,6 +36,9 @@ struct factor_vm
// ^^^^^^
//
/* Handle to the main thread we run in */
THREADHANDLE thread;
/* Data stack and retain stack sizes */
cell datastack_size, retainstack_size, callstack_size;
@ -754,7 +757,7 @@ struct factor_vm
void call_fault_handler(exception_type_t exception, exception_data_type_t code, MACH_EXC_STATE_TYPE *exc_state, MACH_THREAD_STATE_TYPE *thread_state, MACH_FLOAT_STATE_TYPE *float_state);
#endif
factor_vm();
factor_vm(THREADHANDLE thread_id);
~factor_vm();
};