Author: Richard Plangger <planri...@gmail.com>
Branch: new-jit-log
Changeset: r84330:5f0da389d027
Date: 2016-05-09 11:44 +0200
http://bitbucket.org/pypy/pypy/changeset/5f0da389d027/

Log:    moved the debug counter in its own file (debug.py). this was
        necessary to get a handle to the loop counters when calling
        jitlog_disable

diff --git a/rpython/jit/backend/arm/assembler.py 
b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -14,7 +14,7 @@
     CoreRegisterManager, check_imm_arg, VFPRegisterManager,
     operations as regalloc_operations)
 from rpython.jit.backend.llsupport import jitframe, rewrite
-from rpython.jit.backend.llsupport.assembler import DEBUG_COUNTER, 
BaseAssembler
+from rpython.jit.backend.llsupport.assembler import BaseAssembler
 from rpython.jit.backend.llsupport.regalloc import get_scale, 
valid_addressing_size
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
 from rpython.jit.backend.model import CompiledLoopToken
diff --git a/rpython/jit/backend/llsupport/assembler.py 
b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -13,13 +13,8 @@
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref, llhelper
 from rpython.rtyper.lltypesystem import rffi, lltype
 
-
-DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER',
-    # 'b'ridge, 'l'abel or # 'e'ntry point
-    ('i', lltype.Signed),      # first field, at offset 0
-    ('type', lltype.Char),
-    ('number', lltype.Signed)
-)
+from rpython.jit.metainterp.debug import (DEBUG_COUNTER, LOOP_RUN_COUNTERS,
+        flush_debug_counters)
 
 class GuardToken(object):
     def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs,
@@ -362,10 +357,6 @@
             ResOperation(rop.INCREMENT_DEBUG_COUNTER, [c_adr]))
 
     def _register_counter(self, tp, number, token):
-        # YYY very minor leak -- we need the counters to stay alive
-        # forever, just because we want to report them at the end
-        # of the process
-
         # XXX the numbers here are ALMOST unique, but not quite, use a counter
         #     or something
         struct = lltype.malloc(DEBUG_COUNTER, flavor='raw',
@@ -377,14 +368,15 @@
         else:
             assert token
             struct.number = compute_unique_id(token)
-        self.loop_run_counters.append(struct)
+        LOOP_RUN_COUNTERS.append(struct)
         return struct
 
     def finish_once(self, jitlog):
         if self._debug:
+            # TODO remove the old logging system when jitlog is complete
             debug_start('jit-backend-counts')
-            for i in range(len(self.loop_run_counters)):
-                struct = self.loop_run_counters[i]
+            for i in range(len(LOOP_RUN_COUNTERS)):
+                struct = LOOP_RUN_COUNTERS[i]
                 if struct.type == 'l':
                     prefix = 'TargetToken(%d)' % struct.number
                 else:
@@ -401,9 +393,7 @@
             debug_stop('jit-backend-counts')
 
         if jitlog:
-            # this is always called, the jitlog knows if it is enabled
-            for i, struct in enumerate(self.loop_run_counters):
-                jitlog.log_jit_counter(struct)
+            flush_debug_counters(jitlog)
 
     @staticmethod
     @rgc.no_collect
diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -3,8 +3,7 @@
 import py
 
 from rpython.jit.backend.llsupport import symbolic, jitframe, rewrite
-from rpython.jit.backend.llsupport.assembler import (GuardToken, BaseAssembler,
-                                                DEBUG_COUNTER, debug_bridge)
+from rpython.jit.backend.llsupport.assembler import (GuardToken, 
BaseAssembler, debug_bridge)
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
 from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
 from rpython.jit.metainterp.history import (Const, VOID, ConstInt)
diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1760,7 +1760,7 @@
         self.cpu = cpu
         self.stats = self.cpu.stats
         self.options = options
-        self.jitlog = jl.VMProfJitLogger()
+        self.jitlog = jl.VMProfJitLogger(self.cpu)
         self.logger_noopt = Logger(self)
         self.logger_ops = Logger(self, guard_number=True)
 
diff --git a/rpython/rlib/jitlog.py b/rpython/rlib/jitlog.py
--- a/rpython/rlib/jitlog.py
+++ b/rpython/rlib/jitlog.py
@@ -222,8 +222,19 @@
         content.append(encode_str(opname.lower()))
     return ''.join(content)
 
+
+def _log_jit_counter(cintf, struct):
+    if not cintf.jitlog_enabled():
+        return
+    le_addr = encode_le_addr(struct.number)
+    # not an address (but a number) but it is a machine word
+    le_count = encode_le_addr(struct.i)
+    out = le_addr + le_count
+    cintf.jitlog_write_marked(MARK_JITLOG_COUNTER, out, len(out))
+
 class VMProfJitLogger(object):
-    def __init__(self):
+    def __init__(self, cpu=None):
+        self.cpu = cpu
         self.cintf = cintf.setup()
         self.memo = {}
         self.trace_id = -1
@@ -265,12 +276,7 @@
         self.cintf.jitlog_write_marked(mark, line, len(line))
 
     def log_jit_counter(self, struct):
-        if not self.cintf.jitlog_enabled():
-            return
-        le_addr = encode_le_addr(struct.number)
-        # not an address (but a number) but it is a machine word
-        le_count = encode_le_addr(struct.i)
-        self._write_marked(MARK_JITLOG_COUNTER, le_addr + le_count)
+        _log_jit_counter(self.cintf, struct)
 
     def log_trace(self, tag, metainterp_sd, mc, memo=None):
         if not self.cintf.jitlog_enabled():
@@ -482,7 +488,7 @@
     def copy_core_dump(self, addr, offset=0, count=-1):
         dump = []
         src = rffi.cast(rffi.CCHARP, addr)
-        end = self.get_relative_pos()
+        end = self.mc.get_relative_pos()
         if count != -1:
             end = offset + count
         for p in range(offset, end):
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -132,6 +132,8 @@
         self.cintf.jitlog_write_marked(jl.MARK_JITLOG_HEADER, blob, len(blob))
 
     def disable_jitlog(self):
+        from rpython.jit.metainterp.debug import flush_debug_counters
+        flush_debug_counters(self.cintf)
         self.cintf.jitlog_teardown()
 
     def disable(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to