[pypy-svn] r68111 - in pypy/trunk/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Thu Oct 1 18:32:27 CEST 2009


Author: arigo
Date: Thu Oct  1 18:32:25 2009
New Revision: 68111

Modified:
   pypy/trunk/pypy/jit/metainterp/codewriter.py
   pypy/trunk/pypy/jit/metainterp/pyjitpl.py
   pypy/trunk/pypy/jit/metainterp/test/test_basic.py
   pypy/trunk/pypy/jit/metainterp/test/test_codewriter.py
Log:
Fix for ootype, sorry.


Modified: pypy/trunk/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/codewriter.py	Thu Oct  1 18:32:25 2009
@@ -183,8 +183,12 @@
             _, meth = T._lookup(methname)
             if not getattr(meth, 'abstract', False):
                 assert meth.graph
-                jitcode = self.get_jitcode(meth.graph,
-                                           oosend_methdescr=methdescr)
+                if self.policy.look_inside_graph(meth.graph,
+                                                 self.cpu.supports_floats):
+                    jitcode = self.get_jitcode(meth.graph,
+                                               oosend_methdescr=methdescr)
+                else:
+                    jitcode = None
                 oocls = ootype.runtimeClass(T)
                 jitcodes[oocls] = jitcode
         methdescr.setup(jitcodes)

Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py	Thu Oct  1 18:32:25 2009
@@ -677,7 +677,13 @@
             self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
         oocls = clsbox.getref(ootype.Class)
         jitcode = methdescr.get_jitcode_for_class(oocls)
-        return self.perform_call(jitcode, varargs)
+        if jitcode is not None:
+            # we should follow calls to this graph
+            return self.perform_call(jitcode, varargs)
+        else:
+            # but we should not follow calls to that graph
+            return self.execute_varargs(rop.OOSEND, varargs,
+                                        descr=methdescr, exc=True)
 
     @arguments("box")
     def opimpl_strlen(self, str):

Modified: pypy/trunk/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_basic.py	Thu Oct  1 18:32:25 2009
@@ -906,7 +906,28 @@
         res = self.interp_operations(f, [3, 5])
         assert res == 5
         self.check_history_(setfield_gc=2, getfield_gc_pure=1)
-        
+
+    def test_oosend_look_inside_only_one(self):
+        class A:
+            pass
+        class B(A):
+            def g(self):
+                return 123
+        class C(A):
+            @dont_look_inside
+            def g(self):
+                return 456
+        def f(n):
+            if n > 3:
+                x = B()
+            else:
+                x = C()
+            return x.g() + x.g()
+        res = self.interp_operations(f, [10])
+        assert res == 123 * 2
+        res = self.interp_operations(f, [-10])
+        assert res == 456 * 2
+
 class TestOOtype(BasicTests, OOJitMixin):
 
     def test_oohash(self):

Modified: pypy/trunk/pypy/jit/metainterp/test/test_codewriter.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_codewriter.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_codewriter.py	Thu Oct  1 18:32:25 2009
@@ -14,9 +14,8 @@
 
 
 class TestCodeWriter:
-    type_system = 'lltype'
 
-    def setup_method(self, _):
+    def make_graph(self, func, values, type_system='lltype'):
         class FakeMetaInterpSd:
             virtualizable_info = None
             def find_opcode(self, name):
@@ -25,13 +24,31 @@
             def _register_indirect_call_target(self, fnaddress, jitcode):
                 self.indirectcalls.append((fnaddress, jitcode))
 
+        class FakeMethDescr:
+            def __init__(self1, CLASS, methname):
+                self.methdescrs.append(self1)
+                self1.CLASS = CLASS
+                self1.methname = methname
+                self1.jitcodes = None
+            def setup(self1, jitcodes):
+                self1.jitcodes = jitcodes
+        self.methdescrs = []
+
         class FakeCPU:
-            ts = typesystem.llhelper
             supports_floats = False
             def fielddescrof(self, STRUCT, fieldname):
                 return ('fielddescr', STRUCT, fieldname)
             def calldescrof(self, FUNC, NON_VOID_ARGS, RESULT):
                 return ('calldescr', FUNC, NON_VOID_ARGS, RESULT)
+            def typedescrof(self, CLASS):
+                return ('typedescr', CLASS)
+            def methdescrof(self, CLASS, methname):
+                return FakeMethDescr(CLASS, methname)
+
+        if type_system == 'lltype':
+            FakeCPU.ts = typesystem.llhelper
+        else:
+            FakeCPU.ts = typesystem.oohelper
 
         self.metainterp_sd = FakeMetaInterpSd()
         self.metainterp_sd.opcode_implementations = None
@@ -39,9 +56,7 @@
         self.metainterp_sd.indirectcalls = []
         self.metainterp_sd.cpu = FakeCPU()
 
-    def make_graph(self, func, values):
-        rtyper = support.annotate(func, values,
-                                  type_system=self.type_system)
+        rtyper = support.annotate(func, values, type_system=type_system)
         self.metainterp_sd.cpu.rtyper = rtyper
         return rtyper.annotator.translator.graphs[0]
 
@@ -100,6 +115,36 @@
                                in self.metainterp_sd.indirectcalls]
         assert dict.fromkeys(names) == {'g': None}
 
+    def test_oosend_look_inside_only_one(self):
+        class A:
+            pass
+        class B(A):
+            def g(self):
+                return 123
+        class C(A):
+            @jit.dont_look_inside
+            def g(self):
+                return 456
+        def f(n):
+            if n > 3:
+                x = B()
+            else:
+                x = C()
+            return x.g() + x.g()
+        graph = self.make_graph(f, [5], type_system='ootype')
+        cw = CodeWriter(self.metainterp_sd, JitPolicy())
+        jitcode = cw.make_one_bytecode((graph, None), False)
+        assert len(self.methdescrs) == 1
+        assert self.methdescrs[0].CLASS._name.endswith('.A')
+        assert self.methdescrs[0].methname == 'og'
+        assert len(self.methdescrs[0].jitcodes.keys()) == 2
+        values = self.methdescrs[0].jitcodes.values()
+        values.sort()
+        assert values[0] is None
+        assert values[1].name == 'B.g'
+        for graph, _ in cw.all_graphs.keys():
+            assert graph.name in ['f', 'B.g']
+
     def test_instantiate(self):
         class A1:     id = 651
         class A2(A1): id = 652



More information about the Pypy-commit mailing list