Skip to content

Commit

Permalink
vm: strip out call-counting profiler
Browse files Browse the repository at this point in the history
This makes the separate "code" and "entry_point" fields in word and quotation redundant, so also remove them to reclaim an additional cell per word and quotation object, which should help with factor#318.
  • Loading branch information
jckarter committed Nov 11, 2011
1 parent 06fc9ec commit 5b43301
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 193 deletions.
2 changes: 0 additions & 2 deletions GNUmakefile
Expand Up @@ -34,7 +34,6 @@ ifdef CONFIG
vm/code_heap.o \
vm/compaction.o \
vm/contexts.o \
vm/counting_profiler.o \
vm/data_heap.o \
vm/data_heap_checker.o \
vm/debug.o \
Expand Down Expand Up @@ -77,7 +76,6 @@ ifdef CONFIG
vm/contexts.hpp \
vm/run.hpp \
vm/objects.hpp \
vm/counting_profiler.hpp \
vm/sampling_profiler.hpp \
vm/errors.hpp \
vm/bignumint.hpp \
Expand Down
1 change: 0 additions & 1 deletion Nmakefile
Expand Up @@ -37,7 +37,6 @@ DLL_OBJS = $(PLAF_DLL_OBJS) \
vm\code_heap.obj \
vm\compaction.obj \
vm\contexts.obj \
vm\counting_profiler.obj \
vm\data_heap.obj \
vm\data_heap_checker.obj \
vm\debug.obj \
Expand Down
8 changes: 2 additions & 6 deletions basis/bootstrap/image/image.factor
Expand Up @@ -350,11 +350,8 @@ M: f ' drop \ f type-number ;
[ props>> , ]
[ pic-def>> , ]
[ pic-tail-def>> , ]
[ drop 0 , ] ! count
[ word-sub-primitive , ]
[ drop 0 , ] ! xt
[ drop 0 , ] ! code
[ drop 0 , ] ! profiling
[ drop 0 , ] ! entry point
} cleave
] { } make [ ' ] map
] bi
Expand Down Expand Up @@ -493,8 +490,7 @@ M: quotation '
emit ! array
f ' emit ! cached-effect
f ' emit ! cache-counter
0 emit ! xt
0 emit ! code
0 emit ! entry point
] emit-object
] cache-eql-object ;

Expand Down
4 changes: 2 additions & 2 deletions basis/compiler/constants/constants.factor
Expand Up @@ -20,9 +20,9 @@ CONSTANT: deck-bits 18
: alien-offset ( -- n ) 4 alien type-number slot-offset ; inline
: underlying-alien-offset ( -- n ) 1 alien type-number slot-offset ; inline
: tuple-class-offset ( -- n ) 1 tuple type-number slot-offset ; inline
: word-entry-point-offset ( -- n ) 10 \ word type-number slot-offset ; inline
: word-entry-point-offset ( -- n ) 9 \ word type-number slot-offset ; inline
: quot-entry-point-offset ( -- n ) 4 quotation type-number slot-offset ; inline
: word-code-offset ( -- n ) 11 \ word type-number slot-offset ; inline
: code-block-entry-point-offset ( -- n ) 4 bootstrap-cells ; inline
: array-start-offset ( -- n ) 2 array type-number slot-offset ; inline
: compiled-header-size ( -- n ) 4 bootstrap-cells ; inline
: callstack-length-offset ( -- n ) 1 \ callstack type-number slot-offset ; inline
Expand Down
13 changes: 0 additions & 13 deletions basis/cpu/x86/bootstrap.factor
Expand Up @@ -76,19 +76,6 @@ big-endian off
HEX: ffff RET f rc-absolute-2 rel-untagged
] callback-stub jit-define

[
! Load word
temp0 0 MOV f rc-absolute-cell rel-literal
! Bump profiling counter
temp0 profile-count-offset [+] 1 tag-fixnum ADD
! Load word->code
temp0 temp0 word-code-offset [+] MOV
! Compute word entry point
temp0 compiled-header-size ADD
! Jump to entry point
temp0 JMP
] jit-profiling jit-define

[
! load literal
temp0 0 MOV f rc-absolute-cell rel-literal
Expand Down
1 change: 0 additions & 1 deletion core/bootstrap/primitives.factor
Expand Up @@ -241,7 +241,6 @@ bi
"props"
"pic-def"
"pic-tail-def"
{ "counter" { "fixnum" "math" } }
{ "sub-primitive" read-only }
} define-builtin

Expand Down
12 changes: 4 additions & 8 deletions vm/code_block_visitor.hpp
Expand Up @@ -59,19 +59,15 @@ void code_block_visitor<Fixup>::visit_object_code_block(object *obj)
case WORD_TYPE:
{
word *w = (word *)obj;
if(w->code)
w->code = visit_code_block(w->code);
if(w->counting_profiler)
w->counting_profiler = visit_code_block(w->counting_profiler);

parent->update_word_entry_point(w);
if(w->entry_point)
w->entry_point = visit_code_block(w->code())->entry_point();
break;
}
case QUOTATION_TYPE:
{
quotation *q = (quotation *)obj;
if(q->code)
parent->set_quot_entry_point(q,visit_code_block(q->code));
if(q->entry_point)
q->entry_point = visit_code_block(q->code())->entry_point();
break;
}
case CALLSTACK_TYPE:
Expand Down
13 changes: 13 additions & 0 deletions vm/code_blocks.hpp
Expand Up @@ -84,4 +84,17 @@ struct code_block
};

VM_C_API void undefined_symbol(void);

inline code_block *word::code() const {
assert(entry_point != NULL);
return (code_block*)entry_point - 1;
}

