[pypy-commit] lang-smalltalk storage-vrefs-rstackovf-localreturn: use StackOverflow protection from rlib
timfel
noreply at buildbot.pypy.org
Thu Jul 10 15:29:25 CEST 2014
Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: storage-vrefs-rstackovf-localreturn
Changeset: r885:6704ab7a2008
Date: 2014-07-10 12:00 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6704ab7a2008/
Log: use StackOverflow protection from rlib
diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -190,6 +190,5 @@
# Interpreter constants
#
-MAX_LOOP_DEPTH = 100
INTERRUPT_COUNTER_SIZE = 10000
CompileTime = time.time()
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -4,7 +4,7 @@
from spyvm import model, constants, primitives, conftest, wrapper
from spyvm.tool.bitmanipulation import splitter
-from rpython.rlib import jit
+from rpython.rlib import jit, rstackovf
from rpython.rlib import objectmodel, unroll
class MissingBytecode(Exception):
@@ -24,7 +24,7 @@
class Interpreter(object):
_immutable_fields_ = ["space", "image", "image_name",
- "max_stack_depth", "interrupt_counter_size",
+ "interrupt_counter_size",
"startup_time", "evented", "interrupts"]
jit_driver = jit.JitDriver(
@@ -35,8 +35,7 @@
)
def __init__(self, space, image=None, image_name="",
- trace=False, evented=True, interrupts=True,
- max_stack_depth=constants.MAX_LOOP_DEPTH):
+ trace=False, evented=True, interrupts=True):
import time
# === Initialize immutable variables
@@ -47,7 +46,6 @@
self.startup_time = image.startup_time
else:
self.startup_time = constants.CompileTime
- self.max_stack_depth = max_stack_depth
self.evented = evented
self.interrupts = interrupts
try:
@@ -57,7 +55,6 @@
# === Initialize mutable variables
self.interrupt_check_counter = self.interrupt_counter_size
- self.current_stack_depth = 0
self.next_wakeup_tick = 0
self.trace = trace
self.trace_proxy = False
@@ -66,7 +63,6 @@
# This is the top-level loop and is not invoked recursively.
s_new_context = w_active_context.as_context_get_shadow(self.space)
while True:
- assert self.current_stack_depth == 0
# Need to save s_sender, loop_bytecodes will nil this on return
# Virtual references are not allowed here, and neither are "fresh" contexts (except for the toplevel one).
assert s_new_context.virtual_sender is jit.vref_None
@@ -128,16 +124,12 @@
# The same frame object must not pass through here recursively!
if s_frame.is_fresh() and s_sender is not None:
s_frame.virtual_sender = jit.virtual_ref(s_sender)
-
- self.current_stack_depth += 1
- if self.max_stack_depth > 0:
- if self.current_stack_depth >= self.max_stack_depth:
- raise StackOverflow(s_frame)
-
# Now (continue to) execute the context bytecodes
self.loop_bytecodes(s_frame, may_context_switch)
+ except rstackovf.StackOverflow:
+ rstackovf.check_stack_overflow()
+ raise StackOverflow(s_frame)
finally:
- self.current_stack_depth -= 1
# Cleanly leave the context. This will finish the virtual sender-reference, if
# it is still there, which can happen in case of ProcessSwitch or StackOverflow;
# in case of a Return, this will already be handled while unwinding the stack.
@@ -237,7 +229,7 @@
return s_frame
def padding(self, symbol=' '):
- return symbol * self.current_stack_depth
+ return symbol
class ReturnFromTopLevel(Exception):
_attrs_ = ["object"]
@@ -976,11 +968,9 @@
# in order to enable tracing/jumping for message sends etc.
def debugging():
def stepping_debugger_init(original):
- def meth(self, space, image=None, image_name="", trace=False,
- max_stack_depth=constants.MAX_LOOP_DEPTH):
+ def meth(self, space, image=None, image_name="", trace=False):
return_value = original(self, space, image=image,
- image_name=image_name, trace=trace,
- max_stack_depth=max_stack_depth)
+ image_name=image_name, trace=trace)
# ##############################################################
self.message_stepping = False
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -87,7 +87,7 @@
except error.Exit, e:
print e.msg
return 1
-
+
if not as_benchmark:
try:
w_result = interp.perform(w_receiver, selector)
@@ -121,12 +121,11 @@
-b|--benchmark [code string]
-p|--poll_events
-ni|--no-interrupts
- -d|--max-stack-depth [number, default %d, <= 0 disables stack protection]
-l|--storage-log
-L|--storage-log-aggregate
-E|--storage-log-elements
[image path, default: Squeak.image]
- """ % (argv[0], constants.MAX_LOOP_DEPTH)
+ """ % argv[0]
def _arg_missing(argv, idx, arg):
if len(argv) == idx + 1:
@@ -144,9 +143,8 @@
stringarg = ""
code = None
as_benchmark = False
- max_stack_depth = constants.MAX_LOOP_DEPTH
interrupts = True
-
+
while idx < len(argv):
arg = argv[idx]
if arg in ["-h", "--help"]:
@@ -185,10 +183,6 @@
idx += 1
elif arg in ["-ni", "--no-interrupts"]:
interrupts = False
- elif arg in ["-d", "--max-stack-depth"]:
- _arg_missing(argv, idx, arg)
- max_stack_depth = int(argv[idx + 1])
- idx += 1
elif arg in ["-l", "--storage-log"]:
storage_logger.activate()
elif arg in ["-L", "--storage-log-aggregate"]:
@@ -215,13 +209,13 @@
except OSError as e:
os.write(2, "%s -- %s (LoadError)\n" % (os.strerror(e.errno), path))
return 1
-
+
space = prebuilt_space
image_reader = squeakimage.reader_for_image(space, squeakimage.Stream(data=imagedata))
image = create_image(space, image_reader)
interp = interpreter.Interpreter(space, image, image_name=path,
trace=trace, evented=evented,
- interrupts=interrupts, max_stack_depth=max_stack_depth)
+ interrupts=interrupts)
space.runtime_setup(argv[0])
result = 0
if benchmark is not None:
More information about the pypy-commit
mailing list