3 inline static cell callstack_object_size(cell size) {
4 return sizeof(callstack) + size;
7 /* This is a little tricky. The iterator may allocate memory, so we
8 keep the callstack in a GC root and use relative offsets */
10 template <typename Iterator, typename Fixup>
11 inline void factor_vm::iterate_callstack_object(callstack* stack_,
14 data_root<callstack> stack(stack_, this);
15 fixnum frame_length = factor::untag_fixnum(stack->length);
16 fixnum frame_offset = 0;
18 while (frame_offset < frame_length) {
19 cell frame_top = stack->frame_top_at(frame_offset);
20 cell addr = *(cell*)frame_top;
21 cell fixed_addr = Fixup::translated_code_block_map
22 ? (cell)fixup.translate_code((code_block*)addr)
24 code_block* owner = code->code_block_for_address(fixed_addr);
26 cell frame_size = owner->stack_frame_size_for_address(fixed_addr);
28 iterator(frame_top, frame_size, owner, fixed_addr);
29 frame_offset += frame_size;
31 FACTOR_ASSERT(frame_offset == frame_length);
34 /* Allocates memory */
35 template <typename Iterator>
36 inline void factor_vm::iterate_callstack_object(callstack* stack,
39 iterate_callstack_object(stack, iterator, none);
42 /* Allocates memory */
43 template <typename Iterator, typename Fixup>
44 void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
47 FACTOR_ASSERT(!Fixup::translated_code_block_map);
48 cell top = ctx->callstack_top;
50 while (top < ctx->callstack_bottom) {
51 cell addr = *(cell*)top;
52 FACTOR_ASSERT(addr != 0);
54 /* Only the address is valid, if the code heap has been compacted,
55 owner might not point to a real code block. */
56 code_block* owner = code->code_block_for_address(addr);
57 code_block* fixed_owner = fixup.translate_code(owner);
59 cell delta = addr - (cell)owner - sizeof(code_block);
60 cell natural_frame_size = fixed_owner->stack_frame_size();
61 cell size = LEAF_FRAME_SIZE;
62 if (natural_frame_size > 0 && delta > 0)
63 size = natural_frame_size;
65 iterator(top, size, owner, addr);
68 FACTOR_ASSERT(top == ctx->callstack_bottom);
71 /* Allocates memory */
72 template <typename Iterator>
73 inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) {
75 iterate_callstack(ctx, iterator, none);