Commits

Tobias Pape committed 10a0cd2

first jit hints, also: image with special test methods

  • Participants
  • Parent commits c9013e7

Comments (0)

Files changed (6)

File spyvm/fixedstack.py

 
 import types
 
+from rpython.rlib import jit
 from rpython.rlib.rarithmetic import r_uint
 
 class FixedStack(object):
         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

File spyvm/interpreter.py

     """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):
 
     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=""):
             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)
 
 
             ]
 
 
+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:
     assert None not in result
     return result
 
+
 BYTECODE_TABLE = initialize_bytecode_table()
 
 
 # translating the interpreter
 # if objectmodel.we_are_translated():
 Interpreter.step = bytecode_step_translated
+

File spyvm/minitest.image

Binary file added.

File spyvm/shadow.py

 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
         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)

File spyvm/test/jit.py

 
 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
 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, [])
             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)
         

File spyvm/tool/analyseimage.py

 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: