[pypy-svn] r69156 - in pypy/branch/jit-log-class-func/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Wed Nov 11 13:12:00 CET 2009


Author: arigo
Date: Wed Nov 11 13:11:59 2009
New Revision: 69156

Modified:
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/codewriter.py
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_codewriter.py
Log:
(fijal, arigo)
Introduce a list that maps the address of functions and classes
to their name.


Modified: pypy/branch/jit-log-class-func/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/jit-log-class-func/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/jit-log-class-func/pypy/jit/metainterp/codewriter.py	Wed Nov 11 13:11:59 2009
@@ -65,6 +65,8 @@
         self.counter = 0
         self.class_sizes = []
         self._class_sizes_seen = {}
+        self.list_of_addr2name = []
+        self._functions_addr_seen = {}
 
         # set later with .start()
         self.metainterp_sd = None
@@ -172,7 +174,8 @@
         portal_code = self.make_portal_bytecode(portal_graph)
 
         self.metainterp_sd.info_from_codewriter(portal_code, leave_code,
-                                                self.class_sizes)
+                                                self.class_sizes,
+                                                self.list_of_addr2name)
 
     def _start(self, metainterp_sd, portal_runner_ptr):
         self.metainterp_sd = metainterp_sd
@@ -306,6 +309,8 @@
         methdescr.setup(jitcodes)
 
     def getcalldescr(self, v_func, args, result, consider_effects_of=None):
+        if isinstance(v_func, Constant):
+            self.register_known_function(v_func.value)
         non_void_args = [x for x in args if x.concretetype is not lltype.Void]
         NON_VOID_ARGS = [x.concretetype for x in non_void_args]
         RESULT = result.concretetype
@@ -330,6 +335,8 @@
             self._class_sizes_seen[key] = True
             sizedescr = self.cpu.sizeof(STRUCT)
             self.class_sizes.append((vtable, sizedescr))
+            vtable_addr = llmemory.cast_ptr_to_adr(vtable)
+            self.list_of_addr2name.append((vtable_addr, STRUCT.__name__))
 
     def register_known_ooclass(self, cls, CLASS):
         # ootype only
@@ -338,6 +345,12 @@
             typedescr = self.cpu.typedescrof(CLASS)
             self.class_sizes.append((cls, typedescr))
 
+    def register_known_function(self, func):
+        if self.rtyper.type_system.name == 'lltypesystem':
+            if func._obj not in self._functions_addr_seen:
+                self._functions_addr_seen[func._obj] = True
+                func_addr = llmemory.cast_ptr_to_adr(func)
+                self.list_of_addr2name.append((func_addr, func._obj._name))
 
 
 class BytecodeMaker(object):

Modified: pypy/branch/jit-log-class-func/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/jit-log-class-func/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/jit-log-class-func/pypy/jit/metainterp/pyjitpl.py	Wed Nov 11 13:11:59 2009
@@ -1022,15 +1022,18 @@
 
         self.portal_code = None
         self.leave_code = None
-        self._class_sizes = None        
+        self._class_sizes = None
+        self._list_of_addr2name = None
 
     def _freeze_(self):
         return True
 
-    def info_from_codewriter(self, portal_code, leave_code, class_sizes):
+    def info_from_codewriter(self, portal_code, leave_code, class_sizes,
+                             list_of_addr2name=[]):
         self.portal_code = portal_code
         self.leave_code = leave_code
         self._class_sizes = class_sizes
+        self._list_of_addr2name = list_of_addr2name
 
     def finish_setup(self, optimizer=None):
         warmrunnerdesc = self.warmrunnerdesc
@@ -1063,6 +1066,10 @@
             class_sizes[vtable] = sizedescr
         self.cpu.set_class_sizes(class_sizes)
 
+    def get_addr2name_dict(self):
+        # for debugging
+        pass #...
+
     def bytecode_for_address(self, fnaddress):
         if we_are_translated():
             d = self.globaldata.indirectcall_dict

Modified: pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_codewriter.py
==============================================================================
--- pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_codewriter.py	(original)
+++ pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_codewriter.py	Wed Nov 11 13:11:59 2009
@@ -121,12 +121,14 @@
             supports_floats = False
             def fielddescrof(self, STRUCT, fieldname):
                 return ('fielddescr', STRUCT, fieldname)
-            def calldescrof(self, FUNC, NON_VOID_ARGS, RESULT):
+            def calldescrof(self, FUNC, NON_VOID_ARGS, RESULT, stuff=None):
                 return ('calldescr', FUNC, NON_VOID_ARGS, RESULT)
             def typedescrof(self, CLASS):
                 return ('typedescr', CLASS)
             def methdescrof(self, CLASS, methname):
                 return FakeMethDescr(CLASS, methname)
+            def sizeof(self, STRUCT):
+                return ('sizeof', STRUCT)
 
         if type_system == 'lltype':
             FakeCPU.ts = typesystem.llhelper
@@ -366,6 +368,24 @@
         assert jitcode._source.count('oononnull') == 2
         assert jitcode._source.count('ooisnull') == 2
 
+    def test_list_of_addr2name(self):
+        class A1:
+            def g(self):
+                self.x = 123
+                return 5
+        def f():
+            a = A1()
+            a.y = a.g()
+            return a
+        graphs = self.make_graphs(f, [])
+        cw = CodeWriter(self.rtyper)
+        cw.candidate_graphs = [graphs[0]]
+        cw._start(self.metainterp_sd, None)
+        jitcode = cw.make_one_bytecode((graphs[0], None), False)
+        assert len(cw.list_of_addr2name) == 2
+        assert cw.list_of_addr2name[0][1].endswith('.A1')
+        assert cw.list_of_addr2name[1][1] == 'A1.g'
+
 class ImmutableFieldsTests:
 
     def test_fields(self):



More information about the Pypy-commit mailing list