[pypy-svn] r64512 - in pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Tue Apr 21 15:26:01 CEST 2009


Author: arigo
Date: Tue Apr 21 15:25:59 2009
New Revision: 64512

Modified:
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
Log:
(antocuni, arigo)
When producing a BlackHole, don't recurse into oosend'ed graphs.


Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py	Tue Apr 21 15:25:59 2009
@@ -80,7 +80,8 @@
             _, meth = T._lookup(methname)
             if not getattr(meth, 'abstract', False):
                 assert meth.graph
-                jitcode = codewriter.get_jitcode(meth.graph)
+                jitcode = codewriter.get_jitcode(meth.graph,
+                                                 oosend_methdesc=self)
                 oocls = ootype.runtimeClass(T)
                 self.jitcodes[oocls] = jitcode
 
@@ -112,40 +113,48 @@
     def make_portal_bytecode(self, graph):
         log.info("making JitCodes...")
         self.portal_graph = graph
-        jitcode = self.make_one_bytecode(graph, True)
+        graph_key = (graph, None)
+        jitcode = self.make_one_bytecode(graph_key, True)
         while self.unfinished_graphs:
-            graph, called_from = self.unfinished_graphs.pop()
-            self.make_one_bytecode(graph, False, called_from)
+            graph_key, called_from = self.unfinished_graphs.pop()
+            self.make_one_bytecode(graph_key, False, called_from)
         log.info("there are %d JitCode instances." % len(self.all_graphs))
         # xxx annotation hack: make sure there is at least one ConstAddr around
         jitcode.constants.append(history.ConstAddr(llmemory.NULL, self.cpu))
         return jitcode
 
-    def make_one_bytecode(self, graph, portal, called_from=None):
-        maker = BytecodeMaker(self, graph, portal)
+    def make_one_bytecode(self, graph_key, portal, called_from=None):
+        maker = BytecodeMaker(self, graph_key, portal)
         if not hasattr(maker.bytecode, 'code'):
             maker.assemble()
         return maker.bytecode
 
-    def get_jitcode(self, graph, called_from=None):
-        if graph in self.all_graphs:
-            return self.all_graphs[graph]
-        extra = self.get_jitcode_calldescr(graph)
+    def get_jitcode(self, graph, called_from=None, oosend_methdesc=None):
+        key = (graph, oosend_methdesc)
+        if key in self.all_graphs:
+            return self.all_graphs[key]
+        extra = self.get_jitcode_calldescr(graph, oosend_methdesc)
         bytecode = JitCode(graph.name, *extra, **dict(called_from=called_from,
                                                       graph=graph))
         # 'graph.name' is for dump()
-        self.all_graphs[graph] = bytecode
-        self.unfinished_graphs.append((graph, called_from))
+        self.all_graphs[key] = bytecode
+        self.unfinished_graphs.append((key, called_from))
         return bytecode
 
-    def get_jitcode_calldescr(self, graph):
-        if self.metainterp_sd.cpu.is_oo:
-            return ()
+    def get_jitcode_calldescr(self, graph, oosend_methdesc):
         if self.portal_graph is None or graph is self.portal_graph:
             return ()
         fnptr = self.rtyper.getcallable(graph)
-        cfnptr = history.ConstAddr(llmemory.cast_ptr_to_adr(fnptr), self.cpu)
-        FUNC = lltype.typeOf(fnptr).TO
+        if self.metainterp_sd.cpu.is_oo:
+            if oosend_methdesc:
+                return (None, oosend_methdesc)
+            else:
+                cfnptr = history.ConstObj(ootype.cast_to_object(fnptr))
+        else:
+            assert not oosend_methdesc
+            cfnptr = history.ConstAddr(llmemory.cast_ptr_to_adr(fnptr),
+                                       self.cpu)
+        FUNC = get_functype(lltype.typeOf(fnptr))
         # <hack>
         # these functions come from somewhere and are never called. make sure
         # we never store a pointer to them since they make C explode,
@@ -246,11 +255,13 @@
 class BytecodeMaker(object):
     debug = False
     
-    def __init__(self, codewriter, graph, portal):
+    def __init__(self, codewriter, graph_key, portal):
         self.codewriter = codewriter
         self.cpu = codewriter.metainterp_sd.cpu
         self.portal = portal
