]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: always generate safepoints in jit
authorJoe Groff <arcata@gmail.com>
Thu, 3 Nov 2011 18:57:23 +0000 (11:57 -0700)
committerJoe Groff <arcata@gmail.com>
Thu, 3 Nov 2011 18:57:43 +0000 (11:57 -0700)
Even if there's no stack frame we still need to safepoint before leaving the function. Fixes #332.

basis/bootstrap/image/image.factor
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/64/bootstrap.factor
basis/cpu/x86/64/unix/bootstrap.factor
basis/cpu/x86/64/windows/bootstrap.factor
basis/cpu/x86/bootstrap.factor
vm/quotations.cpp
vm/quotations.hpp

index b13b192c8126ca763d74c47bedf494625c0ebf5c..c2d12c4540c46a1366c5371d5a6a94447413cab8 100755 (executable)
@@ -532,6 +532,8 @@ M: quotation '
     \ set-fpu-state set-fpu-state-word set
     \ signal-handler signal-handler-word set
     \ leaf-signal-handler leaf-signal-handler-word set
+    \ ffi-signal-handler ffi-signal-handler-word set
+    \ ffi-leaf-signal-handler ffi-leaf-signal-handler-word set
     undefined-def undefined-quot set ;
 
 : emit-special-objects ( -- )
index 2eaa1f387b00a2373bca63b33e990ca66c4d137a..9ee1d18e9185669177ff47caa577d2b1b340bc24 100755 (executable)
@@ -30,6 +30,7 @@ IN: bootstrap.x86
 : link-reg ( -- reg ) EBX ;
 : fixnum>slot@ ( -- ) temp0 2 SAR ;
 : rex-length ( -- n ) 0 ;
+: red-zone-size ( -- n ) 0 ;
 
 : jit-call ( name -- )
     0 CALL f rc-relative rel-dlsym ;
@@ -390,8 +391,9 @@ IN: bootstrap.x86
     EAX EDX [] MOV
     jit-jump-quot ;
 
-: jit-safepoint ( -- )
+[
     0 EAX MOVABS rc-absolute rel-safepoint ;
+] \ jit-safepoint jit-define
 
 [
     jit-start-context-and-delete
index 0b013e82605ccfe32ffa67ea64d9f523e82df226..223f692cbde612848075991ff5529f7d04460d6b 100755 (executable)
@@ -334,8 +334,9 @@ IN: bootstrap.x86
     jit-push-param
     jit-jump-quot ;
 
-: jit-safepoint ( -- )
-    0 [RIP+] EAX MOV rc-relative rel-safepoint ;
+[
+    0 [RIP+] EAX MOV rc-relative rel-safepoint
+] \ jit-safepoint jit-define
 
 [
     jit-start-context-and-delete
index 292baaa805e741dff6818c0f0939e725886548ce..6b7d93184c7743ce4633da273561e71563ab0b15 100644 (file)
@@ -12,6 +12,7 @@ IN: bootstrap.x86
 : arg2 ( -- reg ) RSI ;
 : arg3 ( -- reg ) RDX ;
 : arg4 ( -- reg ) RCX ;
+: red-zone-size ( -- n ) 128 ;
 
 << "vocab:cpu/x86/unix/bootstrap.factor" parse-file suffix! >> call
 << "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >> call
index 0f99de0fba4e4b2067385945b2d974431e90e069..bee1135d685fa190a1526787ba0ef3021351e823 100644 (file)
@@ -21,6 +21,8 @@ DEFER: stack-reg
 : jit-install-seh ( -- ) stack-reg bootstrap-cell ADD ;
 : jit-update-seh ( ctx-reg -- ) drop ;
 
+: red-zone-size ( -- n ) 0 ;
+
 << "vocab:cpu/x86/windows/bootstrap.factor" parse-file suffix! >> call
 << "vocab:cpu/x86/64/bootstrap.factor" parse-file suffix! >> call
 << "vocab:cpu/x86/bootstrap.factor" parse-file suffix! >> call
index f2c37abad949d7bf651391a30779f3194405065f..570c7c87c50fea2808c50dc07e18b071be44f463 100644 (file)
@@ -102,8 +102,8 @@ big-endian off
     0 CALL f rc-relative rel-word-pic
 ] jit-word-call jit-define
 
-! The signal-handler and leaf-signal-handler subprimitives are special-cased
-! in vm/quotations.cpp not to trigger generation of a stack frame, so they can
+! The *-signal-handler subprimitives are special-cased in vm/quotations.cpp
+! not to trigger generation of a stack frame, so they can
 ! peform their own prolog/epilog preserving registers.
 
 [| |
@@ -126,6 +126,22 @@ big-endian off
     leaf-frame-size cell - RET
 ] \ leaf-signal-handler define-sub-primitive
 
+[| |
+    jit-signal-handler-prolog :> frame-size
+    temp0 vm-reg vm-signal-handler-addr-offset [+] MOV
+    temp0 CALL
+    frame-size jit-signal-handler-epilog
+    red-zone-size RET
+] \ ffi-signal-handler define-sub-primitive
+
+[| |
+    jit-signal-handler-prolog :> frame-size
+    temp0 vm-reg vm-signal-handler-addr-offset [+] MOV
+    temp0 CALL
+    frame-size jit-signal-handler-epilog
+    red-zone-size 16 bootstrap-cell - + RET
+] \ ffi-leaf-signal-handler define-sub-primitive
+
 [
     ! load boolean
     temp0 ds-reg [] MOV
@@ -222,7 +238,6 @@ big-endian off
 ] jit-execute jit-define
 
 [
-    jit-safepoint
     stack-reg stack-frame-size bootstrap-cell - ADD
 ] jit-epilog jit-define
 
index bc3f5591f17abf0ef2a035ceabd025c5d7dd3530..c49092f6491ddffaee5f1f55a6bbddded5d5cd1c 100755 (executable)
@@ -88,7 +88,9 @@ bool quotation_jit::word_stack_frame_p(cell obj)
        // See #295.
        return (to_boolean(untag<word>(obj)->subprimitive)
                        && obj != parent->special_objects[SIGNAL_HANDLER_WORD]
-                       && obj != parent->special_objects[LEAF_SIGNAL_HANDLER_WORD])
+                       && obj != parent->special_objects[LEAF_SIGNAL_HANDLER_WORD]
+                       && obj != parent->special_objects[FFI_SIGNAL_HANDLER_WORD]
+                       && obj != parent->special_objects[FFI_LEAF_SIGNAL_HANDLER_WORD])
                || obj == parent->special_objects[JIT_PRIMITIVE_WORD];
 }
 
