factor/vm/profiler.cpp

55 lines
986 B
C++
Raw Normal View History

2009-05-02 05:04:19 -04:00
#include "master.hpp"
2009-05-04 02:46:13 -04:00
namespace factor
{
2009-09-23 14:05:46 -04:00
void factor_vm::init_profiler()
2009-05-02 05:04:19 -04:00
{
profiling_p = false;
}
/* Allocates memory */
2009-09-23 14:05:46 -04:00
code_block *factor_vm::compile_profiling_stub(cell word_)
2009-05-02 05:04:19 -04:00
{
gc_root<word> word(word_,this);
2009-05-02 10:19:09 -04:00
2009-08-17 16:37:09 -04:00
jit jit(WORD_TYPE,word.value(),this);
2009-05-02 10:19:09 -04:00
jit.emit_with(userenv[JIT_PROFILING],word.value());
2009-05-04 05:50:24 -04:00
return jit.to_code_block();
2009-05-02 05:04:19 -04:00
}
/* Allocates memory */
2009-09-23 14:05:46 -04:00
void factor_vm::set_profiling(bool profiling)
2009-05-02 05:04:19 -04:00
{
if(profiling == profiling_p)
return;
profiling_p = profiling;
/* Push everything to tenured space so that we can heap scan
and allocate profiling blocks if necessary */
gc();
gc_root<array> words(find_all_words(),this);
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
cell i;
cell length = array_capacity(words.untagged());
2009-05-02 05:04:19 -04:00
for(i = 0; i < length; i++)
{
2009-05-04 05:50:24 -04:00
tagged<word> word(array_nth(words.untagged(),i));
2009-05-02 05:04:19 -04:00
if(profiling)
word->counter = tag_fixnum(0);
2009-05-02 10:19:09 -04:00
update_word_xt(word.value());
2009-05-02 05:04:19 -04:00
}
2009-10-06 02:42:17 -04:00
update_code_heap_words();
2009-05-02 05:04:19 -04:00
}
void factor_vm::primitive_profiling()
2009-05-02 05:04:19 -04:00
{
set_profiling(to_boolean(dpop()));
}
2009-05-04 02:46:13 -04:00
}