[pypy-commit] lang-smalltalk default: first jit hints, also: image with special test methods

krono noreply at buildbot.pypy.org
Fri Feb 15 13:50:45 CET 2013


Author: Tobias Pape <tobias at netshed.de>
Branch: 
Changeset: r30:10a0cd258ca6
Date: 2013-02-15 13:48 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/10a0cd258ca6/

Log:	first jit hints, also: image with special test methods

diff --git a/spyvm/fixedstack.py b/spyvm/fixedstack.py
--- a/spyvm/fixedstack.py
+++ b/spyvm/fixedstack.py
@@ -4,6 +4,7 @@
 
 import types
 
+from rpython.rlib import jit
 from rpython.rlib.rarithmetic import r_uint
 
 class FixedStack(object):
@@ -29,18 +30,20 @@
         return s
     
     def push(self, item):
-        ptr = self.ptr
+        ptr = jit.promote(self.ptr)
         self.items[ptr] = item
         self.ptr = ptr + 1
     
     def pop(self):
-        ptr = self.ptr - 1
+        ptr = jit.promote(self.ptr) - 1
         ret = self.items[ptr]   # you get OverflowError if the stack is empty
         self.items[ptr] = None
         self.ptr = ptr
         return ret
-    
+
+    @jit.unroll_safe
     def drop(self, n):
+        jit.promote(self.ptr)
         while n > 0:
             n -= 1
             self.ptr -= 1
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -18,7 +18,9 @@
     """Illegal Store."""
 
 def get_printable_location(pc, self, w_method):
-    return '%d: %s' % (pc, w_method.bytes[pc])
+    bc = ord(w_method.bytes[pc])
+    return '%d: [%s]%s' % (pc, hex(bc), BYTECODE_NAMES[bc])
+
 
 class Interpreter(object):
 
@@ -26,9 +28,9 @@
     cnt = 0
     _last_indent = ""
     jit_driver = jit.JitDriver(
-        greens = ['pc', 'self', 'w_method'],
-        reds = ['s_active_context'],
-        get_printable_location = get_printable_location
+        greens=['pc', 'self', 'w_method'],
+        reds=['s_active_context'],
+        get_printable_location=get_printable_location
     )
     
     def __init__(self, space, image_name=""):
@@ -96,11 +98,8 @@
             w_method = s_active_context.w_method()
 
             self.jit_driver.jit_merge_point(
-                self = self,
-                pc = pc,
-                w_method = w_method,
-                s_active_context = s_active_context)
-
+                pc=pc, self=self, w_method=w_method,
+                s_active_context=s_active_context)
             self.step(s_active_context)
 
 
@@ -548,6 +547,20 @@
             ]
 
 
+def initialize_bytecode_names():
+    result = [None] * 256
+    for entry in BYTECODE_RANGES:
+        if len(entry) == 2:
+            positions = [entry[0]]
+        else:
+            positions = range(entry[0], entry[1]+1)
+        for pos in positions:
+            result[pos] = entry[-1]
+    assert None not in result
+    return result
+
+BYTECODE_NAMES = initialize_bytecode_names()
+
 def initialize_bytecode_table():
     result = [None] * 256
     for entry in BYTECODE_RANGES:
@@ -560,6 +573,7 @@
     assert None not in result
     return result
 
+
 BYTECODE_TABLE = initialize_bytecode_table()
 
 
@@ -594,3 +608,4 @@
 # translating the interpreter
 # if objectmodel.we_are_translated():
 Interpreter.step = bytecode_step_translated
+
diff --git a/spyvm/minitest.image b/spyvm/minitest.image
new file mode 100644
index 0000000000000000000000000000000000000000..5753d32adc6e5ca83c6b7bf990258090ca1812d7
GIT binary patch

[cut]

diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -1,7 +1,7 @@
 import weakref
 from spyvm import model, constants, error
 from rpython.tool.pairtype import extendabletype
-from rpython.rlib import rarithmetic
+from rpython.rlib import rarithmetic, jit
 
 class AbstractShadow(object):
     """A shadow is an optional extra bit of information that
@@ -445,6 +445,7 @@
         return self.s_home().w_method()
 
     def getbytecode(self):
+        jit.promote(self._pc)
         assert self._pc >= 0
         bytecode = self.w_method().bytes[self._pc]
         currentBytecode = ord(bytecode)
diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- a/spyvm/test/jit.py
+++ b/spyvm/test/jit.py
@@ -16,7 +16,7 @@
 
 from spyvm import model, interpreter, primitives, shadow
 from spyvm import objspace
-from spyvm.tool.analyseimage import create_squeakimage
+from spyvm.tool.analyseimage import create_testimage
 
 
 mockclass = objspace.bootstrap_class
@@ -51,18 +51,18 @@
 class TestLLtype(LLJitMixin):
     
 
-    def test_tiny_benchmarks(self):
+    def test_miniloop(self):
 
-        def tinyBenchmarks():
+        def miniloop():
             from spyvm import objspace
             space = objspace.ObjSpace()
-            image = create_squeakimage(space)
+            image = create_testimage(space)
             interp = interpreter.Interpreter(space)
 
             w_object = model.W_SmallInteger(0)
 
             s_class = w_object.shadow_of_my_class(space)
-            w_method = s_class.lookup("tinyBenchmarks")
+            w_method = s_class.lookup("loopTest")
 
             assert w_method
             w_frame = w_method.create_frame(space, w_object, [])
@@ -73,11 +73,9 @@
             from spyvm.interpreter import BYTECODE_TABLE
             return interp
 
-        interp = tinyBenchmarks()
+        interp = miniloop()
         def interp_w():
             interp.interpret()
 
-        self.meta_interp(interp_w, [], listcomp=True, listops=True,
-                        #backendopt=True
-                        )
+        self.meta_interp(interp_w, [], listcomp=True, listops=True, backendopt=True)
         
diff --git a/spyvm/tool/analyseimage.py b/spyvm/tool/analyseimage.py
--- a/spyvm/tool/analyseimage.py
+++ b/spyvm/tool/analyseimage.py
@@ -6,18 +6,29 @@
 import sys
 
 mini_image = py.path.local(__file__).dirpath().dirpath().join('mini.image')
+minitest_image = py.path.local(__file__).dirpath().dirpath().join('minitest.image')
 
 def get_miniimage(space):
     return squeakimage.ImageReader(space, squeakimage.Stream(mini_image.open()))
 
-def create_squeakimage(space):
-    example = get_miniimage(space)
-    example.initialize()
+def get_minitestimage(space):
+    return squeakimage.ImageReader(space, squeakimage.Stream(minitest_image.open()))
+
+def create_image(space, image_reader):
+    image_reader.initialize()
     
     image = squeakimage.SqueakImage()
-    image.from_reader(space, example)
+    image.from_reader(space, image_reader)
     return image
 
+
+def create_squeakimage(space):
+    return create_image(space, get_miniimage(space))
+
+def create_testimage(space):
+    return create_image(space, get_minitestimage(space))
+
+
 def printStringsInImage():
     image = create_squeakimage()
     for each in image.objects:


More information about the pypy-commit mailing list