Author: Patrick Rein <[email protected]>
Branch: stmgc-c7
Changeset: r835:3dab35cc8af7
Date: 2014-05-22 12:40 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/3dab35cc8af7/

Log:    Added and implemented the wait primitive. Therefore we added a
        StmProcessShadow

diff --git a/images/Squeak4.5-12568.changes b/images/Squeak4.5-12568.changes
--- a/images/Squeak4.5-12568.changes
+++ b/images/Squeak4.5-12568.changes
@@ -440,4 +440,4 @@
                at: 14 at: 13 put: 1;
                at: 12 at: 14 put: 1.
                
        ((numberOfRows > 16) and: (numberOfColumns > 16)) ifTrue: [
                newField
                        at: 20 at: 3 put: 1;
                        at: 20 at: 4 put: 1;
                        at: 21 at: 2 put: 1;
                        at: 21 at: 5 put: 1;
                        at: 22 at: 3 put: 1;
                        at: 22 at: 4 put: 1;
                        
                        at: 20 at: 20 put: 1;
                        at: 20 at: 21 put: 1;
                        at: 20 at: 22 put: 1.           
        ].
                
-       ^ newField! !

----SNAPSHOT----{21 January 2014 . 2:05:40 pm} Squeak4.5-12568.image 
priorSource: 84405!

----STARTUP----{17 May 2014 . 11:47:50 pm} as 
/home/hub/hpi/stm/src/lang-smalltalk/images/Squeak4.5-12568.image!


FileStream stdout nextPutAll: 'release.st'; cr; flush.!

----SNAPSHOT----{17 May 2014 . 11:48:30 pm} Squeak4.5-12568.image priorSource: 
86737!
!Integer methodsFor: '*SPy-Benchmarks' stamp: 'hh 5/17/2014 23:49'!
stmBenchmarkTest
        FileStream stdout nextPutAll: 'starting stm process.'.
        "^ StmProcess new fork"! !

----QUIT----{17 May 2014 . 11:49:16 pm} Squeak4.5-12568.image priorSource: 
86999!

----STARTUP----{17 May 2014 . 11:50:46 pm} as 
/home/hub/hpi/stm/src/lang-smalltalk/images/Squeak4.5-12568.image!


Process subclass: #StmProcess
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Kernel-Processes'!
!Integer methodsFor: '*SPy-Benchmarks' stamp: 'hh 5/17/2014 23:53' prior: 
33641587!
stmBenchmarkTest
        FileStream stdout nextPutAll: 'starting stm process.'.
        ^ StmProcess new fork.! !
!StmProcess methodsFor: 'nil' stamp: 'hh 5/17/2014 23:54'!
fork    <primitive: 787>        FileStream stdout nextPutAll: 'Primitive 
stmFork failed'.       self primitiveFailed! !
!StmProcess methodsFor: 'as yet unclassified' stamp: 'hh 5/17/2014 23:55' 
prior: 33642264!
fork    
        <primitive: 787>        
        self primitiveFailed! !

----SNAPSHOT----{17 May 2014 . 11:55:14 pm} Squeak4.5-12568.image priorSource: 
87255!

----QUIT----{17 May 2014 . 11:55:30 pm} Squeak4.5-12568.image priorSource: 
88078!
\ No newline at end of file
+       ^ newField! !

----SNAPSHOT----{21 January 2014 . 2:05:40 pm} Squeak4.5-12568.image 
priorSource: 84405!

----STARTUP----{17 May 2014 . 11:47:50 pm} as 
/home/hub/hpi/stm/src/lang-smalltalk/images/Squeak4.5-12568.image!


FileStream stdout nextPutAll: 'release.st'; cr; flush.!

----SNAPSHOT----{17 May 2014 . 11:48:30 pm} Squeak4.5-12568.image priorSource: 
86737!
!Integer methodsFor: '*SPy-Benchmarks' stamp: 'hh 5/17/2014 23:49'!
stmBenchmarkTest
        FileStream stdout nextPutAll: 'starting stm process.'.
        "^ StmProcess new fork"! !

----QUIT----{17 May 2014 . 11:49:16 pm} Squeak4.5-12568.image priorSource: 
86999!

----STARTUP----{17 May 2014 . 11:50:46 pm} as 
/home/hub/hpi/stm/src/lang-smalltalk/images/Squeak4.5-12568.image!


Process subclass: #StmProcess
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Kernel-Processes'!
!Integer methodsFor: '*SPy-Benchmarks' stamp: 'hh 5/17/2014 23:53' prior: 
33641587!
stmBenchmarkTest
        FileStream stdout nextPutAll: 'starting stm process.'.
        ^ StmProcess new fork.! !
!StmProcess methodsFor: 'nil' stamp: 'hh 5/17/2014 23:54'!
fork    <primitive: 787>        FileStream stdout nextPutAll: 'Primitive 
stmFork failed'.       self primitiveFailed! !
!StmProcess methodsFor: 'as yet unclassified' stamp: 'hh 5/17/2014 23:55' 
prior: 33642264!
fork    
        <primitive: 787>        
        self primitiveFailed! !

----SNAPSHOT----{17 May 2014 . 11:55:14 pm} Squeak4.5-12568.image priorSource: 
87255!

----QUIT----{17 May 2014 . 11:55:30 pm} Squeak4.5-12568.image priorSource: 
88078!

----STARTUP----{22 May 2014 . 11:48:49 am} as 
D:\code\python\spy-vm\lang-smalltalk\images\Squeak4.5-12568.image!

!StmProcess methodsFor: 'as yet unclassified' stamp: 'pre 5/22/2014 11:49'!
wait    
        <primitive: 789>        
        self primitiveFailed! !
!Integer methodsFor: '*SPy-Benchmarks' stamp: 'pre 5/22/2014 11:50' prior: 
33642105!
stmBenchmarkTest
        | p |
        FileStream stdout nextPutAll: 'starting stm process.'.
        p := StmProcess new fork.
        p join! !
!StmProcess methodsFor: 'as yet unclassified' stamp: 'pre 5/22/2014 11:50'!
join    
        <primitive: 789>        
        self primitiveFailed! !

StmProcess removeSelector: #wait!

----QUIT----{22 May 2014 . 11:50:32 am} Squeak4.5-12568.image priorSource: 
88165!
\ No newline at end of file
diff --git a/images/Squeak4.5-12568.image b/images/Squeak4.5-12568.image
index 
f61fe405b1655959263ba4b81b0437800f94fb85..afbdfb32577e6a5f8388a264d6ff6ee8e350c64b
GIT binary patch

[cut]

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -2,7 +2,7 @@
 import os
 import time
 
-from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
+from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound, StmProcessShadow
 from spyvm import model, constants, primitives, conftest, wrapper
 from spyvm.tool.bitmanipulation import splitter
 
@@ -105,10 +105,12 @@
         print "New thread reporting"
         interp = bootstrapper.interp
         w_frame = bootstrapper.w_frame
+
         w_stm_process = bootstrapper.w_stm_process
+
         assert isinstance(interp, Interpreter)
-        #assert isinstance(w_frame, model.W_PointersObject)
-        #assert isinstance(w_stm_process, model.W_PointersObject)
+        assert isinstance(w_frame, model.W_PointersObject)
+        assert isinstance(w_stm_process, model.W_PointersObject)
         bootstrapper.num_threads += 1
         print "Me is started", bootstrapper.num_threads
         bootstrapper.release()
@@ -119,6 +121,9 @@
         # interp.interpret_with_w_frame(w_frame, may_context_switch=False)
         time.sleep(2.5)
 
+        s_stm_process = w_stm_process.as_special_get_shadow(interp.space, 
StmProcessShadow)
+        s_stm_process.lock.release()
+
         # Signal waiting processes
         #wrapper.StmProcessWrapper(interp.space, 
w_stm_process).signal('thread')
 
@@ -182,7 +187,7 @@
         new_interp.interrupt_check_counter = self.interrupt_check_counter
         new_interp.trace_proxy = self.trace_proxy
 
-        bootstrapper.acquire(new_interp, None, None)
+        bootstrapper.acquire(new_interp, w_frame, w_stm_process)
         rthread.start_new_thread(bootstrapper.bootstrap, ())
 
     def interpret_with_w_frame(self, w_frame):
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1470,8 +1470,24 @@
 
     print "STM_FORK primitive called"
 
-    wrapper.StmProcessWrapper(interp.space, w_rcvr).fork(s_frame.w_self())
-    rstm.should_break_transaction()
+    if not isinstance(w_rcvr, model.W_PointersObject):
+            raise PrimitiveFailedError("Fork primitive was not called on an 
StmProcess")
+    process_shadow = w_rcvr.as_special_get_shadow(interp.space, 
shadow.StmProcessShadow)
+    process_shadow.fork(s_frame.w_self())
+
+@expose_primitive(STM_WAIT, unwrap_spec=[object], no_result=True)
+def func(interp, s_frame, w_rcvr):
+    from rpython.rlib import rstm
+
+    print "STM_WAIT primitive called"
+
+    if not isinstance(w_rcvr, model.W_PointersObject):
+            raise PrimitiveFailedError("Join primitive was not called on an 
StmProcess")
+    process_shadow = w_rcvr.as_special_get_shadow(interp.space, 
shadow.StmProcessShadow)
+    process_shadow.join(True)
+
+    print "STM Rendezvous"
+    print "Should break: %s" % rstm.should_break_transaction()
 
 # ___________________________________________________________________________
 # BlockClosure Primitives
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -2,7 +2,7 @@
 from spyvm import model, constants, error, wrapper, version
 from spyvm.version import elidable_for_version, constant_for_version
 from rpython.tool.pairtype import extendabletype
-from rpython.rlib import rarithmetic, jit
+from rpython.rlib import rarithmetic, jit, rthread
 from rpython.rlib.objectmodel import import_from_mixin
 from rpython.rlib.debug import make_sure_not_resized
 
@@ -1122,3 +1122,21 @@
         self.dependent = dependent
 
     def update(self): pass
+
+
+class StmProcessShadow(AbstractShadow):
+
+    def __init__(self, space, w_self):
+        AbstractShadow.__init__(self, space, w_self)
+        self.lock = rthread.allocate_lock()
+
+    def fork(self, w_current_frame):
+        from spyvm.interpreter import STMForkException
+        self.lock.acquire(True)
+        wrapper.StmProcessWrapper(self.space, 
self.w_self()).fork(w_current_frame)
+
+    def join(self, blocking):
+        lock_result = self.lock.acquire(blocking)
+        if lock_result:
+            self.lock.release()
+        return lock_result
\ No newline at end of file
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -145,8 +145,6 @@
 
         assert isinstance(w_frame, model.W_PointersObject)
         print "Breaking interpreter loop for forking"
-        # we need to pass control to the interpreter loop here
-        # self.store_lock(1) Needed for join call
         raise STMForkException(w_frame, self._w_self)
 
 class LinkedListWrapper(Wrapper):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to