Author: Antonio Cuni <[email protected]>
Branch: gc-hooks
Changeset: r94184:f16482adff0b
Date: 2018-03-29 10:56 +0200
http://bitbucket.org/pypy/pypy/changeset/f16482adff0b/
Log: add a hook for gc-collect-step
diff --git a/rpython/memory/gc/hook.py b/rpython/memory/gc/hook.py
--- a/rpython/memory/gc/hook.py
+++ b/rpython/memory/gc/hook.py
@@ -5,6 +5,16 @@
Called after a minor collection
"""
+ def on_gc_collect_step(self, oldstate, newstate):
+ """
+ Called after each individual step of a major collection, in case the
GC is
+ incremental.
+
+ ``oldstate`` and ``newstate`` are integers which indicate the GC
+ state; for incminimark, see incminimark.STATE_* and
+ incminimark.GC_STATES.
+ """
+
def on_gc_collect(self, count, arenas_count_before, arenas_count_after,
arenas_bytes, rawmalloc_bytes_before,
rawmalloc_bytes_after):
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -2243,6 +2243,7 @@
# is done before every major collection step
def major_collection_step(self, reserving_size=0):
debug_start("gc-collect-step")
+ oldstate = self.gc_state
debug_print("starting gc state: ", GC_STATES[self.gc_state])
# Debugging checks
if self.pinned_objects_in_nursery == 0:
@@ -2480,6 +2481,8 @@
debug_print("stopping, now in gc state: ", GC_STATES[self.gc_state])
debug_stop("gc-collect-step")
+ self.hooks.on_gc_collect_step(oldstate=oldstate,
+ newstate=self.gc_state)
def _sweep_old_objects_pointing_to_pinned(self, obj, new_list):
if self.header(obj).tid & GCFLAG_VISITED:
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
@@ -2,6 +2,7 @@
from rpython.memory.gc.hook import GcHooks
from rpython.memory.gc.test.test_direct import BaseDirectGCTest, S
+
class MyGcHooks(GcHooks):
def __init__(self):
@@ -9,11 +10,15 @@
def reset(self):
self.minors = []
+ self.steps = []
self.collects = []
def on_gc_minor(self, **kwds):
self.minors.append(kwds)
+ def on_gc_collect_step(self, **kwds):
+ self.steps.append(kwds)
+
def on_gc_collect(self, **kwds):
self.collects.append(kwds)
@@ -46,8 +51,15 @@
]
def test_on_gc_collect(self):
+ from rpython.memory.gc import incminimark as m
self.malloc(S)
self.gc.collect()
+ assert self.gc.hooks.steps == [
+ {'oldstate': m.STATE_SCANNING, 'newstate': m.STATE_MARKING},
+ {'oldstate': m.STATE_MARKING, 'newstate': m.STATE_SWEEPING},
+ {'oldstate': m.STATE_SWEEPING, 'newstate': m.STATE_FINALIZING},
+ {'oldstate': m.STATE_FINALIZING, 'newstate': m.STATE_SCANNING}
+ ]
assert self.gc.hooks.collects == [
{'count': 1,
'arenas_count_before': 0,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit