From e0dc2367255f96d7622211e90d0617986e339630 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 12 Nov 2011 12:57:24 -0800 Subject: [PATCH] cpu.*.bootstrap: clear faulting flag directly No reason to go through a safepoint in unwind-native-frames really. --- basis/compiler/constants/constants.factor | 1 + basis/cpu/x86/32/bootstrap.factor | 10 +++++----- basis/cpu/x86/64/bootstrap.factor | 11 +++++------ basis/vm/vm.factor | 1 + vm/errors.cpp | 5 ++--- vm/vm.hpp | 4 +++- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/basis/compiler/constants/constants.factor b/basis/compiler/constants/constants.factor index 85aa5c4439..7951c1ef0b 100644 --- a/basis/compiler/constants/constants.factor +++ b/basis/compiler/constants/constants.factor @@ -30,6 +30,7 @@ CONSTANT: deck-bits 18 : vm-context-offset ( -- n ) 0 bootstrap-cells ; inline : vm-spare-context-offset ( -- n ) 1 bootstrap-cells ; inline : vm-signal-handler-addr-offset ( -- n ) 8 bootstrap-cells ; inline +: vm-fault-flag-offset ( -- n ) 9 bootstrap-cells ; inline : context-callstack-top-offset ( -- n ) 0 bootstrap-cells ; inline : context-callstack-bottom-offset ( -- n ) 1 bootstrap-cells ; inline : context-datastack-offset ( -- n ) 2 bootstrap-cells ; inline diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index c234d03a44..23b05548b0 100755 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -140,16 +140,14 @@ IN: bootstrap.x86 [ jit-jump-quot ] \ (call) define-combinator-primitive -: (jit-safepoint) ( -- ) - 0 EAX MOVABS rc-absolute rel-safepoint ; [ ! Load ds and rs registers jit-load-vm jit-load-context jit-restore-context - ! Safepoint to clear the faulting flag in the VM - (jit-safepoint) + ! clear the fault flag + vm-reg vm-fault-flag-offset [+] 0 MOV ! Windows-specific setup ctx-reg jit-update-seh @@ -400,7 +398,9 @@ IN: bootstrap.x86 EAX EDX [] MOV jit-jump-quot ; -[ (jit-safepoint) ] \ jit-safepoint jit-define +[ + 0 EAX MOVABS rc-absolute rel-safepoint +] \ jit-safepoint jit-define [ jit-start-context-and-delete diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index 77e76db9b7..e299dbf348 100755 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -122,9 +122,6 @@ IN: bootstrap.x86 [ jit-jump-quot ] \ (call) define-combinator-primitive -: (jit-safepoint) - 0 [RIP+] EAX MOV rc-relative rel-safepoint ; - [ ! Unwind stack frames RSP arg2 MOV @@ -137,8 +134,8 @@ IN: bootstrap.x86 jit-load-context jit-restore-context - ! Safepoint to clear the faulting flag in the VM - (jit-safepoint) + ! Clear the fault flag + vm-reg vm-fault-flag-offset [+] 0 MOV ! Call quotation jit-jump-quot @@ -342,7 +339,9 @@ IN: bootstrap.x86 jit-push-param jit-jump-quot ; -[ (jit-safepoint) ] \ jit-safepoint jit-define +[ + 0 [RIP+] EAX MOV rc-relative rel-safepoint +] \ jit-safepoint jit-define [ jit-start-context-and-delete diff --git a/basis/vm/vm.factor b/basis/vm/vm.factor index 46bf2954dd..3f18699c4d 100644 --- a/basis/vm/vm.factor +++ b/basis/vm/vm.factor @@ -31,6 +31,7 @@ STRUCT: vm { cards-offset cell } { decks-offset cell } { signal-handler-addr cell } +{ faulting? cell } { special-objects cell[special-object-count] } ; : vm-field-offset ( field -- offset ) vm offset-of ; inline diff --git a/vm/errors.cpp b/vm/errors.cpp index 14a8700dcf..b775eec015 100755 --- a/vm/errors.cpp +++ b/vm/errors.cpp @@ -73,9 +73,8 @@ void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2) ctx->push(error_object); - /* Guard the safepoint, which will clear faulting_p if unwind-native-frames - succeeds */ - code->guard_safepoint(); + /* The unwind-native-frames subprimitive will clear faulting_p + if it was successfully reached. */ unwind_native_frames(special_objects[ERROR_HANDLER_QUOT], ctx->callstack_top); } diff --git a/vm/vm.hpp b/vm/vm.hpp index 5cd8b1f05c..cfe77bd7fd 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -28,6 +28,9 @@ struct factor_vm /* cdecl signal handler address, used by signal handler subprimitives */ cell signal_handler_addr; + /* are we handling a memory error? used to detect double faults */ + cell faulting_p; + /* Various special objects, accessed by special-object and set-special-object primitives */ cell special_objects[special_object_count]; @@ -142,7 +145,6 @@ struct factor_vm segment *signal_callstack_seg; /* Are we already handling a fault? Used to catch double memory faults */ - bool faulting_p; static bool fatal_erroring_p; /* Safepoint state */