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