]> gitweb.factorcode.org Git - factor.git/blob - vm/profiler.cpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / profiler.cpp
1 #include "master.hpp"
2
3 namespace factor
4 {
5
6 bool profiling_p;
7
8 void init_profiler()
9 {
10         profiling_p = false;
11 }
12
13 /* Allocates memory */
14 code_block *compile_profiling_stub(cell word_)
15 {
16         gc_root<word> word(word_);
17
18         jit jit(WORD_TYPE,word.value());
19         jit.emit_with(userenv[JIT_PROFILING],word.value());
20
21         return jit.to_code_block();
22 }
23
24 /* Allocates memory */
25 static void set_profiling(bool profiling)
26 {
27         if(profiling == profiling_p)
28                 return;
29
30         profiling_p = profiling;
31
32         /* Push everything to tenured space so that we can heap scan
33         and allocate profiling blocks if necessary */
34         gc();
35
36         gc_root<array> words(find_all_words());
37
38         cell i;
39         cell length = array_capacity(words.untagged());
40         for(i = 0; i < length; i++)
41         {
42                 tagged<word> word(array_nth(words.untagged(),i));
43                 if(profiling)
44                         word->counter = tag_fixnum(0);
45                 update_word_xt(word.value());
46         }
47
48         /* Update XTs in code heap */
49         iterate_code_heap(relocate_code_block);
50 }
51
52 PRIMITIVE(profiling)
53 {
54         set_profiling(to_boolean(dpop()));
55 }
56
57 }