Simplify code heap layout
parent
fcc7d584e6
commit
c6bc074472
|
@ -19,4 +19,4 @@ IN: compiler.constants
|
|||
: class-hash-offset bootstrap-cell object tag-number - ;
|
||||
: word-xt-offset 8 bootstrap-cells object tag-number - ;
|
||||
: word-code-offset 9 bootstrap-cells object tag-number - ;
|
||||
: compiled-header-size 8 bootstrap-cells ;
|
||||
: compiled-header-size 4 bootstrap-cells ;
|
||||
|
|
|
@ -44,7 +44,7 @@ words kernel math effects definitions compiler.units ;
|
|||
[
|
||||
[ ] [ init-templates ] unit-test
|
||||
|
||||
[ ] [ \ + init-generator ] unit-test
|
||||
[ ] [ init-generator ] unit-test
|
||||
|
||||
[ t ] [ [ end-basic-block ] { } make empty? ] unit-test
|
||||
|
||||
|
|
|
@ -72,8 +72,6 @@ HOOK: %jump-dispatch compiler-backend ( -- )
|
|||
|
||||
HOOK: %dispatch-label compiler-backend ( word -- )
|
||||
|
||||
HOOK: %end-dispatch compiler-backend ( label -- )
|
||||
|
||||
! Return to caller
|
||||
HOOK: %return compiler-backend ( -- )
|
||||
|
||||
|
|
|
@ -144,9 +144,6 @@ M: ppc-backend %jump-dispatch ( -- )
|
|||
M: ppc-backend %dispatch-label ( word -- )
|
||||
0 , rc-absolute-cell rel-word ;
|
||||
|
||||
M: ppc-backend %end-dispatch ( label -- )
|
||||
resolve-label ;
|
||||
|
||||
M: ppc-backend %return ( -- ) %epilogue-later BLR ;
|
||||
|
||||
M: ppc-backend %unwind drop %return ;
|
||||
|
|
|
@ -13,13 +13,6 @@ HELP: add-literal
|
|||
{ $values { "obj" object } { "n" integer } }
|
||||
{ $description "Adds a literal to the " { $link literal-table } ", if it is not already there, and outputs the index of the literal in the table. This literal can then be used as an argument for a " { $link rt-literal } " relocation with " { $link rel-fixup } "." } ;
|
||||
|
||||
HELP: word-table
|
||||
{ $var-description "Holds a vector of words called from the currently compiling word." } ;
|
||||
|
||||
HELP: add-word
|
||||
{ $values { "word" word } { "n" integer } }
|
||||
{ $description "Adds a word to the " { $link word-table } ", if it is not already there, and outputs the index of the word in the table. This literal can then be used as an argument for a " { $link rt-xt } " relocation with " { $link rel-fixup } "." } ;
|
||||
|
||||
HELP: string>symbol
|
||||
{ $values { "str" string } { "alien" alien } }
|
||||
{ $description "Converts the string to a format which is a valid symbol name for the Factor VM's compiled code linker. By performing this conversion ahead of time, the image loader can run without allocating memory."
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
! Copyright (C) 2007 Slava Pestov.
|
||||
! Copyright (C) 2007, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays generic assocs hashtables
|
||||
kernel kernel.private math namespaces sequences words
|
||||
|
@ -110,10 +110,6 @@ SYMBOL: literal-table
|
|||
|
||||
: add-literal ( obj -- n ) literal-table get push-new* ;
|
||||
|
||||
SYMBOL: word-table
|
||||
|
||||
: add-word ( word -- n ) word-table get push-new* ;
|
||||
|
||||
: string>symbol ( str -- alien )
|
||||
wince? [ string>u16-alien ] [ string>char-alien ] if ;
|
||||
|
||||
|
@ -125,10 +121,8 @@ SYMBOL: word-table
|
|||
add-dlsym-literals
|
||||
r> r> rt-dlsym rel-fixup ;
|
||||
|
||||
: rel-dispatch ( word-table# class -- ) rt-dispatch rel-fixup ;
|
||||
|
||||
: rel-word ( word class -- )
|
||||
>r add-word r> rt-xt rel-fixup ;
|
||||
>r add-literal r> rt-xt rel-fixup ;
|
||||
|
||||
: rel-primitive ( word class -- )
|
||||
>r word-def first r> rt-primitive rel-fixup ;
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
! Copyright (C) 2004, 2007 Slava Pestov.
|
||||
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays assocs classes combinators cpu.architecture
|
||||
effects generator.fixup generator.registers generic hashtables
|
||||
inference inference.backend inference.dataflow io kernel
|
||||
kernel.private layouts math namespaces optimizer prettyprint
|
||||
quotations sequences system threads words ;
|
||||
quotations sequences system threads words vectors ;
|
||||
IN: generator
|
||||
|
||||
SYMBOL: compile-queue
|
||||
SYMBOL: compiled
|
||||
|
||||
: 5array 3array >r 2array r> append ;
|
||||
|
||||
: begin-compiling ( word -- )
|
||||
f swap compiled get set-at ;
|
||||
|
||||
: finish-compiling ( word literals words relocation labels code -- )
|
||||
5array swap compiled get set-at ;
|
||||
: finish-compiling ( word literals relocation labels code -- )
|
||||
4array swap compiled get set-at ;
|
||||
|
||||
: queue-compile ( word -- )
|
||||
{
|
||||
|
@ -38,20 +36,18 @@ SYMBOL: current-label-start
|
|||
|
||||
: compiled-stack-traces? ( -- ? ) 36 getenv ;
|
||||
|
||||
: init-generator ( compiling -- )
|
||||
V{ } clone literal-table set
|
||||
V{ } clone word-table set
|
||||
compiled-stack-traces? swap f ?
|
||||
literal-table get push ;
|
||||
: init-generator ( -- )
|
||||
compiled-stack-traces?
|
||||
compiling-word get f ?
|
||||
1vector literal-table set ;
|
||||
|
||||
: generate-1 ( word label node quot -- )
|
||||
pick begin-compiling [
|
||||
roll compiling-word set
|
||||
pick compiling-label set
|
||||
compiling-word get init-generator
|
||||
init-generator
|
||||
call
|
||||
literal-table get >array
|
||||
word-table get >array
|
||||
] { } make fixup finish-compiling ;
|
||||
|
||||
GENERIC: generate-node ( node -- next )
|
||||
|
@ -182,7 +178,7 @@ M: #dispatch generate-node
|
|||
%jump-dispatch dispatch-branches
|
||||
] [
|
||||
0 frame-required
|
||||
%call-dispatch >r dispatch-branches r> %end-dispatch
|
||||
%call-dispatch >r dispatch-branches r> resolve-label
|
||||
] if
|
||||
init-templates iterate-next ;
|
||||
|
||||
|
|
|
@ -245,17 +245,13 @@ void iterate_code_heap(CODE_HEAP_ITERATOR iter)
|
|||
|
||||
/* Copy all literals referenced from a code block to newspace */
|
||||
void collect_literals_step(F_COMPILED *compiled, CELL code_start,
|
||||
CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end)
|
||||
CELL reloc_start, CELL literals_start)
|
||||
{
|
||||
CELL scan;
|
||||
|
||||
CELL literal_end = literals_start + compiled->literals_length;
|
||||
|
||||
for(scan = literals_start; scan < literal_end; scan += CELLS)
|
||||
copy_handle((CELL*)scan);
|
||||
|
||||
for(scan = words_start; scan < words_end; scan += CELLS)
|
||||
copy_handle((CELL*)scan);
|
||||
}
|
||||
|
||||
/* Copy literals referenced from all code blocks to newspace */
|
||||
|
|
|
@ -48,17 +48,15 @@ INLINE F_BLOCK *next_block(F_HEAP *heap, F_BLOCK *block)
|
|||
F_HEAP code_heap;
|
||||
|
||||
typedef void (*CODE_HEAP_ITERATOR)(F_COMPILED *compiled, CELL code_start,
|
||||
CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end);
|
||||
CELL reloc_start, CELL literals_start);
|
||||
|
||||
INLINE void iterate_code_heap_step(F_COMPILED *compiled, CODE_HEAP_ITERATOR iter)
|
||||
{
|
||||
CELL code_start = (CELL)(compiled + 1);
|
||||
CELL reloc_start = code_start + compiled->code_length;
|
||||
CELL literals_start = reloc_start + compiled->reloc_length;
|
||||
CELL words_start = literals_start + compiled->literals_length;
|
||||
CELL words_end = words_start + compiled->words_length;
|
||||
|
||||
iter(compiled,code_start,reloc_start,literals_start,words_start,words_end);
|
||||
iter(compiled,code_start,reloc_start,literals_start);
|
||||
}
|
||||
|
||||
INLINE F_BLOCK *compiled_to_block(F_COMPILED *compiled)
|
||||
|
|
|
@ -38,7 +38,7 @@ void *get_rel_symbol(F_REL *rel, CELL literals_start)
|
|||
|
||||
/* Compute an address to store at a relocation */
|
||||
INLINE CELL compute_code_rel(F_REL *rel,
|
||||
CELL code_start, CELL literals_start, CELL words_start)
|
||||
CELL code_start, CELL literals_start)
|
||||
{
|
||||
switch(REL_TYPE(rel))
|
||||
{
|
||||
|
@ -48,10 +48,8 @@ INLINE CELL compute_code_rel(F_REL *rel,
|
|||
return (CELL)get_rel_symbol(rel,literals_start);
|
||||
case RT_LITERAL:
|
||||
return CREF(literals_start,REL_ARGUMENT(rel));
|
||||
case RT_DISPATCH:
|
||||
return CREF(words_start,REL_ARGUMENT(rel));
|
||||
case RT_XT:
|
||||
return (CELL)untag_word(get(CREF(words_start,REL_ARGUMENT(rel))))->xt;
|
||||
return (CELL)untag_word(get(CREF(literals_start,REL_ARGUMENT(rel))))->xt;
|
||||
case RT_HERE:
|
||||
return rel->offset + code_start;
|
||||
case RT_LABEL:
|
||||
|
@ -127,7 +125,7 @@ void apply_relocation(CELL class, CELL offset, F_FIXNUM absolute_value)
|
|||
|
||||
/* Perform all fixups on a code block */
|
||||
void relocate_code_block(F_COMPILED *relocating, CELL code_start,
|
||||
CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end)
|
||||
CELL reloc_start, CELL literals_start)
|
||||
{
|
||||
if(reloc_start != literals_start)
|
||||
{
|
||||
|
@ -138,8 +136,8 @@ void relocate_code_block(F_COMPILED *relocating, CELL code_start,
|
|||
{
|
||||
CELL offset = rel->offset + code_start;
|
||||
|
||||
F_FIXNUM absolute_value = compute_code_rel(rel,
|
||||
code_start,literals_start,words_start);
|
||||
F_FIXNUM absolute_value = compute_code_rel(
|
||||
rel,code_start,literals_start);
|
||||
|
||||
apply_relocation(REL_CLASS(rel),offset,absolute_value);
|
||||
|
||||
|
@ -228,27 +226,23 @@ F_COMPILED *add_compiled_block(
|
|||
F_ARRAY *code,
|
||||
F_ARRAY *labels,
|
||||
F_ARRAY *relocation,
|
||||
F_ARRAY *words,
|
||||
F_ARRAY *literals)
|
||||
{
|
||||
CELL code_format = compiled_code_format();
|
||||
|
||||
CELL code_length = align8(array_capacity(code) * code_format);
|
||||
CELL rel_length = array_capacity(relocation) * sizeof(unsigned int);
|
||||
CELL words_length = (words ? array_capacity(words) * CELLS : 0);
|
||||
CELL literals_length = array_capacity(literals) * CELLS;
|
||||
|
||||
REGISTER_UNTAGGED(code);
|
||||
REGISTER_UNTAGGED(labels);
|
||||
REGISTER_UNTAGGED(relocation);
|
||||
REGISTER_UNTAGGED(words);
|
||||
REGISTER_UNTAGGED(literals);
|
||||
|
||||
CELL here = allot_code_block(sizeof(F_COMPILED) + code_length
|
||||
+ rel_length + literals_length + words_length);
|
||||
+ rel_length + literals_length);
|
||||
|
||||
UNREGISTER_UNTAGGED(literals);
|
||||
UNREGISTER_UNTAGGED(words);
|
||||
UNREGISTER_UNTAGGED(relocation);
|
||||
UNREGISTER_UNTAGGED(labels);
|
||||
UNREGISTER_UNTAGGED(code);
|
||||
|
@ -259,7 +253,6 @@ F_COMPILED *add_compiled_block(
|
|||
header->code_length = code_length;
|
||||
header->reloc_length = rel_length;
|
||||
header->literals_length = literals_length;
|
||||
header->words_length = words_length;
|
||||
|
||||
here += sizeof(F_COMPILED);
|
||||
|
||||
|
@ -277,13 +270,6 @@ F_COMPILED *add_compiled_block(
|
|||
deposit_objects(here,literals);
|
||||
here += literals_length;
|
||||
|
||||
/* words */
|
||||
if(words)
|
||||
{
|
||||
deposit_objects(here,words);
|
||||
here += words_length;
|
||||
}
|
||||
|
||||
/* fixup labels */
|
||||
if(labels)
|
||||
fixup_labels(labels,code_format,code_start);
|
||||
|
@ -347,10 +333,9 @@ DEFINE_PRIMITIVE(modify_code_heap)
|
|||
F_ARRAY *compiled_code = untag_array(data);
|
||||
|
||||
F_ARRAY *literals = untag_array(array_nth(compiled_code,0));
|
||||
F_ARRAY *words = untag_array(array_nth(compiled_code,1));
|
||||
F_ARRAY *relocation = untag_array(array_nth(compiled_code,2));
|
||||
F_ARRAY *labels = untag_array(array_nth(compiled_code,3));
|
||||
F_ARRAY *code = untag_array(array_nth(compiled_code,4));
|
||||
F_ARRAY *relocation = untag_array(array_nth(compiled_code,1));
|
||||
F_ARRAY *labels = untag_array(array_nth(compiled_code,2));
|
||||
F_ARRAY *code = untag_array(array_nth(compiled_code,3));
|
||||
|
||||
REGISTER_UNTAGGED(alist);
|
||||
REGISTER_UNTAGGED(word);
|
||||
|
@ -360,7 +345,6 @@ DEFINE_PRIMITIVE(modify_code_heap)
|
|||
code,
|
||||
labels,
|
||||
relocation,
|
||||
words,
|
||||
literals);
|
||||
|
||||
UNREGISTER_UNTAGGED(word);
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef struct {
|
|||
} F_REL;
|
||||
|
||||
void relocate_code_block(F_COMPILED *relocating, CELL code_start,
|
||||
CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end);
|
||||
CELL reloc_start, CELL literals_start);
|
||||
|
||||
void default_word_code(F_WORD *word, bool relocate);
|
||||
|
||||
|
@ -65,7 +65,6 @@ F_COMPILED *add_compiled_block(
|
|||
F_ARRAY *code,
|
||||
F_ARRAY *labels,
|
||||
F_ARRAY *rel,
|
||||
F_ARRAY *words,
|
||||
F_ARRAY *literals);
|
||||
|
||||
CELL compiled_code_format(void);
|
||||
|
|
12
vm/image.c
12
vm/image.c
|
@ -179,7 +179,7 @@ void fixup_word(F_WORD *word)
|
|||
{
|
||||
code_fixup((CELL)&word->code);
|
||||
if(word->profiling) code_fixup((CELL)&word->profiling);
|
||||
update_word_xt(word);
|
||||
code_fixup((CELL)&word->xt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ void relocate_data()
|
|||
}
|
||||
|
||||
void fixup_code_block(F_COMPILED *relocating, CELL code_start,
|
||||
CELL reloc_start, CELL literals_start, CELL words_start, CELL words_end)
|
||||
CELL reloc_start, CELL literals_start)
|
||||
{
|
||||
/* relocate literal table data */
|
||||
CELL scan;
|
||||
|
@ -271,14 +271,8 @@ void fixup_code_block(F_COMPILED *relocating, CELL code_start,
|
|||
for(scan = literals_start; scan < literal_end; scan += CELLS)
|
||||
data_fixup((CELL*)scan);
|
||||
|
||||
for(scan = words_start; scan < words_end; scan += CELLS)
|
||||
data_fixup((CELL*)scan);
|
||||
|
||||
if(reloc_start != literals_start)
|
||||
{
|
||||
relocate_code_block(relocating,code_start,reloc_start,
|
||||
literals_start,words_start,words_end);
|
||||
}
|
||||
relocate_code_block(relocating,code_start,reloc_start,literals_start);
|
||||
}
|
||||
|
||||
void relocate_code()
|
||||
|
|
|
@ -151,8 +151,6 @@ typedef struct
|
|||
CELL code_length; /* # bytes */
|
||||
CELL reloc_length; /* # bytes */
|
||||
CELL literals_length; /* # bytes */
|
||||
CELL words_length; /* # bytes */
|
||||
CELL padding[3];
|
||||
} F_COMPILED;
|
||||
|
||||
/* Assembly code makes assumptions about the layout of this struct */
|
||||
|
|
|
@ -25,7 +25,6 @@ F_COMPILED *compile_profiling_stub(F_WORD *word)
|
|||
untag_object(code),
|
||||
NULL, /* no labels */
|
||||
untag_object(relocation),
|
||||
NULL, /* no words */
|
||||
untag_object(literals));
|
||||
}
|
||||
|
||||
|
|
|
@ -116,9 +116,6 @@ void jit_compile(CELL quot, bool relocate)
|
|||
GROWABLE_ARRAY(literals);
|
||||
REGISTER_ROOT(literals);
|
||||
|
||||
GROWABLE_ARRAY(words);
|
||||
REGISTER_ROOT(words);
|
||||
|
||||
GROWABLE_ADD(literals,stack_traces_p() ? quot : F);
|
||||
|
||||
bool stack_frame = jit_stack_frame_p(untag_object(array));
|
||||
|
@ -144,19 +141,19 @@ void jit_compile(CELL quot, bool relocate)
|
|||
current stack frame. */
|
||||
word = untag_object(obj);
|
||||
|
||||
GROWABLE_ADD(words,array_nth(untag_object(array),i));
|
||||
GROWABLE_ADD(literals,array_nth(untag_object(array),i));
|
||||
|
||||
if(i == length - 1)
|
||||
{
|
||||
if(stack_frame)
|
||||
EMIT(JIT_EPILOG,0);
|
||||
|
||||
EMIT(JIT_WORD_JUMP,words_count - 1);
|
||||
EMIT(JIT_WORD_JUMP,literals_count - 1);
|
||||
|
||||
tail_call = true;
|
||||
}
|
||||
else
|
||||
EMIT(JIT_WORD_CALL,words_count - 1);
|
||||
EMIT(JIT_WORD_CALL,literals_count - 1);
|
||||
break;
|
||||
case WRAPPER_TYPE:
|
||||
wrapper = untag_object(obj);
|
||||
|
@ -220,14 +217,12 @@ void jit_compile(CELL quot, bool relocate)
|
|||
GROWABLE_TRIM(code);
|
||||
GROWABLE_TRIM(relocation);
|
||||
GROWABLE_TRIM(literals);
|
||||
GROWABLE_TRIM(words);
|
||||
|
||||
F_COMPILED *compiled = add_compiled_block(
|
||||
QUOTATION_TYPE,
|
||||
untag_object(code),
|
||||
NULL,
|
||||
untag_object(relocation),
|
||||
untag_object(words),
|
||||
untag_object(literals));
|
||||
|
||||
set_quot_xt(untag_object(quot),compiled);
|
||||
|
@ -235,7 +230,6 @@ void jit_compile(CELL quot, bool relocate)
|
|||
if(relocate)
|
||||
iterate_code_heap_step(compiled,relocate_code_block);
|
||||
|
||||
UNREGISTER_ROOT(words);
|
||||
UNREGISTER_ROOT(literals);
|
||||
UNREGISTER_ROOT(relocation);
|
||||
UNREGISTER_ROOT(code);
|
||||
|
|
Loading…
Reference in New Issue