1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-16 16:50:21 +02:00

remove heap links in VM frames, incorporate vm frames into normal backtraces

* doc/ref/vm.texi (Stack Layout): Update to remove references to the
  "heap link".

* gdbinit: Update for "heap link" removal.

* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
  link". As part of this, we also remove "heap frames", replacing them
  with "vm frames", which are much like the interpreter's debug objects,
  but for VM stacks. That is to say, they don't actually hold the stack
  themselves, just the pointers into stack that's held by a continuation
  (either captured or current).

* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
  really a copy of information that comes from somewhere else, it makes
  sense to copy over info from the VM, just as `make-stack' does from the
  evaluator. The tricky bit is to figure out how to interleave VM and
  interpreter frames. We do that by starting in the interpreter, and
  whenever the current frame's procedure is actually a program, we switch
  to the VM stack, switching back when we reach a "bootstrap frame". The
  last bit is hacky, but it does work...
  (is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
  bootstrap frame.
  (scm_make_stack): Accept a VM frame in addition to debug frames.
  Probably has some bugs in this case. But in the case that the arg is
  #t (a common case), do the right thing, capturing the top VM frame as
  well, and interleaving those frames appropriately on the stack.

  As an accident, we lost the ability to limit the number of frames in
  the backtrace. We could add that back, but personally I always want
  *all* frames in the trace... Narrowing still works fine, though there
  are some hiccups sometimes -- e.g. an outer cut to a procedure that
  does a tail-call in VM code will never find the cut, as it no longer
  exists in the continuation.

* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
  stacks in the normal make-stack, there's no more need for `this_frame'
  or `last_frame'. On the other hand, we can take this opportunity to fix
  tracing: when we're in a trace hook, we set `trace_frame' on the VM,
  so we know not to fire hooks when we're already in a hook.
  (struct scm_vm_cont): Expose this, as make-stack needs it to make VM
  frames from VM continuations.

* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
  trace frame.
  (vm_mark, make_vm): Hook up the trace frame.
  (vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
  right thing if the hook exits nonlocally.

* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.

* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
  (ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
  (NEW_FRAME): Adapt for no HL in the frame.

* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
  Adapt for no HL in the frame.

* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
  thought.
This commit is contained in:
Andy Wingo 2008-12-26 17:59:46 +01:00
parent 9f0e9918f4
commit b1b942b74c
12 changed files with 379 additions and 439 deletions

View file

@ -217,11 +217,10 @@
#if VM_USE_HOOKS
#define RUN_HOOK(h) \
{ \
if (!SCM_FALSEP (vp->hooks[h])) \
if (SCM_UNLIKELY (!SCM_FALSEP (vp->hooks[h])))\
{ \
SYNC_REGISTER (); \
vm_heapify_frames (vm); \
scm_c_run_hook (vp->hooks[h], hook_args); \
vm_dispatch_hook (vm, vp->hooks[h], hook_args); \
CACHE_REGISTER (); \
} \
}
@ -311,75 +310,6 @@ do \
} \
} while (0)
/* Below is a (slightly broken) experiment to avoid calling `scm_cell' and to
allocate cells on the stack. This is a significant improvement for
programs which call a lot of procedures, since the procedure call
mechanism uses POP_LIST which normally uses `scm_cons'.
What it does is that it creates a list whose cells are allocated on the
VM's stack instead of being allocated on the heap via `scm_cell'. This is
much faster. However, if the callee does something like:
(lambda (. args)
(set! the-args args))
then terrible things may happen since the list of arguments may be
overwritten later on. */
/* Awful hack that aligns PTR so that it can be considered as a non-immediate
value by Guile. */
#define ALIGN_AS_NON_IMMEDIATE(_ptr) \
{ \
if ((scm_t_bits)(_ptr) & 6) \
{ \
size_t _incr; \
\
_incr = (scm_t_bits)(_ptr) & 6; \
_incr = (~_incr) & 7; \
(_ptr) += _incr; \
} \
}
#define POP_LIST_ON_STACK(n) \
do \
{ \
int i; \
if (n == 0) \
{ \
sp -= n; \
PUSH (SCM_EOL); \
} \
else \
{ \
SCM *list_head, *list; \
\
list_head = sp + 1; \
ALIGN_AS_NON_IMMEDIATE (list_head); \
list = list_head; \
\
sp -= n; \
for (i = 1; i <= n; i++) \
{ \
/* The cell's car and cdr. */ \
*(list) = sp[i]; \
*(list + 1) = PTR2SCM (list + 2); \
list += 2; \
} \
\
/* The last pair's cdr is '(). */ \
list--; \
*list = SCM_EOL; \
/* Push the SCM object that points */ \
/* to the first cell. */ \
PUSH (PTR2SCM (list_head)); \
} \
} \
while (0)
/* end of the experiment */
#define POP_LIST_MARK() \
do { \
@ -476,7 +406,7 @@ do { \
/* New registers */ \
fp = sp - bp->nargs + 1; \
data = SCM_FRAME_DATA_ADDRESS (fp); \
sp = data + 4; \
sp = data + 3; \
CHECK_OVERFLOW (); \
stack_base = sp; \
ip = bp->base; \
@ -486,10 +416,9 @@ do { \
data[-i] = SCM_UNDEFINED; \
\
/* Set frame data */ \
data[4] = (SCM)ra; \
data[3] = 0x0; \
data[2] = (SCM)dl; \
data[1] = SCM_BOOL_F; \
data[3] = (SCM)ra; \
data[2] = 0x0; \
data[1] = (SCM)dl; \
\
/* Postpone initializing external vars, \
because if the CONS causes a GC, we \