[pypy-commit] lang-smalltalk default: Fixed sefault by moving STMProcess>>wait to STMProcess>>primWait and calling "self wait."
amintos
noreply at buildbot.pypy.org
Thu Apr 3 11:32:10 CEST 2014
Author: amintos
Branch:
Changeset: r756:da0b32b19670
Date: 2014-01-16 21:54 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/da0b32b19670/
Log: Fixed sefault by moving STMProcess>>wait to STMProcess>>primWait and
calling "self wait." Reused priority as lock-variable. Reconstructed
STMProcessWrapper inside the new thread instead of passing it via
the bootstrapper.
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
@@ -1,2 +1,2 @@
-
----STARTUP----{15 January 2014 . 2:16:33 pm} as /home/bot/lang-smalltalk/images/Squeak4.5-12568.image!
!Integer methodsFor: 'benchmarks' stamp: 'toma 1/15/2014 14:33' prior: 42646392!
benchStm
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 1 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 2 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 3 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 4 reporting!!']] parallelFork.
(1 to: 1000)
do: [:x | SPyVM print: '* spinlock *'].
^ 42 printString! !
----SNAPSHOT----{15 January 2014 . 2:33:47 pm} Squeak4.5-12568.image priorSource: 9103122!
!Integer methodsFor: 'benchmarks' stamp: 'toma 1/15/2014 14:35' prior: 42656801!
benchStm3
| t1 t2 |
t1 := [(1 to: 100)
do: [:t3 | SPyVM print: 'Thread 1 reporting!!']] parallelFork.
t2 := [(1 to: 100)
do: [:t3 | SPyVM print: 'Thread 2 reporting!!']] parallelFork.
SPyVM print: 'Waiting for Task 1'.
t1 wait.
SPyVM print: 'Waiting for Task 2'.
t2 wait.
SPyVM print: 'Finished waiting.'! !
----SNAPSHOT----{15 January 2014 . 2:36:01 pm} Squeak4.5-12568.image priorSource: 594!
!STMProcess methodsFor: 'as yet unclassified' stamp: 'toma 1/15/2014 14:37' prior: 42653846!
wait
<primitive: 789>
SPyVM print: ' Failed to wait for process!! '! !
----SNAPSHOT----{15 January 2014 . 2:37:09 pm} Squeak4.5-12568.image priorSource: 1091!
\ No newline at end of file
+
----STARTUP----{15 January 2014 . 2:16:33 pm} as /home/bot/lang-smalltalk/images/Squeak4.5-12568.image!
!Integer methodsFor: 'benchmarks' stamp: 'toma 1/15/2014 14:33' prior: 42646392!
benchStm
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 1 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 2 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 3 reporting!!']] parallelFork.
[(1 to: 1000)
do: [:t1 | SPyVM print: 'Thread 4 reporting!!']] parallelFork.
(1 to: 1000)
do: [:x | SPyVM print: '* spinlock *'].
^ 42 printString! !
----SNAPSHOT----{15 January 2014 . 2:33:47 pm} Squeak4.5-12568.image priorSource: 9103122!
!Integer methodsFor: 'benchmarks' stamp: 'toma 1/15/2014 14:35' prior: 42656801!
benchStm3
| t1 t2 |
t1 := [(1 to: 100)
do: [:t3 | SPyVM print: 'Thread 1 reporting!!']] parallelFork.
t2 := [(1 to: 100)
do: [:t3 | SPyVM print: 'Thread 2 reporting!!']] parallelFork.
SPyVM print: 'Waiting for Task 1'.
t1 wait.
SPyVM print: 'Waiting for Task 2'.
t2 wait.
SPyVM print: 'Finished waiting.'! !
----SNAPSHOT----{15 January 2014 . 2:36:01 pm} Squeak4.5-12568.image priorSource: 594!
!STMProcess methodsFor: 'as yet unclassified' stamp: 'toma 1/15/2014 14:37' prior: 42653846!
wait
<primitive: 789>
SPyVM print: ' Failed to wait for process!! '! !
----SNAPSHOT----{15 January 2014 . 2:37:09 pm} Squeak4.5-12568.image priorSource: 1091!
----STARTUP----{16 January 2014 . 9:13:20 pm} as /home/bot/lang-smalltalk/images/Squeak4.5-12568.image!
!BlockClosure methodsFor: 'scheduling' stamp: 'toma 1/16/2014 21:13' prior: 42654183!
parallelFork
^ (self newSTMProcess) fork; yourself! !
----SNAPSHOT----{16 January 2014 . 9:14:01 pm} Squeak4.5-12568.image priorSource: 1345!
!STMProcess methodsFor: 'as yet unclassified' stamp: 'toma 1/16/2014 21:14'!
primWait
<primitive: 789>
SPyVM print: ' Failed to wait for process!! '! !
!STMProcess methodsFor: 'as yet unclassified' stamp: 'toma 1/16/2014 21:15' prior: 33555705!
wait
SPyVM print: '[squeak] wait'
self primWait! !
!STMProcess methodsFor: 'as yet unclassified' stamp: 'toma 1/16/2014 21:15' prior: 33556450!
wait
SPyVM print: '[squeak] wait'.
self primWait! !
----SNAPSHOT----{16 January 2014 . 9:15:29 pm} Squeak4.5-12568.image priorSource: 1681!
\ No newline at end of file
diff --git a/images/Squeak4.5-12568.image b/images/Squeak4.5-12568.image
index 4af3b0fd809db80daefbccdd3d8413855fd13f69..dc45966a305272c20be414ebb0d82b0468d38509
GIT binary patch
[cut]
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -81,7 +81,7 @@
# wait for previous thread to start, then set global state
def acquire(interp, w_frame, w_stm_process):
#bootstrapper.lock.acquire(True)
- bootstrapper.lock.wait(1)
+ bootstrapper.lock.wait(1, 'bootstrap')
bootstrapper.interp = interp
bootstrapper.w_frame = w_frame
bootstrapper.w_stm_process = w_stm_process
@@ -93,7 +93,7 @@
bootstrapper.interp = None
bootstrapper.w_frame = None
bootstrapper.w_stm_process = None
- bootstrapper.lock.signal()
+ bootstrapper.lock.signal('bootstrap')
#bootstrapper.lock.release()
release = staticmethod(release)
@@ -106,16 +106,17 @@
w_stm_process = bootstrapper.w_stm_process
assert isinstance(interp, Interpreter)
assert isinstance(w_frame, model.W_PointersObject)
- assert isinstance(w_stm_process, wrapper.StmProcessWrapper)
+ assert isinstance(w_stm_process, model.W_PointersObject)
bootstrapper.num_threads += 1
bootstrapper.release()
# ...aaaaand go!
- interp.interpret_with_w_frame(w_frame)
+ wrapper.StmProcessWrapper(interp.space, w_stm_process).store_lock(1)
+
+ interp.interpret_with_w_frame(w_frame, may_context_switch=False)
# Signal waiting processes
- print "Signal"
- w_stm_process.signal()
+ wrapper.StmProcessWrapper(interp.space, w_stm_process).signal('thread')
# cleanup
bootstrapper.num_threads -= 1
@@ -187,13 +188,13 @@
rthread.start_new_thread(bootstrapper.bootstrap, ())
print "Parent interpreter resuming"
- def interpret_with_w_frame(self, w_frame):
+ def interpret_with_w_frame(self, w_frame, may_context_switch=True):
print "Interpreter starting"
try:
- self.loop(w_frame)
+ self.loop(w_frame, may_context_switch)
except ProcessSwitch, e:
# W00t: Can I haz explainaiatain?
- self.interpret_with_w_frame(e.s_new_context.w_self())
+ self.interpret_with_w_frame(e.s_new_context.w_self(),may_context_switch)
except ReturnFromTopLevel, e:
return e.object
@@ -204,7 +205,7 @@
return conftest.option.bc_trace
return conftest.option.prim_trace
- def loop(self, w_active_context):
+ def loop(self, w_active_context, may_context_switch=True):
# just a trampoline for the actual loop implemented in c_loop
self._loop = True
s_new_context = w_active_context.as_context_get_shadow(self.space)
@@ -214,7 +215,7 @@
s_sender = s_new_context.s_sender()
try:
- self.stmloop(s_new_context)
+ self.stmloop(s_new_context, may_context_switch)
except StackOverflow, e:
s_new_context = e.s_context
except Return, nlr:
@@ -233,8 +234,8 @@
def stmloop(self, s_context, may_context_switch=True):
while True:
- if rstm.should_break_transaction(False):
- print "will break transaction"
+ # if rstm.should_break_transaction():
+ # print "will break transaction"
# STM-ONLY JITDRIVER!
self.jit_driver.jit_merge_point(
@@ -249,7 +250,7 @@
if not jit.we_are_jitted() and may_context_switch:
self.quick_check_for_interrupt(s_context)
- method = s_context.s_method()
+
while True:
pc = s_context.pc()
if pc < old_pc:
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1403,7 +1403,7 @@
from rpython.rlib import rstm
print "STM_SIGNAL primitive called"
- wrapper.StmProcessWrapper(interp.space, w_rcvr).signal()
+ wrapper.StmProcessWrapper(interp.space, w_rcvr).signal('primitive')
#rstm.should_break_transaction()
@@ -1414,7 +1414,7 @@
print "STM_WAIT primitive called"
# wait(0) behaves like a barrier, it waits for but does not acquire the lock
- wrapper.StmProcessWrapper(interp.space, w_rcvr).wait(0)
+ wrapper.StmProcessWrapper(interp.space, w_rcvr).wait(0, 'primitive')
print "STM Rendezvous"
print "Should break: %s" % rstm.should_break_transaction()
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -120,29 +120,40 @@
class PartialBarrier(object):
_mixin_ = True
- def signal(self):
+ def signal(self, what='unknown'):
+ print "[lock] signal %s" % what
self.store_lock(0)
#rstm.should_break_transaction()
- def _test_and_set(self, i):
+ def _test_and_set(self, i, what=''):
rstm.increment_atomic()
old_value = self.lock()
self.store_lock(i)
rstm.decrement_atomic()
+ print "[lock] read %s, set %s, %s" % (old_value, i, what)
return old_value
# i = 0 just waits but does not acquire (Barrier)
# i = 1 waits and acquires (Mutex)
- def wait(self, i):
+ def wait(self, i, what=''):
import time
- while self._test_and_set(i):
+ print '[lock] %s waits' % what
+
+ # first, we have to wait for the lock
+ while self._test_and_set(1, what):
time.sleep(0.005)
#rstm.should_break_transaction()
+ # then we can modify the lock (i.e. setting it back to 0)
+ self.store_lock(i)
+
+ print '[lock] %s continues' % what
+
class StmProcessWrapper(ProcessWrapper, PartialBarrier):
- lock, store_lock = make_int_getter_setter(8)
+ # Mis-using priority as lock, we don't need prios :P
+ lock, store_lock = make_int_getter_setter(2)
def put_to_sleep(self):
# Must not queue
@@ -172,7 +183,7 @@
print "Breaking interpreter loop for forking"
# we need to pass control to the interpreter loop here
self.store_lock(1)
- raise StmProcessFork(w_frame, self)
+ raise StmProcessFork(w_frame, self._w_self)
class LinkedListWrapper(Wrapper):
More information about the pypy-commit
mailing list