Author: Ronan Lamy <[email protected]>
Branch: jit-cleanup
Changeset: r96416:12b8316618ca
Date: 2019-04-05 00:52 +0100
http://bitbucket.org/pypy/pypy/changeset/12b8316618ca/

Log:    move some utility functions from heaptracker to
        rpython.jit.metainterp.support

diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -9,6 +9,7 @@
 from rpython.jit.metainterp.resoperation import rop
 from rpython.jit.metainterp.optimizeopt import intbounds
 from rpython.jit.metainterp.optimize import SpeculativeError
+from rpython.jit.metainterp.support import adr2int, int2adr, int_signext
 from rpython.jit.codewriter import longlong, heaptracker
 from rpython.jit.codewriter.effectinfo import EffectInfo
 
@@ -136,7 +137,7 @@
         if self._vtable is Ellipsis:
             self._vtable = heaptracker.get_vtable_for_gcstruct(self._runner,
                                                                self.S)
-        return heaptracker.adr2int(llmemory.cast_ptr_to_adr(self._vtable))
+        return adr2int(llmemory.cast_ptr_to_adr(self._vtable))
 
     def is_immutable(self):
         return heaptracker.is_immutable_struct(self.S)
@@ -877,7 +878,7 @@
     def bh_classof(self, struct):
         struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
         result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
