[pypy-commit] pypy default: Tweak inspector.get_rpy_roots()
arigo
pypy.commits at gmail.com
Wed Sep 13 16:41:55 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r92378:f3070ec0eeb3
Date: 2017-09-13 22:36 +0200
http://bitbucket.org/pypy/pypy/changeset/f3070ec0eeb3/
Log: Tweak inspector.get_rpy_roots()
diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -22,6 +22,7 @@
can_usually_pin_objects = False
object_minimal_size = 0
gcflag_extra = 0 # or a real GC flag that is always 0 when not collecting
+ _totalroots_rpy = 0 # for inspector.py
def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
translated_to_c=True):
diff --git a/rpython/memory/gc/inspector.py b/rpython/memory/gc/inspector.py
--- a/rpython/memory/gc/inspector.py
+++ b/rpython/memory/gc/inspector.py
@@ -10,73 +10,62 @@
# ---------- implementation of rpython.rlib.rgc.get_rpy_roots() ----------
-def _counting_rpy_root(obj, gc):
- gc._count_rpy += 1
-
-def _do_count_rpy_roots(gc):
- gc._count_rpy = 0
- gc.enumerate_all_roots(_counting_rpy_root, gc)
- return gc._count_rpy
-
def _append_rpy_root(obj, gc):
# Can use the gc list, but should not allocate!
# It is essential that the list is not resizable!
lst = gc._list_rpy
index = gc._count_rpy
- if index >= len(lst):
- raise ValueError
+ if index < len(lst):
+ lst[index] = llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
+ #else:
+ # too many items. This situation is detected at the end
gc._count_rpy = index + 1
- lst[index] = llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
def _do_append_rpy_roots(gc, lst):
gc._count_rpy = 0
gc._list_rpy = lst
gc.enumerate_all_roots(_append_rpy_root, gc)
gc._list_rpy = None
+ return gc._count_rpy
def get_rpy_roots(gc):
- count = _do_count_rpy_roots(gc)
- extra = 16
while True:
- result = [lltype.nullptr(llmemory.GCREF.TO)] * (count + extra)
- try:
- _do_append_rpy_roots(gc, result)
- except ValueError:
- extra *= 3
- else:
+ result = [lltype.nullptr(llmemory.GCREF.TO)] * gc._totalroots_rpy
+ count = _do_append_rpy_roots(gc, result)
+ if count <= len(result): # 'count' fits inside the list
return result
+ count += (count // 8)
+ gc._totalroots_rpy = count + 10
# ---------- implementation of rpython.rlib.rgc.get_rpy_referents() ----------
-def _count_rpy_referent(pointer, gc):
- gc._count_rpy += 1
-
-def _do_count_rpy_referents(gc, gcref):
- gc._count_rpy = 0
- gc.trace(llmemory.cast_ptr_to_adr(gcref), _count_rpy_referent, gc)
- return gc._count_rpy
-
def _append_rpy_referent(pointer, gc):
# Can use the gc list, but should not allocate!
# It is essential that the list is not resizable!
lst = gc._list_rpy
index = gc._count_rpy
- if index >= len(lst):
- raise ValueError
+ if index < len(lst):
+ lst[index] = llmemory.cast_adr_to_ptr(pointer.address[0],
+ llmemory.GCREF)
+ #else:
+ # too many items. This situation is detected at the end
gc._count_rpy = index + 1
- lst[index] = llmemory.cast_adr_to_ptr(pointer.address[0],
- llmemory.GCREF)
def _do_append_rpy_referents(gc, gcref, lst):
gc._count_rpy = 0
gc._list_rpy = lst
gc.trace(llmemory.cast_ptr_to_adr(gcref), _append_rpy_referent, gc)
+ gc._list_rpy = None
+ return gc._count_rpy
def get_rpy_referents(gc, gcref):
- count = _do_count_rpy_referents(gc, gcref)
- result = [lltype.nullptr(llmemory.GCREF.TO)] * count
- _do_append_rpy_referents(gc, gcref, result)
- return result
+ count = 7
+ while True:
+ result = [lltype.nullptr(llmemory.GCREF.TO)] * count
+ count = _do_append_rpy_referents(gc, gcref, result)
+ if count <= len(result): # 'count' fits inside the list
+ return result
+ count += (count // 8)
# ----------
More information about the pypy-commit
mailing list