| 1 |
from rpython.rlib import rgc |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
class GcHooks(object): |
| 6 |
""" |
| 7 |
Base class to write your own GC hooks. |
| 8 |
|
| 9 |
Subclasses are expected to override the on_* methods. Note that such |
| 10 |
methods can do only simple stuff such as updating statistics and/or |
| 11 |
setting a flag: in particular, they cannot do anything which can possibly |
| 12 |
trigger a GC collection. |
| 13 |
""" |
| 14 |
|
| 15 |
def is_gc_minor_enabled(self): |
| 16 |
return False |
| 17 |
|
| 18 |
def is_gc_collect_step_enabled(self): |
| 19 |
return False |
| 20 |
|
| 21 |
def is_gc_collect_enabled(self): |
| 22 |
return False |
| 23 |
|
| 24 |
def on_gc_minor(self, duration, total_memory_used, pinned_objects): |
| 25 |
""" |
| 26 |
Called after a minor collection |
| 27 |
""" |
| 28 |
|
| 29 |
def on_gc_collect_step(self, duration, oldstate, newstate): |
| 30 |
""" |
| 31 |
Called after each individual step of a major collection, in case the GC is |
| 32 |
incremental. |
| 33 |
|
| 34 |
``oldstate`` and ``newstate`` are integers which indicate the GC |
| 35 |
state; for incminimark, see incminimark.STATE_* and |
| 36 |
incminimark.GC_STATES. |
| 37 |
""" |
| 38 |
|
| 39 |
|
| 40 |
def on_gc_collect(self, num_major_collects, |
| 41 |
arenas_count_before, arenas_count_after, |
| 42 |
arenas_bytes, rawmalloc_bytes_before, |
| 43 |
rawmalloc_bytes_after, pinned_after): |
| 44 |
""" |
| 45 |
Called after a major collection is fully done |
| 46 |
""" |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
@rgc.no_collect |
| 52 |
def fire_gc_minor(self, duration, total_memory_used, pinned_objects): |
| 53 |
if self.is_gc_minor_enabled(): |
| 54 |
self.on_gc_minor(duration, total_memory_used, pinned_objects) |
| 55 |
|
| 56 |
@rgc.no_collect |
| 57 |
def fire_gc_collect_step(self, duration, oldstate, newstate): |
| 58 |
if self.is_gc_collect_step_enabled(): |
| 59 |
self.on_gc_collect_step(duration, oldstate, newstate) |
| 60 |
|
| 61 |
@rgc.no_collect |
| 62 |
def fire_gc_collect(self, num_major_collects, |
| 63 |
arenas_count_before, arenas_count_after, |
| 64 |
arenas_bytes, rawmalloc_bytes_before, |
| 65 |
rawmalloc_bytes_after, pinned_objects): |
| 66 |
if self.is_gc_collect_enabled(): |
| 67 |
self.on_gc_collect(num_major_collects, |
| 68 |
arenas_count_before, arenas_count_after, |
| 69 |
arenas_bytes, rawmalloc_bytes_before, |
| 70 |
rawmalloc_bytes_after, pinned_objects) |