1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

229 commits

Author SHA1 Message Date
Andy Wingo
2cb7c4c4d7 Remove unused static definitions
* libguile/expand.c:
* libguile/vm.c: Remove unused static definitions.
2016-06-11 18:29:35 +02:00
Andy Wingo
f5b9a53bd0 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.
2016-05-04 12:36:41 +02:00
Andy Wingo
105e36543f 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.
2016-04-26 23:07:28 +02:00
Andy Wingo
c3240d09b2 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.
2015-12-01 15:42:24 +01:00
Andy Wingo
a08b3d40f8 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.
2015-12-01 15:42:24 +01:00
Andy Wingo
3b3405e504 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.
2015-12-01 11:30:45 +01:00
Andy Wingo
02fc5a772b 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.
2015-12-01 10:57:20 +01:00
Andy Wingo
e7660a607c 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.
2015-10-28 16:40:53 +00:00
Andy Wingo
70c317ab51 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.
2015-10-21 11:49:20 +02:00
Andy Wingo
72353de77d 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.
2015-10-21 11:49:20 +02:00
Andy Wingo
8f027385db 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.
2015-10-21 11:49:20 +02:00
Andy Wingo
30c06bfbb3 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.
2015-10-21 11:49:20 +02:00
Andy Wingo
0007507340 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.
2015-10-21 11:49:20 +02:00
Andy Wingo
567a6d1ee7 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.
2015-01-23 16:16:03 +01:00
Andy Wingo
73fc4e73e4 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.
2014-04-16 19:20:23 +02:00
Andy Wingo
a2ebdba7ac 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.
2014-04-16 19:18:29 +02:00
Andy Wingo
4cfa92d60f 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.
2014-04-16 19:16:10 +02:00
Andy Wingo
c2247b782a 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.
2014-03-22 15:49:31 +01:00
Andy Wingo
f764e2590f 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.
2014-03-12 17:18:13 +01:00
Andy Wingo
c53d0f01dd 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.
2014-02-20 21:09:08 +01:00
Andy Wingo
698c55b04b 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.
2014-02-20 19:57:47 +01:00
Andy Wingo
2a62eda85a 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.
2014-02-20 10:43:40 +01:00
Andy Wingo
24af549ac1 Remove the hard stack size limit
* libguile/vm.c (vm_expand_stack): Remove the hard stack size limit.
2014-02-20 10:21:51 +01:00
Andy Wingo
c2ae85beab 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.
2014-02-20 10:17:51 +01:00
Andy Wingo
7e2fd4e7f5 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.
2014-02-20 09:45:01 +01:00
Andy Wingo
ee1c6b575f Fix scm_i_vm_capture_stack comment.
* libguile/vm.c (scm_i_vm_capture_stack): Fix a comment.
2014-02-19 11:19:10 +01:00
Andy Wingo
f2d592185f Default stack size is one page.
* libguile/vm.c (initialize_default_stack_size): Initial stack size is
  one page.
2014-02-19 11:15:50 +01:00
Andy Wingo
b8321c24aa 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.
2014-02-19 11:11:24 +01:00
Andy Wingo
a32488ba13 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.
2014-02-08 17:19:52 +01:00
Andy Wingo
b914b236c3 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.
2014-02-05 22:52:00 +01:00
Andy Wingo
aef1fcf94e 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.
2014-02-02 16:17:54 +01:00
Andy Wingo
407190060b 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.
2014-02-02 11:43:03 +01:00
Andy Wingo
7dba1c2ff1 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.
2014-01-31 21:41:36 +01:00
Andy Wingo
7161ec1133 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.
2014-01-31 20:31:31 +01:00
Andy Wingo
02c624fc09 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.
2014-01-26 20:55:04 +01:00
Andy Wingo
87fc4596e5 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.
2013-11-28 11:53:57 +01:00
Andy Wingo
f689dd6982 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.
2013-11-27 22:03:58 +01:00
Andy Wingo
22d425ec55 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.
2013-11-22 18:45:01 +01:00
Andy Wingo
1cdf9b788e More precise stack marking.
* libguile/vm.c (scm_i_vm_mark_stack): Mark the stack more precisely.
2013-11-22 15:02:17 +01:00
Andy Wingo
5f18bc8450 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.
2013-11-22 14:41:19 +01:00
Andy Wingo
dd1c7deccc 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).
2013-11-21 21:15:58 +01:00
Andy Wingo
bd63e5b2c3 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.
2013-11-21 19:05:43 +01:00
Andy Wingo
b85cd20f80 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.
2013-11-21 18:50:12 +01:00
Andy Wingo
350930756c 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.
2013-11-21 18:39:21 +01:00
Andy Wingo
3506b1521e Remove last use of SCM vm
* libguile/threads.h (scm_i_thread): Hold a struct scm_vm*, not a SCM
  vm.
* libguile/threads.c (guilify_self_2):
* libguile/vm.c (make_vm): Adapt.
2013-11-21 18:33:06 +01:00
Andy Wingo
e7f9ababe0 scm_the_vm now returns raw struct scm_vm pointer
* libguile/vm.h (scm_the_vm): Return struct scm_vm*.
  (scm_c_vm_run): Remove.

* libguile/control.c:
* libguile/eval.c:
* libguile/throw.c:
* libguile/vm.c: Adapt.
2013-11-21 18:28:06 +01:00
Andy Wingo
55ee360700 Prefer scm_call_n to scm_c_vm_run (scm_the_vm())
* libguile/vm.c (scm_i_capture_current_stack): Cosmetic tweak.
  (scm_call_n): Define here instead of in eval.c.  All callers of
  scm_c_vm_run were passing scm_the_vm() as the VM.  Eventually
  scm_call_n will replace scm_c_vm_run.

* libguile/eval.c: Adapt all callers.
2013-11-21 18:23:08 +01:00
Andy Wingo
9b4c3ab5fa Engine takes struct scm_vm* as argument
* libguile/vm-engine.c:
* libguile/vm.c (scm_c_vm_run): VM engine now takes struct scm_vm* as
  argument, not SCM vm.
2013-11-21 17:52:00 +01:00
Andy Wingo
796e54a74c One more SCM vm user: continuations.
* libguile/continuations.c:
* libguile/continuations.h (struct scm_t_contregs): Rename SCM vm member
  to struct scm_vm *vp.
  (scm_i_make_continuation): Take vp instead of vm.
  (scm_i_contregs_vp): Rename from scm_i_contregs_vm, return vp.

* libguile/vm-engine.c (continuation-call, call/cc): Fix remaining SCM
  vm user.

* libguile/vm.c (vm_return_to_continuation): Adapt prototype.
2013-11-21 17:50:33 +01:00
Andy Wingo
b44f5451f8 Remove last use of SCM vm in VM
* libguile/control.h:
* libguile/control.c (reify_partial_continuation, scm_c_abort): Take
  struct scm_vm *vp as an arg.

* libguile/dynstack.h: Remove control.h include.

* libguile/vm.c (vm_abort): Take struct scm_vm *vp as an arg.

* libguile/vm-engine.c (abort): Adapt to vm_abort change.
2013-11-21 17:36:22 +01:00