@@ -122,6 +124,12 @@ bool quotation_jit::trivial_quotation_p(array *elements)
        return array_capacity(elements) == 1 && tagged<object>(array_nth(elements,0)).type_p(WORD_TYPE);
 }
 
+void quotation_jit::emit_epilog(bool stack_frame)
+{
+       emit(parent->special_objects[JIT_SAFEPOINT]);
+       if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
+}
+
 void quotation_jit::emit_quot(cell quot_)
 {
        data_root<quotation> quot(quot_,parent);
@@ -172,7 +180,7 @@ void quotation_jit::iterate_quotation()
                        /* Everything else */
                        else if(i == length - 1)
                        {
-                               if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
+                               emit_epilog(stack_frame);
                                tail_call = true;
                                word_jump(obj.value());
                        }
@@ -210,7 +218,7 @@ void quotation_jit::iterate_quotation()
                           mutually recursive in the library, but both still work) */
                        if(fast_if_p(i,length))
                        {
-                               if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
+                               emit_epilog(stack_frame);
                                tail_call = true;
 
                                emit_quot(array_nth(elements.untagged(),i));
@@ -247,7 +255,7 @@ void quotation_jit::iterate_quotation()
                        /* Method dispatch */
                        if(mega_lookup_p(i,length))
                        {
-                               if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
+                               emit_epilog(stack_frame);
                                tail_call = true;
                                emit_mega_cache_lookup(
                                        array_nth(elements.untagged(),i),
@@ -271,7 +279,7 @@ void quotation_jit::iterate_quotation()
        {
                set_position(length);
 
-               if(stack_frame) emit(parent->special_objects[JIT_EPILOG]);
+               emit_epilog(stack_frame);
                emit(parent->special_objects[JIT_RETURN]);
        }
 }
index 69755302ea8df5cdd901b24a12c1555acaa047d3..9de64bd970e1bcd0d7267381c543b6a263bbbb4d 100755 (executable)
@@ -16,6 +16,7 @@ struct quotation_jit : public jit {
        bool primitive_call_p(cell i, cell length);
        bool trivial_quotation_p(array *elements);
        void emit_quot(cell quot);
+       void emit_epilog(bool stack_frame);
        bool fast_if_p(cell i, cell length);
        bool fast_dip_p(cell i, cell length);
        bool fast_2dip_p(cell i, cell length);