]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/safepoints.cpp
audio.engine.test: cleanup using
[factor.git] / vm / safepoints.cpp
index 55a76c685287ae2d3c5b2e9731809ee131a36319..c23baf3f30b6c5904156034fadd6802d22943202 100644 (file)
@@ -1,62 +1,61 @@
 #include "master.hpp"
 
-namespace factor
-{
+namespace factor {
 
-void safepoint_state::enqueue_safepoint() volatile
-{
-       parent->code->guard_safepoint();
+void factor_vm::enqueue_fep() {
+  if (fep_p)
+    fatal_error("Low-level debugger interrupted", 0);
+  atomic::store(&safepoint_fep_p, true);
+  code->set_safepoint_guard(true);
 }
 
-void safepoint_state::enqueue_fep() volatile
-{
-       if (parent->fep_p)
-               fatal_error("Low-level debugger interrupted", 0);
-       atomic::store(&fep_p, true);
-       enqueue_safepoint();
+void factor_vm::enqueue_samples(cell samples,
+                                cell pc,
+                                bool foreign_thread_p) {
+
+  if (!atomic::load(&sampling_profiler_p))
+    return;
+  atomic::fetch_add(&current_sample.sample_count, samples);
+
+  if (foreign_thread_p)
+    atomic::fetch_add(&current_sample.foreign_thread_sample_count, samples);
+  else {
+    if (atomic::load(&current_gc_p))
+      atomic::fetch_add(&current_sample.gc_sample_count, samples);
+    if (atomic::load(&current_jit_count) > 0)
+      atomic::fetch_add(&current_sample.jit_sample_count, samples);
+    if (!code->seg->in_segment_p(pc))
+      atomic::fetch_add(&current_sample.foreign_sample_count, samples);
+  }
+  code->set_safepoint_guard(true);
 }
 
-void safepoint_state::enqueue_signal(cell signal) volatile
-{
-       atomic::store(&queued_signal, signal);
-       enqueue_safepoint();
-}
-
-void safepoint_state::enqueue_samples(cell samples, cell pc, bool foreign_thread_p) volatile
-{
-       if (atomic::load(&parent->sampling_profiler_p))
-       {
-               atomic::add(&sample_counts.sample_count, samples);
-               if (foreign_thread_p)
-                       atomic::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);
-               }
-               enqueue_safepoint();
-       }
-}
-
-void safepoint_state::handle_safepoint() volatile
-{
-       parent->code->unguard_safepoint();
-
-       report_signal(parent->signal_pipe_input);
-
-       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))
-               parent->record_sample();
+// Allocates memory (record_sample)
+void factor_vm::handle_safepoint(cell pc) {
+  code->set_safepoint_guard(false);
+  faulting_p = false;
+
+  if (atomic::load(&safepoint_fep_p)) {
+    if (atomic::load(&sampling_profiler_p))
+      end_sampling_profiler();
+    std::cout << "Interrupted\n";
+    if (stop_on_ctrl_break) {
+      /* Ctrl-Break throws an exception, interrupting the main thread, same
+         as the "t" command in the factorbug debugger. But for Ctrl-Break to
+         work we don't require the debugger to be activated, or even enabled. */
+      atomic::store(&safepoint_fep_p, false);
+      general_error(ERROR_INTERRUPT, false_object, false_object);
+      FACTOR_ASSERT(false);
+    }
+    factorbug();
+    atomic::store(&safepoint_fep_p, false);
+  } else if (atomic::load(&sampling_profiler_p)) {
+    FACTOR_ASSERT(code->seg->in_segment_p(pc));
+    code_block* block = code->code_block_for_address(pc);
+    bool prolog_p = block->entry_point() == pc;
+
+    record_sample(prolog_p);
+  }
 }
 
 }