]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix potential assertion failure if GC was invoked while enabling profiling
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 19 Nov 2009 07:49:26 +0000 (01:49 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 19 Nov 2009 07:49:26 +0000 (01:49 -0600)
basis/tools/profiler/profiler-tests.factor
vm/profiler.cpp
vm/words.cpp

index 6e5177fbae9088df87b844b137cb4a271d0f8948..8f3260d649bfbe40ebe9cd7eac11f0f1077c4da4 100644 (file)
@@ -64,3 +64,11 @@ IN: tools.profiler.tests
 : crash-bug-2 ( -- ) 100000 [ crash-bug-1 drop ] times ;
 
 [ ] [ [ crash-bug-2 ] profile ] unit-test
+
+[ 1 ] [
+    [
+        [ [ ] (( -- )) define-temp ] with-compilation-unit
+        dup execute( -- )
+    ] profile
+    counter>>
+] unit-test
index 403d26f0ca92036796d89bf026170ce4234e4257..19348be4efc1fabc333001e779032b49b92f17b9 100755 (executable)
@@ -37,8 +37,21 @@ void factor_vm::set_profiling(bool profiling)
        for(cell i = 0; i < length; 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(!word->profiling)
+                       {
+                               code_block *profiling_block = compile_profiling_stub(word.value());
+                               word->profiling = profiling_block;
+                       }
+
                        word->counter = tag_fixnum(0);
+               }
+
                update_word_xt(word.untagged());
        }
 
index dfaeed2496300b5e844a9f49dc088f2a11934a4b..a9375cfbc669188b385dd2b0842c3dfc10a0293a 100644 (file)
@@ -23,10 +23,14 @@ word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_)
        new_word->code = NULL;
 
        jit_compile_word(new_word.value(),new_word->def,true);
-       update_word_xt(new_word.untagged());
-
        if(profiling_p)
+       {
+               code_block *profiling_block = compile_profiling_stub(new_word.value());
+               new_word->profiling = profiling_block;
                relocate_code_block(new_word->profiling);
+       }
+
+       update_word_xt(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)
-       {
-               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;
-               }
-
+       if(profiling_p && w->profiling)
                w->xt = w->profiling->xt();
-       }
        else
                w->xt = w->code->xt();
 }