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 = 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);
35 template <typename Iterator>
36 inline void factor_vm::iterate_callstack_object(callstack* stack,
39 iterate_callstack_object(stack, iterator, none);
42 // Iterates the callstack from innermost to outermost
43 // callframe. Allocates memory
44 template <typename Iterator, typename Fixup>
45 void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
48 cell top = ctx->callstack_top;
49 cell bottom = ctx->callstack_bottom;
50 // When we are translating the code block maps, all callstacks must
52 FACTOR_ASSERT(!Fixup::translated_code_block_map || top == bottom);
54 while (top < bottom) {
55 cell addr = *(cell*)top;
56 FACTOR_ASSERT(addr != 0);
58 // Only the address is valid, if the code heap has been compacted,
59 // owner might not point to a real code block.
60 code_block* owner = code->code_block_for_address(addr);
61 code_block* fixed_owner = fixup.translate_code(owner);
63 cell delta = addr - (cell)owner - sizeof(code_block);
64 cell natural_frame_size = fixed_owner->stack_frame_size();
65 cell size = LEAF_FRAME_SIZE;
66 if (natural_frame_size > 0 && delta > 0)
67 size = natural_frame_size;
69 iterator(top, size, owner, addr);
72 FACTOR_ASSERT(top == bottom);
76 template <typename Iterator>
77 inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) {
79 iterate_callstack(ctx, iterator, none);