Author: Antonio Cuni <[email protected]>
Branch: gc-hooks
Changeset: r94185:9bb5a3a3e292
Date: 2018-03-29 18:59 +0200
http://bitbucket.org/pypy/pypy/changeset/9bb5a3a3e292/
Log: WIP: hack around until we can pass a prebuilt instance of gchooks to
the GC transformer, which will then forward it to the GCClass; start
to test the behavior inside test_transformed_gc, but for now some
tests fail because our testing hooks allocate too much, causing
infinite recursion
diff --git a/rpython/memory/gc/test/test_hook.py
b/rpython/memory/gc/test/test_hook.py
--- a/rpython/memory/gc/test/test_hook.py
+++ b/rpython/memory/gc/test/test_hook.py
@@ -1,8 +1,11 @@
+from rpython.rlib.rarithmetic import intmask
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.memory.gc.hook import GcHooks
from rpython.memory.gc.test.test_direct import BaseDirectGCTest, S
+# The following class is used also by test_transformed_gc and so it needs to
+# be RPython, that's why we have to use intmask to get consistent types
class MyGcHooks(GcHooks):
def __init__(self):
@@ -13,14 +16,26 @@
self.steps = []
self.collects = []
- def on_gc_minor(self, **kwds):
- self.minors.append(kwds)
+ def on_gc_minor(self, total_memory_used, pinned_objects):
+ self.minors.append({
+ 'total_memory_used': intmask(total_memory_used),
+ 'pinned_objects': pinned_objects})
- def on_gc_collect_step(self, **kwds):
- self.steps.append(kwds)
+ def on_gc_collect_step(self, oldstate, newstate):
+ self.steps.append({
+ 'oldstate': oldstate,
+ 'newstate': newstate})
- def on_gc_collect(self, **kwds):
- self.collects.append(kwds)
+ def on_gc_collect(self, count, arenas_count_before, arenas_count_after,
+ arenas_bytes, rawmalloc_bytes_before,
+ rawmalloc_bytes_after):
+ self.collects.append({
+ 'count': count,
+ 'arenas_count_before': arenas_count_before,
+ 'arenas_count_after': arenas_count_after,
+ 'arenas_bytes': intmask(arenas_bytes),
+ 'rawmalloc_bytes_before': intmask(rawmalloc_bytes_before),
+ 'rawmalloc_bytes_after': intmask(rawmalloc_bytes_after)})
class TestIncMiniMarkHooks(BaseDirectGCTest):
diff --git a/rpython/memory/gctransform/framework.py
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -116,7 +116,7 @@
class BaseFrameworkGCTransformer(GCTransformer):
root_stack_depth = None # for tests to override
- def __init__(self, translator):
+ def __init__(self, translator, gchooks=None):
from rpython.memory.gc.base import choose_gc_from_config
super(BaseFrameworkGCTransformer, self).__init__(translator,
@@ -162,7 +162,8 @@
self.finalizer_queue_indexes = {}
self.finalizer_handlers = []
- gcdata.gc = GCClass(translator.config.translation, **GC_PARAMS)
+ gcdata.gc = GCClass(translator.config.translation, hooks=gchooks,
+ **GC_PARAMS)
root_walker = self.build_root_walker()
root_walker.finished_minor_collection_func = finished_minor_collection
self.root_walker = root_walker
diff --git a/rpython/memory/test/test_transformed_gc.py
b/rpython/memory/test/test_transformed_gc.py
--- a/rpython/memory/test/test_transformed_gc.py
+++ b/rpython/memory/test/test_transformed_gc.py
@@ -15,6 +15,7 @@
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import LONG_BIT
from rpython.rtyper.rtyper import llinterp_backend
+from rpython.memory.gc.test.test_hook import MyGcHooks
WORD = LONG_BIT // 8
@@ -48,6 +49,7 @@
gcpolicy = None
GC_CAN_MOVE = False
taggedpointers = False
+ gchooks = None
def setup_class(cls):
cls.marker = lltype.malloc(rffi.CArray(lltype.Signed), 1,
@@ -112,7 +114,8 @@
fixup(t)
cbuild = CStandaloneBuilder(t, entrypoint, config=t.config,
- gcpolicy=cls.gcpolicy)
+ gcpolicy=cls.gcpolicy,
+ gchooks=cls.gchooks)
cbuild.make_entrypoint_wrapper = False
db = cbuild.build_database()
entrypointptr = cbuild.getentrypointptr()
@@ -1405,6 +1408,11 @@
}
root_stack_depth = 200
+ gchooks = MyGcHooks()
+
+ def setup_method(self, m):
+ self.gchooks.reset()
+
def define_malloc_array_of_gcptr(self):
S = lltype.GcStruct('S', ('x', lltype.Signed))
A = lltype.GcArray(lltype.Ptr(S))
diff --git a/rpython/translator/c/database.py b/rpython/translator/c/database.py
--- a/rpython/translator/c/database.py
+++ b/rpython/translator/c/database.py
@@ -29,6 +29,7 @@
def __init__(self, translator=None, standalone=False,
gcpolicyclass=None,
+ gchooks=None,
exctransformer=None,
thread_enabled=False,
sandbox=False):
@@ -56,7 +57,7 @@
self.namespace = CNameManager()
if translator is not None:
- self.gctransformer = self.gcpolicy.gettransformer(translator)
+ self.gctransformer = self.gcpolicy.gettransformer(translator,
gchooks)
self.completed = False
self.instrument_ncounter = 0
diff --git a/rpython/translator/c/gc.py b/rpython/translator/c/gc.py
--- a/rpython/translator/c/gc.py
+++ b/rpython/translator/c/gc.py
@@ -302,9 +302,9 @@
class BasicFrameworkGcPolicy(BasicGcPolicy):
- def gettransformer(self, translator):
+ def gettransformer(self, translator, gchooks):
if hasattr(self, 'transformerclass'): # for rpython/memory tests
- return self.transformerclass(translator)
+ return self.transformerclass(translator, gchooks=gchooks)
raise NotImplementedError
def struct_setup(self, structdefnode, rtti):
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -64,13 +64,14 @@
split = False
def __init__(self, translator, entrypoint, config, gcpolicy=None,
- secondary_entrypoints=()):
+ gchooks=None, secondary_entrypoints=()):
self.translator = translator
self.entrypoint = entrypoint
self.entrypoint_name = getattr(self.entrypoint, 'func_name', None)
self.originalentrypoint = entrypoint
self.config = config
self.gcpolicy = gcpolicy # for tests only, e.g. rpython/memory/
+ self.gchooks = gchooks
self.eci = self.get_eci()
self.secondary_entrypoints = secondary_entrypoints
@@ -91,6 +92,7 @@
exctransformer = translator.getexceptiontransformer()
db = LowLevelDatabase(translator, standalone=self.standalone,
gcpolicyclass=gcpolicyclass,
+ gchooks=self.gchooks,
exctransformer=exctransformer,
thread_enabled=self.config.translation.thread,
sandbox=self.config.translation.sandbox)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit