[pypy-svn] r75117 - in pypy/branch/blackhole-improvement/pypy: jit/backend jit/backend/llgraph jit/backend/llgraph/test jit/backend/llsupport jit/backend/test jit/backend/x86 jit/codewriter jit/codewriter/test jit/metainterp jit/metainterp/test rpython rpython/lltypesystem/test rpython/memory/test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 4 19:24:26 CEST 2010


Author: arigo
Date: Fri Jun  4 19:24:22 2010
New Revision: 75117

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/test/test_llgraph.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/gc.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/llmodel.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/model.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/test/runner_test.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/x86/assembler.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/x86/regalloc.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/x86/ri386.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_assembler.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/logger.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/resoperation.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/oparser.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_optimizefindnode.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_resume.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/typesystem.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/virtualref.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmstate.py
   pypy/branch/blackhole-improvement/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
   pypy/branch/blackhole-improvement/pypy/rpython/memory/test/test_lldict.py
   pypy/branch/blackhole-improvement/pypy/rpython/raddress.py
Log:
Whole bunch of fixes in the jit: call heaptracker.adr2int(),
which calls llmemory.cast_adr_to_int() with the new extra argument.


Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	Fri Jun  4 19:24:22 2010
@@ -970,9 +970,9 @@
 def cast_to_int(x):
     TP = lltype.typeOf(x)
     if isinstance(TP, lltype.Ptr):
-        return llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+        return heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
     if TP == llmemory.Address:
-        return llmemory.cast_adr_to_int(x)
+        return heaptracker.adr2int(x)
     return lltype.cast_primitive(lltype.Signed, x)
 
 def cast_from_int(TYPE, x):
@@ -987,7 +987,7 @@
         return x
     else:
         if lltype.typeOf(x) == llmemory.Address:
-            x = llmemory.cast_adr_to_int(x)
+            x = heaptracker.adr2int(x)
         return lltype.cast_primitive(TYPE, x)
 
 def cast_to_ptr(x):

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py	Fri Jun  4 19:24:22 2010
@@ -15,6 +15,7 @@
 from pypy.jit.backend import model
 from pypy.jit.backend.llgraph import llimpl, symbolic
 from pypy.jit.metainterp.typesystem import llhelper, oohelper
+from pypy.jit.codewriter import heaptracker
 from pypy.rlib import rgc
 
 class MiniStats:
@@ -254,7 +255,7 @@
 
     def get_latest_force_token(self):
         token = llimpl.get_frame_forced_token(self.latest_frame)
-        return llmemory.cast_adr_to_int(token)
+        return heaptracker.adr2int(token)
 
     def clear_latest_values(self, count):
         llimpl.frame_clear_latest_values(self.latest_frame, count)
@@ -357,7 +358,7 @@
         struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
         result = struct.typeptr
         result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
-        return llmemory.cast_adr_to_int(result_adr)
+        return heaptracker.adr2int(result_adr)
 
     def bh_new_array(self, arraydescr, length):
         assert isinstance(arraydescr, Descr)
@@ -437,9 +438,6 @@
             for x in args_f:
                 llimpl.do_call_pushfloat(x)
 
-    def bh_cast_ptr_to_int(self, ptr):
-        return llimpl.cast_to_int(ptr)
-
     def force(self, force_token):
         token = llmemory.cast_int_to_adr(force_token)
         frame = llimpl.get_forced_token_frame(token)

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/test/test_llgraph.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/test/test_llgraph.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/test/test_llgraph.py	Fri Jun  4 19:24:22 2010
@@ -7,6 +7,7 @@
      TreeLoop
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.metainterp.executor import execute
+from pypy.jit.codewriter import heaptracker
 from pypy.jit.backend.test.runner_test import LLtypeBackendTest
 
 class TestLLTypeLLGraph(LLtypeBackendTest):
@@ -24,12 +25,12 @@
     x = lltype.malloc(X, immortal=True)
     x.foo = 42
     a = llmemory.cast_ptr_to_adr(x)
-    i = llmemory.cast_adr_to_int(a)
+    i = heaptracker.adr2int(a)
     assert lltype.typeOf(i) is lltype.Signed
-    a2 = llmemory.cast_int_to_adr(i)
+    a2 = heaptracker.int2adr(i)
     assert llmemory.cast_adr_to_ptr(a2, lltype.Ptr(X)) == x
-    assert llmemory.cast_adr_to_int(llmemory.NULL) == 0
-    assert llmemory.cast_int_to_adr(0) == llmemory.NULL
+    assert heaptracker.adr2int(llmemory.NULL) == 0
+    assert heaptracker.int2adr(0) == llmemory.NULL
 
 ## these tests never worked
 ## class TestOOTypeLLGraph(LLGraphTest):

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/gc.py	Fri Jun  4 19:24:22 2010
@@ -170,8 +170,7 @@
         # first look in the hashtable, using an inexact hash (fails after
         # the object moves)
         addr = llmemory.cast_ptr_to_adr(gcref)
-        hash = llmemory.cast_adr_to_int(addr)
-        hash = rffi.get_real_int(hash)
+        hash = llmemory.cast_adr_to_int(addr, "forced")
         hash -= hash >> self.HASHTABLE_BITS
         hash &= self.HASHTABLE_SIZE - 1
         addr_ref = self.hashtable[hash]

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/llmodel.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/llmodel.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llsupport/llmodel.py	Fri Jun  4 19:24:22 2010
@@ -7,6 +7,7 @@
 from pypy.jit.metainterp.history import BoxInt, BoxPtr, set_future_values,\
      BoxFloat
 from pypy.jit.metainterp import history
+from pypy.jit.codewriter import heaptracker
 from pypy.jit.backend.model import AbstractCPU
 from pypy.jit.backend.llsupport import symbolic
 from pypy.jit.backend.llsupport.symbolic import WORD, unroll_basic_sizes
@@ -18,7 +19,6 @@
 from pypy.jit.backend.llsupport.descr import FloatCallDescr, VoidCallDescr
 from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
 
-empty_int_box = BoxInt(0)
 
 class AbstractLLCPU(AbstractCPU):
     from pypy.jit.metainterp.typesystem import llhelper as ts
@@ -118,11 +118,11 @@
 
         def pos_exception():
             addr = llop.get_exception_addr(llmemory.Address)
-            return llmemory.cast_adr_to_int(addr)
+            return heaptracker.adr2int(addr)
 
         def pos_exc_value():
             addr = llop.get_exc_value_addr(llmemory.Address)
-            return llmemory.cast_adr_to_int(addr)
+            return heaptracker.adr2int(addr)
 
         def save_exception():
             addr = llop.get_exception_addr(llmemory.Address)
@@ -422,7 +422,7 @@
         struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
         result = struct.typeptr
         result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
-        return llmemory.cast_adr_to_int(result_adr)
+        return heaptracker.adr2int(result_adr)
 
     def bh_new_array(self, arraydescr, length):
         return self.gc_ll_descr.gc_malloc_array(arraydescr, length)
@@ -464,6 +464,3 @@
         if not we_are_translated():
             calldescr.verify_types(args_i, args_r, args_f, history.VOID)
         return calldescr.call_stub(func, args_i, args_r, args_f)
-
-    def bh_cast_ptr_to_int(self, ptr):
-        return self.cast_gcref_to_int(ptr)

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/model.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/model.py	Fri Jun  4 19:24:22 2010
@@ -217,9 +217,6 @@
     def bh_call_v(self, func, calldescr, args_i, args_r, args_f):
         raise NotImplementedError
 
-    def bh_cast_ptr_to_int(self, ptr):
-        raise NotImplementedError
-
     def bh_strlen(self, string):
         raise NotImplementedError
     def bh_strgetitem(self, string, index):

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/test/runner_test.py	Fri Jun  4 19:24:22 2010
@@ -1096,7 +1096,7 @@
     @classmethod
     def get_funcbox(cls, cpu, func_ptr):
         addr = llmemory.cast_ptr_to_adr(func_ptr)
-        return ConstInt(llmemory.cast_adr_to_int(addr))
+        return ConstInt(heaptracker.adr2int(addr))
 
     
     MY_VTABLE = rclass.OBJECT_VTABLE    # for tests only
@@ -1128,7 +1128,7 @@
         elif T == self.U:
             t.parent.parent.parent.typeptr = vtable_for_T
         t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
-        T_box = ConstInt(llmemory.cast_adr_to_int(vtable_for_T_addr))
+        T_box = ConstInt(heaptracker.adr2int(vtable_for_T_addr))
         return t_box, T_box
 
     def null_instance(self):
@@ -1157,22 +1157,23 @@
 
 
     def test_casts(self):
+        py.test.skip("xxx fix or kill")
         from pypy.rpython.lltypesystem import lltype, llmemory
         TP = lltype.GcStruct('x')
         x = lltype.malloc(TP)        
         x = lltype.cast_opaque_ptr(llmemory.GCREF, x)
         res = self.execute_operation(rop.CAST_PTR_TO_INT,
                                      [BoxPtr(x)],  'int').value
-        expected = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+        expected = self.cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
         assert rffi.get_real_int(res) == rffi.get_real_int(expected)
         res = self.execute_operation(rop.CAST_PTR_TO_INT,
                                      [ConstPtr(x)],  'int').value
-        expected = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+        expected = self.cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
         assert rffi.get_real_int(res) == rffi.get_real_int(expected)
 
     def test_ooops_non_gc(self):
         x = lltype.malloc(lltype.Struct('x'), flavor='raw')
-        v = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+        v = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
         r = self.execute_operation(rop.PTR_EQ, [BoxInt(v), BoxInt(v)], 'int')
         assert r.value == 1
         r = self.execute_operation(rop.PTR_NE, [BoxInt(v), BoxInt(v)], 'int')
@@ -1202,7 +1203,7 @@
         S = lltype.Struct('S', ('x', lltype.Signed))
         s = lltype.malloc(S, flavor='raw')
         sa = llmemory.cast_ptr_to_adr(s)
-        s_box = BoxInt(llmemory.cast_adr_to_int(sa))
+        s_box = BoxInt(heaptracker.adr2int(sa))
         for get_op, set_op in ((rop.GETFIELD_RAW, rop.SETFIELD_RAW),
                                (rop.GETFIELD_RAW_PURE, rop.SETFIELD_RAW)):
             fd = self.cpu.fielddescrof(S, 'x')
@@ -1593,12 +1594,12 @@
         rs = lltype.malloc(RS, immortal=True)
         rs.x = '?'
         x = cpu.bh_getfield_raw_i(
-            llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs)),
+            heaptracker.adr2int(llmemory.cast_ptr_to_adr(rs)),
             descrfld_rx)
         assert x == ord('?')
         #
         cpu.bh_setfield_raw_i(
-            llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(rs)),
+            heaptracker.adr2int(llmemory.cast_ptr_to_adr(rs)),
             descrfld_rx, ord('!'))
         assert rs.x == '!'
         #
@@ -1636,7 +1637,7 @@
         #
         descrsize2 = cpu.sizeof(rclass.OBJECT)
         vtable2 = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
-        vtable2_int = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(vtable2))
+        vtable2_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(vtable2))
         heaptracker.register_known_gctype(cpu, vtable2, rclass.OBJECT)
         x = cpu.bh_new_with_vtable(descrsize2, vtable2_int)
         lltype.cast_opaque_ptr(lltype.Ptr(rclass.OBJECT), x)    # type check
@@ -1662,12 +1663,12 @@
         cpu.bh_strsetitem(x, 4, ord('/'))
         assert str.chars[4] == '/'
         #
-        x = cpu.bh_newstr(5)
-        y = cpu.bh_cast_ptr_to_int(x)
-        z = cpu.bh_cast_ptr_to_int(x)
-        y = rffi.get_real_int(y)
-        z = rffi.get_real_int(z)
-        assert type(y) == type(z) == int and y == z
+##        x = cpu.bh_newstr(5)
+##        y = cpu.bh_cast_ptr_to_int(x)
+##        z = cpu.bh_cast_ptr_to_int(x)
+##        y = rffi.get_real_int(y)
+##        z = rffi.get_real_int(z)
+##        assert type(y) == type(z) == int and y == z
 
     def test_sorting_of_fields(self):
         S = self.S
@@ -1680,7 +1681,7 @@
 
     def test_guards_nongc(self):
         x = lltype.malloc(lltype.Struct('x'), flavor='raw')
-        v = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+        v = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
         vbox = BoxInt(v)
         ops = [
             (rop.GUARD_NONNULL, vbox, False),

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py	Fri Jun  4 19:24:22 2010
@@ -182,7 +182,7 @@
 # ____________________________________________________________
 
 def ConstAddr(addr, cpu):
-    return ConstInt(llmemory.cast_adr_to_int(addr))
+    return ConstInt(heaptracker.adr2int(addr))
 
 class GuardClassOperation(test_random.GuardOperation):
     def gen_guard(self, builder, r):

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/x86/assembler.py	Fri Jun  4 19:24:22 2010
@@ -749,7 +749,7 @@
 
     def genop_same_as(self, op, arglocs, resloc):
         self.mov(arglocs[0], resloc)
-    genop_cast_ptr_to_int = genop_same_as
+    #genop_cast_ptr_to_int = genop_same_as
 
     def genop_int_mod(self, op, arglocs, resloc):
         self.mc.CDQ()

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/x86/regalloc.py	Fri Jun  4 19:24:22 2010
@@ -871,7 +871,7 @@
         self.possibly_free_var(op.args[0])
         resloc = self.force_allocate_reg(op.result)
         self.Perform(op, [argloc], resloc)
-    consider_cast_ptr_to_int = consider_same_as
+    #consider_cast_ptr_to_int = consider_same_as
 
     def consider_strlen(self, op):
         base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/x86/ri386.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/x86/ri386.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/x86/ri386.py	Fri Jun  4 19:24:22 2010
@@ -1,7 +1,6 @@
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.objectmodel import ComputedIntSymbolic, we_are_translated
 from pypy.rlib.debug import make_sure_not_resized
-from pypy.rpython.lltypesystem.rffi import get_real_int
 
 class OPERAND(object):
     _attrs_ = []
@@ -287,6 +286,10 @@
 rel32 = REL32
 rel8 = REL8
 
+def get_real_int(x):
+    from pypy.rpython.lltypesystem import rffi, lltype
+    return rffi.cast(lltype.Signed, x)    # force as a real int
+
 def imm(value):
     if isinstance(value, ComputedIntSymbolic):
         value = value.compute_fn()

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/assembler.py	Fri Jun  4 19:24:22 2010
@@ -3,6 +3,7 @@
 from pypy.jit.codewriter.flatten import ListOfKind, IndirectCallTargets
 from pypy.jit.codewriter.format import format_assembler
 from pypy.jit.codewriter.jitcode import SwitchDictDescr, JitCode
+from pypy.jit.codewriter import heaptracker
 from pypy.rlib.objectmodel import ComputedIntSymbolic
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype, llmemory, rclass
@@ -69,7 +70,7 @@
                     value = llmemory.cast_ptr_to_adr(value)
                     TYPE = llmemory.Address
                 if TYPE == llmemory.Address:
-                    value = llmemory.cast_adr_to_int(value)
+                    value = heaptracker.adr2int(value)
                 elif not isinstance(value, ComputedIntSymbolic):
                     value = lltype.cast_primitive(lltype.Signed, value)
                     if allow_short and -128 <= value <= 127:

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py	Fri Jun  4 19:24:22 2010
@@ -2,6 +2,16 @@
 from pypy.rlib.objectmodel import we_are_translated
 
 
+def adr2int(addr):
+    # Cast an address to an int.  Returns an AddressAsInt object which
+    # can be cast back to an address.
+    return llmemory.cast_adr_to_int(addr, "symbolic")
+
+def int2adr(int):
+    return llmemory.cast_int_to_adr(int)
+
+# ____________________________________________________________
+
 def has_gcstruct_a_vtable(GCSTRUCT):
     if not isinstance(GCSTRUCT, lltype.GcStruct):
         return False
@@ -69,7 +79,7 @@
 
 def vtable2descr(cpu, vtable):
     assert lltype.typeOf(vtable) is lltype.Signed
-    vtable = llmemory.cast_int_to_adr(vtable)
+    vtable = int2adr(vtable)
     if we_are_translated():
         # Build the dict {vtable: sizedescr} at runtime.
         # This is necessary because the 'vtables' are just pointers to
@@ -94,5 +104,4 @@
     assert isinstance(descr, history.AbstractDescr)
     vtable = descr.as_vtable_size_descr()._corresponding_vtable
     vtable = llmemory.cast_ptr_to_adr(vtable)
-    vtable = llmemory.cast_adr_to_int(vtable)
-    return vtable
+    return adr2int(vtable)

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jitcode.py	Fri Jun  4 19:24:22 2010
@@ -1,4 +1,5 @@
 from pypy.jit.metainterp.history import AbstractDescr
+from pypy.jit.codewriter import heaptracker
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rpython.lltypesystem import llmemory
 
@@ -33,7 +34,7 @@
         self._alllabels = alllabels       # debugging
 
     def get_fnaddr_as_int(self):
-        return llmemory.cast_adr_to_int(self.fnaddr)
+        return heaptracker.adr2int(self.fnaddr)
 
     def num_regs_i(self):
         return self.num_regs_encoded >> 16

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	Fri Jun  4 19:24:22 2010
@@ -675,7 +675,8 @@
 
     def rewrite_op_cast_ptr_to_int(self, op):
         if self._is_gc(op.args[0]):
-            return op
+            #return op
+            raise NotImplementedError("cast_ptr_to_int")
 
     # ----------
     # Renames, from the _old opname to the _new one.

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_assembler.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_assembler.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_assembler.py	Fri Jun  4 19:24:22 2010
@@ -3,6 +3,7 @@
 from pypy.jit.codewriter.flatten import SSARepr, Label, TLabel, Register
 from pypy.jit.codewriter.flatten import ListOfKind, IndirectCallTargets
 from pypy.jit.codewriter.jitcode import MissingLiveness
+from pypy.jit.codewriter import heaptracker
 from pypy.jit.metainterp.history import AbstractDescr
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype, llmemory
@@ -83,7 +84,7 @@
     assert assembler.insns == {'int_return/c': 0,
                                'int_return/i': 1,
                                'ref_return/r': 2}
-    f_int = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(f))
+    f_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(f))
     assert jitcode.constants_i == [0x1234, f_int]
     s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
     assert jitcode.constants_r == [s_gcref]

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	Fri Jun  4 19:24:22 2010
@@ -424,7 +424,7 @@
     assert op1.opname == 'new_with_vtable'
     assert op1.args == [('sizedescr', S)]
     #assert heaptracker.descr2vtable(cpu, op1.args[0]) == vtable [type check]
-    vtable_int = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(vtable))
+    vtable_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(vtable))
     assert heaptracker.vtable2descr(cpu, vtable_int) == op1.args[0]
 
 def test_malloc_new_with_destructor():

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Fri Jun  4 19:24:22 2010
@@ -734,7 +734,7 @@
 
     @arguments("self", "i", "L", "pc", returns="L")
     def bhimpl_goto_if_exception_mismatch(self, vtable, target, pc):
-        adr = llmemory.cast_int_to_adr(vtable)
+        adr = heaptracker.int2adr(vtable)
         bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
         real_instance = self.exception_last_value
         assert real_instance
@@ -748,7 +748,7 @@
         real_instance = self.exception_last_value
         assert real_instance
         adr = llmemory.cast_ptr_to_adr(real_instance.typeptr)
-        return llmemory.cast_adr_to_int(adr)
+        return heaptracker.adr2int(adr)
 
     @arguments("self", returns="r")
     def bhimpl_last_exc_value(self):
@@ -807,7 +807,7 @@
     def get_portal_runner(self):
         metainterp_sd = self.builder.metainterp_sd
         fnptr = llmemory.cast_ptr_to_adr(metainterp_sd._portal_runner_ptr)
-        fnptr = llmemory.cast_adr_to_int(fnptr)
+        fnptr = heaptracker.adr2int(fnptr)
         calldescr = metainterp_sd.portal_code.calldescr
         return fnptr, calldescr
 
@@ -1120,10 +1120,6 @@
     def bhimpl_guard_class(cpu, struct):
         return cpu.bh_classof(struct)
 
-    @arguments("cpu", "r", returns="i")
-    def bhimpl_cast_ptr_to_int(cpu, p):
-        return cpu.bh_cast_ptr_to_int(p)
-
     @arguments("cpu", "i", returns="r")
     def bhimpl_newstr(cpu, length):
         return cpu.bh_newstr(length)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py	Fri Jun  4 19:24:22 2010
@@ -9,6 +9,7 @@
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import ResOperation, rop
+from pypy.jit.codewriter import heaptracker
 
 # ____________________________________________________________
 
@@ -202,7 +203,7 @@
         kind = getkind(T)
         if kind == "int":
             if isinstance(T, lltype.Ptr):
-                intval = llmemory.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
+                intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
             else:
                 intval = lltype.cast_primitive(lltype.Signed, x)
             return ConstInt(intval)
@@ -265,7 +266,7 @@
         return self.value
 
     def getaddr(self):
-        return llmemory.cast_int_to_adr(self.value)
+        return heaptracker.int2adr(self.value)
 
     def _get_hash_(self):
         return make_hashable_int(self.value)
@@ -506,7 +507,7 @@
         return self.value
 
     def getaddr(self):
-        return llmemory.cast_int_to_adr(self.value)
+        return heaptracker.int2adr(self.value)
 
     def _get_hash_(self):
         return make_hashable_int(self.value)
@@ -675,8 +676,8 @@
 def make_hashable_int(i):
     if not we_are_translated() and isinstance(i, llmemory.AddressAsInt):
         # Warning: such a hash changes at the time of translation
-        adr = llmemory.cast_int_to_adr(i)
-        return lltype.cast_ptr_to_int(adr.ptr)
+        adr = heaptracker.int2adr(i)
+        return llmemory.cast_adr_to_int(adr, "emulated")
     return i
 
 # ____________________________________________________________

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/logger.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/logger.py	Fri Jun  4 19:24:22 2010
@@ -2,7 +2,7 @@
 from pypy.rlib.debug import have_debug_prints
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
 from pypy.rlib.objectmodel import we_are_translated
-from pypy.rpython.lltypesystem import llmemory, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import Const, ConstInt, Box, \
      BoxInt, ConstFloat, BoxFloat, AbstractFailDescr
@@ -108,7 +108,7 @@
 
 def int_could_be_an_address(x):
     if we_are_translated():
-        x = rffi.get_real_int(x)
+        x = rffi.cast(lltype.Signed, x)       # force it
         return not (-32768 <= x <= 32767)
     else:
         return isinstance(x, llmemory.AddressAsInt)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	Fri Jun  4 19:24:22 2010
@@ -20,6 +20,7 @@
 from pypy.rlib.objectmodel import specialize
 from pypy.rlib.jit import DEBUG_OFF, DEBUG_PROFILE, DEBUG_STEPS, DEBUG_DETAILED
 from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
+from pypy.jit.codewriter import heaptracker
 
 # ____________________________________________________________
 
@@ -194,8 +195,8 @@
         ''' % (_opimpl, _opimpl.upper())).compile()
 
     for _opimpl in ['int_is_true', 'int_is_zero', 'int_neg', 'int_invert',
-                    'cast_ptr_to_int', 'cast_float_to_int',
-                    'cast_int_to_float', 'float_neg', 'float_abs',
+                    'cast_float_to_int', 'cast_int_to_float',
+                    'float_neg', 'float_abs',
                     ]:
         exec py.code.Source('''
             @arguments("box")
@@ -334,7 +335,6 @@
 
     @arguments("descr")
     def opimpl_new_with_vtable(self, sizedescr):
-        from pypy.jit.codewriter import heaptracker
         cpu = self.metainterp.cpu
         cls = heaptracker.descr2vtable(cpu, sizedescr)
         return self.execute(rop.NEW_WITH_VTABLE, ConstInt(cls))
@@ -672,7 +672,7 @@
             self.verify_green_args(greenboxes)
         #
         k = llmemory.cast_ptr_to_adr(metainterp_sd._portal_runner_ptr)
-        funcbox = ConstInt(llmemory.cast_adr_to_int(k))
+        funcbox = ConstInt(heaptracker.adr2int(k))
         return self.do_residual_call(funcbox, portal_code.calldescr,
                                      allboxes, assembler_call_token=token)
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/resoperation.py	Fri Jun  4 19:24:22 2010
@@ -138,7 +138,6 @@
     #'OOSEND_PURE',    # ootype operation
     'CALL_PURE',
     #
-    'CAST_PTR_TO_INT/1',
     'INT_ADD/2',
     'INT_SUB/2',
     'INT_MUL/2',

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/oparser.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/oparser.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/oparser.py	Fri Jun  4 19:24:22 2010
@@ -8,6 +8,7 @@
      LoopToken
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.typesystem import llhelper
+from pypy.jit.codewriter.heaptracker import adr2int
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.annlowlevel import llstr
@@ -74,8 +75,7 @@
                 return ConstPtr(obj)
             else:
                 assert typ == 'class'
-                return ConstInt(llmemory.cast_adr_to_int(
-                    llmemory.cast_ptr_to_adr(obj)))
+                return ConstInt(adr2int(llmemory.cast_ptr_to_adr(obj)))
         else:
             if typ == 'ptr':
                 return ConstObj(obj)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	Fri Jun  4 19:24:22 2010
@@ -1548,6 +1548,7 @@
         assert self.interp_operations(f, [0, 1]) == expected
 
     def test_casts(self):
+        py.test.skip("xxx fix or kill")
         if not self.basic:
             py.test.skip("test written in a style that "
                          "means it's frontend only")

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_optimizefindnode.py	Fri Jun  4 19:24:22 2010
@@ -17,7 +17,7 @@
 from pypy.jit.metainterp.specnode import VirtualStructSpecNode
 from pypy.jit.metainterp.specnode import ConstantSpecNode
 from pypy.jit.codewriter.effectinfo import EffectInfo
-from pypy.jit.codewriter.heaptracker import register_known_gctype
+from pypy.jit.codewriter.heaptracker import register_known_gctype, adr2int
 from pypy.jit.metainterp.test.oparser import parse
 
 def test_sort_descrs():
@@ -219,9 +219,7 @@
         #
         def constclass(cls_vtable):
             if self.type_system == 'lltype':
-                return ConstInt(
-                    llmemory.cast_adr_to_int(
-                        llmemory.cast_ptr_to_adr(cls_vtable)))
+                return ConstInt(adr2int(llmemory.cast_ptr_to_adr(cls_vtable)))
             else:
                 return ConstObj(ootype.cast_to_object(cls_vtable))
         def constant(value):

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_resume.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_resume.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_resume.py	Fri Jun  4 19:24:22 2010
@@ -7,6 +7,7 @@
 from pypy.jit.metainterp.history import ConstPtr, ConstFloat
 from pypy.jit.metainterp.test.test_optimizefindnode import LLtypeMixin
 from pypy.jit.metainterp import executor
+from pypy.jit.codewriter import heaptracker
 
 class Storage:
     rd_frame_info_list = None
@@ -444,8 +445,8 @@
         pass
 fakeoptimizer = FakeOptimizer_VirtualValue()
 
-def ConstAddr(addr, cpu=None):   # compatibility
-    return ConstInt(llmemory.cast_adr_to_int(addr))
+def ConstAddr(addr, cpu):   # compatibility
+    return ConstInt(heaptracker.adr2int(addr))
 
 def virtual_value(keybox, value, next):
     vv = VirtualValue(fakeoptimizer, ConstAddr(LLtypeMixin.node_vtable_adr,

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/typesystem.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/typesystem.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/typesystem.py	Fri Jun  4 19:24:22 2010
@@ -4,6 +4,7 @@
 from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
 from pypy.rpython.annlowlevel import cast_instance_to_base_obj
 from pypy.jit.metainterp import history
+from pypy.jit.codewriter import heaptracker
 from pypy.rlib.objectmodel import r_dict
 
 def deref(T):
@@ -74,7 +75,7 @@
     def cls_of_box(self, box):
         obj = box.getref(lltype.Ptr(rclass.OBJECT))
         cls = llmemory.cast_ptr_to_adr(obj.typeptr)
-        return history.ConstInt(llmemory.cast_adr_to_int(cls))
+        return history.ConstInt(heaptracker.adr2int(cls))
 
     def instanceOf(self, instbox, clsbox):
         adr = clsbox.getaddr()
@@ -119,7 +120,7 @@
 
     def cast_vtable_to_hashable(self, cpu, ptr):
         adr = llmemory.cast_ptr_to_adr(ptr)
-        return llmemory.cast_adr_to_int(adr)
+        return heaptracker.adr2int(adr)
 
     def cast_from_ref(self, TYPE, value):
         return lltype.cast_opaque_ptr(TYPE, value)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/virtualref.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/virtualref.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/virtualref.py	Fri Jun  4 19:24:22 2010
@@ -1,6 +1,7 @@
 from pypy.rpython.rmodel import inputconst, log
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass
 from pypy.jit.metainterp import history
+from pypy.jit.codewriter import heaptracker
 
 
 class VirtualRefInfo:
@@ -20,7 +21,7 @@
             'jit_virtual_ref')
         # build some constants
         adr = llmemory.cast_ptr_to_adr(self.jit_virtual_ref_vtable)
-        adr = llmemory.cast_adr_to_int(adr)
+        adr = heaptracker.adr2int(adr)
         self.jit_virtual_ref_const_class = history.ConstInt(adr)
         fielddescrof = self.cpu.fielddescrof
         self.descr_virtual_token = fielddescrof(self.JIT_VIRTUAL_REF,

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmstate.py	Fri Jun  4 19:24:22 2010
@@ -12,7 +12,7 @@
 from pypy.rlib.jit import BaseJitCell
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
 from pypy.jit.metainterp import history
-from pypy.jit.codewriter import support
+from pypy.jit.codewriter import support, heaptracker
 
 # ____________________________________________________________
 
@@ -54,7 +54,7 @@
                 return history.BoxPtr(value)
         else:
             adr = llmemory.cast_ptr_to_adr(value)
-            value = llmemory.cast_adr_to_int(adr)
+            value = heaptracker.adr2int(adr)
             # fall through to the end of the function
     elif isinstance(lltype.typeOf(value), ootype.OOType):
         value = ootype.cast_to_object(value)

Modified: pypy/branch/blackhole-improvement/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Fri Jun  4 19:24:22 2010
@@ -1208,9 +1208,9 @@
         S = lltype.Struct('S')
         p = lltype.malloc(S, flavor='raw')
         a = llmemory.cast_ptr_to_adr(p)
-        i = rffi.get_real_int(llmemory.cast_adr_to_int(a))
+        i = llmemory.cast_adr_to_int(a, "forced")
         assert type(i) is int
-        assert i == rffi.get_real_int(llmemory.cast_adr_to_int(a))
+        assert i == llmemory.cast_adr_to_int(a, "forced")
         lltype.free(p, flavor='raw')
 
 class TestPlatform(object):

Modified: pypy/branch/blackhole-improvement/pypy/rpython/memory/test/test_lldict.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/rpython/memory/test/test_lldict.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/rpython/memory/test/test_lldict.py	Fri Jun  4 19:24:22 2010
@@ -100,7 +100,7 @@
     _TYPE = llmemory.Address
     def __init__(self, intval):
         self.intval = intval
-    def _cast_to_int(self):
+    def _cast_to_int(self, symbolic="?"):
         return self.intval
     def __repr__(self):
         return '<intaddr 0x%x>' % (self.intval & (sys.maxint*2+1),)

Modified: pypy/branch/blackhole-improvement/pypy/rpython/raddress.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/rpython/raddress.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/rpython/raddress.py	Fri Jun  4 19:24:22 2010
@@ -57,9 +57,7 @@
     get_ll_fasthash_function = get_ll_hash_function
 
 def ll_addrhash(addr1):
-    # we don't want to have an AddressAsInt instance in this case
-    from pypy.rpython.lltypesystem import rffi
-    return rffi.get_real_int(cast_adr_to_int(addr1))
+    return cast_adr_to_int(addr1, "forced")
 
 address_repr = AddressRepr()
 



More information about the Pypy-commit mailing list