[pypy-svn] r36382 - in pypy/dist/pypy/jit/timeshifter: . test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Jan 9 18:28:33 CET 2007
Author: pedronis
Date: Tue Jan 9 18:28:30 2007
New Revision: 36382
Modified:
pypy/dist/pypy/jit/timeshifter/hrtyper.py
pypy/dist/pypy/jit/timeshifter/rcontainer.py
pypy/dist/pypy/jit/timeshifter/rvalue.py
pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
Log:
(arre, pedronis)
do the correct thing for virtualizable structs escaping to the outside jit world with setfield or return.
with tests.
(fix some typos in the tests)
Modified: pypy/dist/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/hrtyper.py (original)
+++ pypy/dist/pypy/jit/timeshifter/hrtyper.py Tue Jan 9 18:28:30 2007
@@ -141,6 +141,12 @@
assert jitstate.resuming is None
returnbox = rtimeshift.getreturnbox(jitstate)
gv_ret = returnbox.getgenvar(jitstate.curbuilder)
+ builder = jitstate.curbuilder
+ for virtualizable_box in jitstate.virtualizables:
+ assert isinstance(virtualizable_box, rvalue.PtrRedBox)
+ content = virtualizable_box.content
+ assert isinstance(content, rcontainer.VirtualizableStruct)
+ content.store_back(builder)
store_global_excdata(jitstate)
jitstate.curbuilder.finish_and_return(graphsigtoken, gv_ret)
self.ll_finish_jitstate = ll_finish_jitstate
Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py Tue Jan 9 18:28:30 2007
@@ -43,7 +43,7 @@
arrayfielddesc = None
alloctoken = None
varsizealloctoken = None
- materialize = None
+ materialize = None
def __init__(self, RGenOp, TYPE):
self.TYPE = TYPE
@@ -84,6 +84,9 @@
if TYPE._hints.get('virtualizable', False):
self.__class__ = VirtualizableStructTypeDesc
+ self.VStructCls = VirtualizableStruct
+ else:
+ self.VStructCls = VirtualStruct
if self.immutable and self.noidentity:
descs = unrolling_iterable(fielddescs)
@@ -250,6 +253,7 @@
class VirtualStruct(VirtualContainer):
+ typedesc = None
def __init__(self, typedesc):
self.typedesc = typedesc
@@ -257,6 +261,7 @@
#self.ownbox = ... set in factory()
def enter_block(self, incoming, memo):
+ assert self.typedesc is not None
contmemo = memo.containers
if self not in contmemo:
contmemo[self] = None
@@ -265,6 +270,7 @@
def force_runtime_container(self, builder):
typedesc = self.typedesc
+ assert typedesc is not None
boxes = self.content_boxes
self.content_boxes = None
if typedesc.materialize is not None:
@@ -291,21 +297,25 @@
def freeze(self, memo):
contmemo = memo.containers
assert self not in contmemo # contmemo no longer used
+ assert self.typedesc is not None
result = contmemo[self] = FrozenVirtualStruct(self.typedesc)
frozens = [box.freeze(memo) for box in self.content_boxes]
result.fz_content_boxes = frozens
return result
-
+
def copy(self, memo):
+ typedesc = self.typedesc
+ assert typedesc is not None
contmemo = memo.containers
assert self not in contmemo # contmemo no longer used
- result = contmemo[self] = VirtualStruct(self.typedesc)
+ result = contmemo[self] = typedesc.VStructCls(typedesc)
result.content_boxes = [box.copy(memo)
for box in self.content_boxes]
result.ownbox = self.ownbox.copy(memo)
return result
def replace(self, memo):
+ assert self.typedesc is not None
contmemo = memo.containers
assert self not in contmemo # contmemo no longer used
contmemo[self] = None
@@ -326,7 +336,11 @@
class VirtualizableStruct(VirtualStruct):
def force_runtime_container(self, builder):
- assert 0, "not implemented for now"
+ assert 0
+
+ def getgenvar(self):
+ assert self.typedesc is not None
+ return self.content_boxes[-1].genvar
def store_back(self, builder):
fielddescs = self.typedesc.fielddescs
Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py (original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py Tue Jan 9 18:28:30 2007
@@ -274,16 +274,18 @@
if not self.genvar:
content = self.content
from pypy.jit.timeshifter import rcontainer
+ if isinstance(content, rcontainer.VirtualizableStruct):
+ return content.getgenvar()
assert isinstance(content, rcontainer.VirtualContainer)
content.force_runtime_container(builder)
assert self.genvar
return self.genvar
-## def forcevar(self, builder, memo):
-## RedBox.forcevar(self, builder, memo)
-## # if self.content is still there, it's a PartialDataStruct
-## # - for now, we always remove it in this situation
-## self.content = None
+ def forcevar(self, builder, memo):
+ from pypy.jit.timeshifter import rcontainer
+ # xxx
+ assert not isinstance(self.content, rcontainer.VirtualizableStruct)
+ return RedBox.forcevar(self, builder, memo)
def enter_block(self, incoming, memo):
if self.genvar:
Modified: pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py Tue Jan 9 18:28:30 2007
@@ -99,7 +99,7 @@
x = xy.x
xy_access = xy.access
if xy_access:
- xy_access.set_y(xy, 1)
+ xy_access.set_y(xy, 3)
else:
xy.y = 3
xy_access = xy.access
@@ -125,4 +125,67 @@
assert ([v.concretetype for v in residual_graph.startblock.inputargs] ==
[lltype.Ptr(XY), lltype.Signed, lltype.Signed])
-
+ def test_simple_explicit_escape(self):
+ E = lltype.GcStruct('e', ('xy', lltype.Ptr(XY)))
+
+ def f(e, xy):
+ xy_access = xy.access
+ if xy_access:
+ xy_access.set_y(xy, 3)
+ else:
+ xy.y = 3
+ e.xy = xy
+ return 0
+
+ def main(x, y):
+ xy = lltype.malloc(XY)
+ xy.access = lltype.nullptr(XY_ACCESS)
+ xy.x = x
+ xy.y = y
+ e = lltype.malloc(E)
+ f(e, xy)
+ return e.xy.x+e.xy.y
+
+ res = self.timeshift_from_portal(main, f, [20, 22], policy=P_NOVIRTUAL)
+ assert res == 23
+ self.check_insns(getfield=0)
+ residual_graph = self.get_residual_graph()
+ assert len(residual_graph.startblock.inputargs) == 4
+ assert ([v.concretetype for v in residual_graph.startblock.inputargs] ==
+ [lltype.Ptr(E), lltype.Ptr(XY), lltype.Signed, lltype.Signed])
+
+ def test_simple_explicit_return_it(self):
+ def f(which, xy1, xy2):
+ xy1_access = xy1.access
+ if xy1_access:
+ xy1_access.set_y(xy1, 3)
+ else:
+ xy1.y = 3
+ xy2_access = xy2.access
+ if xy2_access:
+ xy2_access.set_y(xy2, 7)
+ else:
+ xy2.y = 7
+ if which == 1:
+ return xy1
+ else:
+ return xy2
+
+ def main(which, x, y):
+ xy1 = lltype.malloc(XY)
+ xy1.access = lltype.nullptr(XY_ACCESS)
+ xy2 = lltype.malloc(XY)
+ xy2.access = lltype.nullptr(XY_ACCESS)
+ xy1.x = x
+ xy1.y = y
+ xy2.x = y
+ xy2.y = x
+ xy = f(which, xy1, xy2)
+ assert xy is xy1 or xy is xy2
+ return xy.x+xy.y
+
+ res = self.timeshift_from_portal(main, f, [1, 20, 22],
+ policy=P_NOVIRTUAL)
+ assert res == 23
+ self.check_insns(getfield=0)
+
More information about the Pypy-commit
mailing list