]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: sample thread object rather than raw context
authorJoe Groff <arcata@gmail.com>
Wed, 2 Nov 2011 02:39:54 +0000 (19:39 -0700)
committerJoe Groff <arcata@gmail.com>
Wed, 2 Nov 2011 20:23:18 +0000 (13:23 -0700)
vm/sampling_profiler.cpp
vm/sampling_profiler.hpp
vm/slot_visitor.hpp

index 24ac5c8bdef10024ffc5fc2d1638e33f9f2c514a..9655728bab109c0f62437c434b254a261a1e286c 100644 (file)
@@ -29,10 +29,10 @@ void profiling_sample_count::clear() volatile
 
 profiling_sample::profiling_sample(factor_vm *vm,
        profiling_sample_count const &counts,
-       context *ctx)
+       cell thread)
        :
        counts(counts),
-       ctx(ctx)
+       thread(thread)
 {
        vm->record_callstack_sample(&callstack_begin, &callstack_end);
 }
@@ -41,7 +41,8 @@ void factor_vm::record_sample()
 {
        profiling_sample_count counts = safepoint_sample_counts.record_counts();
        if (!counts.empty())
-               samples.push_back(profiling_sample(this, counts, ctx));
+               samples.push_back(profiling_sample(this,
+                       counts, special_objects[OBJ_CURRENT_THREAD]));
 }
 
 void factor_vm::record_callstack_sample(cell *begin, cell *end)
@@ -121,8 +122,7 @@ void factor_vm::primitive_get_samples()
                        set_array_nth(sample.untagged(),2,tag_fixnum(from_iter->counts.foreign_sample_count));
                        set_array_nth(sample.untagged(),3,tag_fixnum(from_iter->counts.foreign_thread_sample_count));
 
-                       cell ctx = allot_alien((void*)from_iter->ctx);
-                       set_array_nth(sample.untagged(),4,ctx);
+                       set_array_nth(sample.untagged(),4,from_iter->thread);
 
                        cell callstack_size = from_iter->callstack_end - from_iter->callstack_begin;
                        data_root<array> callstack(allot_array(callstack_size,false_object),this);
index 8a599938cb48bef5dfb55069b16e59fac8e99b69..48bae883d1bb818a1293ae04e93a7e326fb66752 100644 (file)
@@ -43,15 +43,15 @@ struct profiling_sample
 {
        // Sample counts
        profiling_sample_count counts;
-       // Active context during sample
-       context *ctx;
+       // Active thread during sample
+       cell thread;
        /* The callstack at safepoint time. Indexes to the beginning and ending
        code_block entries in the vm sample_callstacks array. */
        cell callstack_begin, callstack_end;
 
        profiling_sample(factor_vm *vm,
                profiling_sample_count const &counts,
-               context *ctx);
+               cell thread);
 };
 
 }
index b2fd5d3c4b033ebd5899e11d69bee3c8bcb0cec0..4fda73814072c6030faec1ed437c20ea5b256759 100755 (executable)
@@ -135,6 +135,7 @@ template<typename Fixup> struct slot_visitor {
        void visit_code_block_objects(code_block *compiled);
        void visit_embedded_literals(code_block *compiled);
        void visit_sample_callstacks();
+       void visit_sample_threads();
 };
 
 template<typename Fixup>
@@ -261,6 +262,17 @@ void slot_visitor<Fixup>::visit_sample_callstacks()
        }
 }
 
+template<typename Fixup>
+void slot_visitor<Fixup>::visit_sample_threads()
+{
+       for (std::vector<profiling_sample>::iterator iter = parent->samples.begin();
+               iter != parent->samples.end();
+               ++iter)
+       {
+               visit_handle(&iter->thread);
+       }
+}
+
 template<typename Fixup>
 void slot_visitor<Fixup>::visit_roots()
 {
@@ -274,6 +286,7 @@ void slot_visitor<Fixup>::visit_roots()
        visit_callback_roots();
        visit_literal_table_roots();
        visit_sample_callstacks();
+       visit_sample_threads();
 
        visit_object_array(parent->special_objects,parent->special_objects + special_object_count);
 }