Commits

Maciej Fijalkowski committed 291fb30

add _freeze_ to the CPU and move movable state somewhere else. this is needed for hacking at hacks

Comments (0)

Files changed (6)

rpython/jit/backend/model.py

 from rpython.jit.metainterp import compile
 from rpython.rtyper.lltypesystem import lltype
 
+class CPUTotalTracker(object):
+    total_compiled_loops = 0
+    total_compiled_bridges = 0
+    total_freed_loops = 0
+    total_freed_bridges = 0    
 
 class AbstractCPU(object):
     supports_floats = False
     # Boxes and Consts are BoxFloats and ConstFloats.
     supports_singlefloats = False
 
-    total_compiled_loops = 0
-    total_compiled_bridges = 0
-    total_freed_loops = 0
-    total_freed_bridges = 0
-
     propagate_exception_descr = None
 
     # for heaptracker
     # _all_size_descrs_with_vtable = None
     _vtable_to_descr_dict = None
 
-
     def __init__(self):
         self.__dict__.update(compile.make_done_loop_tokens())
+        self.tracker = CPUTotalTracker()
+
+    def _freeze_(self):
+        return True
 
     def setup_once(self):
         """Called once by the front-end when the program starts."""
     frame_depth = 0
 
     def __init__(self, cpu, number):
-        cpu.total_compiled_loops += 1
+        cpu.tracker.total_compiled_loops += 1
         self.cpu = cpu
         self.number = number
         self.bridges_count = 0
         return n
 
     def compiling_a_bridge(self):
-        self.cpu.total_compiled_bridges += 1
+        self.cpu.tracker.total_compiled_bridges += 1
         self.bridges_count += 1
         debug_start("jit-mem-looptoken-alloc")
         debug_print("allocating Bridge #", self.bridges_count, "of Loop #", self.number)
         debug_print("freeing Loop #", self.number, 'with',
                     self.bridges_count, 'attached bridges')
         self.cpu.free_loop_and_bridges(self)
-        self.cpu.total_freed_loops += 1
-        self.cpu.total_freed_bridges += self.bridges_count
+        self.cpu.tracker.total_freed_loops += 1
+        self.cpu.tracker.total_freed_bridges += self.bridges_count
         debug_stop("jit-mem-looptoken-free")

rpython/jit/backend/test/runner_test.py

         assert not wr_i1() and not wr_guard()
 
     def test_compile_bridge(self):
-        self.cpu.total_compiled_loops = 0
-        self.cpu.total_compiled_bridges = 0
+        self.cpu.tracker.total_compiled_loops = 0
+        self.cpu.tracker.total_compiled_bridges = 0
         i0 = BoxInt()
         i1 = BoxInt()
         i2 = BoxInt()
         res = self.cpu.get_int_value(deadframe, 0)
         assert res == 20
 
-        assert self.cpu.total_compiled_loops == 1
-        assert self.cpu.total_compiled_bridges == 1
+        assert self.cpu.tracker.total_compiled_loops == 1
+        assert self.cpu.tracker.total_compiled_bridges == 1
         return looptoken
 
     def test_compile_bridge_with_holes(self):

rpython/jit/backend/x86/regalloc.py

         i = 0
         for loc in locs:
             if loc is None: # xxx bit kludgy
-                continue
+                loc = ebp
             arg = inputargs[i]
             i += 1
             if isinstance(loc, RegLoc):

rpython/jit/backend/x86/runner.py

                                        immortal=True)
 
     def force(self, addr_of_force_token):
-        descr = self.gc_ll_descr.getframedescrs(self).arraydescr
+        descr = self.signedarraydescr
         ofs = self.unpack_arraydescr(descr)
         frame = rffi.cast(jitframe.JITFRAMEPTR, addr_of_force_token - ofs)
         frame.jf_descr = frame.jf_force_descr
