factor/vm/profiler.cpp

78 lines
1.3 KiB
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-05-02 05:04:19 -04:00
bool profiling_p;
2009-08-17 16:37:04 -04:00
void factorvm::init_profiler()
2009-05-02 05:04:19 -04:00
{
profiling_p = false;
}
2009-08-17 16:37:04 -04:00
void init_profiler()
{
return vm->init_profiler();
}
2009-05-02 05:04:19 -04:00
/* Allocates memory */
2009-08-17 16:37:04 -04:00
code_block *factorvm::compile_profiling_stub(cell word_)
2009-05-02 05:04:19 -04:00
{
2009-05-04 05:50:24 -04:00
gc_root<word> word(word_);
2009-05-02 10:19:09 -04:00
jit jit(WORD_TYPE,word.value());
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
}
2009-08-17 16:37:04 -04:00
code_block *compile_profiling_stub(cell word_)
{
return vm->compile_profiling_stub(word_);
}
2009-05-02 05:04:19 -04:00
/* Allocates memory */
2009-08-17 16:37:04 -04:00
void factorvm::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();
2009-05-04 05:50:24 -04:00
gc_root<array> words(find_all_words());
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
}
/* Update XTs in code heap */
2009-08-17 16:37:08 -04:00
iterate_code_heap(factor::relocate_code_block);
2009-05-02 05:04:19 -04:00
}
2009-08-17 16:37:04 -04:00
void set_profiling(bool profiling)
{
return vm->set_profiling(profiling);
}
inline void factorvm::vmprim_profiling()
2009-05-02 05:04:19 -04:00
{
set_profiling(to_boolean(dpop()));
}
2009-05-04 02:46:13 -04:00
2009-08-17 16:37:04 -04:00
PRIMITIVE(profiling)
{
PRIMITIVE_GETVM()->vmprim_profiling();
}
2009-05-04 02:46:13 -04:00
}