-        return heaptracker.adr2int(result_adr)
+        return adr2int(result_adr)
 
     # vector operations
     vector_arith_code = """
@@ -977,7 +978,7 @@
     bh_vec_expand_i = _bh_vec_expand
 
     def bh_vec_int_signext(self, vx, ext, count):
-        return [heaptracker.int_signext(_vx, ext) for _vx in vx]
+        return [int_signext(_vx, ext) for _vx in vx]
 
     def build_load(func):
         def load(self, struct, offset, scale, disp, descr, _count):
@@ -1551,7 +1552,7 @@
         return res
 
     def execute_restore_exception(self, descr, kls, e):
-        kls = heaptracker.int2adr(kls)
+        kls = int2adr(kls)
         if e:
             value = lltype.cast_opaque_ptr(rclass.OBJECTPTR, e)
             assert llmemory.cast_ptr_to_adr(value.typeptr) == kls
diff --git a/rpython/jit/backend/llgraph/support.py 
b/rpython/jit/backend/llgraph/support.py
--- a/rpython/jit/backend/llgraph/support.py
+++ b/rpython/jit/backend/llgraph/support.py
@@ -1,7 +1,6 @@
 
 from rpython.jit.codewriter import longlong
-from rpython.jit.codewriter import heaptracker
-
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.metainterp.history import getkind
 
 from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint
@@ -20,9 +19,9 @@
 def cast_to_int(x):
     TP = lltype.typeOf(x)
     if isinstance(TP, lltype.Ptr):
-        return heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
+        return adr2int(llmemory.cast_ptr_to_adr(x))
     if TP == llmemory.Address:
-        return heaptracker.adr2int(x)
+        return adr2int(x)
     if TP is lltype.SingleFloat:
         return longlong.singlefloat2int(x)
     return lltype.cast_primitive(lltype.Signed, x)
@@ -82,7 +81,7 @@
         return longlong.int2singlefloat(x)
     else:
         if lltype.typeOf(x) == llmemory.Address:
-            x = heaptracker.adr2int(x)
+            x = adr2int(x)
         return lltype.cast_primitive(TYPE, x)
 
 def cast_from_ptr(TYPE, x):
diff --git a/rpython/jit/backend/llgraph/test/test_llgraph.py 
b/rpython/jit/backend/llgraph/test/test_llgraph.py
--- a/rpython/jit/backend/llgraph/test/test_llgraph.py
+++ b/rpython/jit/backend/llgraph/test/test_llgraph.py
@@ -1,6 +1,4 @@
 import py
-from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.jit.codewriter import heaptracker
 from rpython.jit.backend.test.runner_test import LLtypeBackendTest
 from rpython.jit.backend.llgraph.runner import LLGraphCPU
 
@@ -17,16 +15,3 @@
 
     def test_call_release_gil_variable_function_and_arguments(self):
         py.test.skip("the arguments seem not correctly casted")
-
-
-def test_cast_adr_to_int_and_back():
-    X = lltype.Struct('X', ('foo', lltype.Signed))
-    x = lltype.malloc(X, immortal=True)
-    x.foo = 42
-    a = llmemory.cast_ptr_to_adr(x)
-    i = heaptracker.adr2int(a)
-    assert lltype.typeOf(i) is lltype.Signed
-    a2 = heaptracker.int2adr(i)
-    assert llmemory.cast_adr_to_ptr(a2, lltype.Ptr(X)) == x
-    assert heaptracker.adr2int(llmemory.NULL) == 0
-    assert heaptracker.int2adr(0) == llmemory.NULL
diff --git a/rpython/jit/backend/llsupport/descr.py 
b/rpython/jit/backend/llsupport/descr.py
--- a/rpython/jit/backend/llsupport/descr.py
+++ b/rpython/jit/backend/llsupport/descr.py
@@ -4,6 +4,7 @@
 from rpython.jit.backend.llsupport import symbolic, support
 from rpython.jit.metainterp.history import AbstractDescr, getkind, FLOAT, INT
 from rpython.jit.metainterp import history
+from rpython.jit.metainterp.support import adr2int, int2adr
 from rpython.jit.codewriter import heaptracker, longlong
 from rpython.jit.codewriter.longlong import is_longlong
 from rpython.jit.metainterp.optimizeopt import intbounds
@@ -84,7 +85,7 @@
     def is_valid_class_for(self, struct):
         objptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
         cls = llmemory.cast_adr_to_ptr(
-            heaptracker.int2adr(self.get_vtable()),
+            int2adr(self.get_vtable()),
             lltype.Ptr(rclass.OBJECT_VTABLE))
         # this first comparison is necessary, since we want to make sure
         # that vtable for JitVirtualRef is the same without actually reading
@@ -95,7 +96,7 @@
         return self.immutable_flag
 
     def get_vtable(self):
-        return heaptracker.adr2int(llmemory.cast_ptr_to_adr(self.vtable))
+        return adr2int(llmemory.cast_ptr_to_adr(self.vtable))
 
     def get_type_id(self):
         assert self.tid
diff --git a/rpython/jit/backend/llsupport/gc.py 
b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -11,6 +11,7 @@
 from rpython.jit.codewriter import heaptracker
 from rpython.jit.metainterp.history import ConstPtr, AbstractDescr, ConstInt
 from rpython.jit.metainterp.resoperation import rop, ResOperation
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.backend.llsupport import symbolic, jitframe
 from rpython.jit.backend.llsupport.symbolic import WORD
 from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr, 
FieldDescr
@@ -66,7 +67,7 @@
     @specialize.arg(1)
     def get_malloc_fn_addr(self, funcname):
         ll_func = self.get_malloc_fn(funcname)
-        return heaptracker.adr2int(llmemory.cast_ptr_to_adr(ll_func))
+        return adr2int(llmemory.cast_ptr_to_adr(ll_func))
 
     def _freeze_(self):
         return True
diff --git a/rpython/jit/backend/llsupport/llmodel.py 
b/rpython/jit/backend/llsupport/llmodel.py
--- a/rpython/jit/backend/llsupport/llmodel.py
+++ b/rpython/jit/backend/llsupport/llmodel.py
@@ -8,7 +8,8 @@
 from rpython.rlib.objectmodel import we_are_translated, specialize, 
compute_hash
 from rpython.jit.metainterp import history, compile
 from rpython.jit.metainterp.optimize import SpeculativeError
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.metainterp.support import adr2int
+from rpython.jit.codewriter import longlong
 from rpython.jit.backend.model import AbstractCPU
 from rpython.jit.backend.llsupport import symbolic, jitframe
 from rpython.jit.backend.llsupport.symbolic import WORD, unroll_basic_sizes
@@ -158,7 +159,7 @@
             graph = mixlevelann.getgraph(realloc_frame, args_s, s_result)
             fptr = mixlevelann.graph2delayed(graph, FUNC)
             mixlevelann.finish()
-        self.realloc_frame = 
heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
+        self.realloc_frame = adr2int(llmemory.cast_ptr_to_adr(fptr))
 
         if not translate_support_code:
             fptr = llhelper(FUNC_TP, realloc_frame_crash)
@@ -170,7 +171,7 @@
             graph = mixlevelann.getgraph(realloc_frame_crash, args_s, s_result)
             fptr = mixlevelann.graph2delayed(graph, FUNC)
             mixlevelann.finish()
-        self.realloc_frame_crash = 
heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
+        self.realloc_frame_crash = adr2int(llmemory.cast_ptr_to_adr(fptr))
 
     def _setup_exception_handling_untranslated(self):
         # for running un-translated only, all exceptions occurring in the
@@ -207,11 +208,11 @@
 
         def pos_exception():
             addr = llop.get_exception_addr(llmemory.Address)
-            return heaptracker.adr2int(addr)
+            return adr2int(addr)
 
         def pos_exc_value():
             addr = llop.get_exc_value_addr(llmemory.Address)
-            return heaptracker.adr2int(addr)
+            return adr2int(addr)
 
         from rpython.rlib import rstack
 
@@ -775,7 +776,7 @@
     def bh_classof(self, struct):
         struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
         result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
-        return heaptracker.adr2int(result_adr)
+        return adr2int(result_adr)
 
     def bh_new_array(self, length, arraydescr):
         return self.gc_ll_descr.gc_malloc_array(length, arraydescr)
diff --git a/rpython/jit/backend/llsupport/rewrite.py 
b/rpython/jit/backend/llsupport/rewrite.py
--- a/rpython/jit/backend/llsupport/rewrite.py
+++ b/rpython/jit/backend/llsupport/rewrite.py
@@ -6,7 +6,7 @@
 from rpython.jit.metainterp.history import (
     ConstInt, ConstPtr, JitCellToken, new_ref_dict)
 from rpython.jit.metainterp.resoperation import ResOperation, rop, OpHelpers
-from rpython.jit.codewriter import heaptracker
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.backend.llsupport.symbolic import (WORD,
         get_field_token, get_array_token)
 from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr
@@ -607,7 +607,7 @@
         loop_token = op.getdescr()
         assert isinstance(loop_token, JitCellToken)
         jfi = loop_token.compiled_loop_token.frame_info
-        llfi = heaptracker.adr2int(llmemory.cast_ptr_to_adr(jfi))
+        llfi = adr2int(llmemory.cast_ptr_to_adr(jfi))
         frame = self.gen_malloc_frame(llfi)
         self.emit_setfield(frame, ConstInt(llfi),
                            descr=descrs.jf_frame_info)
diff --git a/rpython/jit/backend/test/calling_convention_test.py 
b/rpython/jit/backend/test/calling_convention_test.py
--- a/rpython/jit/backend/test/calling_convention_test.py
+++ b/rpython/jit/backend/test/calling_convention_test.py
@@ -2,11 +2,12 @@
 from rpython.jit.metainterp.history import BasicFinalDescr,\
      JitCellToken, ConstInt, ConstFloat
 from rpython.jit.metainterp.resoperation import rop, InputArgInt, InputArgFloat
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.tool.oparser import parse
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper.annlowlevel import llhelper
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.jit.backend.detect_cpu import getcpuclass
 from rpython.jit.backend.test.runner_test import Runner
 import py
@@ -50,7 +51,7 @@
     @classmethod
     def get_funcbox(cls, cpu, func_ptr):
         addr = llmemory.cast_ptr_to_adr(func_ptr)
-        return ConstInt(heaptracker.adr2int(addr))
+        return ConstInt(adr2int(addr))
 
     def test_call_aligned_with_spilled_values(self):
         cpu = self.cpu
diff --git a/rpython/jit/backend/test/runner_test.py 
b/rpython/jit/backend/test/runner_test.py
--- a/rpython/jit/backend/test/runner_test.py
+++ b/rpython/jit/backend/test/runner_test.py
@@ -11,13 +11,14 @@
 from rpython.jit.metainterp.resoperation import (
     ResOperation, rop, InputArgInt, InputArgFloat, InputArgRef)
 from rpython.jit.metainterp.executor import wrap_constant
+from rpython.jit.metainterp.support import adr2int, int_signext
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.tool.oparser import parse
 from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rffi
 from rpython.rtyper import rclass
 from rpython.rtyper.annlowlevel import llhelper
 from rpython.rtyper.llinterp import LLException
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.rlib import longlong2float
 from rpython.rlib.rarithmetic import intmask, is_valid_int
 from rpython.jit.backend.detect_cpu import autodetect
@@ -1846,7 +1847,7 @@
     @classmethod
     def get_funcbox(cls, cpu, func_ptr):
         addr = llmemory.cast_ptr_to_adr(func_ptr)
-        return ConstInt(heaptracker.adr2int(addr))
+        return ConstInt(adr2int(addr))
 
 
     MY_VTABLE = rclass.OBJECT_VTABLE    # for tests only
@@ -1897,7 +1898,7 @@
             T_box = None
         else:
             vtable = vtable_for_T
-            T_box = ConstInt(heaptracker.adr2int(vtable_for_T_addr))
+            T_box = ConstInt(adr2int(vtable_for_T_addr))
         descr = cpu.sizeof(T, vtable)
         return t_box, T_box, descr
 
@@ -1986,7 +1987,7 @@
 
     def test_ooops_non_gc(self):
         x = lltype.malloc(lltype.Struct('x'), flavor='raw')
-        v = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
+        v = adr2int(llmemory.cast_ptr_to_adr(x))
         r = self.execute_operation(rop.PTR_EQ, [InputArgInt(v), 
InputArgInt(v)], 'int')
         assert r == 1
         r = self.execute_operation(rop.PTR_NE, [InputArgInt(v), 
InputArgInt(v)], 'int')
@@ -2779,7 +2780,7 @@
 
         cpu = self.cpu
         func_adr = llmemory.cast_ptr_to_adr(c_GetCurrentDir.funcsym)
-        funcbox = ConstInt(heaptracker.adr2int(func_adr))
+        funcbox = ConstInt(adr2int(func_adr))
         calldescr = cpu._calldescr_dynamic_for_tests(
             [types.ulong, types.pointer],
             types.ulong,
@@ -3619,12 +3620,12 @@
         rs = lltype.malloc(RS, immortal=True)
         rs.x = '?'
         x = cpu.bh_getfield_raw_i(
-            heaptracker.adr2int(llmemory.cast_ptr_to_adr(rs)),
+            adr2int(llmemory.cast_ptr_to_adr(rs)),
             descrfld_rx)
         assert x == ord('?')
         #
         cpu.bh_setfield_raw_i(
-            heaptracker.adr2int(llmemory.cast_ptr_to_adr(rs)),
+            adr2int(llmemory.cast_ptr_to_adr(rs)),
             ord('!'), descrfld_rx)
         assert rs.x == '!'
         #
@@ -3699,7 +3700,7 @@
 
     def test_guards_nongc(self):
         x = lltype.malloc(lltype.Struct('x'), flavor='raw')
-        v = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
+        v = adr2int(llmemory.cast_ptr_to_adr(x))
         vbox = InputArgInt(v)
         ops = [
             (rop.GUARD_NONNULL, vbox, False),
@@ -3907,7 +3908,7 @@
         a = lltype.malloc(ARRAY, 10, flavor='raw')
         a[7] = -4242
         addr = llmemory.cast_ptr_to_adr(a)
-        abox = InputArgInt(heaptracker.adr2int(addr))
+        abox = InputArgInt(adr2int(addr))
         r1 = self.execute_operation(rop.GETARRAYITEM_RAW_I, [abox, 
InputArgInt(7)],
                                     'int', descr=descr)
         assert r1 == -4242
@@ -3918,7 +3919,7 @@
         descr = self.cpu.arraydescrof(ARRAY)
         a = lltype.malloc(ARRAY, 10, flavor='raw')
         addr = llmemory.cast_ptr_to_adr(a)
-        abox = InputArgInt(heaptracker.adr2int(addr))
+        abox = InputArgInt(adr2int(addr))
         self.execute_operation(rop.SETARRAYITEM_RAW, [abox, InputArgInt(5),
                                                       InputArgInt(12345)],
                                'void', descr=descr)
@@ -4192,7 +4193,7 @@
             value = intmask(0xFFEEDDCCBBAA9988)
             expected = rffi.cast(lltype.Signed, rffi.cast(RESTYPE, value))
             a[3] = rffi.cast(RESTYPE, value)
-            a_rawint = heaptracker.adr2int(llmemory.cast_ptr_to_adr(a))
+            a_rawint = adr2int(llmemory.cast_ptr_to_adr(a))
             x = cpu.bh_getarrayitem_raw_i(a_rawint, 3, descrarray)
             assert x == expected, (
                 "%r: got %r, expected %r" % (RESTYPE, x, expected))
@@ -4213,7 +4214,7 @@
             value = intmask(0xFFEEDDCCBBAA9988)
             expected = rffi.cast(lltype.Signed, rffi.cast(RESTYPE, value))
             a[3] = rffi.cast(RESTYPE, value)
-            a_rawint = heaptracker.adr2int(llmemory.cast_ptr_to_adr(a))
+            a_rawint = adr2int(llmemory.cast_ptr_to_adr(a))
             res = self.execute_operation(rop.GETARRAYITEM_RAW_I,
                                          [InputArgInt(a_rawint), 
InputArgInt(3)],
                                          'int', descr=descrarray)
@@ -4547,7 +4548,7 @@
             for test_case in test_cases:
                 deadframe = self.cpu.execute_token(looptoken, test_case)
                 got = self.cpu.get_int_value(deadframe, 0)
-                expected = heaptracker.int_signext(test_case, numbytes)
+                expected = int_signext(test_case, numbytes)
                 assert got == expected
 
     def test_compile_asmlen(self):
@@ -5069,7 +5070,7 @@
         a[0] = rffi.cast(rffi.SHORT, 666)
         a[1] = rffi.cast(rffi.SHORT, 777)
         addr = llmemory.cast_ptr_to_adr(a)
-        a_int = heaptracker.adr2int(addr)
+        a_int = adr2int(addr)
         print 'a_int:', a_int
         self.execute_operation(rop.SETARRAYITEM_RAW,
                                [ConstInt(a_int), ConstInt(0), ConstInt(-7654)],
@@ -5104,7 +5105,7 @@
             arraydescr = self.cpu.arraydescrof(A)
             a = lltype.malloc(A, 100)
             addr = llmemory.cast_ptr_to_adr(a)
-            a_int = heaptracker.adr2int(addr)
+            a_int = adr2int(addr)
             a_ref = lltype.cast_opaque_ptr(llmemory.GCREF, a)
             for (start, length) in [(0, 100), (49, 49), (1, 98),
                                     (15, 9), (10, 10), (47, 0),
@@ -5259,7 +5260,7 @@
         xptr = lltype.malloc(X)
         xptr.parent.typeptr = xtp
         x_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, xptr))
-        X_box = ConstInt(heaptracker.adr2int(llmemory.cast_ptr_to_adr(xtp)))
+        X_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(xtp)))
 
         ytp = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
         ytp.subclassrange_min = 2
@@ -5270,7 +5271,7 @@
         yptr = lltype.malloc(Y)
         yptr.parent.parent.typeptr = ytp
         y_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, yptr))
-        Y_box = ConstInt(heaptracker.adr2int(llmemory.cast_ptr_to_adr(ytp)))
+        Y_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(ytp)))
 
         ztp = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
         ztp.subclassrange_min = 4
@@ -5282,7 +5283,7 @@
         zptr = lltype.malloc(Z)
         zptr.parent.typeptr = ztp
         z_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, zptr))
-        Z_box = ConstInt(heaptracker.adr2int(llmemory.cast_ptr_to_adr(ztp)))
+        Z_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(ztp)))
 
         for num, arg, klass, is_subclass in [
                 (1, x_box, X_box, True),
diff --git a/rpython/jit/backend/test/test_ll_random.py 
b/rpython/jit/backend/test/test_ll_random.py
--- a/rpython/jit/backend/test/test_ll_random.py
+++ b/rpython/jit/backend/test/test_ll_random.py
@@ -5,6 +5,7 @@
 from rpython.jit.backend.test.test_random import getint, getref_base, getref
 from rpython.jit.metainterp.resoperation import ResOperation, rop, optypes
 from rpython.jit.metainterp.history import ConstInt, ConstPtr, getkind
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.codewriter import heaptracker
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.rtyper.annlowlevel import llhelper
@@ -219,7 +220,7 @@
 # ____________________________________________________________
 
 def ConstAddr(addr):
-    return ConstInt(heaptracker.adr2int(addr))
+    return ConstInt(adr2int(addr))
 
 class GuardClassOperation(test_random.GuardOperation):
     def gen_guard(self, builder, r):
diff --git a/rpython/jit/codewriter/assembler.py 
b/rpython/jit/codewriter/assembler.py
--- a/rpython/jit/codewriter/assembler.py
+++ b/rpython/jit/codewriter/assembler.py
@@ -1,9 +1,10 @@
 from rpython.jit.metainterp.history import AbstractDescr, getkind
+from rpython.jit.metainterp.support import adr2int, int2adr
 from rpython.jit.codewriter.flatten import Register, Label, TLabel, KINDS
 from rpython.jit.codewriter.flatten import ListOfKind, IndirectCallTargets
 from rpython.jit.codewriter.format import format_assembler
 from rpython.jit.codewriter.jitcode import SwitchDictDescr, JitCode
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.rlib.objectmodel import ComputedIntSymbolic
 from rpython.rlib.rarithmetic import r_int
 from rpython.flowspace.model import Constant
@@ -77,7 +78,7 @@
                 value = llmemory.cast_ptr_to_adr(value)
                 TYPE = llmemory.Address
             if TYPE == llmemory.Address:
-                value = heaptracker.adr2int(value)
+                value = adr2int(value)
             if TYPE is lltype.SingleFloat:
                 value = longlong.singlefloat2int(value)
             if not isinstance(value, (llmemory.AddressAsInt,
@@ -265,7 +266,7 @@
         # Helper called at the end of assembling.  Registers the extra
         # functions shown in _callinfo_for_oopspec.
         for func in callinfocollection.all_function_addresses_as_int():
-            func = heaptracker.int2adr(func)
+            func = int2adr(func)
             self.see_raw_object(func.ptr)
 
 
diff --git a/rpython/jit/codewriter/effectinfo.py 
b/rpython/jit/codewriter/effectinfo.py
--- a/rpython/jit/codewriter/effectinfo.py
+++ b/rpython/jit/codewriter/effectinfo.py
@@ -3,6 +3,7 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.translator.backendopt.graphanalyze import BoolGraphAnalyzer
 from rpython.tool.algo import bitstring
+from rpython.jit.metainterp.support import int2adr
 
 
 class UnsupportedFieldExc(Exception):
@@ -445,9 +446,8 @@
             return (None, 0)
 
     def _funcptr_for_oopspec_memo(self, oopspecindex):
-        from rpython.jit.codewriter import heaptracker
         _, func_as_int = self.callinfo_for_oopspec(oopspecindex)
-        funcadr = heaptracker.int2adr(func_as_int)
+        funcadr = int2adr(func_as_int)
         return funcadr.ptr
     _funcptr_for_oopspec_memo._annspecialcase_ = 'specialize:memo'
 
diff --git a/rpython/jit/codewriter/heaptracker.py 
b/rpython/jit/codewriter/heaptracker.py
--- a/rpython/jit/codewriter/heaptracker.py
+++ b/rpython/jit/codewriter/heaptracker.py
@@ -1,30 +1,9 @@
-from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper import rclass
-from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib.rarithmetic import r_uint, intmask
-
-
-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 int_signext(value, numbytes):
-    b8 = numbytes * 8
-    a = r_uint(value)
-    a += r_uint(1 << (b8 - 1))     # a += 128
-    a &= r_uint((1 << b8) - 1)     # a &= 255
-    a -= r_uint(1 << (b8 - 1))     # a -= 128
-    return intmask(a)
 
 def is_immutable_struct(S):
     return isinstance(S, lltype.GcStruct) and S._hints.get('immutable', False)
 
-# ____________________________________________________________
-
 def has_gcstruct_a_vtable(GCSTRUCT):
     if not isinstance(GCSTRUCT, lltype.GcStruct):
         return False
@@ -132,4 +111,3 @@
             return cur_index
         cur_index += 1
     return -cur_index - 1 # not found
-    
diff --git a/rpython/jit/codewriter/jitcode.py 
b/rpython/jit/codewriter/jitcode.py
--- a/rpython/jit/codewriter/jitcode.py
+++ b/rpython/jit/codewriter/jitcode.py
@@ -1,5 +1,5 @@
 from rpython.jit.metainterp.history import AbstractDescr, ConstInt
-from rpython.jit.codewriter import heaptracker
+from rpython.jit.metainterp.support import adr2int
 from rpython.rlib.objectmodel import we_are_translated
 from rpython.rlib.rarithmetic import base_int
 
@@ -8,7 +8,7 @@
     _empty_i = []
     _empty_r = []
     _empty_f = []
-    
+
     def __init__(self, name, fnaddr=None, calldescr=None, called_from=None):
         self.name = name
         self.fnaddr = fnaddr
@@ -41,7 +41,7 @@
         self._resulttypes = resulttypes   # debugging
 
     def get_fnaddr_as_int(self):
-        return heaptracker.adr2int(self.fnaddr)
+        return adr2int(self.fnaddr)
 
     def num_regs_i(self):
         return ord(self.c_num_regs_i)
diff --git a/rpython/jit/codewriter/jtransform.py 
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -7,6 +7,7 @@
 from rpython.jit.metainterp import quasiimmut
 from rpython.jit.metainterp.history import getkind
 from rpython.jit.metainterp.blackhole import BlackholeInterpreter
+from rpython.jit.metainterp.support import adr2int
 from rpython.flowspace.model import SpaceOperation, Variable, Constant
 from rpython.rlib import objectmodel
 from rpython.rlib.jit import _we_are_jitted
@@ -1954,7 +1955,7 @@
         if isinstance(op.args[0].value, str):
             pass  # for tests only
         else:
-            func = heaptracker.adr2int(
+            func = adr2int(
                 llmemory.cast_ptr_to_adr(op.args[0].value))
             self.callcontrol.callinfocollection.add(oopspecindex,
                                                     calldescr, func)
@@ -1982,7 +1983,7 @@
         if isinstance(c_func.value, str):    # in tests only
             func = c_func.value
         else:
-            func = heaptracker.adr2int(
+            func = adr2int(
                 llmemory.cast_ptr_to_adr(c_func.value))
         self.callcontrol.callinfocollection.add(oopspecindex, calldescr, func)
 
diff --git a/rpython/jit/codewriter/test/test_assembler.py 
b/rpython/jit/codewriter/test/test_assembler.py
--- a/rpython/jit/codewriter/test/test_assembler.py
+++ b/rpython/jit/codewriter/test/test_assembler.py
@@ -3,8 +3,9 @@
 from rpython.jit.codewriter.flatten import SSARepr, Label, TLabel, Register
 from rpython.jit.codewriter.flatten import ListOfKind, IndirectCallTargets
 from rpython.jit.codewriter.jitcode import MissingLiveness
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.jit.metainterp.history import AbstractDescr
+from rpython.jit.metainterp.support import adr2int
 from rpython.flowspace.model import Constant
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rlib.rarithmetic import r_int, r_uint
@@ -106,7 +107,7 @@
     assert assembler.insns == {'int_return/c': 0,
                                'int_return/i': 1,
                                'ref_return/r': 2}
-    f_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(f))
+    f_int = 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]
diff --git a/rpython/jit/codewriter/test/test_flatten.py 
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -1,12 +1,12 @@
 import py, sys
 from rpython.jit.codewriter import support
-from rpython.jit.codewriter.heaptracker import int_signext
 from rpython.jit.codewriter.flatten import flatten_graph, reorder_renaming_list
 from rpython.jit.codewriter.flatten import GraphFlattener, ListOfKind, Register
 from rpython.jit.codewriter.format import assert_format
 from rpython.jit.codewriter import longlong
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.metainterp.history import AbstractDescr
+from rpython.jit.metainterp.support import int_signext
 from rpython.rtyper.lltypesystem import lltype, rstr, rffi
 from rpython.rtyper import rclass
 from rpython.flowspace.model import SpaceOperation, Variable, Constant
diff --git a/rpython/jit/codewriter/test/test_jtransform.py 
b/rpython/jit/codewriter/test/test_jtransform.py
--- a/rpython/jit/codewriter/test/test_jtransform.py
+++ b/rpython/jit/codewriter/test/test_jtransform.py
@@ -12,6 +12,7 @@
 from rpython.jit.codewriter import heaptracker, effectinfo
 from rpython.jit.codewriter.flatten import ListOfKind
 from rpython.jit.codewriter.jtransform import Transformer, 
UnsupportedMallocFlags
+from rpython.jit.metainterp.support import int2adr
 from rpython.jit.metainterp.history import getkind
 
 def const(x):
@@ -1198,7 +1199,7 @@
     got = cc.callinfocollection.seen[0]
     assert got[0] == effectinfo.EffectInfo.OS_UNI_CONCAT
     assert got[1] == op1.args[2]    # the calldescr
-    assert heaptracker.int2adr(got[2]) == llmemory.cast_ptr_to_adr(func)
+    assert int2adr(got[2]) == llmemory.cast_ptr_to_adr(func)
 
 def test_str_slice():
     # test that the oopspec is present and correctly transformed
diff --git a/rpython/jit/metainterp/blackhole.py 
b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -1,9 +1,10 @@
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.jit.codewriter.jitcode import JitCode, SwitchDictDescr
 from rpython.jit.metainterp.compile import ResumeAtPositionDescr
 from rpython.jit.metainterp.jitexc import get_llexception, reraise
 from rpython.jit.metainterp import jitexc
 from rpython.jit.metainterp.history import MissingValue
+from rpython.jit.metainterp.support import adr2int, int2adr, int_signext
 from rpython.rlib import longlong2float
 from rpython.rlib.debug import ll_assert, make_sure_not_resized
 from rpython.rlib.debug import check_annotation
@@ -539,7 +540,7 @@
         return i
     @arguments("i", "i", returns="i")
     def bhimpl_int_signext(a, b):
-        return heaptracker.int_signext(a, b)
+        return int_signext(a, b)
 
     @arguments("i", "i", returns="i")
     def bhimpl_uint_lt(a, b):
@@ -930,7 +931,7 @@
 
     @arguments("self", "i", "L", "pc", returns="L")
     def bhimpl_goto_if_exception_mismatch(self, vtable, target, pc):
-        adr = heaptracker.int2adr(vtable)
+        adr = int2adr(vtable)
         bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
         real_instance = self.exception_last_value
         assert real_instance
@@ -944,7 +945,7 @@
         real_instance = self.exception_last_value
         assert real_instance
         adr = llmemory.cast_ptr_to_adr(real_instance.typeptr)
-        return heaptracker.adr2int(adr)
+        return adr2int(adr)
 
     @arguments("self", returns="r")
     def bhimpl_last_exc_value(self):
@@ -1050,7 +1051,7 @@
 
     def get_portal_runner(self, jdindex):
         jitdriver_sd = self.builder.metainterp_sd.jitdrivers_sd[jdindex]
-        fnptr = heaptracker.adr2int(jitdriver_sd.portal_runner_adr)
+        fnptr = adr2int(jitdriver_sd.portal_runner_adr)
         calldescr = jitdriver_sd.mainjitcode.calldescr
         return fnptr, calldescr
 
@@ -1233,45 +1234,45 @@
 
     @arguments("cpu", "j", "R", returns="i")
     def bhimpl_inline_call_r_i(cpu, jitcode, args_r):
-        return cpu.bh_call_i(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_i(adr2int(jitcode.fnaddr),
                              None, args_r, None, jitcode.calldescr)
     @arguments("cpu", "j", "R", returns="r")
     def bhimpl_inline_call_r_r(cpu, jitcode, args_r):
-        return cpu.bh_call_r(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_r(adr2int(jitcode.fnaddr),
                              None, args_r, None, jitcode.calldescr)
     @arguments("cpu", "j", "R")
     def bhimpl_inline_call_r_v(cpu, jitcode, args_r):
-        return cpu.bh_call_v(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_v(adr2int(jitcode.fnaddr),
                              None, args_r, None, jitcode.calldescr)
 
     @arguments("cpu", "j", "I", "R", returns="i")
     def bhimpl_inline_call_ir_i(cpu, jitcode, args_i, args_r):
-        return cpu.bh_call_i(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_i(adr2int(jitcode.fnaddr),
                              args_i, args_r, None, jitcode.calldescr)
     @arguments("cpu", "j", "I", "R", returns="r")
     def bhimpl_inline_call_ir_r(cpu, jitcode, args_i, args_r):
-        return cpu.bh_call_r(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_r(adr2int(jitcode.fnaddr),
                              args_i, args_r, None, jitcode.calldescr)
     @arguments("cpu", "j", "I", "R")
     def bhimpl_inline_call_ir_v(cpu, jitcode, args_i, args_r):
-        return cpu.bh_call_v(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_v(adr2int(jitcode.fnaddr),
                              args_i, args_r, None, jitcode.calldescr)
 
     @arguments("cpu", "j", "I", "R", "F", returns="i")
     def bhimpl_inline_call_irf_i(cpu, jitcode, args_i, args_r, args_f):
-        return cpu.bh_call_i(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_i(adr2int(jitcode.fnaddr),
                              args_i, args_r, args_f, jitcode.calldescr)
     @arguments("cpu", "j", "I", "R", "F", returns="r")
     def bhimpl_inline_call_irf_r(cpu, jitcode, args_i, args_r, args_f):
-        return cpu.bh_call_r(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_r(adr2int(jitcode.fnaddr),
                              args_i, args_r, args_f, jitcode.calldescr)
     @arguments("cpu", "j", "I", "R", "F", returns="f")
     def bhimpl_inline_call_irf_f(cpu, jitcode, args_i, args_r, args_f):
-        return cpu.bh_call_f(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_f(adr2int(jitcode.fnaddr),
                              args_i, args_r, args_f, jitcode.calldescr)
     @arguments("cpu", "j", "I", "R", "F")
     def bhimpl_inline_call_irf_v(cpu, jitcode, args_i, args_r, args_f):
-        return cpu.bh_call_v(jitcode.get_fnaddr_as_int(),
+        return cpu.bh_call_v(adr2int(jitcode.fnaddr),
                              args_i, args_r, args_f, jitcode.calldescr)
 
     @arguments("cpu", "i", "d", returns="r")
diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -21,7 +21,8 @@
 from rpython.jit.metainterp.resume import (PENDINGFIELDSP,
         ResumeDataDirectReader, AccumInfo)
 from rpython.jit.metainterp.resumecode import NUMBERING
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.metainterp.support import adr2int
+from rpython.jit.codewriter import longlong
 
 
 def giveup():
@@ -1147,7 +1148,7 @@
             raise AssertionError
         inputargs.append(box)
     k = jitdriver_sd.portal_runner_adr
-    funcbox = history.ConstInt(heaptracker.adr2int(k))
+    funcbox = history.ConstInt(adr2int(k))
     callargs = [funcbox] + greenboxes + inputargs
     #
 
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
@@ -14,7 +14,8 @@
 from rpython.jit.metainterp.resoperation import ResOperation, rop,\
     AbstractValue, oparity, AbstractResOp, IntOp, RefOp, FloatOp,\
     opclasses
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.metainterp.support import adr2int, int2adr
+from rpython.jit.codewriter import longlong
 import weakref
 from rpython.jit.metainterp import jitexc
 
@@ -181,7 +182,7 @@
         kind = getkind(T)
         if kind == "int":
             if isinstance(T, lltype.Ptr):
-                intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
+                intval = adr2int(llmemory.cast_ptr_to_adr(x))
             else:
                 intval = lltype.cast_primitive(lltype.Signed, x)
             return ConstInt(intval)
@@ -228,7 +229,7 @@
     getvalue = getint
 
     def getaddr(self):
-        return heaptracker.int2adr(self.value)
+        return int2adr(self.value)
 
     def _get_hash_(self):
         return make_hashable_int(self.value)
@@ -351,7 +352,7 @@
     from rpython.rtyper.lltypesystem.ll2ctypes import 
NotCtypesAllocatedStructure
     if not we_are_translated() and isinstance(i, llmemory.AddressAsInt):
         # Warning: such a hash changes at the time of translation
-        adr = heaptracker.int2adr(i)
+        adr = int2adr(i)
         try:
             return llmemory.cast_adr_to_int(adr, "emulated")
         except NotCtypesAllocatedStructure:
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_unroll.py 
b/rpython/jit/metainterp/optimizeopt/test/test_unroll.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_unroll.py
@@ -11,6 +11,7 @@
                                             JitCellToken, TargetToken)
 from rpython.jit.metainterp.resoperation import rop, ResOperation,\
      InputArgRef, InputArgInt
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.metainterp.optimizeopt.shortpreamble import \
      ShortPreambleBuilder, PreambleOp, ShortInputArg
 from rpython.jit.metainterp.compile import LoopCompileData
@@ -18,7 +19,6 @@
      NotVirtualStateInfo, LEVEL_CONSTANT, LEVEL_UNKNOWN, LEVEL_KNOWNCLASS,\
      VirtualStateInfo
 from rpython.jit.metainterp.optimizeopt import info, optimizer
-from rpython.jit.codewriter import heaptracker
 from rpython.jit.tool import oparser
 
 class FakeOptimizer(object):
@@ -36,10 +36,10 @@
 
     def get_box_replacement(self, box):
         return box
-     
+
 class BaseTestUnroll(BaseTest, LLtypeMixin):
     enable_opts = 
"intbounds:rewrite:virtualize:string:earlyforce:pure:heap:unroll"
-    
+
     def optimize(self, ops):
         loop = self.parse(ops)
         self.add_guard_future_condition(loop)
@@ -72,7 +72,7 @@
 
 def producable_short_boxes(l):
     return [x for x in l if not isinstance(x.short_op, ShortInputArg)]
-        
+
 class TestUnroll(BaseTestUnroll):
     def test_simple(self):
         loop = """
@@ -133,7 +133,7 @@
         """
         es, loop, preamble = self.optimize(loop)
         p0 = preamble.inputargs[0]
-        expected_class = heaptracker.adr2int(self.node_vtable_adr)
+        expected_class = adr2int(self.node_vtable_adr)
         assert expected_class == es.exported_infos[p0]._known_class.getint()
         vs = es.virtual_state
         assert vs.state[0].level == LEVEL_KNOWNCLASS
@@ -160,7 +160,7 @@
         p.set_forwarded(ptrinfo)
         vs.make_inputargs([p, p, i], FakeOptimizer())
 
-    def test_short_boxes_heapcache(self):        
+    def test_short_boxes_heapcache(self):
         loop = """
         [p0, i1]
         i0 = getfield_gc_i(p0, descr=valuedescr)
@@ -230,7 +230,7 @@
         assert len(es.short_boxes) == 4
         # both getfields are available as
         # well as getfield_gc
-        
+
     def test_p123_anti_nested(self):
         loop = """
         [i1, p2, p3]
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
@@ -2,7 +2,7 @@
 
 import py
 
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.codewriter.jitcode import JitCode, SwitchDictDescr
 from rpython.jit.metainterp import history, compile, resume, executor, jitexc
@@ -13,6 +13,7 @@
 from rpython.jit.metainterp.logger import Logger
 from rpython.jit.metainterp.optimizeopt.util import args_dict
 from rpython.jit.metainterp.resoperation import rop, OpHelpers, GuardResOp
+from rpython.jit.metainterp.support import adr2int
 from rpython.rlib.rjitlog import rjitlog as jl
 from rpython.rlib import nonconst, rstack
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
@@ -1161,7 +1162,7 @@
                           assembler_call=False):
         portal_code = targetjitdriver_sd.mainjitcode
         k = targetjitdriver_sd.portal_runner_adr
-        funcbox = ConstInt(heaptracker.adr2int(k))
+        funcbox = ConstInt(adr2int(k))
         return self.do_residual_call(funcbox, allboxes, portal_code.calldescr, 
pc,
                                      assembler_call=assembler_call,
                                      assembler_call_jd=targetjitdriver_sd)
@@ -2675,7 +2676,7 @@
 
             exception_obj = lltype.cast_opaque_ptr(rclass.OBJECTPTR, exception)
             if exception_obj:
-                exc_class = heaptracker.adr2int(
+                exc_class = adr2int(
                     llmemory.cast_ptr_to_adr(exception_obj.typeptr))
             else:
                 exc_class = 0
@@ -2974,7 +2975,7 @@
 
     def handle_possible_exception(self):
         if self.last_exc_value:
-            exception_box = ConstInt(heaptracker.adr2int(
+            exception_box = ConstInt(adr2int(
                 llmemory.cast_ptr_to_adr(self.last_exc_value.typeptr)))
             op = self.generate_guard(rop.GUARD_EXCEPTION,
                                      None, [exception_box])
@@ -3269,7 +3270,7 @@
             calldescr._original_func_ = argboxes[0].getint()
         effectinfo = calldescr.get_extra_info()
         realfuncaddr, saveerr = effectinfo.call_release_gil_target
-        funcbox = ConstInt(heaptracker.adr2int(realfuncaddr))
+        funcbox = ConstInt(adr2int(realfuncaddr))
         savebox = ConstInt(saveerr)
         opnum = rop.call_release_gil_for_descr(calldescr)
         return self.history.record_nospec(opnum,
diff --git a/rpython/jit/metainterp/support.py 
b/rpython/jit/metainterp/support.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/metainterp/support.py
@@ -0,0 +1,26 @@
+from rpython.rtyper.lltypesystem import llmemory
+from rpython.rlib.rarithmetic import r_uint, intmask
+
+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):
+    """
+    Cast an int back to an address.
+
+    Inverse of adr2int().
+    """
+    return llmemory.cast_int_to_adr(int)
+
+def int_signext(value, numbytes):
+    b8 = numbytes * 8
+    a = r_uint(value)
+    a += r_uint(1 << (b8 - 1))     # a += 128
+    a &= r_uint((1 << b8) - 1)     # a &= 255
+    a -= r_uint(1 << (b8 - 1))     # a -= 128
+    return intmask(a)
diff --git a/rpython/jit/metainterp/test/test_resume.py 
b/rpython/jit/metainterp/test/test_resume.py
--- a/rpython/jit/metainterp/test/test_resume.py
+++ b/rpython/jit/metainterp/test/test_resume.py
@@ -19,9 +19,10 @@
 from rpython.jit.metainterp.history import (
     ConstInt, Const, AbstractDescr, ConstPtr, ConstFloat, IntFrontendOp,
     RefFrontendOp, CONST_NULL)
+from rpython.jit.metainterp.support import adr2int
 from rpython.jit.metainterp.optimizeopt.test.test_util import LLtypeMixin
 from rpython.jit.metainterp import executor
-from rpython.jit.codewriter import heaptracker, longlong
+from rpython.jit.codewriter import longlong
 from rpython.jit.metainterp.resoperation import ResOperation, rop
 from rpython.rlib.debug import debug_start, debug_stop, debug_print,\
     have_debug_prints
@@ -639,7 +640,7 @@
 fakeoptimizer = FakeOptimizer_VirtualValue()
 
 def ConstAddr(addr):   # compatibility
-    return ConstInt(heaptracker.adr2int(addr))
+    return ConstInt(adr2int(addr))
 
 def virtual_value(keybox, value, next):
     vv = VirtualValue(
diff --git a/rpython/jit/metainterp/test/test_support.py 
b/rpython/jit/metainterp/test/test_support.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/metainterp/test/test_support.py
@@ -0,0 +1,14 @@
+from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.jit.metainterp.support import adr2int, int2adr
+
+def test_cast_adr_to_int_and_back():
+    X = lltype.Struct('X', ('foo', lltype.Signed))
+    x = lltype.malloc(X, immortal=True)
+    x.foo = 42
+    a = llmemory.cast_ptr_to_adr(x)
+    i = adr2int(a)
+    assert lltype.typeOf(i) is lltype.Signed
+    a2 = int2adr(i)
+    assert llmemory.cast_adr_to_ptr(a2, lltype.Ptr(X)) == x
+    assert adr2int(llmemory.NULL) == 0
+    assert int2adr(0) == llmemory.NULL
diff --git a/rpython/jit/metainterp/typesystem.py 
b/rpython/jit/metainterp/typesystem.py
--- a/rpython/jit/metainterp/typesystem.py
+++ b/rpython/jit/metainterp/typesystem.py
@@ -1,7 +1,7 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper import rclass
 from rpython.jit.metainterp import history
-from rpython.jit.codewriter import heaptracker
+from rpython.jit.metainterp.support import adr2int
 from rpython.rlib.objectmodel import r_dict
 
 
@@ -17,6 +17,6 @@
     def cls_of_box(self, box):
         obj = lltype.cast_opaque_ptr(rclass.OBJECTPTR, box.getref_base())
         cls = llmemory.cast_ptr_to_adr(obj.typeptr)
-        return history.ConstInt(heaptracker.adr2int(cls))
+        return history.ConstInt(adr2int(cls))
 
 llhelper = LLTypeHelper()
diff --git a/rpython/jit/metainterp/virtualref.py 
b/rpython/jit/metainterp/virtualref.py
--- a/rpython/jit/metainterp/virtualref.py
+++ b/rpython/jit/metainterp/virtualref.py
@@ -2,8 +2,9 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rtyper import rclass
 from rpython.jit.metainterp import history
-from rpython.jit.metainterp.virtualizable import TOKEN_NONE
-from rpython.jit.metainterp.virtualizable import TOKEN_TRACING_RESCALL
+from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.virtualizable import (
+    TOKEN_NONE, TOKEN_TRACING_RESCALL)
 from rpython.jit.codewriter import heaptracker
 from rpython.rlib.jit import InvalidVirtualRef
 
@@ -34,7 +35,7 @@
             'jit_virtual_ref')
         # build some constants
         adr = llmemory.cast_ptr_to_adr(self.jit_virtual_ref_vtable)
-        adr = heaptracker.adr2int(adr)
+        adr = adr2int(adr)
         self.jit_virtual_ref_const_class = history.ConstInt(adr)
         fielddescrof = self.cpu.fielddescrof
         self.descr_virtual_token = fielddescrof(self.JIT_VIRTUAL_REF,
diff --git a/rpython/jit/metainterp/warmstate.py 
b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -1,8 +1,9 @@
 import sys
 import weakref
 
-from rpython.jit.codewriter import support, heaptracker, longlong
+from rpython.jit.codewriter import support, longlong
 from rpython.jit.metainterp import resoperation, history, jitexc
+from rpython.jit.metainterp.support import adr2int, int2adr
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
 from rpython.rlib.debug import have_debug_prints_for
 from rpython.rlib.jit import PARAMETERS
@@ -48,7 +49,7 @@
             return lltype.cast_opaque_ptr(llmemory.GCREF, value)
         else:
             adr = llmemory.cast_ptr_to_adr(value)
-            return heaptracker.adr2int(adr)
+            return adr2int(adr)
     elif isinstance(value, float):
         return longlong.getfloatstorage(value)
     else:
@@ -62,7 +63,7 @@
         if TYPE.TO._gckind == "gc":
             return box.getref(TYPE)
         else:
-            adr = heaptracker.int2adr(box.getint())
+            adr = int2adr(box.getint())
             return llmemory.cast_adr_to_ptr(adr, TYPE)
     if TYPE == lltype.Float:
         return box.getfloat()
@@ -82,7 +83,7 @@
                 return res
         else:
             adr = llmemory.cast_ptr_to_adr(value)
-            value = heaptracker.adr2int(adr)
+            value = adr2int(adr)
             # fall through to the end of the function
     elif (isinstance(value, float) or
           longlong.is_longlong(lltype.typeOf(value))):
@@ -150,7 +151,7 @@
     app-level Python code.
 
     We create subclasses of BaseJitCell --one per jitdriver-- so that
-    they can store greenkeys of different types.  
+    they can store greenkeys of different types.
 
     Note that we don't create a JitCell the first time we see a given
     greenkey position in the interpreter.  At first, we only hash the
@@ -384,7 +385,7 @@
             if vinfo is not None:
                 virtualizable = args[index_of_virtualizable]
                 vinfo.clear_vable_token(virtualizable)
-            
+
             deadframe = func_execute_token(loop_token, *args)
             #
             # Record in the memmgr that we just ran this loop,
@@ -698,7 +699,7 @@
             drivername = jitdriver.name
         else:
             drivername = '<unknown jitdriver>'
-        # get_location returns 
+        # get_location returns
         get_location_ptr = getattr(self.jitdriver_sd, '_get_location_ptr', 
None)
         if get_location_ptr is not None:
             types = self.jitdriver_sd._get_loc_types
diff --git a/rpython/jit/tool/oparser_model.py 
b/rpython/jit/tool/oparser_model.py
--- a/rpython/jit/tool/oparser_model.py
+++ b/rpython/jit/tool/oparser_model.py
@@ -1,3 +1,5 @@
+from rpython.jit.metainterp.support import adr2int
+
 class Boxes(object):
     pass
 
@@ -21,7 +23,6 @@
 
         @staticmethod
         def ptr_to_int(obj):
-            from rpython.jit.codewriter.heaptracker import adr2int
             from rpython.rtyper.lltypesystem import llmemory
             return adr2int(llmemory.cast_ptr_to_adr(obj))
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to