Author: Armin Rigo <[email protected]>
Branch: improve-gc-tracing-hooks
Changeset: r74039:9a6efa2d4493
Date: 2014-10-21 16:01 +0200
http://bitbucket.org/pypy/pypy/changeset/9a6efa2d4493/
Log: Port the custom trace in the shadowstack's SHADOWSTACKREF objects.
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
@@ -241,8 +241,7 @@
root_walker.need_stacklet_support(self, getfn)
self.layoutbuilder.encode_type_shapes_now()
- self.create_custom_trace_funcs(gcdata.gc,
- translator.rtyper.custom_trace_funcs)
+ self.create_custom_trace_funcs(gcdata.gc, translator.rtyper)
annhelper.finish() # at this point, annotate all mix-level helpers
annhelper.backend_optimize()
@@ -494,7 +493,11 @@
[SomeAddress()],
annmodel.s_None)
- def create_custom_trace_funcs(self, gc, custom_trace_funcs):
+ def create_custom_trace_funcs(self, gc, rtyper):
+ custom_trace_funcs = tuple(rtyper.custom_trace_funcs)
+ rtyper.custom_trace_funcs = custom_trace_funcs
+ # too late to register new custom trace functions afterwards
+
custom_trace_funcs_unrolled = unrolling_iterable(
[(self.get_type_id(TP), func) for TP, func in custom_trace_funcs])
diff --git a/rpython/memory/gctransform/shadowstack.py
b/rpython/memory/gctransform/shadowstack.py
--- a/rpython/memory/gctransform/shadowstack.py
+++ b/rpython/memory/gctransform/shadowstack.py
@@ -73,16 +73,13 @@
return top
self.decr_stack = decr_stack
- root_iterator = get_root_iterator(gctransformer)
def walk_stack_root(callback, start, end):
- root_iterator.setcontext(NonConstant(llmemory.NULL))
gc = self.gc
addr = end
- while True:
- addr = root_iterator.nextleft(gc, start, addr)
- if addr == llmemory.NULL:
- return
- callback(gc, addr)
+ while addr != start:
+ addr -= sizeofaddr
+ if gc.points_to_valid_gc_object(addr):
+ callback(gc, addr)
self.rootstackhook = walk_stack_root
self.shadow_stack_pool = ShadowStackPool(gcdata)
@@ -349,25 +346,6 @@
raise MemoryError
-def get_root_iterator(gctransformer):
- if hasattr(gctransformer, '_root_iterator'):
- return gctransformer._root_iterator # if already built
- class RootIterator(object):
- def _freeze_(self):
- return True
- def setcontext(self, context):
- pass
- def nextleft(self, gc, start, addr):
- while addr != start:
- addr -= sizeofaddr
- if gc.points_to_valid_gc_object(addr):
- return addr
- return llmemory.NULL
- result = RootIterator()
- gctransformer._root_iterator = result
- return result
-
-
def get_shadowstackref(root_walker, gctransformer):
if hasattr(gctransformer, '_SHADOWSTACKREF'):
return gctransformer._SHADOWSTACKREF
@@ -381,19 +359,19 @@
rtti=True)
SHADOWSTACKREFPTR.TO.become(SHADOWSTACKREF)
+ def customtrace(gc, obj, callback, arg):
+ obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
+ addr = obj.top
+ start = obj.base
+ while addr != start:
+ addr -= sizeofaddr
+ gc._trace_callback(callback, arg, addr)
+
gc = gctransformer.gcdata.gc
- root_iterator = get_root_iterator(gctransformer)
-
- def customtrace(obj, prev):
- obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
- if not prev:
- root_iterator.setcontext(obj.context)
- prev = obj.top
- return root_iterator.nextleft(gc, obj.base, prev)
-
- CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
- llmemory.Address)
- customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
+ assert not hasattr(gc, 'custom_trace_dispatcher')
+ # ^^^ create_custom_trace_funcs() must not run before this
+ gctransformer.translator.rtyper.custom_trace_funcs.append(
+ (SHADOWSTACKREF, customtrace))
def shadowstack_destructor(shadowstackref):
if root_walker.stacklet_support:
@@ -414,8 +392,7 @@
destrptr = gctransformer.annotate_helper(shadowstack_destructor,
[SHADOWSTACKREFPTR], lltype.Void)
- lltype.attachRuntimeTypeInfo(SHADOWSTACKREF, customtraceptr=customtraceptr,
- destrptr=destrptr)
+ lltype.attachRuntimeTypeInfo(SHADOWSTACKREF, destrptr=destrptr)
gctransformer._SHADOWSTACKREF = SHADOWSTACKREF
return SHADOWSTACKREF
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit