[pypy-commit] pypy heapcache-refactor: Starting to port the flags to RefFrontendOp: likely_virtual first

arigo pypy.commits at gmail.com
Thu Mar 17 06:10:03 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: heapcache-refactor
Changeset: r83098:ea3280600306
Date: 2016-03-17 11:09 +0100
http://bitbucket.org/pypy/pypy/changeset/ea3280600306/

Log:	Starting to port the flags to RefFrontendOp: likely_virtual first

diff --git a/rpython/jit/metainterp/heapcache.py b/rpython/jit/metainterp/heapcache.py
--- a/rpython/jit/metainterp/heapcache.py
+++ b/rpython/jit/metainterp/heapcache.py
@@ -1,10 +1,33 @@
-from rpython.jit.metainterp.history import ConstInt
+from rpython.jit.metainterp.history import ConstInt, RefFrontendOp
 from rpython.jit.metainterp.resoperation import rop, OpHelpers
+from rpython.rlib.rarithmetic import r_uint32, r_uint
+from rpython.rlib.objectmodel import always_inline
+
+
+# RefFrontendOp._heapc_flags:
+HF_LIKELY_VIRTUAL = 0x01
+
+ at always_inline
+def add_flags(ref_frontend_op, flags):
+    f = r_uint(ref_frontend_op._heapc_flags)
+    f |= r_uint(flags)
+    ref_frontend_op._heapc_flags = r_uint32(f)
+
+ at always_inline
+def remove_flags(ref_frontend_op, flags):
+    f = r_uint(ref_frontend_op._heapc_flags)
+    f &= r_uint(~flags)
+    ref_frontend_op._heapc_flags = r_uint32(f)
+
+ at always_inline
+def test_flags(ref_frontend_op, flags):
+    f = r_uint(ref_frontend_op._heapc_flags)
+    return bool(f & flags)
+
 
 class HeapCacheValue(object):
     def __init__(self, box):
         self.box = box
-        self.likely_virtual = False
         self.reset_keep_likely_virtual()
 
     def reset_keep_likely_virtual(self):
@@ -84,6 +107,7 @@
 class HeapCache(object):
     def __init__(self):
         self.reset()
+        self.version = r_uint32(1)
 
     def reset(self):
         # maps boxes to HeapCacheValue
@@ -158,14 +182,13 @@
                 self._escape_box(box)
 
     def _escape_box(self, box):
+        if isinstance(box, RefFrontendOp):
+            remove_flags(box, HF_LIKELY_VIRTUAL)
+        #
         value = self.getvalue(box, create=False)
         if not value:
             return
-        self._escape(value)
-
-    def _escape(self, value):
         value.is_unescaped = False
-        value.likely_virtual = False
         deps = value.dependencies
         value.dependencies = None
         if deps is not None:
@@ -301,15 +324,14 @@
         return False
 
     def is_likely_virtual(self, box):
-        value = self.getvalue(box, create=False)
-        if value:
-            return value.likely_virtual
-        return False
+        return (isinstance(box, RefFrontendOp) and
+                    test_flags(box, HF_LIKELY_VIRTUAL))
 
     def new(self, box):
+        assert isinstance(box, RefFrontendOp)
+        add_flags(box, HF_LIKELY_VIRTUAL)
         value = self.getvalue(box)
         value.is_unescaped = True
-        value.likely_virtual = True
         value.seen_allocation = True
 
     def new_array(self, box, lengthbox):
diff --git a/rpython/jit/metainterp/history.py b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -2,7 +2,7 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rlib.objectmodel import we_are_translated, Symbolic
 from rpython.rlib.objectmodel import compute_unique_id, specialize
-from rpython.rlib.rarithmetic import r_int64, is_valid_int
+from rpython.rlib.rarithmetic import r_uint32, r_int64, is_valid_int
 
 from rpython.conftest import option
 
@@ -664,7 +664,10 @@
         self._resfloat = other.getfloatstorage()
 
 class RefFrontendOp(RefOp, FrontendOp):
-    _attrs_ = ('position', '_resref')
+    _attrs_ = ('position', '_resref', '_heapc_flags', '_heapc_version')
+
+    _heapc_flags = r_uint32(0)
+    _heapc_version = r_uint32(0)
 
     def copy_value_from(self, other):
         self._resref = other.getref_base()
diff --git a/rpython/jit/metainterp/test/test_heapcache.py b/rpython/jit/metainterp/test/test_heapcache.py
--- a/rpython/jit/metainterp/test/test_heapcache.py
+++ b/rpython/jit/metainterp/test/test_heapcache.py
@@ -1,6 +1,7 @@
 from rpython.jit.metainterp.heapcache import HeapCache
 from rpython.jit.metainterp.resoperation import rop, InputArgInt
 from rpython.jit.metainterp.history import ConstInt, BasicFailDescr
+from rpython.jit.metainterp.history import RefFrontendOp
 
 box1 = "box1"
 box2 = "box2"
@@ -624,6 +625,7 @@
 
     def test_is_likely_virtual(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
         h.new(box1)
         assert h.is_unescaped(box1)
         assert h.is_likely_virtual(box1)


More information about the pypy-commit mailing list