[pypy-svn] r25599 - in pypy/dist/pypy/rpython/memory: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Apr 8 22:51:24 CEST 2006
Author: cfbolz
Date: Sat Apr 8 22:51:23 2006
New Revision: 25599
Modified:
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/gctransform.py
pypy/dist/pypy/rpython/memory/gcwrapper.py
pypy/dist/pypy/rpython/memory/support.py
pypy/dist/pypy/rpython/memory/test/test_gc.py
pypy/dist/pypy/rpython/memory/test/test_support.py
Log:
don't use global freelist. bad idea. (slightly messy to remove, though)
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Sat Apr 8 22:51:23 2006
@@ -1,6 +1,6 @@
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, raw_memcopy
from pypy.rpython.memory.lladdress import NULL, address
-from pypy.rpython.memory.support import AddressLinkedList
+from pypy.rpython.memory.support import get_address_linked_list
from pypy.rpython.memory import lltypesimulation
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.objectmodel import free_non_gc_object
@@ -29,9 +29,9 @@
class GCError(Exception):
pass
-def get_dummy_annotate(gc_class):
+def get_dummy_annotate(gc_class, AddressLinkedList):
def dummy_annotate():
- gc = gc_class()
+ gc = gc_class(AddressLinkedList)
gc.get_roots = dummy_get_roots1 #prevent the get_roots attribute to
gc.get_roots = dummy_get_roots2 #be constants
a = gc.malloc(1, 2)
@@ -39,28 +39,29 @@
gc.write_barrier(raw_malloc(1), raw_malloc(2), raw_malloc(1))
gc.collect()
return a - b
- return dummy_annotate
+
+ def dummy_get_roots1():
+ ll = AddressLinkedList()
+ ll.append(NULL)
+ ll.append(raw_malloc(10))
+ ll.pop() #make the annotator see pop
+ return ll
+
+ def dummy_get_roots2():
+ ll = AddressLinkedList()
+ ll.append(raw_malloc(10))
+ ll.append(NULL)
+ ll.pop() #make the annotator see pop
+ return ll
+ return dummy_annotate, dummy_get_roots1, dummy_get_roots2
+
gc_interface = {
"malloc": lltype.FuncType((lltype.Signed, lltype.Signed), lltype.Signed),
"collect": lltype.FuncType((), lltype.Void),
"write_barrier": lltype.FuncType((llmemory.Address, ) * 3, lltype.Void),
}
-
-def dummy_get_roots1():
- ll = AddressLinkedList()
- ll.append(NULL)
- ll.append(raw_malloc(10))
- ll.pop() #make the annotator see pop
- return ll
-
-def dummy_get_roots2():
- ll = AddressLinkedList()
- ll.append(raw_malloc(10))
- ll.append(NULL)
- ll.pop() #make the annotator see pop
- return ll
-
+
class GCBase(object):
_alloc_flavor_ = "raw"
@@ -89,7 +90,7 @@
class DummyGC(GCBase):
_alloc_flavor_ = "raw"
- def __init__(self, dummy=None, get_roots=None):
+ def __init__(self, AddressLinkedList, dummy=None, get_roots=None):
self.get_roots = get_roots
#self.set_query_functions(None, None, None, None, None, None, None)
@@ -115,12 +116,13 @@
_size_gc_header = gc_header_one_int
- def __init__(self, start_heap_size=4096, get_roots=None):
+ def __init__(self, AddressLinkedList, start_heap_size=4096, get_roots=None):
self.bytes_malloced = 0
self.heap_size = start_heap_size
#need to maintain a list of malloced objects, since we used the systems
#allocator and can't walk the heap
self.malloced_objects = AddressLinkedList()
+ self.AddressLinkedList = AddressLinkedList
#self.set_query_functions(None, None, None, None, None, None, None)
self.get_roots = get_roots
@@ -164,7 +166,7 @@
## print "collecting"
self.bytes_malloced = 0
roots = self.get_roots()
- objects = AddressLinkedList()
+ objects = self.AddressLinkedList()
while 1:
curr = roots.pop()
## print "root: ", curr
@@ -209,7 +211,7 @@
i += 1
gc_info.signed[0] = gc_info.signed[0] | 1
free_non_gc_object(objects)
- newmo = AddressLinkedList()
+ newmo = self.AddressLinkedList()
curr_heap_size = 0
freed_size = 0
while 1: #sweep
@@ -244,7 +246,8 @@
class SemiSpaceGC(GCBase):
_alloc_flavor_ = "raw"
- def __init__(self, space_size=1024*int_size, get_roots=None):
+ def __init__(self, AddressLinkedList, space_size=1024*int_size,
+ get_roots=None):
self.bytes_malloced = 0
self.space_size = space_size
self.tospace = raw_malloc(space_size)
@@ -382,8 +385,9 @@
class DeferredRefcountingGC(GCBase):
_alloc_flavor_ = "raw"
- def __init__(self, max_refcount_zero=50, get_roots=None):
+ def __init__(self, AddressLinkedList, max_refcount_zero=50, get_roots=None):
self.zero_ref_counts = AddressLinkedList()
+ self.AddressLinkedList = AddressLinkedList
self.length_zero_ref_counts = 0
self.max_refcount_zero = max_refcount_zero
#self.set_query_functions(None, None, None, None, None, None, None)
@@ -407,7 +411,7 @@
else:
self.collecting = True
roots = self.get_roots()
- roots_copy = AddressLinkedList()
+ roots_copy = self.AddressLinkedList()
curr = roots.pop()
while curr != NULL:
## print "root", root, root.address[0]
@@ -416,7 +420,7 @@
roots_copy.append(curr)
curr = roots.pop()
roots = roots_copy
- dealloc_list = AddressLinkedList()
+ dealloc_list = self.AddressLinkedList()
self.length_zero_ref_counts = 0
while 1:
candidate = self.zero_ref_counts.pop()
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Sat Apr 8 22:51:23 2006
@@ -666,7 +666,9 @@
class FrameworkGCTransformer(BoehmGCTransformer):
def __init__(self, translator):
+ from pypy.rpython.memory.support import get_address_linked_list
super(FrameworkGCTransformer, self).__init__(translator, inline=True)
+ AddressLinkedList = get_address_linked_list()
class GCData(object):
from pypy.rpython.memory.gc import MarkSweepGC as GCClass
startheapsize = 8*1024*1024 # XXX adjust
@@ -747,7 +749,7 @@
stackbase = lladdress.raw_malloc(GCData.rootstacksize)
gcdata.root_stack_top = stackbase
gcdata.root_stack_base = stackbase
- gcdata.gc = GCData.GCClass(GCData.startheapsize, StackRootIterator)
+ gcdata.gc = GCData.GCClass(AddressLinkedList, GCData.startheapsize, StackRootIterator)
gcdata.gc.set_query_functions(
q_is_varsize,
q_offsets_to_gc_pointers,
Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py Sat Apr 8 22:51:23 2006
@@ -1,7 +1,7 @@
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.rpython.rtyper import RPythonTyper
from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rpython.memory.support import AddressLinkedList, INT_SIZE
+from pypy.rpython.memory.support import get_address_linked_list, INT_SIZE
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory import lltypelayout
from pypy.rpython.memory import lltypesimulation
@@ -175,10 +175,11 @@
class GcWrapper(object):
def __init__(self, llinterp, flowgraphs, gc_class):
self.query_types = QueryTypes()
+ self.AddressLinkedList = get_address_linked_list(3)
# XXX there might me GCs that have headers that depend on the type
# therefore we have to change the query functions to annotatable ones
# later
- self.gc = gc_class()
+ self.gc = gc_class(self.AddressLinkedList)
self.gc.set_query_functions(*self.query_types.get_setup_query_functions())
fgcc = FlowGraphConstantConverter(flowgraphs, self.gc, self.query_types)
fgcc.convert()
@@ -251,7 +252,7 @@
def get_roots(self):
self.get_roots_from_llinterp()
- ll = AddressLinkedList()
+ ll = self.AddressLinkedList()
for i, root in enumerate(self.roots):
self.pseudo_root_pointers.address[i] = root._address
ll.append(self.pseudo_root_pointers + INT_SIZE * i)
@@ -268,15 +269,17 @@
def annotate_rtype_gc(self):
# annotate and specialize functions
gc_class = self.gc.__class__
+ AddressLinkedList = self.AddressLinkedList
def instantiate_linked_list():
return AddressLinkedList()
f1, f2, f3, f4, f5, f6, f7 = self.query_types.create_query_functions()
def instantiate_gc():
- gc = gc_class()
+ gc = gc_class(AddressLinkedList)
gc.set_query_functions(f1, f2, f3, f4, f5, f6, f7)
return gc
- func = gc.get_dummy_annotate(self.gc.__class__)
- self.gc.get_roots = gc.dummy_get_roots1
+ func, dummy_get_roots1, dummy_get_roots2 = gc.get_dummy_annotate(
+ self.gc.__class__, self.AddressLinkedList)
+ self.gc.get_roots = dummy_get_roots1
a = RPythonAnnotator()
a.build_types(instantiate_gc, [])
a.build_types(func, [])
@@ -295,7 +298,7 @@
self.gcptr = self.llinterp.eval_graph(
a.bookkeeper.getdesc(instantiate_gc).cachedgraph(None))
GETROOTS_FUNCTYPE = lltype.typeOf(
- getfunctionptr(a, gc.dummy_get_roots1)).TO
+ getfunctionptr(a, dummy_get_roots1)).TO
setattr(self.gcptr, "inst_get_roots",
lltypesimulation.functionptr(GETROOTS_FUNCTYPE, "get_roots",
_callable=self.get_roots))
Modified: pypy/dist/pypy/rpython/memory/support.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/support.py (original)
+++ pypy/dist/pypy/rpython/memory/support.py Sat Apr 8 22:51:23 2006
@@ -25,41 +25,42 @@
chunk.address[0] = self.free_list
self.free_list = chunk
-class AddressLinkedList(object):
- _alloc_flavor_ = "raw"
-
- unused_chunks = FreeList(CHUNK_SIZE + 2)
-
- def __init__(self):
- self.chunk = NULL
-
- def append(self, addr):
- if addr == NULL:
- return
- if self.chunk == NULL or self.chunk.signed[1] == CHUNK_SIZE:
- new = AddressLinkedList.unused_chunks.get()
- new.address[0] = self.chunk
- new.signed[1] = 0
- self.chunk = new
- used_chunks = self.chunk.signed[1]
- self.chunk.signed[1] += 1
- self.chunk.address[used_chunks + 2] = addr
+def get_address_linked_list(chunk_size=CHUNK_SIZE):
+ unused_chunks = FreeList(chunk_size + 2)
+ class AddressLinkedList(object):
+ _alloc_flavor_ = "raw"
- def pop(self):
- used_chunks = self.chunk.signed[1]
- if used_chunks == 0:
- old = self.chunk
- previous = old.address[0]
- if previous == NULL:
- return NULL
- self.chunk = previous
- AddressLinkedList.unused_chunks.put(old)
+ def __init__(self):
+ self.chunk = NULL
+
+ def append(self, addr):
+ if addr == NULL:
+ return
+ if self.chunk == NULL or self.chunk.signed[1] == chunk_size:
+ new = unused_chunks.get()
+ new.address[0] = self.chunk
+ new.signed[1] = 0
+ self.chunk = new
+ used_chunks = self.chunk.signed[1]
+ self.chunk.signed[1] += 1
+ self.chunk.address[used_chunks + 2] = addr
+
+ def pop(self):
used_chunks = self.chunk.signed[1]
- result = self.chunk.address[used_chunks + 1]
- self.chunk.address[used_chunks + 1] = NULL
- self.chunk.signed[1] = used_chunks - 1
- return result
+ if used_chunks == 0:
+ old = self.chunk
+ previous = old.address[0]
+ if previous == NULL:
+ return NULL
+ self.chunk = previous
+ unused_chunks.put(old)
+ used_chunks = self.chunk.signed[1]
+ result = self.chunk.address[used_chunks + 1]
+ self.chunk.address[used_chunks + 1] = NULL
+ self.chunk.signed[1] = used_chunks - 1
+ return result
- def free(self):
- while self.pop() != NULL:
- pass
+ def free(self):
+ while self.pop() != NULL:
+ pass
+ return AddressLinkedList
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 Sat Apr 8 22:51:23 2006
@@ -6,7 +6,7 @@
from pypy.rpython.rtyper import RPythonTyper
from pypy.rpython.memory.gc import GCError, MarkSweepGC, SemiSpaceGC
from pypy.rpython.memory.gc import DeferredRefcountingGC, DummyGC
-from pypy.rpython.memory.support import AddressLinkedList, INT_SIZE, CHUNK_SIZE, FreeList
+from pypy.rpython.memory.support import INT_SIZE, CHUNK_SIZE
from pypy.rpython.memory import support
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory.simulator import MemorySimulatorError
@@ -29,11 +29,9 @@
py.log.setconsumer("llinterp frame", stdout_ignore_ll_functions)
py.log.setconsumer("llinterp operation", None)
gclltype.prepare_graphs_and_create_gc = gclltype.create_gc
- support.CHUNK_SIZE = 1
def teardown_module(mod):
gclltype.prepare_graphs_and_create_gc = gclltype.create_no_gc
- support.CHUNK_SIZE = CHUNK_SIZE
class TestMarkSweepGC(object):
def setup_class(cls):
@@ -100,7 +98,6 @@
class TestMarkSweepGCRunningOnLLinterp(TestMarkSweepGC):
def setup_class(cls):
- AddressLinkedList.unused_chunks = FreeList(3) # 'leaks' but well
cls.prep_old = gclltype.prepare_graphs_and_create_gc
gclltype.prepare_graphs_and_create_gc = gclltype.create_gc_run_on_llinterp
def teardown_class(cls):
@@ -115,7 +112,6 @@
class TestSemiSpaceGCRunningOnLLinterp(TestMarkSweepGC):
def setup_class(cls):
- AddressLinkedList.unused_chunks = FreeList(3) # 'leaks' but well
cls.prep_old = gclltype.prepare_graphs_and_create_gc
gclltype.prepare_graphs_and_create_gc = gclltype.create_gc_run_on_llinterp
gclltype.use_gc = SemiSpaceGC
@@ -135,7 +131,6 @@
class TestDeferredRefcountingGCRunningOnLLinterp(TestMarkSweepGC):
def setup_class(cls):
- AddressLinkedList.unused_chunks = FreeList(3) # 'leaks' but well
cls.prep_old = gclltype.prepare_graphs_and_create_gc
gclltype.prepare_graphs_and_create_gc = gclltype.create_gc_run_on_llinterp
gclltype.use_gc = DeferredRefcountingGC
@@ -154,7 +149,6 @@
class TestDummyGCRunningOnLLinterp(TestMarkSweepGC):
def setup_class(cls):
- AddressLinkedList.unused_chunks = FreeList(3) # 'leaks' but well
cls.prep_old = gclltype.prepare_graphs_and_create_gc
gclltype.prepare_graphs_and_create_gc = gclltype.create_gc_run_on_llinterp
gclltype.use_gc = DummyGC
Modified: pypy/dist/pypy/rpython/memory/test/test_support.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_support.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_support.py Sat Apr 8 22:51:23 2006
@@ -1,5 +1,5 @@
from pypy.rpython.objectmodel import free_non_gc_object
-from pypy.rpython.memory.support import AddressLinkedList, FreeList, CHUNK_SIZE
+from pypy.rpython.memory.support import get_address_linked_list, FreeList
from pypy.rpython.memory import support
from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
from pypy.rpython.memory.test.test_llinterpsim import interpret
@@ -7,6 +7,7 @@
class TestAddressLinkedList(object):
def test_simple_access(self):
+ AddressLinkedList = get_address_linked_list()
addr = raw_malloc(100)
ll = AddressLinkedList()
ll.append(addr)
@@ -32,6 +33,7 @@
raw_free(addr)
def test_big_access(self):
+ AddressLinkedList = get_address_linked_list()
addr = raw_malloc(1)
ll = AddressLinkedList()
for i in range(3000):
@@ -51,6 +53,7 @@
raw_free(addr)
def test_linked_list_annotate():
+ AddressLinkedList = get_address_linked_list()
def f():
addr = raw_malloc(100)
ll = AddressLinkedList()
@@ -91,7 +94,6 @@
## a.translator.specialize()
## a.translator.view()
assert f()
- # grumpf: make sure that we don't get a polluted class attribute
- AddressLinkedList.unused_chunks = FreeList(CHUNK_SIZE + 2)
+ AddressLinkedList = get_address_linked_list()
res = interpret(f, [])
assert res
More information about the Pypy-commit
mailing list