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
|
|
|
{
|
2009-11-02 19:10:34 -05:00
|
|
|
data_root<word> word(word_,this);
|
2009-05-02 10:19:09 -04:00
|
|
|
|
2009-10-20 10:37:24 -04:00
|
|
|
jit jit(code_block_profiling,word.value(),this);
|
2009-12-02 05:28:15 -05:00
|
|
|
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 */
|
2009-10-16 05:33:35 -04:00
|
|
|
primitive_full_gc();
|
2009-05-02 05:04:19 -04:00
|
|
|
|
2009-11-02 19:10:34 -05: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));
|
2009-11-19 02:49:26 -05:00
|
|
|
|
|
|
|
/* 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)
|
2009-11-19 02:49:26 -05:00
|
|
|
{
|
|
|
|
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);
|
2009-11-19 02:49:26 -05:00
|
|
|
}
|
|
|
|
|
2010-01-18 02:51:27 -05:00
|
|
|
update_word_entry_point(word.untagged());
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2010-02-01 08:49:05 -05:00
|
|
|
update_code_heap_words(false);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_profiling()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-12-18 16:59:56 -05:00
|
|
|
set_profiling(to_boolean(ctx->pop()));
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
2009-05-04 02:46:13 -04:00
|
|
|
|
|
|
|
}
|