Author: Lars Wassermann <lars.wasserm...@gmail.com> Branch: Changeset: r152:ec80277220dc Date: 2013-03-08 15:35 +0100 http://bitbucket.org/pypy/lang-smalltalk/changeset/ec80277220dc/
Log: created a caching shadow specialy for arrays which seldom change, like the special messages array diff --git a/spyvm/constants.py b/spyvm/constants.py --- a/spyvm/constants.py +++ b/spyvm/constants.py @@ -1,3 +1,4 @@ +from rpython.rlib.jit import elidable # ___________________________________________________________________________ # Slot Names @@ -149,7 +150,7 @@ 'at:put:', 'size', 'next', 'nextPut:', 'atEnd', '==', 'class', 'blockCopy:', 'value', 'value:', 'do:', 'new', 'new:', 'x', 'y'] - +@elidable def find_selectorindex(selector): return SPECIAL_SELECTORS.index(selector) * 2 find_selectorindex._annspecialcase_ = "specialize:memo" diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -365,6 +365,10 @@ from spyvm.shadow import MethodDictionaryShadow return self.as_special_get_shadow(space, MethodDictionaryShadow) + def as_cached_array_get_shadow(self, space): + from spyvm.shadow import CachedArrayShadow + return self.as_special_get_shadow(space, CachedArrayShadow) + def become(self, w_other): if not isinstance(w_other, W_PointersObject): return False diff --git a/spyvm/objspace.py b/spyvm/objspace.py --- a/spyvm/objspace.py +++ b/spyvm/objspace.py @@ -149,6 +149,7 @@ self.w_two = model.W_SmallInteger(2) w_special_selectors = model.W_PointersObject( self.classtable['w_Array'], len(constants.SPECIAL_SELECTORS) * 2) + w_special_selectors.as_cached_array_get_shadow(self) self.w_special_selectors = w_special_selectors self.objtable = {} diff --git a/spyvm/shadow.py b/spyvm/shadow.py --- a/spyvm/shadow.py +++ b/spyvm/shadow.py @@ -892,3 +892,28 @@ s_new = MethodContextShadow.make_context( space, self, receiver, arguments, sender) return s_new + +class CachedArrayShadow(AbstractCachingShadow): + _attr_ = ['version'] + + def __init__(self, space, w_self): + AbstractCachingShadow.__init__(self, space, w_self) + self.version = 0 + + def fetch(self, n0): + jit.promote(self) + version = self.version + jit.promote(version) + return self.safe_fetch(n0, version) + + @jit.elidable + def safe_fetch(self, n0, version): + assert version is self.version + return self._w_self._fetch(n0) + + def store(self, n0, w_value): + self.version = self.version + 1 + return self._w_self._store(n0, w_value) + + def update_shadow(self): + self.version = self.version + 1 \ No newline at end of file diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py --- a/spyvm/test/jit.py +++ b/spyvm/test/jit.py @@ -58,7 +58,7 @@ image = create_testimage(space) interp = interpreter.Interpreter(space, image) - w_selector = interp.perform(space.wrap_string('loopTest'), "asSymbol") + w_selector = interp.perform(space.wrap_string('loopTest3'), "asSymbol") assert isinstance(w_selector, model.W_BytesObject) def interp_w(): interp.perform(model.W_SmallInteger(1000), w_selector) diff --git a/spyvm/todo.txt b/spyvm/todo.txt --- a/spyvm/todo.txt +++ b/spyvm/todo.txt @@ -44,3 +44,14 @@ Shadows: [ ] Fix invalidation of methoddictshadow when the w_self of its values array changes + +Optimizations: +use integer tagging primitives to get more compact code: + def wrap_int(self, val): + from rpython.rlib import rerased + try: + return model.W_SmallInteger(rerased.erase_int(val)) + except OverflowError: + raise WrappingError("integer too large to fit into a tagged pointer") + +make classes \ No newline at end of file _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit