summaryrefslogtreecommitdiff
path: root/libguile/vm.c
Commit message (Expand)AuthorAgeFilesLines
* Better errors for odd-length keyword args...* libguile/vm-engine.c (bind-kwargs): * libguile/vm.c (vm_error_kwargs_missing_value): * libguile/eval.c (error_missing_value) (prepare_boot_closure_env_for_apply): Adapt to mirror VM behavior. * libguile/keywords.c (scm_c_bind_keyword_arguments): Likewise. * module/ice-9/eval.scm (primitive-eval): Update to error on (foo #:kw) with a "Keyword argument has no value" instead of the horrible "odd argument list length". Also adapts to the expected args format for the keyword-argument-error exception printer in all cases. Matches 1.8 optargs behavior also. * test-suite/standalone/test-scm-c-bind-keyword-arguments.c (test_missing_value): (missing_value_error_handler): Update test. * test-suite/tests/optargs.test: Add tests. Andy Wingo2017-02-281-4/+4
* VM continuations store FP/SP by offset...* libguile/continuations.c (scm_i_continuation_to_frame): * libguile/stacks.c (scm_make_stack): * libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack): (vm_return_to_continuation_inner) (struct vm_reinstate_partial_continuation_data): (vm_reinstate_partial_continuation_inner): (vm_reinstate_partial_continuation): * libguile/vm.h (sstruct scm_vm_cont): Simplify VM continuations by recording the top FP by offset, not value + reloc. * libguile/frames.c (frame_offset, scm_i_vm_frame_offset): Remove unused functions. * libguile/frames.h (SCM_VALIDATE_VM_FRAME, scm_i_vm_frame_offset): Remove. * libguile/control.c (reify_partial_continuation): Once we know the base_fp, relocate the dynamic stack. * libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_relocate_prompts): New function. (scm_dynstack_wind_prompt): Adapt to add new fp offset. Andy Wingo2017-02-121-23/+9
* Add suspendable-continuation?...* doc/ref/api-control.texi (Prompt Primitives): Document suspendable-continuation?. * libguile/control.c (scm_suspendable_continuation_p): New procedure. (scm_init_ice_9_control): New extension procedure, defines suspendable-continuation?. (scm_init_control): Register scm_init_ice_9_control. * libguile/eval.c (eval): * libguile/throw.c (catch): * libguile/continuations.c (scm_i_make_continuation): Restore resumable prompt cookie after continuation invocation. * libguile/vm.c (scm_call_n): Arrange to set resumable_prompt_cookie during invocation of VM. * libguile/vm.h (struct scm_vm): Add resumable_prompt_cookie member. * module/ice-9/control.scm: Export suspendable-continuation?. * test-suite/tests/control.test ("suspendable-continuation?"): New test. Andy Wingo2016-12-121-3/+10
* Reimplement dynamic states...There are two goals: one, to use less memory per dynamic state in order to allow millions of dynamic states to be allocated in light-weight threading scenarios. The second goal is to prevent dynamic states from being actively mutated in two threads at once. This second goal does mean that dynamic states object that escape into scheme are now copies that won't receive further updates; an incompatible change, but one which we hope doesn't affect anyone. * libguile/cache-internal.h: New file. * libguile/fluids.c (is_dynamic_state, get_dynamic_state) (save_dynamic_state, restore_dynamic_state, add_entry) (copy_value_table): New functions. (scm_i_fluid_print, scm_i_dynamic_state_print): Move up. (new_fluid): No need for a number. (scm_fluid_p: scm_is_fluid): Inline IS_FLUID uses. (fluid_set_x, fluid_ref): Adapt to dynamic state changes. (scm_fluid_set_x, scm_fluid_unset_x): Call fluid_set_x. (scm_swap_fluid): Rewrite in terms of fluid_ref and fluid_set. (swap_fluid): Use internal fluid_set_x. (scm_i_make_initial_dynamic_state): Adapt to dynamic state representation change. (scm_dynamic_state_p, scm_is_dynamic_state): Use new accessors. (scm_current_dynamic_state): Use make_dynamic_state. (scm_dynwind_current_dynamic_state): Use new accessor. * libguile/fluids.h: Remove internal definitions. Add new struct definition. * libguile/threads.h (scm_i_thread): Use scm_t_dynamic_state for dynamic state. * libguile/threads.c (guilify_self_1, guilify_self_2): (scm_i_init_thread_for_guile, scm_init_guile): (scm_call_with_new_thread): (scm_init_threads, scm_init_threads_default_dynamic_state): Adapt to scm_i_thread change. (scm_i_with_guile, with_guile): Remove "and parent" suffix. (scm_i_reset_fluid): Remove unneeded function. * doc/ref/api-scheduling.texi (Fluids and Dynamic States): Remove scm_make_dynamic_state docs. Update current-dynamic-state docs. * libguile/vm-engine.c (vm_engine): Update fluid-ref and fluid-set! inlined fast paths for dynamic state changes. * libguile/vm.c (vm_error_unbound_fluid): Remove now-unused function. * NEWS: Update. * module/ice-9/deprecated.scm (make-dynamic-state): New definition. * libguile/deprecated.h: * libguile/deprecated.c (scm_make_dynamic_state): Move here. * libguile/__scm.h (scm_t_dynamic_state): New typedef. * libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_push_fluid): (scm_dynstack_unwind_fluid): Take raw dynstate in these internal functions. * libguile/throw.c (catch): Adapt to dynstack changes. Andy Wingo2016-12-051-10/+1
* Inline interrupts...* libguile/async.c: * libguile/async.h (scm_i_async_push, scm_i_async_pop): Make internally available. * libguile/vm-engine.c (vm_engine): Invoke interrupts inline. Add return-from-interrupt instruction. * libguile/vm.c (vm_handle_interrupt_code): New "builtin". Andy Wingo2016-11-191-0/+7
* Compiler support for atomics...* doc/ref/vm.texi (Inlined Atomic Instructions): New section. * libguile/vm-engine.c (VM_VALIDATE_ATOMIC_BOX, make-atomic-box) (atomic-box-ref, atomic-box-set!, atomic-box-swap!) (atomic-box-compare-and-swap!): New instructions. * libguile/vm.c: Include atomic and atomics-internal.h. (vm_error_not_a_atomic_box): New function. * module/ice-9/atomic.scm: Register primitives with the compiler. * module/language/cps/compile-bytecode.scm (compile-function): Add support for atomic ops. * module/language/cps/effects-analysis.scm: Add comment about why no effects analysis needed. * module/language/cps/reify-primitives.scm (primitive-module): Add case for (ice-9 atomic). * module/language/tree-il/primitives.scm (*effect-free-primitives*): (*effect+exception-free-primitives*): Add atomic-box?. * module/system/vm/assembler.scm: Add new instructions. * test-suite/tests/atomic.test: Test with compilation and interpretation. Andy Wingo2016-09-061-10/+20
* Remove unused static definitions...* libguile/expand.c: * libguile/vm.c: Remove unused static definitions. Andy Wingo2016-06-111-36/+0
* Add integer->char and char->integer opcodes...* libguile/vm-engine.c (integer_to_char, char_to_integer): New opcodes. * libguile/vm.c (vm_error_not_a_char): New error case. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/slot-allocation.scm (compute-var-representations): * module/language/cps/types.scm: * module/language/tree-il/compile-cps.scm (convert): * doc/ref/vm.texi (Inlined Scheme Instructions): * module/system/vm/assembler.scm: Add support for new opcodes. Andy Wingo2016-05-041-0/+7
* Remove scm_puts_unlocked....* libguile/ports.h (scm_puts_unlocked): Remove. * libguile/ports.c (scm_puts): Replace implementation with scm_puts_unlocked's implementation. * libguile/arbiters.c: * libguile/backtrace.c: * libguile/bitvectors.c: * libguile/continuations.c: * libguile/deprecation.c: * libguile/dynl.c: * libguile/eval.c: * libguile/filesys.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/fports.c: * libguile/frames.c: * libguile/guardians.c: * libguile/hashtab.c: * libguile/hooks.c: * libguile/load.c: * libguile/macros.c: * libguile/mallocs.c: * libguile/print.c: * libguile/programs.c: * libguile/promises.c: * libguile/smob.c: * libguile/srcprop.c: * libguile/srfi-14.c: * libguile/stackchk.c: * libguile/struct.c: * libguile/threads.c: * libguile/throw.c: * libguile/values.c: * libguile/variable.c: * libguile/vm.c: * libguile/weak-set.c: * libguile/weak-table.c: Use scm_puts instead of scm_puts_unlocked. Andy Wingo2016-04-261-2/+2
* Unbox indexes of vectors, strings, and structs...* libguile/vm-engine.c (string-length, string-ref) (make-vector, vector-ref, vector-set!) (allocate-struct, struct-ref, struct-set!): Take indexes and return lengths as untagged u64 values. * libguile/vm.c (vm_error_not_a_string): New helper. * module/language/tree-il/compile-cps.scm (convert): * module/language/cps/constructors.scm (inline-vector): * module/language/cps/closure-conversion.scm (convert-one): Untag arguments to {string,vector,struct}-{ref,set!}, make-vector, and allocate-struct. Tag return values from {string,vector}-length. * module/language/cps/slot-allocation.scm (compute-var-representations): vector-length and string-length define u64 slots. * module/language/cps/effects-analysis.scm: make-vector no longer causes a &type-check effect. * module/language/cps/types.scm: Update to expect &u64 values for lengths and indexes. Andy Wingo2015-12-011-0/+7
* Untag values and indexes for all bytevector instructions...* libguile/vm-engine.c (bv-s8-ref, bv-s16-ref, bv-s32-ref, bv-s64-ref): Unbox index and return unboxed S32 value. (bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Unbox index and take unboxed S32 value. (bv-u8-ref, bv-u16-ref, bv-u32-ref, bv-u64-ref) (bv-s8-set!, bv-s16-set!, bv-s32-set!, bv-s64-set!): Likewise, but with unsigned values. (bv-f32-ref, bv-f32-set!, bv-f64-ref, bv-f64-set!): Use memcpy to access the value so we don't have to think about alignment. GCC will inline this to a single instruction on architectures that support unaligned access. * libguile/vm.c (vm_error_out_of_range_uint64) (vm_error_out_of_range_int64): New helpers. * module/language/cps/slot-allocation.scm (compute-var-representations): All bytevector ref operations produce untagged values. * module/language/cps/types.scm (define-bytevector-accessors): Update for bytevector untagged indices and values. * module/language/cps/utils.scm (compute-constant-values): Fix s64 case. * module/language/tree-il/compile-cps.scm (convert): Box results of all bytevector accesses, and unbox incoming indices and values. Andy Wingo2015-12-011-0/+14
* Apply of non-programs has IP that is not from prev frame...* libguile/vm-engine.c (vm_engine) * libguile/vm.c (vm_apply_non_program_code): Arrange so that the code to apply a non-program has its own IP, so that frame-instruction-pointer for a non-program application doesn't point into the previously active frame. Andy Wingo2015-12-011-0/+4
* Identify boot continuations by code, not closure...* libguile/vm.h: * libguile/vm.c (scm_i_vm_is_boot_continuation_code): New internal procedure. * libguile/stacks.c (scm_make_stack): * libguile/frames.c (scm_c_frame_previous): Use new helper to identify boot frames. Andy Wingo2015-12-011-0/+6
* VM support for raw slots...* libguile/loader.c (scm_find_slot_map_unlocked): Rename from scm_find_dead_slot_map_unlocked. * libguile/vm.c (struct slot_map_cache_entry, struct slot_map_cache) (find_slot_map): Rename, changing "dead_slot" to "slot". (enum slot_desc): New type. (scm_i_vm_mark_stack): Interpret slot maps as having two bits per slot, allowing us to indicate that a slot is live but not a pointer. * module/language/cps/compile-bytecode.scm (compile-function): Adapt to emit-slot-map name change. * module/system/vm/assembler.scm (<asm>): Rename dead-slot-maps field to slot-maps. (emit-slot-map): Rename from emit-dead-slot-map. (link-frame-maps): 2 bits per slot. * module/language/cps/slot-allocation.scm (lookup-slot-map): Rename from lookup-dead-slot-map. (compute-var-representations): New function. (allocate-slots): Adapt to encode two-bit slot representations. Andy Wingo2015-10-281-32/+45
* SP-relative local addressing...* libguile/vm-engine.c: S24/S12/S8 operands addressed relative to the SP, not the FP. Cache the SP instead of a FP-relative locals pointer. Further cleanups to follow. * libguile/vm.c (vm_builtin_call_with_values_code): Adapt to mov operand addresing change. * module/language/cps/compile-bytecode.scm (compile-function): Reify SP-relative local indexes where appropriate. * module/system/vm/assembler.scm (emit-fmov*): New helper, exported as emit-fmov. (shuffling-assembler, define-shuffling-assembler): Rewrite to shuffle via push/pop/drop. (standard-prelude, opt-prelude, kw-prelude): No need to provide for shuffling args. * test-suite/tests/rtl.test: Update. * module/language/cps/slot-allocation.scm: Don't reserve slots 253-255. Andy Wingo2015-10-211-2/+2
* Replace dynamic link on stack with previous frame size...* libguile/frames.h (SCM_FRAME_DYNAMIC_LINK) (SCM_FRAME_SET_DYNAMIC_LINK): Instead of storing the absolute value of the previous FP, store its offset from the current FP. This allows us to avoid relinking when composing continuations or when relocating the stack. * libguile/frames.c (scm_frame_dynamic_link, scm_c_frame_previous): No need to relocate the dynamic link. * libguile/vm.c (vm_return_to_continuation_inner): (vm_reinstate_partial_continuation_inner, vm_expand_stack_inner): Don't relocate the frame pointer chain. (scm_i_vm_mark_stack): Terminate when FP is above stack_top, not when 0. (make_vm): Init FP to stack_top. Andy Wingo2015-10-211-42/+7
* Rename union scm_vm_stack_element members...* libguile/frames.h (union scm_vm_stack_element): Rename members from scm, ip, etc to as_scm, as_ip, etc. Adapt users. Andy Wingo2015-10-211-10/+11
* Remove sp from scm_vm_cont...* libguile/vm.h (struct scm_vm_cont): Remove "sp" member; it's always the same as stack_bottom. * libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack): (vm_return_to_continuation_inner): * libguile/stacks.c (scm_make_stack): * libguile/continuations.c (scm_i_continuation_to_frame): Adapt. Andy Wingo2015-10-211-3/+2
* VM stack grows downward...Adapt VM stack to grow downward. This will make native compilation look more like the VM code, as we will be able to use native CALL instructions, taking proper advantage of the return address buffer. * libguile/continuations.c (scm_i_continuation_to_frame): Record offsets from stack top. * libguile/control.c (scm_i_prompt_pop_abort_args_x): Adapt for reversed order of arguments, and instead of relying on the abort to push on the number of arguments, make the caller save the stack depth, which allows us to compute the number of arguments ourselves. (reify_partial_continuation, scm_c_abort): Adapt to reversed stack order. * libguile/dynstack.c (scm_dynstack_wind_prompt): Since we wind the stack in a downward direction, subtract the reloc instead of adding it. * libguile/dynstack.h (SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY): Remove flag; instead rely on prompt-establishing code to save the stack depth. * libguile/eval.c (eval): Remove extraneous "volatile" declarations for variables that are not re-set between the setjmp and any longjmp. Adapt to save stack depth before instating the prompt. * libguile/foreign.c (scm_i_foreign_call): Adapt to receive arguments in reverse order. * libguile/frames.c (frame_stack_top, scm_i_frame_stack_top): Adapt to compute stack top instead of stack bottom. (scm_c_frame_closure): Adapt to stack growth change. (scm_frame_num_locals, scm_frame_local_ref, scm_frame_set_x): Use union data type to access stack. (RELOC): Reformat. (scm_c_frame_previous): Adapt to stack growth change. * libguile/frames.h: Adapt stack diagram to indicate that the stack grows up. (union scm_vm_stack_element): New data type used to access items on the stack. (SCM_FRAME_PREVIOUS_SP) (SCM_FRAME_RETURN_ADDRESS, SCM_FRAME_SET_RETURN_ADDRESS) (SCM_FRAME_DYNAMIC_LINK, SCM_FRAME_SET_DYNAMIC_LINK) (SCM_FRAME_LOCAL, SCM_FRAME_NUM_LOCALS): Adapt to stack representation change. (SCM_FRAME_SLOT): New helper. (SCM_VM_FRAME_FP, SCM_VM_FRAME_SP): Adapt to stack growth change. * libguile/stacks.c (scm_make_stack): Record offsets from top of stack. * libguile/throw.c (catch): Adapt to scm_i_prompt_pop_abort_args_x change. * libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME): (FRAME_LOCALS_COUNT_FROM): Adapt to stack growth change. (LOCAL_ADDRESS): Use SCM_FRAME_SLOT to get the address as the proper data type. (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Adapt to stack growth change. (apply): Shuffling up the SMOB apply args can cause the stack to expand, so use ALLOC_FRAME instead of RESET_FRAME. (vm_engine): Adapt for stack growth change. * libguile/vm.c (vm_increase_sp, vm_push_sp, vm_restore_sp): Adapt to stack representation change. (scm_i_vm_cont_to_frame): Adapt to take offsets from the top. (scm_i_vm_capture_stack): Adapt to capture from the top. (vm_return_to_continuation_inner): Adapt for data type changes. (vm_return_to_continuation): Likewise, and instead of looping, just splat the saved arguments on with memcpy. (vm_dispatch_hook): Adapt to receive arguments in the reverse order. Adapt callers. (vm_abort): There is never a tail argument. Adapt to stack representation change. (vm_reinstate_partial_continuation) (vm_reinstate_partial_continuation_inner): Adapt to stack growth change. (allocate_stack, free_stack): Adapt to data type change. (expand_stack): Don't try to mremap(), as you can't grow a mapping from the bottom. Without knowing that there's a free mapping space right below the old stack, which there usually isn't on Linux, we have to copy. We can't use MAP_GROWSDOWN because Linux is buggy. (make_vm): Adapt to stack representation changes. (return_unused_stack_to_os): Round down instead of up, as the stack grows down. (scm_i_vm_mark_stack): Adapt to walk up the stack. (scm_i_vm_free_stack): Adapt to scm_vm changes. (vm_expand_stack_inner, reset_stack_limit, vm_expand_stack): Adapt to the stack growing down. (scm_call_n): Adapt to the stack growing down. Don't allow argv to point into the stack. * libguile/vm.h (struct scm_vm, struct scm_vm_cont): Adapt to hold the stack top and bottom. Andy Wingo2015-10-211-197/+197
* The GOOPS "unbound" value is a unique pair...* libguile/goops.c (SCM_GOOPS_UNBOUND, SCM_GOOPS_UNBOUNDP): Remove internal macros. (scm_make_unbound, scm_unbound_p): Remove internal functions. (scm_sys_clear_fields_x): Add "unbound" parameter, for the init value. * module/oop/goops.scm (*unbound*): Define in Scheme as a simple heap-allocated value. (unbound?): New definition. (%allocate-instance): Pass *unbound* to %clear-fields!. (make-class, slot-definition-init-value) (slot-definition-init-form, make-closure-variable): Use *unbound* instead of (make-unbound), which is now gone. * module/oop/goops/active-slot.scm (compute-get-n-set): Use *unbound* instead of make-unbound. This module uses the GOOPS internals module; perhaps we should export make-unbound or something... * module/oop/goops/save.scm (make-unbound): Export our own make-unbound definition, for use by residualized save code. * module/language/ecmascript/base.scm (<undefined>, *undefined*): Use a unique object kind and instance for the undefined value. * libguile/vm.c (scm_i_vm_mark_stack): Fill the stack with SCM_UNSPECIFIED instead of SCM_UNBOUND. Andy Wingo2015-01-231-2/+2
* VM robustness for optimized closures...* libguile/vm.c (vm_error_unbound, vm_error_unbound_fluid): Remove proc argument. The value in slot 0 is not necessarily the procedure being applied, after the prelude is done. * libguile/vm-engine.c (vm_engine): Use LOCAL_REF (0) instead of SCM_FRAME_PROGRAM, and adapt to above changes. Andy Wingo2014-04-161-6/+6
* Fix rewinding continuations when outermost frame has zero locals...* libguile/vm.c (vm_reinstate_partial_continuation_inner): Fix boundary condition when the outermost frame has zero locals. Andy Wingo2014-04-161-1/+1
* make-stack works on delimited continuations...* libguile/stacks.c (scm_make_stack, scm_stack_id): * libguile/vm.c (scm_i_vm_cont_to_frame): Allow delimited continuations as the argument to make-stack. Andy Wingo2014-04-161-0/+13
* Out-of-memory situations raise exceptions instead of aborting...* libguile/gc.c (scm_oom_fn, scm_init_gc): Install an out-of-memory handler that raises an unwind-only out-of-memory exception. (scm_gc_warn_proc, scm_init_gc): Install a warning proc that tries to print to the current warning port, if the current warning port is a file port. (scm_gc_after_nonlocal_exit): New interface. Should be called after a nonlocal return to potentially collect memory; otherwise allocations could try to expand again when they should collect. * libguile/continuations.c (scm_i_make_continuation): * libguile/eval.c (eval): * libguile/throw.c (catch): * libguile/vm.c (scm_call_n): Call scm_gc_after_nonlocal_exit after nonlocal returns. * libguile/throw.c (abort_to_prompt, throw_without_pre_unwind): Rework to avoid allocating memory. (scm_report_out_of_memory): New interface. (scm_init_throw): Pre-allocate the arguments for stack-overflow and out-of-memory errors. * module/ice-9/boot-9.scm: Add an out-of-memory exception printer. * module/system/repl/error-handling.scm (call-with-error-handling): Add out-of-memory to the report-keys set. * libguile/gc-malloc.c (scm_realloc): Call scm_report_out_of_memory if realloc fails. * libguile/error.h: * libguile/error.c: * libguile/deprecated.h: * libguile/deprecated.c (scm_memory_error): Deprecate. * test-suite/standalone/Makefile.am: * test-suite/standalone/test-out-of-memory: New test case. Andy Wingo2014-03-221-2/+5
* Remove default soft stack limit; add call-with-stack-overflow-handler...* libguile/vm.h: * libguile/vm.c (default_max_stack_size, initialize_default_stack_size): Remove the default stack limit. In this way, programs run from the command line or outside of the REPL will have no soft stack limit. (make_vm): Change `max_stack_size' field to be a stack of limits and handlers. (current_overflow_size, should_handle_stack_overflow) (reset_stack_limit, wind_overflow_handler, unwind_overflow_handler) (vm_expand_stack): If the stack surpasses a user-set limit, call the user-specified handler within its outer stack limit. (call-with-stack-overflow-handler): New interface. * module/system/vm/vm.scm: Export call-with-stack-overflow-handler. Andy Wingo2014-03-121-42/+145
* Threadsafe stack relocation...* libguile/vm.c (vm_return_to_continuation, vm_expand_stack): (vm_reinstate_partial_continuation): Hold the GC lock while relocating the stack. Andy Wingo2014-02-201-61/+132
* assertion refactor in the vm...* libguile/vm.c: * libguile/vm-engine.c: Change the one use of VM_ENABLE_PARANOID_ASSERTIONS to ASSERT. That becomes the one use of VM_ENABLE_ASSERTIONS, so disable that too. Andy Wingo2014-02-201-3/+1
* Fix "VM never extends vp->sp ..." commit...* libguile/vm.c (vm_expand_stack): Make sure the new SP is visible to vm_error if we throw because of stack overflow. Andy Wingo2014-02-201-4/+3
* Remove the hard stack size limit...* libguile/vm.c (vm_expand_stack): Remove the hard stack size limit. Andy Wingo2014-02-201-17/+0
* VM never extends vp->sp beyond mapped region of stack...* libguile/vm-engine.c (ALLOC_FRAME): Fold CHECK_OVERFLOW into this routine, and rework to not extend vp->sp until the stack has been expanded. * libguile/vm.c (vm_increase_sp): Likewise, don't extend vp->sp until the stack has expanded. (vm_expand_stack): Rework to take the new stack pointer as an argument, and also to update vp->sp_max_since_gc and vp->sp. Andy Wingo2014-02-201-9/+14
* Unwind-only stack overflow exceptions...* module/ice-9/boot-9.scm (catch): Signal an early error if the handler or pre-unwind handler types aren't right. This is more important than it was, given that we dispatch on type now when finding matching catch clauses. * libguile/vm.c (vm_expand_stack): Use the standard scm_report_stack_overflow to signal stack overflow. This will avoid running pre-unwind handlers. * libguile/throw.h: Move scm_report_stack_overflow here. * libguile/throw.c (catch): Define a version of catch in C. (throw_without_pre_unwind): New helper. Besides serving as the pre-boot "throw" binding, it allows stack overflow to throw without running pre-unwind handlers. (scm_catch, scm_catch_with_pre_unwind_handler) (scm_with_throw_handler): Use the new catch in C. (scm_report_stack_overflow): Moved from stackchk.c; throws an unwind-only exception. * libguile/stackchk.h: * libguile/stackchk.c: Remove the scm_report_stack_overflow bits. Andy Wingo2014-02-201-7/+3
* Fix scm_i_vm_capture_stack comment....* libguile/vm.c (scm_i_vm_capture_stack): Fix a comment. Andy Wingo2014-02-191-11/+3
* Default stack size is one page....* libguile/vm.c (initialize_default_stack_size): Initial stack size is one page. Andy Wingo2014-02-191-7/+14
* More robust stack expansion and contraction...* libguile/vm.c (allocate_stack, expand_stack): Return NULL on allocation failure instead of throwing an exception. Throwing an exception is tricky to get right, and we need more context to do it correctly. (return_unused_stack_to_os): Try again if madvise returns -EAGAIN. If madvise fails, print an error message. (vm_expand_stack): Abort if stack expansion fails. We'll fix this in a future patch. (make_vm): Abort if we can't mmap a single page. Andy Wingo2014-02-191-7/+38
* SCM_I_IS_VECTOR only true for tc7_vector, not weak vectors...* libguile/tags.h (SCM_TYP7S, SCM_HAS_TYP7S): Remove these, as we no longer do the differs-by-one-bit thing for vectors and weak vectors. * libguile/vectors.h (SCM_I_IS_VECTOR): Use SCM_HAS_TYP7. (SCM_I_IS_NONWEAK_VECTOR): Remove. * libguile/vm-engine.c (vector-length, vector-ref, vector-set!) (vector-ref/immediate, vector-set!/immediate): We can inline these instructions completely now. * libguile/vm.c (vm_error_not_a_vector, vm_error_out_of_range): New error conditions. Andy Wingo2014-02-081-0/+15
* Various VM stack management fixes...* libguile/vm.c (vm_increase_sp): New interface, to increase the SP to some new level, possibly expanding the stack. (vm_push_sp, vm_restore_sp): Intefaces to vm_increase_sp. (vm_return_to_continuation): Don't throw an error if there's not enough space; instead, expand. (vm_reinstate_partial_continuation): Use the new helper. (return_unused_stack_to_os): Avoid off-by-one error (sp points to valid memory.) (scm_call_n): Never write beyond the sp. Andy Wingo2014-02-051-64/+90
* Add thread-local lock-free, TLS-free freelists....* libguile/bdw-gc.h: Remove a needless compatibility hack. * libguile/gc-inline.h: New file, implementing thread-local freelists providing faster allocation if we already have a scm_i_thread* pointer. Based on gc_inline.h from libgc. * libguile/threads.h (scm_i_thread): Add freelists here. * libguile/threads.c (guilify_self_1, guilify_self_2): Initialize freelists. * libguile/vm.c: Include gc-inline.h. * libguile/vm-engine.c: Rename current_thread to thread. Use scm_inline_cons instead of scm_cons, scm_inline_cell instead of scm_cell, and scm_inline_words instead of words. Andy Wingo2014-02-021-0/+1
* Add dead slot map cache...* libguile/vm.c (find_dead_slot_map, scm_i_vm_mark_stack): Use a little cache for dead slot maps. Helps when marking very deep recursive stacks. Andy Wingo2014-02-021-2/+36
* Return unused parts of the stack to the OS...* libguile/vm.h (struct scm_vm): Reorder fields. Add "sp_max_since_gc" field. * libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME): * libguile/vm.c (vm_return_to_continuation) (vm_reinstate_partial_continuation, scm_call_n): In places where we could increase the stack height, update sp_max_since_gc. (vm_expand_stack): Relocate sp_max_since_gc on expansion. (scm_bootstrap_vm): Record the page size using gnulib's getpagesize. (return_unused_stack_to_os): New routine, run when marking stacks. Andy Wingo2014-01-311-8/+55
* Micro-optimization to scm_i_vm_mark_stack...* libguile/vm.c (scm_i_vm_mark_stack): Micro-optimize GC_MARK_AND_PUSH to cache the plausible heap bounds locally. Andy Wingo2014-01-311-2/+5
* More precise stack marking via .guile.frame-maps section...* module/language/cps/slot-allocation.scm (lookup-dead-slot-map) (allocate-slots): For each non-tail call in a function, compute the set of slots that are dead after the function has begun the call. * module/language/cps/compile-bytecode.scm (compile-fun): Emit the `dead-slot-map' macro instruction for non-tail calls. * module/system/vm/assembler.scm (<asm>): Add `dead-slot-maps' member. (dead-slot-map): New macro-instruction. (link-frame-maps, link-dynamic-section, link-objects): Write dead slots information into .guile.frame-maps sections of ELF files. * module/system/vm/elf.scm (DT_GUILE_FRAME_MAPS): New definition. * libguile/loader.h: * libguile/loader.c (DT_GUILE_FRAME_MAPS, process_dynamic_segment): (load_thunk_from_memory, register_elf): Arrange to parse DT_GUILE_FRAME_MAPS out of the dynamic section. (find_mapped_elf_image_unlocked, find_mapped_elf_image): New helpers. (scm_find_mapped_elf_image): Refactor. (scm_find_dead_slot_map_unlocked): New interface. * libguile/vm.c (scm_i_vm_mark_stack): Mark the hottest frame conservatively, as before. Otherwise use the dead slots map, if available, to avoid marking data that isn't live. Andy Wingo2014-01-261-4/+31
* Remove private-gc.h...* libguile/simpos.c (scm_getenv_int): Move here, from gc.c. * libguile/private-gc.h: Remove, unused. * libguile/simpos.h: Move scm_getenv_int declaration here. * libguile/vm.c: * libguile/gc.c: Adapt scm_getenv_int users. * libguile/gc-malloc.c: * libguile/load.c: * libguile/script.c: Remove private-gc includes from non-users of scm_getenv_int. * libguile/Makefile.am: Adapt. Andy Wingo2013-11-281-2/+1
* Remove the restore-continuation-hook....* libguile/vm.h: * libguile/vm.c: * libguile/vm-engine.c: * module/system/vm/traps.scm: * module/system/vm/vm.scm: Remove the unused and redundant restore-continuation-hook. Andy Wingo2013-11-271-14/+0
* Expandable stacks....* libguile/vm-engine.c (CHECK_OVERFLOW): Call vm_expand_stack, not vm_error_stack_overflow. * libguile/vm.c (hard_max_stack_size, default_max_stack_size): Recast #defines as locals. Have both hard and soft stack limits. (initialize_default_stack_size): Set soft stack limit from GUILE_STACK_SIZE. (expand_stack, vm_expand_stack): Support for expanding stacks as needed. Whee! (make_vm): Adapt limits. (scm_call_n): Expand stack if needed. * libguile/vm.h (struct scm_vm): Add max_stack_size member. Andy Wingo2013-11-221-28/+122
* More precise stack marking....* libguile/vm.c (scm_i_vm_mark_stack): Mark the stack more precisely. Andy Wingo2013-11-221-5/+13
* Allocate stacks using mmap, and mark them via the thread marker...* libguile/threads.c (thread_mark): Mark the VM stack, if we have one. (on_thread_exit): Free the VM stack here. * libguile/vm.c (make_vm): Allocate the VM stack using mmap, and arrange for it to be marked by the thread marker. (scm_i_vm_mark_stack, scm_i_vm_free_stack): New internal interfaces. (allocate_stack, free_stack): New helpers. Andy Wingo2013-11-221-51/+51
* Setjmp before calling into the VM...* libguile/vm-engine.c (CACHE_REGISTER): Remove an unneeded cast. (VM_NAME): * libguile/vm.c (scm_call_n): Setjmp out here. This leaves the VM without any initialization work to do. It also makes it possible to restart the VM in another mode (with hooks, for example). Andy Wingo2013-11-211-2/+13
* scm_call_n sets up boot continuation frame for VM...* libguile/vm-engine.c: * libguile/vm.c (scm_call_n): Move boot continuation setup to scm_call_n, so that vm-engine takes all of its state from the vp. Andy Wingo2013-11-211-3/+35
* scm_call_n avoids double TLS lookup...* libguile/vm-engine.c (VM_NAME): Take the current thread as an argument. * libguile/vm.c (scm_i_capture_current_stack): Call thread_vm. (thread_vm): New helper. (scm_the_vm): Call thread_vm. (scm_call_n): Call thread_vm. Avoids a double TLS lookup. Andy Wingo2013-11-211-11/+21
* Remove scm_tc7_vm...* libguile/tags.h (scm_tc7_vm): Return to pool. * libguile/goops.c: * libguile/gc.c (scm_i_tag_name): * libguile/evalext.c (scm_self_evaluating_p): * libguile/print.c (iprin1): Remove tc7_vm things. * libguile/vm.h (scm_the_vm_fluid): Remove stray declaration. Remove SCM_VM_P. Remove SCM_VM_DATA. Remove SCM_VALIDATE_VM. * libguile/vm.c (scm_i_vm_print): Remove. Andy Wingo2013-11-211-30/+0