-        return frame
+        return lltype.cast_opaque_ptr(llmemory.GCREF, frame)
 
     def redirect_call_assembler(self, oldlooptoken, newlooptoken):
         self.assembler.redirect_call_assembler(oldlooptoken, newlooptoken)
         descrs = self.gc_ll_descr.getframedescrs(self)
         ad = descrs.arraydescr
         # the same as normal JITFRAME, however with an array of pointers
+        self.signedarraydescr = ad
         self.refarraydescr = ArrayDescr(ad.basesize, ad.itemsize, ad.lendescr,
                                         FLAG_POINTER)
         self.floatarraydescr = ArrayDescr(ad.basesize, ad.itemsize, ad.lendescr,
         elif type == history.REF:
             descr = self.refarraydescr
         else:
-            descrs = self.gc_ll_descr.getframedescrs(self)
-            descr = descrs.arraydescr
+            descr = self.signedarraydescr
         return JITFRAME_FIXED_SIZE + index, descr
 
 CPU = CPU386

rpython/jit/backend/x86/test/test_gc_integration.py

 """ Tests for register allocation for common constructs
 """
 
-from rpython.jit.metainterp.history import TargetToken, AbstractDescr
-from rpython.jit.backend.llsupport.gc import GcLLDescription, GcLLDescr_boehm
+from rpython.jit.metainterp.history import TargetToken, BasicFinalDescr
+from rpython.jit.backend.llsupport.gc import GcLLDescription, GcLLDescr_boehm,\
+     GcLLDescr_framework
 from rpython.jit.backend.detect_cpu import getcpuclass
 from rpython.jit.backend.x86.arch import WORD
 from rpython.jit.backend.llsupport import jitframe
             s1ref = self.cpu.get_ref_value(self.deadframe, i)
             s1 = lltype.cast_opaque_ptr(lltype.Ptr(S1), s1ref)
             assert s1 == getattr(s2, 's%d' % i)
+
+class TestGcShadowstackDirect(object):
+    
+    cpu = CPU(None, None)
+    cpu.gc_ll_descr = GcLLDescr_framework(None, None, None)
+    cpu.setup_once()
+
+    def test_shadowstack_call(self):
+        ops = parse("""
+        []
+        finish(i0, descr=finaldescr)
+        """, namespace={'finaldescr': BasicFinalDescr()})

rpython/jit/metainterp/jitprof.py

 
     def get_counter(self, num):
         if num == Counters.TOTAL_COMPILED_LOOPS:
-            return self.cpu.total_compiled_loops
+            return self.cpu.tracker.total_compiled_loops
         elif num == Counters.TOTAL_COMPILED_BRIDGES:
-            return self.cpu.total_compiled_bridges
+            return self.cpu.tracker.total_compiled_bridges
         elif num == Counters.TOTAL_FREED_LOOPS:
-            return self.cpu.total_freed_loops
+            return self.cpu.tracker.total_freed_loops
         elif num == Counters.TOTAL_FREED_BRIDGES:
-            return self.cpu.total_freed_bridges
+            return self.cpu.tracker.total_freed_bridges
         return self.counters[num]
 
     def count_ops(self, opnum, kind=Counters.OPS):
         cpu = self.cpu
         if cpu is not None:   # for some tests
             self._print_intline("Total # of loops",
-                                cpu.total_compiled_loops)
+                                cpu.tracker.total_compiled_loops)
             self._print_intline("Total # of bridges",
-                                cpu.total_compiled_bridges)
+                                cpu.tracker.total_compiled_bridges)
             self._print_intline("Freed # of loops",
-                                cpu.total_freed_loops)
+                                cpu.tracker.total_freed_loops)
             self._print_intline("Freed # of bridges",
-                                cpu.total_freed_bridges)
+                                cpu.tracker.total_freed_bridges)
 
     def _print_line_time(self, string, i, tim):
         final = "%s:%s\t%d\t%f" % (string, " " * max(0, 13-len(string)), i, tim)