[pypy-svn] r79146 - in pypy/branch/jit-free/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 16 14:14:47 CET 2010


Author: arigo
Date: Tue Nov 16 14:14:45 2010
New Revision: 79146

Modified:
   pypy/branch/jit-free/pypy/jit/metainterp/compile.py
   pypy/branch/jit-free/pypy/jit/metainterp/history.py
   pypy/branch/jit-free/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/jit-free/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/jit-free/pypy/jit/metainterp/test/test_memmgr.py
   pypy/branch/jit-free/pypy/jit/metainterp/warmstate.py
Log:
(antocuni, arigo)
Managed to really really(?) make test_memmgr.py fail.  Argh again.


Modified: pypy/branch/jit-free/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/compile.py	Tue Nov 16 14:14:45 2010
@@ -42,10 +42,11 @@
     name = metainterp.staticdata.stats.name_for_new_loop()
     return TreeLoop(name)
 
-def make_loop_token(cpu, nb_args, jitdriver_sd):
+def make_loop_token(cpu, nb_args, jitdriver_sd, greenkey):
     loop_token = LoopToken(cpu)
     loop_token.specnodes = [prebuiltNotSpecNode] * nb_args
     loop_token.outermost_jitdriver_sd = jitdriver_sd
+    loop_token.outermost_greenkey = greenkey
     return loop_token
 
 # ____________________________________________________________
@@ -64,8 +65,10 @@
     loop.operations = [h_ops[i].clone() for i in range(start, len(h_ops))]
     metainterp_sd = metainterp.staticdata
     jitdriver_sd = metainterp.jitdriver_sd
-    loop_token = make_loop_token(metainterp.cpu, len(loop.inputargs),
-                                 jitdriver_sd)
+    loop_token = metainterp.original_loop_token
+    assert len(loop_token.specnodes) == len(loop.inputargs)
+    assert loop_token.outermost_jitdriver_sd is jitdriver_sd
+    assert loop_token.outermost_greenkey == greenkey
     loop.token = loop_token
     loop.operations[-1].setdescr(loop_token)     # patch the target of the JUMP
     try:
@@ -78,7 +81,9 @@
         return old_loop_token
     send_loop_to_backend(metainterp_sd, loop, "loop")
     insert_loop_token(old_loop_tokens, loop_token)
+    # mostly for tests: make sure we don't keep a reference to the LoopToken
     loop.token = None
+    metainterp.original_loop_token = None
     return loop_token
 
 def insert_loop_token(old_loop_tokens, loop_token):
@@ -210,8 +215,8 @@
             }
 
 class ResumeDescr(AbstractFailDescr):
-    def __init__(self, original_greenkey):
-        self.original_greenkey = original_greenkey
+    def __init__(self, wref_original_loop_token):
+        self.wref_original_loop_token = wref_original_loop_token
 
 class ResumeGuardDescr(ResumeDescr):
     _counter = 0        # if < 0, there is one counter per value;
@@ -317,7 +322,7 @@
         # to the corrsponding guard_op and compile from there
         inputargs = metainterp.history.inputargs
         if not we_are_translated():
-            pass #self._debug_suboperations = new_loop.operations
+            self._debug_suboperations = new_loop.operations
         send_bridge_to_backend(metainterp.staticdata, self, inputargs,
                                new_loop.operations)
 
@@ -331,14 +336,14 @@
         res.rd_pendingfields = self.rd_pendingfields
 
     def _clone_if_mutable(self):
-        res = ResumeGuardDescr(self.original_greenkey)
+        res = ResumeGuardDescr(self.wref_original_loop_token)
         self.copy_all_attrbutes_into(res)
         return res
 
 class ResumeGuardForcedDescr(ResumeGuardDescr):
 
-    def __init__(self, metainterp_sd, original_greenkey, jitdriver_sd):
-        ResumeGuardDescr.__init__(self, original_greenkey)
+    def __init__(self, metainterp_sd, wref_original_loop_token, jitdriver_sd):
+        ResumeGuardDescr.__init__(self, wref_original_loop_token)
         self.metainterp_sd = metainterp_sd
         self.jitdriver_sd = jitdriver_sd
 
@@ -406,7 +411,7 @@
 
     def _clone_if_mutable(self):
         res = ResumeGuardForcedDescr(self.metainterp_sd,
-                                     self.original_greenkey,
+                                     self.wref_original_loop_token,
                                      self.jitdriver_sd)
         self.copy_all_attrbutes_into(res)
         return res
@@ -473,8 +478,8 @@
 
 
 class ResumeFromInterpDescr(ResumeDescr):
-    def __init__(self, original_greenkey, redkey):
-        ResumeDescr.__init__(self, original_greenkey)
+    def __init__(self, wref_original_loop_token, redkey):
+        ResumeDescr.__init__(self, wref_original_loop_token)
         self.redkey = redkey
 
     def compile_and_attach(self, metainterp, new_loop):
@@ -485,24 +490,28 @@
         metainterp_sd = metainterp.staticdata
         jitdriver_sd = metainterp.jitdriver_sd
         metainterp.history.inputargs = self.redkey
-        new_loop_token = make_loop_token(metainterp.cpu, len(self.redkey),
-                                         metainterp.jitdriver_sd)
+        new_loop_token = metainterp.original_loop_token
+        # assert that the wref_original_loop_token was kept alive, because
+        # it's just the same as metainterp.original_loop_token
+        assert new_loop_token is self.wref_original_loop_token()
         new_loop.inputargs = self.redkey
         new_loop.token = new_loop_token
         send_loop_to_backend(metainterp_sd, new_loop, "entry bridge")
         # send the new_loop to warmspot.py, to be called directly the next time
         jitdriver_sd.warmstate.attach_unoptimized_bridge_from_interp(
-            self.original_greenkey,
             new_loop_token)
         # store the new loop in compiled_merge_points_wref too
         old_loop_tokens = metainterp.get_compiled_merge_points(
-            self.original_greenkey)
+            new_loop_token.outermost_greenkey)
         # it always goes at the end of the list, as it is the most
         # general loop token
         old_loop_tokens.append(new_loop_token)
