[pypy-svn] r68737 - in pypy/branch/gc-dump-heap/pypy/rpython: . lltypesystem memory/gc memory/gctransform memory/test
fijal at codespeak.net
fijal at codespeak.net
Sun Oct 25 16:33:11 CET 2009
Author: fijal
Date: Sun Oct 25 16:33:11 2009
New Revision: 68737
Modified:
pypy/branch/gc-dump-heap/pypy/rpython/llinterp.py
pypy/branch/gc-dump-heap/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/gc-dump-heap/pypy/rpython/memory/gc/semispace.py
pypy/branch/gc-dump-heap/pypy/rpython/memory/gctransform/framework.py
pypy/branch/gc-dump-heap/pypy/rpython/memory/test/test_transformed_gc.py
Log:
in-progress a dump heap operation
Modified: pypy/branch/gc-dump-heap/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/gc-dump-heap/pypy/rpython/llinterp.py (original)
+++ pypy/branch/gc-dump-heap/pypy/rpython/llinterp.py Sun Oct 25 16:33:11 2009
@@ -824,6 +824,9 @@
def op_gc_assume_young_pointers(self, addr):
raise NotImplementedError
+ def op_gc_dump_heap(self, fd):
+ raise NotImplementedError # impossible
+
def op_gc_obtain_free_space(self, size):
raise NotImplementedError
Modified: pypy/branch/gc-dump-heap/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/gc-dump-heap/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/gc-dump-heap/pypy/rpython/lltypesystem/lloperation.py Sun Oct 25 16:33:11 2009
@@ -459,6 +459,7 @@
'gc_thread_run' : LLOp(),
'gc_thread_die' : LLOp(),
'gc_assume_young_pointers': LLOp(),
+ 'gc_dump_heap' : LLOp(),
# ------- JIT & GC interaction, only for some GCs ----------
Modified: pypy/branch/gc-dump-heap/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/gc-dump-heap/pypy/rpython/memory/gc/semispace.py (original)
+++ pypy/branch/gc-dump-heap/pypy/rpython/memory/gc/semispace.py Sun Oct 25 16:33:11 2009
@@ -24,6 +24,8 @@
memoryError = MemoryError()
+ARRAY_OF_SIGNED = lltype.Array(lltype.Signed)
+
class SemiSpaceGC(MovingGCBase):
_alloc_flavor_ = "raw"
@@ -636,3 +638,25 @@
hdr.tid |= GCFLAG_HASHTAKEN
#
return llmemory.cast_adr_to_int(obj) # direct case
+
+ def _dump_heap_extraarg(self, addr, ignored):
+ self._dump_heap(addr)
+
+ def _dump_heap(self, addr):
+ os.write(self._fd_dump, "X")
+ self.trace(addr, self._dump_heap_extraarg, None)
+
+ def dump_heap(self, fd):
+ ll_typeid_usage = lltype.nullptr(ARRAY_OF_SIGNED)
+ self._fd_dump = fd
+ try:
+ ll_typeid_usage = lltype.malloc(ARRAY_OF_SIGNED,
+ self.root_walker.gcdata.max_type_id, flavor='raw')
+ self.root_walker.walk_roots(
+ SemiSpaceGC._dump_heap, # stack roots
+ SemiSpaceGC._dump_heap, # static in prebuilt non-gc structures
+ SemiSpaceGC._dump_heap) # static in prebuilt gc objects
+ finally:
+ if ll_typeid_usage:
+ lltype.free(ll_typeid_usage, flavor='raw')
+ self._fd_dump = -1
Modified: pypy/branch/gc-dump-heap/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/gc-dump-heap/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/gc-dump-heap/pypy/rpython/memory/gctransform/framework.py Sun Oct 25 16:33:11 2009
@@ -24,7 +24,6 @@
TYPE_ID = rffi.USHORT
-
class CollectAnalyzer(graphanalyze.BoolGraphAnalyzer):
def analyze_direct_call(self, graph, seen=None):
@@ -152,6 +151,7 @@
gcdata.static_root_start = a_random_address # patched in finish()
gcdata.static_root_nongcend = a_random_address # patched in finish()
gcdata.static_root_end = a_random_address # patched in finish()
+ gcdata.max_type_id = 13 # patched in finish()
self.gcdata = gcdata
self.malloc_fnptr_cache = {}
@@ -188,6 +188,9 @@
data_classdef.generalize_attr(
'static_root_end',
annmodel.SomeAddress())
+ data_classdef.generalize_attr(
+ 'max_type_id',
+ annmodel.SomeInteger())
annhelper = annlowlevel.MixLevelHelperAnnotator(self.translator.rtyper)
@@ -267,6 +270,12 @@
[s_gc, annmodel.SomeAddress()],
annmodel.s_None)
+ if hasattr(GCClass, 'dump_heap'):
+ self.dump_heap_ptr = getfn(
+ GCClass.dump_heap.im_func,
+ [s_gc, annmodel.SomeInteger()],
+ annmodel.s_None)
+
# in some GCs we can inline the common case of
# malloc_fixedsize(typeid, size, True, False, False)
if getattr(GCClass, 'inline_simple_malloc', False):
@@ -497,14 +506,16 @@
ll_static_roots_inside = lltype.malloc(lltype.Array(llmemory.Address),
len(addresses_of_static_ptrs),
immortal=True)
+
for i in range(len(addresses_of_static_ptrs)):
ll_static_roots_inside[i] = addresses_of_static_ptrs[i]
ll_instance.inst_static_root_start = llmemory.cast_ptr_to_adr(ll_static_roots_inside) + llmemory.ArrayItemsOffset(lltype.Array(llmemory.Address))
ll_instance.inst_static_root_nongcend = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(self.layoutbuilder.addresses_of_static_ptrs_in_nongc)
ll_instance.inst_static_root_end = ll_instance.inst_static_root_start + llmemory.sizeof(llmemory.Address) * len(addresses_of_static_ptrs)
-
newgcdependencies = []
newgcdependencies.append(ll_static_roots_inside)
+ ll_instance.inst_max_type_id = len(group.members)
+
self.write_typeid_list()
return newgcdependencies
@@ -634,6 +645,12 @@
hop.genop("direct_call", [self.assume_young_pointers_ptr,
self.c_const_gc, v_addr])
+ def gct_gc_dump_heap(self, hop):
+ op = hop.spaceop
+ v_fd = op.args[0]
+ hop.genop("direct_call", [self.dump_heap_ptr,
+ self.c_const_gc, v_fd])
+
def gct_gc_adr_of_nursery_free(self, hop):
if getattr(self.gcdata.gc, 'nursery_free', None) is None:
raise NotImplementedError("gc_adr_of_nursery_free only for generational gcs")
Modified: pypy/branch/gc-dump-heap/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/gc-dump-heap/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/gc-dump-heap/pypy/rpython/memory/test/test_transformed_gc.py Sun Oct 25 16:33:11 2009
@@ -796,6 +796,26 @@
run = self.runner("do_malloc_operations_in_call")
run([])
+ def define_gc_dump_heap(cls):
+ S = lltype.GcStruct('S', ('x', lltype.Signed))
+
+ def f(fd, ign):
+ l = []
+ for i in range(10):
+ l.append(lltype.malloc(S))
+ rgc.dump_heap(fd)
+ return 0
+ return f
+
+ def test_gc_dump_heap(self):
+ from pypy.tool.udir import udir
+ f = udir.join("gcdump.log")
+ handle = open(str(f), "w")
+ run = self.runner("gc_dump_heap")
+ run([handle.fileno(), 0])
+ handle.close()
+ assert f.read() == 'xxx'
+
# ________________________________________________________________
class TestMarkSweepGC(GenericGCTests):
More information about the Pypy-commit
mailing list