vm: pre-allocate context alien

release
Slava Pestov 2010-04-01 22:12:45 -04:00
parent 0c0935dfc1
commit 0faa3bcf4a
11 changed files with 34 additions and 26 deletions

View File

@ -244,6 +244,7 @@ M: x86.32 %alien-indirect ( -- )
M: x86.32 %begin-callback ( -- ) M: x86.32 %begin-callback ( -- )
0 save-vm-ptr 0 save-vm-ptr
ESP 4 [+] 0 MOV
"begin_callback" f %alien-invoke ; "begin_callback" f %alien-invoke ;
M: x86.32 %alien-callback ( quot -- ) M: x86.32 %alien-callback ( quot -- )

View File

@ -82,11 +82,9 @@ IN: bootstrap.x86
[ [
jit-load-vm jit-load-vm
ESP [] vm-reg MOV ESP [] vm-reg MOV
"begin_callback" jit-call
! load quotation - EBP is ctx-reg so it will get clobbered
! later on
EAX EBP 8 [+] MOV EAX EBP 8 [+] MOV
ESP 4 [+] EAX MOV
"begin_callback" jit-call
jit-load-vm jit-load-vm
jit-load-context jit-load-context

View File

@ -231,6 +231,7 @@ M: x86.64 %alien-indirect ( -- )
M: x86.64 %begin-callback ( -- ) M: x86.64 %begin-callback ( -- )
param-reg-0 %mov-vm-ptr param-reg-0 %mov-vm-ptr
param-reg-1 0 MOV
"begin_callback" f %alien-invoke ; "begin_callback" f %alien-invoke ;
M: x86.64 %alien-callback ( quot -- ) M: x86.64 %alien-callback ( quot -- )

View File

@ -76,8 +76,7 @@ IN: bootstrap.x86
: jit-call-quot ( -- ) arg1 quot-entry-point-offset [+] CALL ; : jit-call-quot ( -- ) arg1 quot-entry-point-offset [+] CALL ;
[ [
nv-reg arg1 MOV arg2 arg1 MOV
arg1 vm-reg MOV arg1 vm-reg MOV
"begin_callback" jit-call "begin_callback" jit-call
@ -85,7 +84,7 @@ IN: bootstrap.x86
jit-restore-context jit-restore-context
! call the quotation ! call the quotation
arg1 nv-reg MOV arg1 return-reg MOV
jit-call-quot jit-call-quot
jit-save-context jit-save-context

View File

@ -355,7 +355,6 @@ M: bad-executable summary
\ code-room { } { byte-array } define-primitive \ code-room make-flushable \ code-room { } { byte-array } define-primitive \ code-room make-flushable
\ compact-gc { } { } define-primitive \ compact-gc { } { } define-primitive
\ compute-identity-hashcode { object } { } define-primitive \ compute-identity-hashcode { object } { } define-primitive
\ context { } { c-ptr } define-primitive \ context make-flushable
\ context-object { fixnum } { object } define-primitive \ context-object make-flushable \ context-object { fixnum } { object } define-primitive \ context-object make-flushable
\ context-object-for { fixnum c-ptr } { object } define-primitive \ context-object-for make-flushable \ context-object-for { fixnum c-ptr } { object } define-primitive \ context-object-for make-flushable
\ current-callback { } { fixnum } define-primitive \ current-callback make-flushable \ current-callback { } { fixnum } define-primitive \ current-callback make-flushable

View File

@ -11,17 +11,20 @@ IN: threads
! Wrap sub-primitives; we don't want them inlined into callers ! Wrap sub-primitives; we don't want them inlined into callers
! since their behavior depends on what frames are on the callstack ! since their behavior depends on what frames are on the callstack
: context ( -- context )
2 context-object ; inline
: set-context ( obj context -- obj' ) : set-context ( obj context -- obj' )
(set-context) ; (set-context) ; inline
: start-context ( obj quot: ( obj -- * ) -- obj' ) : start-context ( obj quot: ( obj -- * ) -- obj' )
(start-context) ; (start-context) ; inline
: set-context-and-delete ( obj context -- * ) : set-context-and-delete ( obj context -- * )
(set-context-and-delete) ; (set-context-and-delete) ; inline
: start-context-and-delete ( obj quot: ( obj -- * ) -- * ) : start-context-and-delete ( obj quot: ( obj -- * ) -- * )
(start-context-and-delete) ; (start-context-and-delete) ; inline
! Context introspection ! Context introspection
: namestack-for ( context -- namestack ) : namestack-for ( context -- namestack )

View File

@ -538,7 +538,6 @@ tuple
{ "system-micros" "system" "primitive_system_micros" (( -- us )) } { "system-micros" "system" "primitive_system_micros" (( -- us )) }
{ "(sleep)" "threads.private" "primitive_sleep" (( nanos -- )) } { "(sleep)" "threads.private" "primitive_sleep" (( nanos -- )) }
{ "callstack-for" "threads.private" "primitive_callstack_for" (( context -- array )) } { "callstack-for" "threads.private" "primitive_callstack_for" (( context -- array )) }
{ "context" "threads.private" "primitive_context" (( -- context )) }
{ "context-object-for" "threads.private" "primitive_context_object_for" (( n context -- obj )) } { "context-object-for" "threads.private" "primitive_context_object_for" (( n context -- obj )) }
{ "datastack-for" "threads.private" "primitive_datastack_for" (( context -- array )) } { "datastack-for" "threads.private" "primitive_datastack_for" (( context -- array )) }
{ "retainstack-for" "threads.private" "primitive_retainstack_for" (( context -- array )) } { "retainstack-for" "threads.private" "primitive_retainstack_for" (( context -- array )) }

View File

@ -108,9 +108,16 @@ context *factor_vm::new_context()
return new_context; return new_context;
} }
void factor_vm::init_context(context *ctx)
{
ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
}
context *new_context(factor_vm *parent) context *new_context(factor_vm *parent)
{ {
return parent->new_context(); context *new_context = parent->new_context();
parent->init_context(new_context);
return new_context;
} }
void factor_vm::delete_context(context *old_context) void factor_vm::delete_context(context *old_context)
@ -124,16 +131,22 @@ VM_C_API void delete_context(factor_vm *parent, context *old_context)
parent->delete_context(old_context); parent->delete_context(old_context);
} }
void factor_vm::begin_callback() cell factor_vm::begin_callback(cell quot_)
{ {
data_root<object> quot(quot_,this);
ctx->reset(); ctx->reset();
spare_ctx = new_context(); spare_ctx = new_context();
callback_ids.push_back(callback_id++); callback_ids.push_back(callback_id++);
init_context(ctx);
return quot.value();
} }
void begin_callback(factor_vm *parent) cell begin_callback(factor_vm *parent, cell quot)
{ {
parent->begin_callback(); return parent->begin_callback(quot);
} }
void factor_vm::end_callback() void factor_vm::end_callback()
@ -296,9 +309,4 @@ void factor_vm::primitive_load_locals()
ctx->retainstack += sizeof(cell) * count; ctx->retainstack += sizeof(cell) * count;
} }
void factor_vm::primitive_context()
{
ctx->push(allot_alien(ctx));
}
} }

View File

@ -6,6 +6,7 @@ static const cell context_object_count = 10;
enum context_object { enum context_object {
OBJ_NAMESTACK, OBJ_NAMESTACK,
OBJ_CATCHSTACK, OBJ_CATCHSTACK,
OBJ_CONTEXT,
}; };
static const cell stack_reserved = 1024; static const cell stack_reserved = 1024;
@ -71,7 +72,7 @@ struct context {
VM_C_API context *new_context(factor_vm *parent); VM_C_API context *new_context(factor_vm *parent);
VM_C_API void delete_context(factor_vm *parent, context *old_context); VM_C_API void delete_context(factor_vm *parent, context *old_context);
VM_C_API void begin_callback(factor_vm *parent); VM_C_API cell begin_callback(factor_vm *parent, cell quot);
VM_C_API void end_callback(factor_vm *parent); VM_C_API void end_callback(factor_vm *parent);
} }

View File

@ -43,7 +43,6 @@ namespace factor
_(code_room) \ _(code_room) \
_(compact_gc) \ _(compact_gc) \
_(compute_identity_hashcode) \ _(compute_identity_hashcode) \
_(context) \
_(context_object) \ _(context_object) \
_(context_object_for) \ _(context_object_for) \
_(current_callback) \ _(current_callback) \

View File

@ -112,10 +112,11 @@ struct factor_vm
// contexts // contexts
context *new_context(); context *new_context();
void init_context(context *ctx);
void delete_context(context *old_context); void delete_context(context *old_context);
void init_contexts(cell datastack_size_, cell retainstack_size_, cell callstack_size_); void init_contexts(cell datastack_size_, cell retainstack_size_, cell callstack_size_);
void delete_contexts(); void delete_contexts();
void begin_callback(); cell begin_callback(cell quot);
void end_callback(); void end_callback();
void primitive_current_callback(); void primitive_current_callback();
void primitive_context_object(); void primitive_context_object();
@ -135,7 +136,6 @@ struct factor_vm
void primitive_set_retainstack(); void primitive_set_retainstack();
void primitive_check_datastack(); void primitive_check_datastack();
void primitive_load_locals(); void primitive_load_locals();
void primitive_context();
template<typename Iterator> void iterate_active_callstacks(Iterator &iter) template<typename Iterator> void iterate_active_callstacks(Iterator &iter)
{ {