factor/vm/profiler.cpp

67 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-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
{
data_root<word> word(word_,this);
2009-05-02 10:19:09 -04:00
jit jit(code_block_profiling,word.value(),this);
jit.emit_with_literal(special_objects[JIT_PROFILING],word.value());
2009-05-02 10:19:09 -04:00
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;
/* Push everything to tenured space so that we can heap scan
and allocate profiling blocks if necessary */
primitive_full_gc();
2009-05-02 05:04:19 -04:00
data_root<array> words(find_all_words(),this);
2009-05-02 05:04:19 -04:00
2009-11-06 02:22:53 -05:00
profiling_p = profiling;
2009-05-04 05:50:24 -04:00
cell length = array_capacity(words.untagged());
2009-11-06 02:22:53 -05:00
for(cell i = 0; i < length; i++)
2009-05-02 05:04:19 -04:00
{
2009-05-04 05:50:24 -04:00
tagged<word> word(array_nth(words.untagged(),i));
/* Note: can't do w->profiling = ... since LHS evaluates
before RHS, and if RHS does a GC, we will have an
invalid pointer on the LHS */
2009-05-02 05:04:19 -04:00
if(profiling)
{
if(!word->profiling)
{
code_block *profiling_block = compile_profiling_stub(word.value());
word->profiling = profiling_block;
}
2009-05-02 05:04:19 -04:00
word->counter = tag_fixnum(0);
}
update_word_entry_point(word.untagged());
2009-05-02 05:04:19 -04:00
}
update_code_heap_words(false);
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(ctx->pop()));
2009-05-02 05:04:19 -04:00
}
2009-05-04 02:46:13 -04:00
}