-        metainterp.set_compiled_merge_points(self.original_greenkey,
+        metainterp.set_compiled_merge_points(new_loop_token.outermost_greenkey,
                                              old_loop_tokens)
+        # mostly for tests: make sure we don't keep a reference
+        # to the LoopToken
         new_loop.token = None
+        metainterp.original_loop_token = None
 
     def reset_counter_from_failure(self):
         pass
@@ -570,7 +579,7 @@
     """
     # 'redboxes' is only used to know the types of red arguments.
     inputargs = [box.clonebox() for box in redboxes]
-    loop_token = make_loop_token(cpu, len(inputargs), jitdriver_sd)
+    loop_token = make_loop_token(cpu, len(inputargs), jitdriver_sd, greenboxes)
     # 'nb_red_args' might be smaller than len(redboxes),
     # because it doesn't include the virtualizable boxes.
     nb_red_args = jitdriver_sd.num_red_args

Modified: pypy/branch/jit-free/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/history.py	Tue Nov 16 14:14:45 2010
@@ -730,13 +730,14 @@
     """
     terminating = False # see TerminatingLoopToken in compile.py
     outermost_jitdriver_sd = None
+    outermost_greenkey     = None
     # specnodes = ...
     # and more data specified by the backend when the loop is compiled
     cpu = None
-    number = 0
+    number = -1
 
     def __init__(self, cpu=None):
-        assert not isinstance(cpu, int)    # xxx temporary
+        assert 'CPU' in type(cpu).__name__   # xxx temporary
         self.cpu = cpu
         # See get_fail_descr_number() in backend/model.py: this growing
         # list gives the 'descr_number' of all fail descrs that belong to
@@ -749,7 +750,7 @@
     def __del__(self):
         for i in range(160):
             print '#',
-        print
+        print repr(self), self.cpu
         if self.cpu is None:
             return
         if self.generation > r_longlong(0):

Modified: pypy/branch/jit-free/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/pyjitpl.py	Tue Nov 16 14:14:45 2010
@@ -1,4 +1,4 @@
-import py, os, sys
+import py, os, sys, weakref
 from pypy.rpython.lltypesystem import lltype, llmemory, rclass
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
@@ -1048,13 +1048,14 @@
         else:
             moreargs = list(extraargs)
         metainterp_sd = metainterp.staticdata
-        original_greenkey = metainterp.resumekey.original_greenkey
+        resumekey = metainterp.resumekey
+        wref_original_loop_token = resumekey.wref_original_loop_token
         if opnum == rop.GUARD_NOT_FORCED:
             resumedescr = compile.ResumeGuardForcedDescr(metainterp_sd,
-                                                   original_greenkey,
+                                                   wref_original_loop_token,
                                                    metainterp.jitdriver_sd)
         else:
-            resumedescr = compile.ResumeGuardDescr(original_greenkey)
+            resumedescr = compile.ResumeGuardDescr(wref_original_loop_token)
         guard_op = metainterp.history.record(opnum, moreargs, None,
                                              descr=resumedescr)
         virtualizable_boxes = None
@@ -1642,8 +1643,15 @@
         num_green_args = self.jitdriver_sd.num_green_args
         original_greenkey = original_boxes[:num_green_args]
         redkey = original_boxes[num_green_args:]
-        self.resumekey = compile.ResumeFromInterpDescr(original_greenkey,
-                                                       redkey)
+        # make a new loop token and store a strong ref to it for as long as
+        # this MetaInterp is alive (we will give it to the MemoryManager after
+        # the backend has emitted assembler)
+        self.original_loop_token = compile.make_loop_token(self.cpu,
+                                                           len(redkey),
+                                                           self.jitdriver_sd,
+                                                           original_greenkey)
+        self.resumekey = compile.ResumeFromInterpDescr(
+            weakref.ref(self.original_loop_token), redkey)
         self.seen_loop_header_for_jdindex = -1
         try:
             self.interpret()
@@ -1666,15 +1674,20 @@
             debug_stop('jit-tracing')
 
     def _handle_guard_failure(self, key):
-        original_greenkey = key.original_greenkey
-        # notice that here we just put the greenkey
-        # use -1 to mark that we will have to give up
-        # because we cannot reconstruct the beginning of the proper loop
-        self.current_merge_points = [(original_greenkey, -1)]
+        # store the original_loop_token on 'self' to make sure that it stays
+        # alive as long as this MetaInterp
         self.resumekey = key
-        self.seen_loop_header_for_jdindex = -1
+        self.original_loop_token = key.wref_original_loop_token()
         try:
             self.prepare_resume_from_failure(key.guard_opnum)
+            if self.original_loop_token is None:
+                raise SwitchToBlackhole(ABORT_BRIDGE)
+            # notice that here we just put the greenkey
+            # use -1 to mark that we will have to give up
+            # because we cannot reconstruct the beginning of the proper loop
+            original_greenkey = self.original_loop_token.outermost_greenkey
+            self.current_merge_points = [(original_greenkey, -1)]
+            self.seen_loop_header_for_jdindex = -1
             self.interpret()
         except GenerateMergePoint, gmp:
             return self.designate_target_loop(gmp)

Modified: pypy/branch/jit-free/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/test/test_basic.py	Tue Nov 16 14:14:45 2010
@@ -26,7 +26,7 @@
             self.__compiled_merge_points = lst
 
     class FakeWarmRunnerState:
-        def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
+        def attach_unoptimized_bridge_from_interp(self, newloop):
             pass
 
         def jit_cell_at_key(self, greenkey):

Modified: pypy/branch/jit-free/pypy/jit/metainterp/test/test_memmgr.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/test/test_memmgr.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/test/test_memmgr.py	Tue Nov 16 14:14:45 2010
@@ -79,3 +79,7 @@
 
         # we should see only the loop and the entry bridge
         self.check_tree_loop_count(2)
+
+
+    # we need another test that fails because we store
+    # self._debug_suboperations in compile.py

Modified: pypy/branch/jit-free/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/branch/jit-free/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/branch/jit-free/pypy/jit/metainterp/warmstate.py	Tue Nov 16 14:14:45 2010
@@ -255,9 +255,8 @@
         debug_print("disabled inlining", loc)
         debug_stop("jit-disableinlining")
 
-    def attach_unoptimized_bridge_from_interp(self, greenkey,
-                                              entry_loop_token):
-        cell = self.jit_cell_at_key(greenkey)
+    def attach_unoptimized_bridge_from_interp(self, entry_loop_token):
+        cell = self.jit_cell_at_key(entry_loop_token.outermost_greenkey)
         cell.counter = -1
         old_token = cell.get_entry_loop_token()
         cell.set_entry_loop_token(entry_loop_token)
@@ -341,6 +340,7 @@
             # ---------- execute assembler ----------
             while True:     # until interrupted by an exception
                 fail_descr = warmrunnerdesc.execute_token(loop_token)
+                loop_token = None     # for test_memmgr
                 if vinfo is not None:
                     vinfo.reset_vable_token(virtualizable)
                 loop_token = fail_descr.handle_fail(metainterp_sd,



More information about the Pypy-commit mailing list