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

arigo at codespeak.net arigo at codespeak.net
Wed Nov 11 13:37:58 CET 2009


Author: arigo
Date: Wed Nov 11 13:37:57 2009
New Revision: 69159

Modified:
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/logger.py
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_logger.py
Log:
Have the logger use the information.


Modified: pypy/branch/jit-log-class-func/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/branch/jit-log-class-func/pypy/jit/metainterp/logger.py	(original)
+++ pypy/branch/jit-log-class-func/pypy/jit/metainterp/logger.py	Wed Nov 11 13:37:57 2009
@@ -7,9 +7,10 @@
 
 class Logger(object):
 
-    def __init__(self, ts, guard_number=False):
-        self.ts = ts
-        self.guard_number=guard_number
+    def __init__(self, metainterp_sd, guard_number=False):
+        self.metainterp_sd = metainterp_sd
+        self.ts = metainterp_sd.cpu.ts
+        self.guard_number = guard_number
 
     def log_loop(self, inputargs, operations, number=0, type=None):
         if type is None:
@@ -57,7 +58,11 @@
         elif isinstance(arg, BoxFloat):
             return 'f' + str(mv)
         elif isinstance(arg, self.ts.ConstAddr):
-            return 'ConstClass(cls' + str(mv) + ')'
+            addr = arg.getaddr(self.metainterp_sd.cpu)
+            name = self.metainterp_sd.get_name_from_address(addr)
+            if not name:
+                name = 'cls' + str(mv)
+            return 'ConstClass(' + name + ')'
         else:
             return '?'
 

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:37:57 2009
@@ -996,8 +996,8 @@
         self.cpu = cpu
         self.stats = stats
         self.options = options
-        self.logger_noopt = Logger(cpu.ts)
-        self.logger_ops = Logger(cpu.ts, guard_number=True)
+        self.logger_noopt = Logger(self)
+        self.logger_ops = Logger(self, guard_number=True)
 
         RESULT = portal_graph.getreturnvar().concretetype
         self.result_type = history.getkind(RESULT)
@@ -1023,7 +1023,8 @@
         self.portal_code = None
         self.leave_code = None
         self._class_sizes = None
-        self._list_of_addr2name = None
+        self._addr2name_keys = None
+        self._addr2name_values = None
 
     def _freeze_(self):
         return True
@@ -1033,7 +1034,8 @@
         self.portal_code = portal_code
         self.leave_code = leave_code
         self._class_sizes = class_sizes
-        self._list_of_addr2name = list_of_addr2name
+        self._addr2name_keys   = [key   for key, value in list_of_addr2name]
+        self._addr2name_values = [value for key, value in list_of_addr2name]
 
     def finish_setup(self, optimizer=None):
         warmrunnerdesc = self.warmrunnerdesc
@@ -1066,9 +1068,26 @@
             class_sizes[vtable] = sizedescr
         self.cpu.set_class_sizes(class_sizes)
 
-    def get_addr2name_dict(self):
-        # for debugging
-        pass #...
+    def get_name_from_address(self, addr):
+        # for debugging only
+        if we_are_translated():
+            d = self.globaldata.addr2name
+            if d is None:
+                # Build the dictionary at run-time.  This is needed
+                # because the keys are function/class addresses, so they
+                # can change from run to run.
+                d = {}
+                keys = self._addr2name_keys
+                values = self._addr2name_values
+                for i in range(len(keys)):
+                    d[keys[i]] = values[i]
+                self.globaldata.addr2name = d
+            return d.get(addr, '')
+        else:
+            for i in range(len(self._addr2name_keys)):
+                if fnaddress == self._addr2name_keys[i]:
+                    return self._addr2name_values[i]
+            return ''
 
     def bytecode_for_address(self, fnaddress):
         if we_are_translated():
@@ -1122,6 +1141,7 @@
     def __init__(self, staticdata, prebuilt_fail_descr_list):
         self.initialized = False
         self.indirectcall_dict = None
+        self.addr2name = None
         self.fail_descr_list = prebuilt_fail_descr_list[:]
         self.loopnumbering = 0
         #

Modified: pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_logger.py
==============================================================================
--- pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_logger.py	(original)
+++ pypy/branch/jit-log-class-func/pypy/jit/metainterp/test/test_logger.py	Wed Nov 11 13:37:57 2009
@@ -34,6 +34,14 @@
 class TestLogger(object):
     ts = llhelper
 
+    def make_metainterp_sd(self):
+        class FakeMetaInterpSd:
+            class cpu:
+                ts = self.ts
+            def get_name_from_address(self, addr):
+                return 'Name'
+        return FakeMetaInterpSd()
+
     def reparse(self, inp, namespace=None, check_equal=True):
         """ parse loop once, then log it and parse again.
         Checks that we get the same thing.
@@ -41,7 +49,7 @@
         if namespace is None:
             namespace = {}
         loop = pure_parse(inp, namespace=namespace)
-        logger = Logger(self.ts)
+        logger = Logger(self.make_metainterp_sd())
         output = logger.log_loop(loop, namespace)
         oloop = pure_parse(output, namespace=namespace)
         if check_equal:
@@ -99,7 +107,7 @@
         jump(i0, descr=target)
         '''
         loop = pure_parse(inp, namespace=namespace)
-        logger = Logger(self.ts)
+        logger = Logger(self.make_metainterp_sd())
         output = logger.log_loop(loop)
         assert output.splitlines()[-1] == "jump(i0, descr=<Loop3>)"
         pure_parse(output)
@@ -111,7 +119,7 @@
         guard_true(i0, descr=fdescr) [i0]
         '''
         loop = pure_parse(inp, namespace=namespace)
-        logger = Logger(self.ts, guard_number=True)
+        logger = Logger(self.make_metainterp_sd(), guard_number=True)
         output = logger.log_loop(loop)
         assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard4>) [i0]"
         pure_parse(output)
@@ -119,18 +127,34 @@
         def boom():
             raise Exception
         namespace['fdescr'].get_index = boom
-        logger = Logger(self.ts, guard_number=False)
+        logger = Logger(self.make_metainterp_sd(), guard_number=False)
         output = logger.log_loop(loop)
         assert output.splitlines()[-1].startswith("guard_true(i0, descr=<")
 
+    def test_class_name(self):
+        from pypy.rpython.lltypesystem import lltype
+        AbcVTable = lltype.Struct('AbcVTable')
+        abcvtable = lltype.malloc(AbcVTable, immortal=True)
+        namespace = {'Name': abcvtable}
+        inp = '''
+        [i0]
+        p = new_with_vtable(ConstClass(Name))
+        '''
+        loop = pure_parse(inp, namespace=namespace)
+        logger = Logger(self.make_metainterp_sd())
+        output = logger.log_loop(loop)
+        assert output.splitlines()[-1].endswith(
+            " = new_with_vtable(ConstClass(Name))")
+        pure_parse(output, namespace=namespace)
+
     def test_intro_loop(self):
-        bare_logger = logger.Logger(self.ts)
+        bare_logger = logger.Logger(self.make_metainterp_sd())
         output = capturing(bare_logger.log_loop, [], [], 1, "foo")
         assert output.splitlines()[0] == "# Loop 1 : foo with 0 ops"
         pure_parse(output)
 
     def test_intro_bridge(self):
-        bare_logger = logger.Logger(self.ts)
+        bare_logger = logger.Logger(self.make_metainterp_sd())
         output = capturing(bare_logger.log_bridge, [], [], 3)
         assert output.splitlines()[0] == "# bridge out of Guard 3 with 0 ops"
         pure_parse(output)



More information about the Pypy-commit mailing list