]> gitweb.factorcode.org Git - factor.git/blob - vm/counting_profiler.cpp
init signals or console after stage2 init
[factor.git] / vm / counting_profiler.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 void factor_vm::init_counting_profiler()
7 {
8         counting_profiler_p = false;
9 }
10
11 /* Allocates memory */
12 code_block *factor_vm::compile_counting_profiler_stub(cell word_)
13 {
14         data_root<word> word(word_,this);
15
16         jit jit(code_block_counting_profiler,word.value(),this);
17         jit.emit_with_literal(special_objects[JIT_PROFILING],word.value());
18
19         return jit.to_code_block();
20 }
21
22 /* Allocates memory */
23 void factor_vm::set_counting_profiler(bool counting_profiler)
24 {
25         if(counting_profiler == counting_profiler_p)
26                 return;
27
28         /* Push everything to tenured space so that we can heap scan
29         and allocate counting_profiler blocks if necessary */
30         primitive_full_gc();
31
32         data_root<array> words(find_all_words(),this);
33
34         counting_profiler_p = counting_profiler;
35
36         cell length = array_capacity(words.untagged());
37         for(cell i = 0; i < length; i++)
38         {
39                 tagged<word> word(array_nth(words.untagged(),i));
40
41                 /* Note: can't do w->counting_profiler = ... since LHS evaluates
42                 before RHS, and if RHS does a GC, we will have an
43                 invalid pointer on the LHS */
44                 if(counting_profiler)
45                 {
46                         if(!word->counting_profiler)
47                         {
48                                 code_block *counting_profiler_block = compile_counting_profiler_stub(word.value());
49                                 word->counting_profiler = counting_profiler_block;
50                         }
51
52                         word->counter = tag_fixnum(0);
53                 }
54
55                 update_word_entry_point(word.untagged());
56         }
57
58         update_code_heap_words(false);
59 }
60
61 void factor_vm::primitive_counting_profiler()
62 {
63         set_counting_profiler(to_boolean(ctx->pop()));
64 }
65
66 }