]> gitweb.factorcode.org Git - factor.git/blob - vm/profiler.cpp
constants for special object hardcoded literals
[factor.git] / vm / profiler.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 void factor_vm::init_profiler()
7 {
8         counting_profiler_p = false;
9 }
10
11 /* Allocates memory */
12 code_block *factor_vm::compile_profiling_stub(cell word_)
13 {
14         data_root<word> word(word_,this);
15
16         jit jit(code_block_profiling,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_profiling(bool profiling)
24 {
25         if(profiling == counting_profiler_p)
26                 return;
27
28         /* Push everything to tenured space so that we can heap scan
29         and allocate profiling blocks if necessary */
30         primitive_full_gc();
31
32         data_root<array> words(find_all_words(),this);
33
34         counting_profiler_p = profiling;
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->profiling = ... since LHS evaluates
42                 before RHS, and if RHS does a GC, we will have an
43                 invalid pointer on the LHS */
44                 if(profiling)
45                 {
46                         if(!word->profiling)
47                         {
48                                 code_block *profiling_block = compile_profiling_stub(word.value());
49                                 word->profiling = profiling_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_profiling()
62 {
63         set_profiling(to_boolean(ctx->pop()));
64 }
65
66 }