moved code_heap functions to vm
parent
0097e76a82
commit
ee07c0b4e5
|
@ -6,18 +6,28 @@ namespace factor
|
|||
heap code;
|
||||
|
||||
/* Allocate a code heap during startup */
|
||||
void init_code_heap(cell size)
|
||||
void factorvm::init_code_heap(cell size)
|
||||
{
|
||||
new_heap(&code,size);
|
||||
}
|
||||
|
||||
bool in_code_heap_p(cell ptr)
|
||||
void init_code_heap(cell size)
|
||||
{
|
||||
return vm->init_code_heap(size);
|
||||
}
|
||||
|
||||
bool factorvm::in_code_heap_p(cell ptr)
|
||||
{
|
||||
return (ptr >= code.seg->start && ptr <= code.seg->end);
|
||||
}
|
||||
|
||||
bool in_code_heap_p(cell ptr)
|
||||
{
|
||||
return vm->in_code_heap_p(ptr);
|
||||
}
|
||||
|
||||
/* Compile a word definition with the non-optimizing compiler. Allocates memory */
|
||||
void jit_compile_word(cell word_, cell def_, bool relocate)
|
||||
void factorvm::jit_compile_word(cell word_, cell def_, bool relocate)
|
||||
{
|
||||
gc_root<word> word(word_);
|
||||
gc_root<quotation> def(def_);
|
||||
|
@ -30,8 +40,13 @@ void jit_compile_word(cell word_, cell def_, bool relocate)
|
|||
if(word->pic_tail_def != F) jit_compile(word->pic_tail_def,relocate);
|
||||
}
|
||||
|
||||
void jit_compile_word(cell word_, cell def_, bool relocate)
|
||||
{
|
||||
return vm->jit_compile_word(word_,def_,relocate);
|
||||
}
|
||||
|
||||
/* Apply a function to every code block */
|
||||
void iterate_code_heap(code_heap_iterator iter)
|
||||
void factorvm::iterate_code_heap(code_heap_iterator iter)
|
||||
{
|
||||
heap_block *scan = first_block(&code);
|
||||
|
||||
|
@ -43,21 +58,36 @@ void iterate_code_heap(code_heap_iterator iter)
|
|||
}
|
||||
}
|
||||
|
||||
void iterate_code_heap(code_heap_iterator iter)
|
||||
{
|
||||
return vm->iterate_code_heap(iter);
|
||||
}
|
||||
|
||||
/* Copy literals referenced from all code blocks to newspace. Only for
|
||||
aging and nursery collections */
|
||||
void factorvm::copy_code_heap_roots()
|
||||
{
|
||||
iterate_code_heap(factor::copy_literal_references);
|
||||
}
|
||||
|
||||
void copy_code_heap_roots()
|
||||
{
|
||||
iterate_code_heap(copy_literal_references);
|
||||
return vm->copy_code_heap_roots();
|
||||
}
|
||||
|
||||
/* Update pointers to words referenced from all code blocks. Only after
|
||||
defining a new word. */
|
||||
void update_code_heap_words()
|
||||
void factorvm::update_code_heap_words()
|
||||
{
|
||||
iterate_code_heap(update_word_references);
|
||||
iterate_code_heap(factor::update_word_references);
|
||||
}
|
||||
|
||||
PRIMITIVE(modify_code_heap)
|
||||
void update_code_heap_words()
|
||||
{
|
||||
return vm->update_code_heap_words();
|
||||
}
|
||||
|
||||
inline void factorvm::vmprim_modify_code_heap()
|
||||
{
|
||||
gc_root<array> alist(dpop());
|
||||
|
||||
|
@ -108,8 +138,13 @@ PRIMITIVE(modify_code_heap)
|
|||
update_code_heap_words();
|
||||
}
|
||||
|
||||
PRIMITIVE(modify_code_heap)
|
||||
{
|
||||
PRIMITIVE_GETVM()->vmprim_modify_code_heap();
|
||||
}
|
||||
|
||||
/* Push the free space and total size of the code heap */
|
||||
PRIMITIVE(code_room)
|
||||
inline void factorvm::vmprim_code_room()
|
||||
{
|
||||
cell used, total_free, max_free;
|
||||
heap_usage(&code,&used,&total_free,&max_free);
|
||||
|
@ -119,14 +154,24 @@ PRIMITIVE(code_room)
|
|||
dpush(tag_fixnum(max_free / 1024));
|
||||
}
|
||||
|
||||
PRIMITIVE(code_room)
|
||||
{
|
||||
PRIMITIVE_GETVM()->vmprim_code_room();
|
||||
}
|
||||
|
||||
static unordered_map<heap_block *,char *> forwarding;
|
||||
|
||||
code_block *forward_xt(code_block *compiled)
|
||||
code_block *factorvm::forward_xt(code_block *compiled)
|
||||
{
|
||||
return (code_block *)forwarding[compiled];
|
||||
}
|
||||
|
||||
void forward_frame_xt(stack_frame *frame)
|
||||
code_block *forward_xt(code_block *compiled)
|
||||
{
|
||||
return vm->forward_xt(compiled);
|
||||
}
|
||||
|
||||
void factorvm::forward_frame_xt(stack_frame *frame)
|
||||
{
|
||||
cell offset = (cell)FRAME_RETURN_ADDRESS(frame) - (cell)frame_code(frame);
|
||||
code_block *forwarded = forward_xt(frame_code(frame));
|
||||
|
@ -134,7 +179,12 @@ void forward_frame_xt(stack_frame *frame)
|
|||
FRAME_RETURN_ADDRESS(frame) = (void *)((cell)forwarded + offset);
|
||||
}
|
||||
|
||||
void forward_object_xts()
|
||||
void forward_frame_xt(stack_frame *frame)
|
||||
{
|
||||
return vm->forward_frame_xt(frame);
|
||||
}
|
||||
|
||||
void factorvm::forward_object_xts()
|
||||
{
|
||||
begin_scan();
|
||||
|
||||
|
@ -165,7 +215,7 @@ void forward_object_xts()
|
|||
case CALLSTACK_TYPE:
|
||||
{
|
||||
callstack *stack = untag<callstack>(obj);
|
||||
iterate_callstack_object(stack,forward_frame_xt);
|
||||
iterate_callstack_object(stack,factor::forward_frame_xt);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -176,8 +226,13 @@ void forward_object_xts()
|
|||
end_scan();
|
||||
}
|
||||
|
||||
void forward_object_xts()
|
||||
{
|
||||
return vm->forward_object_xts();
|
||||
}
|
||||
|
||||
/* Set the XT fields now that the heap has been compacted */
|
||||
void fixup_object_xts()
|
||||
void factorvm::fixup_object_xts()
|
||||
{
|
||||
begin_scan();
|
||||
|
||||
|
@ -205,11 +260,16 @@ void fixup_object_xts()
|
|||
end_scan();
|
||||
}
|
||||
|
||||
void fixup_object_xts()
|
||||
{
|
||||
return vm->fixup_object_xts();
|
||||
}
|
||||
|
||||
/* Move all free space to the end of the code heap. This is not very efficient,
|
||||
since it makes several passes over the code and data heaps, but we only ever
|
||||
do this before saving a deployed image and exiting, so performaance is not
|
||||
critical here */
|
||||
void compact_code_heap()
|
||||
void factorvm::compact_code_heap()
|
||||
{
|
||||
/* Free all unreachable code blocks */
|
||||
gc();
|
||||
|
@ -231,4 +291,9 @@ void compact_code_heap()
|
|||
build_free_list(&code,size);
|
||||
}
|
||||
|
||||
void compact_code_heap()
|
||||
{
|
||||
return vm->compact_code_heap();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
vm/vm.hpp
15
vm/vm.hpp
|
@ -382,6 +382,21 @@ struct factorvm {
|
|||
void fixup_labels(array *labels, code_block *compiled);
|
||||
code_block *allot_code_block(cell size);
|
||||
code_block *add_code_block(cell type,cell code_,cell labels_,cell relocation_,cell literals_);
|
||||
|
||||
//code_heap
|
||||
void init_code_heap(cell size);
|
||||
bool in_code_heap_p(cell ptr);
|
||||
void jit_compile_word(cell word_, cell def_, bool relocate);
|
||||
void iterate_code_heap(code_heap_iterator iter);
|
||||
void copy_code_heap_roots();
|
||||
void update_code_heap_words();
|
||||
inline void vmprim_modify_code_heap();
|
||||
inline void vmprim_code_room();
|
||||
code_block *forward_xt(code_block *compiled);
|
||||
void forward_frame_xt(stack_frame *frame);
|
||||
void forward_object_xts();
|
||||
void fixup_object_xts();
|
||||
void compact_code_heap();
|
||||
// next method here:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue