]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: pre-allocate context alien
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 2 Apr 2010 02:12:45 +0000 (22:12 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 2 Apr 2010 04:02:21 +0000 (00:02 -0400)
basis/cpu/x86/32/32.factor
basis/cpu/x86/32/bootstrap.factor
basis/cpu/x86/64/64.factor
basis/cpu/x86/64/bootstrap.factor
basis/stack-checker/known-words/known-words.factor
basis/threads/threads.factor
core/bootstrap/primitives.factor
vm/contexts.cpp
vm/contexts.hpp
vm/primitives.hpp
vm/vm.hpp

index 8b97eb9351a501ab135bd243448bcf61d1c8de2d..97f0cfb66845e4b7e08a3bd75c4cba789956ac27 100755 (executable)
@@ -244,6 +244,7 @@ M: x86.32 %alien-indirect ( -- )
 
 M: x86.32 %begin-callback ( -- )
     0 save-vm-ptr
+    ESP 4 [+] 0 MOV
     "begin_callback" f %alien-invoke ;
 
 M: x86.32 %alien-callback ( quot -- )
index a428a66ace0775c072a5a3666bcdedba0de003be..293d99fe93d48b22fb3a7150529404f4861f2b7a 100644 (file)
@@ -82,11 +82,9 @@ IN: bootstrap.x86
 [
     jit-load-vm
     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
+    ESP 4 [+] EAX MOV
+    "begin_callback" jit-call
 
     jit-load-vm
     jit-load-context
index bea5d4da1fc06a37322ccd5cd27cb47d47c4ef4c..7e1c5c1f48fe6cd8ceb00624c640a7ce7702ce92 100644 (file)
@@ -231,6 +231,7 @@ M: x86.64 %alien-indirect ( -- )
 
 M: x86.64 %begin-callback ( -- )
     param-reg-0 %mov-vm-ptr
+    param-reg-1 0 MOV
     "begin_callback" f %alien-invoke ;
 
 M: x86.64 %alien-callback ( quot -- )
index 4cd2d8104b904b55a5eb648c5daa3371e300f47d..6c0d50f1b7e58733590ab9e898ad83a412b5f458 100644 (file)
@@ -76,8 +76,7 @@ IN: bootstrap.x86
 : jit-call-quot ( -- ) arg1 quot-entry-point-offset [+] CALL ;
 
 [
-    nv-reg arg1 MOV
-
+    arg2 arg1 MOV
     arg1 vm-reg MOV
     "begin_callback" jit-call
 
@@ -85,7 +84,7 @@ IN: bootstrap.x86
     jit-restore-context
 
     ! call the quotation
-    arg1 nv-reg MOV
+    arg1 return-reg MOV
     jit-call-quot
 
     jit-save-context
index 01f3ff77c07423e22df961341e80e328e118e6cc..15895184df8c25d7698831cf452f16c386b01df1 100644 (file)
@@ -355,7 +355,6 @@ M: bad-executable summary
 \ code-room { } { byte-array } define-primitive \ code-room  make-flushable
 \ compact-gc { } { } 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-for { fixnum c-ptr } { object } define-primitive \ context-object-for make-flushable
 \ current-callback { } { fixnum } define-primitive \ current-callback make-flushable
index 404c8112fb401711370b39b6f9bc7303572d5831..330b4abd6cae99b88a9b61d9302f061f3d8e8739 100644 (file)
@@ -11,17 +11,20 @@ IN: threads
 
 ! Wrap sub-primitives; we don't want them inlined into callers
 ! since their behavior depends on what frames are on the callstack
+: context ( -- context )
+    2 context-object ; inline
+
 : set-context ( obj context -- obj' )
-    (set-context) ;
+    (set-context) ; inline
 
 : start-context ( obj quot: ( obj -- * ) -- obj' )
-    (start-context) ;
+    (start-context) ; inline
 
 : 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) ;
+    (start-context-and-delete) ; inline
 
 ! Context introspection
 : namestack-for ( context -- namestack )
index 52ee1e14b4b98811e9a8c34170291e8073067cda..8a412b8a1482c8115b58165b208717faef934885 100644 (file)
@@ -538,7 +538,6 @@ tuple
     { "system-micros" "system" "primitive_system_micros" (( -- us )) }
     { "(sleep)" "threads.private" "primitive_sleep" (( nanos -- )) }
     { "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 )) }
     { "datastack-for" "threads.private" "primitive_datastack_for" (( context -- array )) }
     { "retainstack-for" "threads.private" "primitive_retainstack_for" (( context -- array )) }
index 9364f2e3623afbacb22a1f81b6198b93b7b97f1d..25fe0e5280cc43a82617111119e981303ec6424b 100644 (file)
@@ -108,9 +108,16 @@ context *factor_vm::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)
 {
-       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)
@@ -124,16 +131,22 @@ VM_C_API void delete_context(factor_vm *parent, 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();
        spare_ctx = new_context();
        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()
@@ -296,9 +309,4 @@ void factor_vm::primitive_load_locals()
        ctx->retainstack += sizeof(cell) * count;
 }
 
-void factor_vm::primitive_context()
-{
-       ctx->push(allot_alien(ctx));
-}
-
 }
index f3aba0e5a606b9784fc322bdee94d7b878ce4bfd..85338ca91d657624711078aa9e5d6d90d28a4807 100644 (file)
@@ -6,6 +6,7 @@ static const cell context_object_count = 10;
 enum context_object {
        OBJ_NAMESTACK,
        OBJ_CATCHSTACK,
+       OBJ_CONTEXT,
 };
 
 static const cell stack_reserved = 1024;
@@ -71,7 +72,7 @@ struct context {
 
 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 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);
 
 }
index 7e95a3bad587cc4c0e9204ab681cdc37b7b68942..ff0947912cad70cd3c35a3f1cb35e224bc753afb 100644 (file)
@@ -43,7 +43,6 @@ namespace factor
        _(code_room) \
        _(compact_gc) \
        _(compute_identity_hashcode) \
-       _(context) \
        _(context_object) \
        _(context_object_for) \
        _(current_callback) \
index ad74a8e09073d642aca8dd2747cbaa7babce89fd..cf2f0ca433bb5787b6580cc49d3d9e59a14a2128 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -112,10 +112,11 @@ struct factor_vm
 
        // contexts
        context *new_context();
+       void init_context(context *ctx);
        void delete_context(context *old_context);
        void init_contexts(cell datastack_size_, cell retainstack_size_, cell callstack_size_);
        void delete_contexts();
-       void begin_callback();
+       cell begin_callback(cell quot);
        void end_callback();
        void primitive_current_callback();
        void primitive_context_object();
@@ -135,7 +136,6 @@ struct factor_vm
        void primitive_set_retainstack();
        void primitive_check_datastack();
        void primitive_load_locals();
-       void primitive_context();
 
        template<typename Iterator> void iterate_active_callstacks(Iterator &iter)
        {