[pypy-commit] lang-smalltalk storage: Fixed up jit.py a little bit.

anton_gulenko noreply at buildbot.pypy.org
Mon Apr 7 13:52:28 CEST 2014


Author: Anton Gulenko <anton.gulenko at googlemail.com>
Branch: storage
Changeset: r774:41968a0bc9f3
Date: 2014-04-03 21:43 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/41968a0bc9f3/

Log:	Fixed up jit.py a little bit.

diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- a/spyvm/test/jit.py
+++ b/spyvm/test/jit.py
@@ -4,7 +4,7 @@
 # view jit.
 #
 
-import sys, os
+import sys
 from rpython import conftest
 class o:
     view = False
@@ -12,31 +12,65 @@
 conftest.option = o
 
 from rpython.jit.metainterp.test.test_ajit import LLJitMixin
+from spyvm.test.util import import_bytecodes, read_image
+from spyvm import model, shadow
 
-from .util import import_bytecodes
-from spyvm import model, interpreter, primitives, shadow
-from spyvm import objspace, squeakimage
-from spyvm.tool.analyseimage import create_squeakimage, create_testimage
-from rpython.rlib.streamio import open_file_as_stream
-
-import_bytecodes(__name__)
-
-space = objspace.ObjSpace()
+imagename = "mini.image"
+# imagename = "minitest.image"
 
 sys.setrecursionlimit(5000)
+import_bytecodes(__name__)
+jit = LLJitMixin()
 
-class TestLLtype(LLJitMixin):
+# Pass a function inside here to meta-interpret it and show all encountered loops.
+def meta_interp(func):
+    res = jit.meta_interp(func, [], listcomp=True, listops=True, backendopt=True, inline=True)
+    if res:
+        print res.__repr__()
 
-    def test_miniloop(self):
+# ==== The following are factories for functions to be passed into meta_interp() ====
 
-        from spyvm import objspace
-        space = objspace.ObjSpace()
+# This will build a small jit just for the specified message-send
+def perform(receiver, selector, *args):
+    _, interp, _, _ = read_image(imagename)
+    def interp_miniloop():
+        interp.perform(receiver, selector, *args)
+    return interp_miniloop
 
-        image = create_testimage(space)
-        interp = interpreter.Interpreter(space, image)
-        w_selector = interp.perform(space.wrap_string('loopTest2'), "asSymbol")
-        assert isinstance(w_selector, model.W_BytesObject)
-        def interp_w():
-            interp.perform(model.W_SmallInteger(1000), w_selector)
+# This will build a jit executing a synthetic method composed of the given bytecodes and literals,
+# and operating on the given stack. The receiver of the 'message' must be at the bottom of the stack.
+# The bytecodes can be composed from constants created in this module in above import_bytecodes() call.
+def execute_frame(bytes, literals, stack):
+    space, interp, _, _ = read_image(imagename)
+    w_method = model.W_CompiledMethod(space, header=512)
+    w_method.literals = literals
+    w_method.setbytes(bytes)
+    w_receiver = stack[0]
+    s_frame = shadow.MethodContextShadow(space, None, w_method, w_receiver, [])
+    w_frame = s_frame.w_self()
+    def interp_execute_bytes_with_stack():
+        interp.loop(w_frame)
+    return interp_execute_bytes_with_stack
 
-        self.meta_interp(interp_w, [], listcomp=True, listops=True, backendopt=True, inline=True)
+# This will build a JIT for the entire VM.
+def full_vm():
+    import targetimageloadingsmalltalk
+    argv = sys.argv
+    def interp_full_vm():
+        targetimageloadingsmalltalk.entry_point(argv)
+    return interp_full_vm
+
+def main():
+    # func = perform(model.W_SmallInteger(1000), 'loopTest2')
+    # func = perform(model.W_SmallInteger(777), 'name')
+    func = execute_frame([returnReceiver], [], [model.W_SmallInteger(42)])
+    # func = full_vm()
+    meta_interp(func)
+
+# This is for execution using pytest.py. This way you can get a pdb on assertion-errors etc.
+# Execute e.g. $ pypy ../pypy/pytest.py spyvm/test/jit.py -s --pdb -k test_main
+def test_main():
+    main()
+
+if __name__ == "__main__":
+    main()


More information about the pypy-commit mailing list