[pypy-svn] r16146 - pypy/dist/pypy/rpython/memory
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Aug 18 17:48:25 CEST 2005
Author: cfbolz
Date: Thu Aug 18 17:48:24 2005
New Revision: 16146
Modified:
pypy/dist/pypy/rpython/memory/convertlltype.py
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/gclltype.py
Log:
made convertlltype independent of the gc being used.
Modified: pypy/dist/pypy/rpython/memory/convertlltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/convertlltype.py (original)
+++ pypy/dist/pypy/rpython/memory/convertlltype.py Thu Aug 18 17:48:24 2005
@@ -18,12 +18,13 @@
INT_SIZE = struct.calcsize("i")
class LLTypeConverter(object):
- def __init__(self, address):
+ def __init__(self, address, gc=None):
self.type_to_typeid = {}
self.types = []
self.converted = {}
self.curraddress = address
self.constantroots = []
+ self.gc = gc
def get_typeid(self, TYPE):
if TYPE not in self.type_to_typeid:
@@ -66,12 +67,14 @@
startaddr = inline_to_addr
else:
startaddr = self.curraddress
- startaddr.signed[0] = 0
- startaddr.signed[1] = self.get_typeid(TYPE)
- startaddr += 2 * INT_SIZE
+ if self.gc is not None:
+ self.gc.init_gc_object(startaddr, self.get_typeid(TYPE))
+ startaddr += self.gc.size_gc_header()
self.constantroots.append(
simulatorptr(lltype.Ptr(TYPE), startaddr))
- self.curraddress += size + 2 * INT_SIZE
+ self.curraddress += size
+ if self.gc is not None:
+ self.curraddress += self.gc.size_gc_header()
self.converted[_array] = startaddr
startaddr.signed[0] = arraylength
curraddr = startaddr + get_fixed_size(TYPE)
@@ -102,12 +105,14 @@
startaddr = inline_to_addr
else:
startaddr = self.curraddress
- startaddr.signed[0] = 0
- startaddr.signed[1] = self.get_typeid(TYPE)
- startaddr += 2 * INT_SIZE
+ if self.gc is not None:
+ self.gc.init_gc_object(startaddr, self.get_typeid(TYPE))
+ startaddr += self.gc.size_gc_header()
self.constantroots.append(
simulatorptr(lltype.Ptr(TYPE), startaddr))
- self.curraddress += size + 2 * INT_SIZE
+ self.curraddress += size
+ if self.gc is not None:
+ self.curraddress += self.gc.size_gc_header()
self.converted[_struct] = startaddr
for name in TYPE._flds:
addr = startaddr + layout[name]
@@ -132,11 +137,12 @@
return lladdress.get_address_of_object(_obj)
class FlowGraphConstantConverter(object):
- def __init__(self, flowgraphs):
+ def __init__(self, flowgraphs, gc=None):
self.flowgraphs = flowgraphs
self.memory = lladdress.NULL
self.cvter = None
self.total_size = 0
+ self.gc = gc
def collect_constants(self):
constants = {}
@@ -182,7 +188,9 @@
elif isinstance(cand, lltype._array):
seen[cand] = True
length = len(cand.items)
- total_size += sizeof(cand._TYPE, length) * 2 * INT_SIZE
+ total_size += sizeof(cand._TYPE, length)
+ if self.gc is not None:
+ total_size += self.gc.size_gc_header()
for item in cand.items:
candidates.append(item)
elif isinstance(cand, lltype._struct):
@@ -200,7 +208,8 @@
TYPE, len(getattr(cand, TYPE._arrayfld).items))
else:
total_size += sizeof(TYPE)
- total_size += INT_SIZE * 2
+ if self.gc is not None:
+ total_size += self.gc.size_gc_header()
for name in TYPE._flds:
candidates.append(getattr(cand, name))
elif isinstance(cand, lltype._opaque):
@@ -215,7 +224,7 @@
def convert_constants(self):
self.memory = lladdress.raw_malloc(self.total_size)
- self.cvter = LLTypeConverter(self.memory)
+ self.cvter = LLTypeConverter(self.memory, self.gc)
for constant in self.constants.iterkeys():
if isinstance(constant.value, lltype.LowLevelType):
self.constants[constant] = constant.value
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Thu Aug 18 17:48:24 2005
@@ -1,9 +1,9 @@
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory.support import AddressLinkedList
+from pypy.rpython import lltype
+from pypy.rpython.memory import lltypesimulation
import struct
-INT_SIZE = struct.calcsize("i")
-
class GCError(Exception):
pass
@@ -22,6 +22,7 @@
class MarkSweepGC(object):
_raw_allocate_ = True
+
def __init__(self, objectmodel, collect_every_bytes):
self.bytes_malloced = 0
self.collect_every_bytes = collect_every_bytes
@@ -33,14 +34,13 @@
def malloc(self, typeid, size):
if self.bytes_malloced > self.collect_every_bytes:
self.collect()
- result = raw_malloc(size + 2 * INT_SIZE)
+ size_gc_header = self.size_gc_header()
+ result = raw_malloc(size + size_gc_header)
print "mallocing %s, size %s at %s" % (typeid, size, result)
- print "real size: %s" % (size + 2 * INT_SIZE, )
- result.signed[0] = 0
- result.signed[1] = typeid
+ self.init_gc_object(result, typeid)
self.malloced_objects.append(result)
- self.bytes_malloced += size + 2 * INT_SIZE
- return result + 2 * INT_SIZE
+ self.bytes_malloced += size + size_gc_header
+ return result + size_gc_header
def collect(self):
print "collecting"
@@ -54,7 +54,7 @@
break
# roots is a list of addresses to addresses:
objects.append(curr.address[0])
- gc_info = curr.address[0] - 2 * INT_SIZE
+ gc_info = curr.address[0] - self.size_gc_header()
# constants roots are not malloced and thus don't have their mark
# bit reset
gc_info.signed[0] = 0
@@ -63,7 +63,7 @@
print "object: ", curr
if curr == NULL:
break
- gc_info = curr - 2 * INT_SIZE
+ gc_info = curr - self.size_gc_header()
if gc_info.signed[0] == 1:
continue
pointers = self.objectmodel.get_contained_pointers(
@@ -86,3 +86,12 @@
raw_free(curr)
free_non_gc_object(self.malloced_objects)
self.malloced_objects = newmo
+
+ def size_gc_header(self):
+ return lltypesimulation.sizeof(lltype.Signed) * 2
+
+
+ def init_gc_object(self, addr, typeid):
+ addr.signed[0] = 0
+ addr.signed[1] = typeid
+
Modified: pypy/dist/pypy/rpython/memory/gclltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gclltype.py (original)
+++ pypy/dist/pypy/rpython/memory/gclltype.py Thu Aug 18 17:48:24 2005
@@ -38,12 +38,14 @@
def create_mark_sweep_gc(llinterp, flowgraphs):
from pypy.rpython.memory.gcwrapper import GcWrapper, LLInterpObjectModel
from pypy.rpython.memory.gc import MarkSweepGC
- fgcc = FlowGraphConstantConverter(flowgraphs)
+ #XXX hackish: we need the gc before the object model is ready
+ gc = MarkSweepGC(None, 4096)
+ fgcc = FlowGraphConstantConverter(flowgraphs, gc)
fgcc.convert()
om = LLInterpObjectModel(llinterp, fgcc.cvter.types,
fgcc.cvter.type_to_typeid,
fgcc.cvter.constantroots)
- gc = MarkSweepGC(om, 4096)
+ gc.objectmodel = om
wrapper = GcWrapper(llinterp, gc)
return wrapper
More information about the Pypy-commit
mailing list