[pypy-svn] r16021 - in pypy/dist/pypy/rpython: . memory memory/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Aug 12 21:47:04 CEST 2005
Author: cfbolz
Date: Fri Aug 12 21:47:03 2005
New Revision: 16021
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/memory/convertlltype.py
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/gclltype.py
pypy/dist/pypy/rpython/memory/gcwrapper.py
pypy/dist/pypy/rpython/memory/test/test_gc.py
pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py
Log:
changed convertllype so that the gc can also handle programs where
globals contain root point
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Fri Aug 12 21:47:03 2005
@@ -16,11 +16,9 @@
class LLInterpreter(object):
""" low level interpreter working with concrete values. """
- def __init__(self, flowgraphs, typer, lltype=lltype, prepare_graphs=None):
- if prepare_graphs is not None:
- prepare_graphs(flowgraphs)
- if hasattr(lltype, "create_gc"):
- self.gc = lltype.create_gc(self)
+ def __init__(self, flowgraphs, typer, lltype=lltype):
+ if hasattr(lltype, "prepare_graphs_and_create_gc"):
+ self.gc = lltype.prepare_graphs_and_create_gc(self, flowgraphs)
else:
self.gc = None
self.flowgraphs = flowgraphs
Modified: pypy/dist/pypy/rpython/memory/convertlltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/convertlltype.py (original)
+++ pypy/dist/pypy/rpython/memory/convertlltype.py Fri Aug 12 21:47:03 2005
@@ -15,10 +15,23 @@
FUNCTIONTYPES = (types.FunctionType, types.UnboundMethodType,
types.BuiltinFunctionType)
+INT_SIZE = struct.calcsize("i")
+
class LLTypeConverter(object):
def __init__(self, address):
+ self.type_to_typeid = {}
+ self.types = []
self.converted = {}
self.curraddress = address
+ self.constantroots = []
+
+ def get_typeid(self, TYPE):
+ if TYPE not in self.type_to_typeid:
+ index = len(self.types)
+ self.type_to_typeid[TYPE] = index
+ self.types.append(TYPE)
+ typeid = self.type_to_typeid[TYPE]
+ return typeid
def convert(self, val_or_ptr, inline_to_addr=None, from_parent=False):
TYPE = lltype.typeOf(val_or_ptr)
@@ -53,11 +66,16 @@
startaddr = inline_to_addr
else:
startaddr = self.curraddress
+ startaddr.signed[0] = 0
+ startaddr.signed[1] = self.get_typeid(TYPE)
+ startaddr += 2 * INT_SIZE
+ self.constantroots.append(
+ simulatorptr(lltype.Ptr(TYPE), startaddr))
+ self.curraddress += size + 2 * INT_SIZE
self.converted[_array] = startaddr
startaddr.signed[0] = arraylength
curraddr = startaddr + get_fixed_size(TYPE)
varsize = get_variable_size(TYPE)
- self.curraddress += size
for item in _array.items:
self.convert(item, curraddr, from_parent=True)
curraddr += varsize
@@ -84,8 +102,13 @@
startaddr = inline_to_addr
else:
startaddr = self.curraddress
+ startaddr.signed[0] = 0
+ startaddr.signed[1] = self.get_typeid(TYPE)
+ startaddr += 2 * INT_SIZE
+ self.constantroots.append(
+ simulatorptr(lltype.Ptr(TYPE), startaddr))
+ self.curraddress += size + 2 * INT_SIZE
self.converted[_struct] = startaddr
- self.curraddress += size
for name in TYPE._flds:
addr = startaddr + layout[name]
self.convert(getattr(_struct, name), addr, from_parent=True)
@@ -159,20 +182,25 @@
elif isinstance(cand, lltype._array):
seen[cand] = True
length = len(cand.items)
- total_size += get_total_size(cand._TYPE, length)
+ total_size += get_total_size(cand._TYPE, length) * 2 * INT_SIZE
for item in cand.items:
candidates.append(item)
elif isinstance(cand, lltype._struct):
seen[cand] = True
parent = cand._parentstructure()
if parent is not None:
+ has_parent = True
candidates.append(parent)
- TYPE = cand._TYPE
- if TYPE._arrayfld is not None:
- total_size += get_total_size(
- TYPE, len(getattr(cand, TYPE._arrayfld).items))
else:
- total_size += get_total_size(TYPE)
+ has_parent = False
+ TYPE = cand._TYPE
+ if not has_parent:
+ if TYPE._arrayfld is not None:
+ total_size += get_total_size(
+ TYPE, len(getattr(cand, TYPE._arrayfld).items))
+ else:
+ total_size += get_total_size(TYPE)
+ total_size += INT_SIZE * 2
for name in TYPE._flds:
candidates.append(getattr(cand, name))
elif isinstance(cand, lltype._opaque):
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Fri Aug 12 21:47:03 2005
@@ -55,7 +55,9 @@
# roots is a list of addresses to addresses:
objects.append(curr.address[0])
gc_info = curr.address[0] - 2 * INT_SIZE
- assert gc_info.signed[0] == 0
+ # constants roots are not malloced and thus don't have their mark
+ # bit reset
+ gc_info.signed[0] = 0
while 1: #mark
curr = objects.pop()
print "object: ", curr
Modified: pypy/dist/pypy/rpython/memory/gclltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gclltype.py (original)
+++ pypy/dist/pypy/rpython/memory/gclltype.py Fri Aug 12 21:47:03 2005
@@ -9,6 +9,7 @@
from pypy.rpython.memory.lltypesimulation import simulatorptr as _ptr
from pypy.rpython.memory.lltypesimulation import malloc, functionptr, nullptr
from pypy.rpython.memory.lltypesimulation import pyobjectptr
+from pypy.rpython.memory.convertlltype import FlowGraphConstantConverter
def notimplemented(*args, **kwargs):
@@ -29,21 +30,21 @@
del notimplemented
-def prepare_graphs(flowgraphs):
- from pypy.rpython.memory.convertlltype import FlowGraphConstantConverter
+def create_no_gc(llinterp, flowgraphs):
fgcc = FlowGraphConstantConverter(flowgraphs)
- fgcc.convert()
-
-def create_no_gc(llinterp):
+ fgcc.convert()
return None
-def create_mark_sweep_gc(llinterp):
+def create_mark_sweep_gc(llinterp, flowgraphs):
from pypy.rpython.memory.gcwrapper import GcWrapper, LLInterpObjectModel
from pypy.rpython.memory.gc import MarkSweepGC
- om = LLInterpObjectModel(llinterp)
+ fgcc = FlowGraphConstantConverter(flowgraphs)
+ fgcc.convert()
+ om = LLInterpObjectModel(llinterp, fgcc.cvter.types,
+ fgcc.cvter.type_to_typeid,
+ fgcc.cvter.constantroots)
gc = MarkSweepGC(om, 4096)
wrapper = GcWrapper(llinterp, gc)
return wrapper
-create_gc = create_no_gc
-
+prepare_graphs_and_create_gc = create_mark_sweep_gc
Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py Fri Aug 12 21:47:03 2005
@@ -5,9 +5,10 @@
from pypy.rpython.memory.gc import MarkSweepGC
class LLInterpObjectModel(object):
- def __init__(self, llinterp):
- self.type_to_typeid = {}
- self.types = []
+ def __init__(self, llinterp, types, type_to_typeid, constantroots):
+ self.types = types
+ self.type_to_typeid = type_to_typeid
+ self.constantroots = constantroots
self.roots = []
self.pseudo_root_pointers = NULL
self.llinterp = llinterp
@@ -30,7 +31,7 @@
print "getting roots"
if self.pseudo_root_pointers != NULL:
raw_free(self.pseudo_root_pointers)
- self.roots = self.llinterp.find_roots()
+ self.roots = self.llinterp.find_roots() + self.constantroots
print "found:", self.roots
if len(self.roots) == 0:
self.pseudo_root_pointers = NULL
Modified: pypy/dist/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_gc.py Fri Aug 12 21:47:03 2005
@@ -6,11 +6,16 @@
from pypy.rpython.memory.simulator import MemorySimulatorError
from pypy.rpython.memory import gclltype
from pypy.rpython.memory.test.test_llinterpsim import interpret
+from pypy.rpython.memory.lladdress import simulator
def setup_module(mod):
mod.logstate = py.log._getstate()
py.log.setconsumer("llinterp", py.log.STDOUT)
py.log.setconsumer("llinterp operation", None)
+ gclltype.prepare_graphs_and_create_gc = gclltype.create_mark_sweep_gc
+
+def teardown_module(mod):
+ gclltype.prepare_graphs_and_create_gc = gclltype.create_no_gc
def test_free_non_gc_object():
class TestClass(object):
@@ -97,8 +102,6 @@
py.test.raises(MemorySimulatorError, "addr2.signed[0]")
def test_llinterp_lists(self):
- from pypy.rpython.memory.lladdress import simulator
- gclltype.create_gc = gclltype.create_mark_sweep_gc
curr = simulator.current_size
def malloc_a_lot():
i = 0
@@ -114,8 +117,6 @@
print "size before: %s, size after %s" % (curr, simulator.current_size)
def test_llinterp_tuples(self):
- from pypy.rpython.memory.lladdress import simulator
- gclltype.create_gc = gclltype.create_mark_sweep_gc
curr = simulator.current_size
def malloc_a_lot():
i = 0
Modified: pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_llinterpsim.py Fri Aug 12 21:47:03 2005
@@ -41,8 +41,7 @@
t, typer = gengraph(func, [annotation(x)
for x in values], viewbefore, policy)
- interp = LLInterpreter(t.flowgraphs, typer, gclltype,
- gclltype.prepare_graphs)
+ interp = LLInterpreter(t.flowgraphs, typer, gclltype)
_tcache[key] = (t, interp)
# keep the cache small
_lastinterpreted.append(key)
More information about the Pypy-commit
mailing list