inline code_block *quotation::code() const {
assert(entry_point != NULL);
return (code_block*)entry_point - 1;
}

}


4 changes: 1 addition & 3 deletions vm/code_heap.cpp
Expand Up @@ -178,15 +178,13 @@ void factor_vm::primitive_modify_code_heap()
parameters,
literals);

word->code = compiled;
word->entry_point = compiled->entry_point();
}
break;
default:
critical_error("Expected a quotation or an array",data.value());
break;
}

update_word_entry_point(word.untagged());
}

if(update_existing_words)
Expand Down
66 changes: 0 additions & 66 deletions vm/counting_profiler.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions vm/counting_profiler.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion vm/cpu-x86.cpp
Expand Up @@ -63,7 +63,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
else
assert(false);

*pc = (cell)handler_word->code->entry_point();
*pc = (cell)handler_word->entry_point;
}
}

Expand Down
12 changes: 4 additions & 8 deletions vm/entry_points.cpp
Expand Up @@ -22,34 +22,30 @@ void factor_vm::c_to_factor(cell quot)

template<typename Func> Func factor_vm::get_entry_point(cell n)
{
/* We return word->code->entry_point() and not word->entry_point,
because if the counting profiler is enabled, we don't want to go through the
entry point's counting profiler stub. This clobbers registers, since entry
points use the C ABI and not the Factor ABI. */
tagged<word> entry_point_word(special_objects[n]);
return (Func)entry_point_word->code->entry_point();
return (Func)entry_point_word->entry_point;
}

void factor_vm::unwind_native_frames(cell quot, stack_frame *to)
{
tagged<word> entry_point_word(special_objects[UNWIND_NATIVE_FRAMES_WORD]);
void *func = entry_point_word->code->entry_point();
void *func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func);
((unwind_native_frames_func_type)func)(quot,to);
}

cell factor_vm::get_fpu_state()
{
tagged<word> entry_point_word(special_objects[GET_FPU_STATE_WORD]);
void *func = entry_point_word->code->entry_point();
void *func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func);
return ((get_fpu_state_func_type)func)();
}

void factor_vm::set_fpu_state(cell state)
{
tagged<word> entry_point_word(special_objects[SET_FPU_STATE_WORD]);
void *func = entry_point_word->code->entry_point();
void *func = entry_point_word->entry_point;
CODE_TO_FUNCTION_POINTER(func);
((set_fpu_state_func_type)func)(state);
}
Expand Down
1 change: 0 additions & 1 deletion vm/jit.cpp
Expand Up @@ -4,7 +4,6 @@ namespace factor
{

/* Simple code generator used by:
- counting_profiler (counting_profiler.cpp),
- quotation compiler (quotations.cpp),
- megamorphic caches (dispatch.cpp),
- polymorphic inline caches (inline_cache.cpp) */
Expand Down
26 changes: 16 additions & 10 deletions vm/layouts.hpp
Expand Up @@ -98,7 +98,6 @@ enum code_block_type
{
code_block_unoptimized,
code_block_optimized,
code_block_counting_profiler,
code_block_pic
};

Expand Down Expand Up @@ -253,7 +252,11 @@ struct string : public object {

struct code_block;

/* Assembly code makes assumptions about the layout of this struct */
/* Assembly code makes assumptions about the layout of this struct:
basis/bootstrap/images/images.factor
basis/compiler/constants/constants.factor
core/bootstrap/primitives.factor
*/
struct word : public object {
static const cell type_number = WORD_TYPE;
/* TAGGED hashcode */
Expand All @@ -270,16 +273,14 @@ struct word : public object {
cell pic_def;
/* TAGGED alternative entry point for direct tail calls. Used for inline caching */
cell pic_tail_def;
/* TAGGED call count for counting_profiler */
cell counter;
/* TAGGED machine code for sub-primitive */
cell subprimitive;
/* UNTAGGED entry point: jump here to execute word */
void *entry_point;
/* UNTAGGED compiled code block */
code_block *code;
/* UNTAGGED counting_profiler stub */
code_block *counting_profiler;

/* defined in code_blocks.hpp */
code_block *code() const;
};

/* Assembly code makes assumptions about the layout of this struct */
Expand All @@ -299,7 +300,11 @@ struct boxed_float : object {
double n;
};

/* Assembly code makes assumptions about the layout of this struct */
/* Assembly code makes assumptions about the layout of this struct:
basis/bootstrap/images/images.factor
basis/compiler/constants/constants.factor
core/bootstrap/primitives.factor
*/
struct quotation : public object {
static const cell type_number = QUOTATION_TYPE;
/* tagged */
Expand All @@ -310,8 +315,9 @@ struct quotation : public object {
cell cache_counter;
/* UNTAGGED entry point; jump here to call quotation */
void *entry_point;
/* UNTAGGED compiled code block */
code_block *code;

/* defined in code_blocks.hpp */
code_block *code() const;
};

/* Assembly code makes assumptions about the layout of this struct */
Expand Down
1 change: 0 additions & 1 deletion vm/master.hpp
Expand Up @@ -96,7 +96,6 @@ namespace factor
#include "contexts.hpp"
#include "run.hpp"
#include "objects.hpp"
#include "counting_profiler.hpp"
#include "sampling_profiler.hpp"
#include "errors.hpp"
#include "bignumint.hpp"
Expand Down
1 change: 0 additions & 1 deletion vm/primitives.hpp
Expand Up @@ -46,7 +46,6 @@ namespace factor
_(context_object) \
_(context_object_for) \
_(current_callback) \
_(counting_profiler) \
_(data_room) \
_(datastack) \
_(datastack_for) \
Expand Down

0 comments on commit 5b43301

Please sign in to comment.