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