-        self.bytecode = self.codewriter.get_jitcode(graph)
+        graph, oosend_methdesc = graph_key
+        self.bytecode = self.codewriter.get_jitcode(graph,
+                                               oosend_methdesc=oosend_methdesc)
         if not codewriter.policy.look_inside_graph(graph):
             assert not portal, "portal has been hidden!"
             graph = make_calling_stub(codewriter.rtyper, graph)
@@ -795,14 +806,15 @@
         kind = self.codewriter.policy.guess_call_kind(op)
         return getattr(self, 'handle_%s_oosend' % kind)(op)
 
-    def handle_regular_call(self, op, skip_first=True):
+    def handle_regular_call(self, op, oosend_methdesc=None):
         self.minimize_variables()
         [targetgraph] = self.codewriter.policy.graphs_from(op)
-        jitbox = self.codewriter.get_jitcode(targetgraph, self.graph)
-        if skip_first:
-            args = op.args[1:]
-        else:
+        jitbox = self.codewriter.get_jitcode(targetgraph, self.graph,
+                                             oosend_methdesc=oosend_methdesc)
+        if oosend_methdesc:
             args = op.args
+        else:
+            args = op.args[1:]
         self.emit('call')
         self.emit(self.get_position(jitbox))
         self.emit_varargs([x for x in args
@@ -845,12 +857,12 @@
         methname = op.args[0].value
         v_obj = op.args[1]
         INSTANCE = v_obj.concretetype
+        methdesc = self.codewriter.get_methdesc(INSTANCE, methname)
         graphs = v_obj.concretetype._lookup_graphs(methname)
         if len(graphs) == 1:
-            self.handle_regular_call(op, skip_first=False)
+            self.handle_regular_call(op, oosend_methdesc=methdesc)
             return
         self.minimize_variables()
-        methdesc = self.codewriter.get_methdesc(INSTANCE, methname)
         self.emit('oosend')
         self.emit(self.get_position(methdesc))
         self.emit_varargs([x for x in op.args

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py	Tue Apr 21 15:25:59 2009
@@ -431,12 +431,18 @@
     @arguments("bytecode", "varargs")
     def opimpl_call(self, callee, varargs):
         if (isinstance(self.metainterp.history, history.BlackHole) and
-            callee.cfnptr is not None):
+            callee.calldescr is not None):
             # when producing only a BlackHole, we can implement this by
             # calling the subfunction directly instead of interpreting it
-            varargs = [callee.cfnptr] + varargs
-            return self.execute_with_exc(rop.CALL, varargs,
-                                         descr=callee.calldescr)
+            if callee.cfnptr is not None:
+                # for non-oosends
+                varargs = [callee.cfnptr] + varargs
+                return self.execute_with_exc(rop.CALL, varargs,
+                                             descr=callee.calldescr)
+            else:
+                # for oosends (ootype only): calldescr is a MethDesc
+                return self.execute_with_exc(rop.OOSEND, varargs,
+                                             descr=callee.calldescr)
         else:
             # when tracing, this bytecode causes the subfunction to be entered
             f = self.metainterp.newframe(callee)
@@ -526,6 +532,7 @@
             self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
         oocls = ootype.cast_from_object(ootype.Class, clsbox.getobj())
         jitcode = methdesc.get_jitcode_for_class(oocls)
+        # XXX if BlackHole, don't recurse but do the call directly
         cpu = self.metainterp.cpu
         f = self.metainterp.newframe(jitcode)
         f.setup_call(varargs)

Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py	Tue Apr 21 15:25:59 2009
@@ -69,10 +69,11 @@
                                             **kwds)
         cw = codewriter.CodeWriter(metainterp.staticdata, policy, self.ts)
         graph = rtyper.annotator.translator.graphs[0]
-        maingraph = cw.make_one_bytecode(graph, False)
+        graph_key = (graph, None)
+        maingraph = cw.make_one_bytecode(graph_key, False)
         while cw.unfinished_graphs:
-            graph, called_from = cw.unfinished_graphs.pop()
-            cw.make_one_bytecode(graph, False, called_from)
+            graph_key, called_from = cw.unfinished_graphs.pop()
+            cw.make_one_bytecode(graph_key, False, called_from)
         metainterp.staticdata.portal_code = maingraph
         metainterp.staticdata.state = FakeWarmRunnerDesc()
         metainterp.staticdata.DoneWithThisFrame = DoneWithThisFrame



More information about the Pypy-commit mailing list