[pypy-svn] r68491 - in pypy/branch/gc-hash/pypy/jit/metainterp: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 15 15:38:08 CEST 2009
Author: arigo
Date: Thu Oct 15 15:38:07 2009
New Revision: 68491
Added:
pypy/branch/gc-hash/pypy/jit/metainterp/test/test_typesystem.py (contents, props changed)
Modified:
pypy/branch/gc-hash/pypy/jit/metainterp/optimizeopt.py
pypy/branch/gc-hash/pypy/jit/metainterp/pyjitpl.py
pypy/branch/gc-hash/pypy/jit/metainterp/resume.py
pypy/branch/gc-hash/pypy/jit/metainterp/test/test_optimizeopt.py
pypy/branch/gc-hash/pypy/jit/metainterp/test/test_resume.py
pypy/branch/gc-hash/pypy/jit/metainterp/typesystem.py
Log:
Fix resume.py and optimizeopt.py to use lltype.identityhash()
systematically to hash the random low-level pointers they get.
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/optimizeopt.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/optimizeopt.py Thu Oct 15 15:38:07 2009
@@ -368,7 +368,7 @@
self.cpu = metainterp_sd.cpu
self.loop = loop
self.values = {}
- self.interned_refs = {}
+ self.interned_refs = self.cpu.ts.new_ref_dict()
self.resumedata_memo = resume.ResumeDataLoopMemo(self.cpu)
self.heap_op_optimizer = HeapOpOptimizer(self)
@@ -384,12 +384,7 @@
value = constbox.getref_base()
if not value:
return box
- key = self.cpu.ts.cast_ref_to_hashable(self.cpu, value)
- try:
- return self.interned_refs[key]
- except KeyError:
- self.interned_refs[key] = box
- return box
+ return self.interned_refs.setdefault(value, box)
else:
return box
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/pyjitpl.py Thu Oct 15 15:38:07 2009
@@ -1024,7 +1024,7 @@
def _setup_class_sizes(self):
class_sizes = {}
for vtable, sizedescr in self._class_sizes:
- vtable = self.cpu.ts.cast_baseclass_to_hashable(self.cpu, vtable)
+ vtable = self.cpu.ts.cast_vtable_to_hashable(self.cpu, vtable)
class_sizes[vtable] = sizedescr
self.cpu.set_class_sizes(class_sizes)
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/resume.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/resume.py Thu Oct 15 15:38:07 2009
@@ -101,7 +101,7 @@
self.cpu = cpu
self.consts = []
self.large_ints = {}
- self.refs = {}
+ self.refs = cpu.ts.new_ref_dict_2()
self.numberings = {}
def getconst(self, const):
@@ -124,7 +124,6 @@
val = const.getref_base()
if not val:
return NULLREF
- val = self.cpu.ts.cast_ref_to_hashable(self.cpu, val)
tagged = self.refs.get(val, UNASSIGNED)
if not tagged_eq(tagged, UNASSIGNED):
return tagged
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/test/test_optimizeopt.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/test/test_optimizeopt.py Thu Oct 15 15:38:07 2009
@@ -1,5 +1,4 @@
import py
-from pypy.rpython.ootypesystem import ootype
from pypy.rlib.objectmodel import instantiate
from pypy.jit.metainterp.test.test_resume import MyMetaInterp
from pypy.jit.metainterp.test.test_optimizefindnode import (LLtypeMixin,
@@ -35,7 +34,8 @@
from pypy.jit.metainterp.resume import tag, TAGBOX
b0 = BoxInt()
b1 = BoxInt()
- opt = optimizeopt.Optimizer(FakeMetaInterpStaticData(None), None)
+ opt = optimizeopt.Optimizer(FakeMetaInterpStaticData(LLtypeMixin.cpu),
+ None)
fdescr = ResumeGuardDescr(None)
op = ResOperation(rop.GUARD_TRUE, [], None, descr=fdescr)
# setup rd data
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/test/test_resume.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/test/test_resume.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/test/test_resume.py Thu Oct 15 15:38:07 2009
@@ -244,7 +244,7 @@
FakeFrame("code1", 3, 7, b3, c2, b1),
FakeFrame("code2", 9, -1, c3, b2)]
capture_resumedata(fs, None, storage)
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
modifier = ResumeDataVirtualAdder(storage, memo)
liveboxes = modifier.finish({})
metainterp = MyMetaInterp()
@@ -268,7 +268,7 @@
FakeFrame("code1", 3, 7, b3, c2, b1),
FakeFrame("code2", 9, -1, c3, b2)]
capture_resumedata(fs, [b4], storage)
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
modifier = ResumeDataVirtualAdder(storage, memo)
liveboxes = modifier.finish({})
metainterp = MyMetaInterp()
@@ -296,7 +296,7 @@
fs = fs[:-1] + [FakeFrame("code2", 10, -1, c3, b2, b4)]
capture_resumedata(fs, None, storage2)
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
modifier = ResumeDataVirtualAdder(storage, memo)
liveboxes = modifier.finish({})
@@ -421,7 +421,7 @@
def test_ResumeDataLoopMemo_ints():
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
tagged = memo.getconst(ConstInt(44))
assert untag(tagged) == (44, TAGINT)
tagged = memo.getconst(ConstInt(-3))
@@ -461,7 +461,7 @@
assert tagged == NULLREF
def test_ResumeDataLoopMemo_other():
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
const = ConstFloat(-1.0)
tagged = memo.getconst(const)
index, tagbits = untag(tagged)
@@ -479,7 +479,7 @@
env2 = [c3, b3, b1, c3]
snap2 = Snapshot(snap, env2)
- memo = ResumeDataLoopMemo(None)
+ memo = ResumeDataLoopMemo(LLtypeMixin.cpu)
numb, liveboxes, v = memo.number({}, snap1)
assert v == 0
Added: pypy/branch/gc-hash/pypy/jit/metainterp/test/test_typesystem.py
==============================================================================
--- (empty file)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/test/test_typesystem.py Thu Oct 15 15:38:07 2009
@@ -0,0 +1,53 @@
+from pypy.jit.metainterp import typesystem
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
+
+
+class TypeSystemTests(object):
+
+ def test_ref_dict(self):
+ d = self.helper.new_ref_dict()
+ ref1 = self.fresh_ref()
+ ref2 = self.fresh_ref()
+ ref3 = self.null_ref()
+ d[ref1] = 123
+ d[ref2] = 456
+ d[ref3] = 789
+ ref1b = self.duplicate_ref(ref1)
+ ref2b = self.duplicate_ref(ref2)
+ ref3b = self.null_ref()
+ assert d[ref1b] == 123
+ assert d[ref2b] == 456
+ assert d[ref3b] == 789
+
+
+class TestLLtype(TypeSystemTests):
+ helper = typesystem.llhelper
+
+ def fresh_ref(self):
+ S = lltype.GcStruct('S')
+ s = lltype.malloc(S)
+ return lltype.cast_opaque_ptr(llmemory.GCREF, s)
+
+ def duplicate_ref(self, x):
+ s = x._obj.container._as_ptr()
+ return lltype.cast_opaque_ptr(llmemory.GCREF, s)
+
+ def null_ref(self):
+ return lltype.nullptr(llmemory.GCREF.TO)
+
+
+class TestOOtype(TypeSystemTests):
+ helper = typesystem.oohelper
+
+ def fresh_ref(self):
+ O = ootype.StaticMethod([], ootype.Signed)
+ o = O._example()
+ return ootype.cast_to_object(o)
+
+ def duplicate_ref(self, x):
+ o = x.obj
+ return ootype.cast_to_object(o)
+
+ def null_ref(self):
+ return ootype.NULL
Modified: pypy/branch/gc-hash/pypy/jit/metainterp/typesystem.py
==============================================================================
--- pypy/branch/gc-hash/pypy/jit/metainterp/typesystem.py (original)
+++ pypy/branch/gc-hash/pypy/jit/metainterp/typesystem.py Thu Oct 15 15:38:07 2009
@@ -4,7 +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.metainterp import history
+from pypy.rlib.objectmodel import r_dict
def deref(T):
if isinstance(T, lltype.Ptr):
@@ -114,11 +114,15 @@
ll = llstr(str)
return history.ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, ll))
- def cast_ref_to_hashable(self, cpu, ptr):
- adr = llmemory.cast_ptr_to_adr(ptr)
- return cpu.cast_adr_to_int(adr)
+ # A dict whose keys are refs (like the .value of BoxPtr).
+ # It is an r_dict on lltype. Two copies, to avoid conflicts with
+ # the value type. Note that NULL is not allowed as a key.
+ def new_ref_dict(self):
+ return r_dict(ll_rd_eq, ll_rd_hash)
+ def new_ref_dict_2(self):
+ return r_dict(ll_rd_eq, ll_rd_hash)
- def cast_baseclass_to_hashable(self, cpu, ptr):
+ def cast_vtable_to_hashable(self, cpu, ptr):
adr = llmemory.cast_ptr_to_adr(ptr)
return cpu.cast_adr_to_int(adr)
@@ -133,6 +137,15 @@
def getaddr_for_box(self, cpu, box):
return box.getaddr(cpu)
+def ll_rd_eq(ref1, ref2):
+ return ref1 == ref2
+
+def ll_rd_hash(ref):
+ assert ref
+ return lltype.identityhash(ref)
+
+# ____________________________________________________________
+
class OOTypeHelper(TypeSystemHelper):
name = 'ootype'
@@ -209,10 +222,15 @@
oo = oostr(str)
return history.ConstObj(ootype.cast_to_object(oo))
- def cast_ref_to_hashable(self, cpu, obj):
- return ootype.cast_to_object(obj)
+ # A dict whose keys are refs (like the .value of BoxObj).
+ # It is a normal dict on ootype. Two copies, to avoid conflicts
+ # with the value type.
+ def new_ref_dict(self):
+ return {}
+ def new_ref_dict_2(self):
+ return {}
- def cast_baseclass_to_hashable(self, cpu, obj):
+ def cast_vtable_to_hashable(self, cpu, obj):
return ootype.cast_to_object(obj)
def cast_from_ref(self, TYPE, value):
More information about the Pypy-commit
mailing list