Fix potential assertion failure if GC was invoked while enabling profiling

db4
Slava Pestov 2009-11-19 01:49:26 -06:00
parent f4450653a9
commit f47b72d98b
3 changed files with 29 additions and 18 deletions

View File

@ -64,3 +64,11 @@ IN: tools.profiler.tests
: crash-bug-2 ( -- ) 100000 [ crash-bug-1 drop ] times ; : crash-bug-2 ( -- ) 100000 [ crash-bug-1 drop ] times ;
[ ] [ [ crash-bug-2 ] profile ] unit-test [ ] [ [ crash-bug-2 ] profile ] unit-test
[ 1 ] [
[
[ [ ] (( -- )) define-temp ] with-compilation-unit
dup execute( -- )
] profile
counter>>
] unit-test

View File

@ -37,8 +37,21 @@ void factor_vm::set_profiling(bool profiling)
for(cell i = 0; i < length; i++) for(cell i = 0; i < length; i++)
{ {
tagged<word> word(array_nth(words.untagged(),i)); 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 */
if(profiling) if(profiling)
{
if(!word->profiling)
{
code_block *profiling_block = compile_profiling_stub(word.value());
word->profiling = profiling_block;
}
word->counter = tag_fixnum(0); word->counter = tag_fixnum(0);
}
update_word_xt(word.untagged()); update_word_xt(word.untagged());
} }

View File

@ -23,10 +23,14 @@ word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_)
new_word->code = NULL; new_word->code = NULL;
jit_compile_word(new_word.value(),new_word->def,true); jit_compile_word(new_word.value(),new_word->def,true);
update_word_xt(new_word.untagged());
if(profiling_p) if(profiling_p)
{
code_block *profiling_block = compile_profiling_stub(new_word.value());
new_word->profiling = profiling_block;
relocate_code_block(new_word->profiling); relocate_code_block(new_word->profiling);
}
update_word_xt(new_word.untagged());
return new_word.untagged(); return new_word.untagged();
} }
@ -58,24 +62,10 @@ void factor_vm::primitive_word_xt()
} }
} }
/* Allocates memory */ void factor_vm::update_word_xt(word *w)
void factor_vm::update_word_xt(word *w_)
{ {
data_root<word> w(w_,this); if(profiling_p && w->profiling)
if(profiling_p)
{
if(!w->profiling)
{
/* 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 */
code_block *profiling = compile_profiling_stub(w.value());
w->profiling = profiling;
}
w->xt = w->profiling->xt(); w->xt = w->profiling->xt();
}
else else
w->xt = w->code->xt(); w->xt = w->code->xt();
} }