Author: Antonio Cuni <[email protected]>
Branch: gc-hooks
Changeset: r94189:696e7ef11214
Date: 2018-03-30 14:59 +0200
http://bitbucket.org/pypy/pypy/changeset/696e7ef11214/

Log:    make it possible to define gchooks in the target, and use the new
        interface to print some stats inside targetgcbench. I ran benchmarks
        on targetgcbench, and it shows no significative difference between
        having or not having the hooks

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
@@ -1397,6 +1397,16 @@
     steps = 0
     collects = 0
 
+    @staticmethod
+    def fix_annotation():
+        # this is needed to "fix" the annotation of GcHooksStats early, and
+        # must be called from the "main" program. Else, we change the
+        # annotation during the GC transform, when it's too late
+        if NonConstant(False):
+            GC_HOOKS_STATS.collects += 42
+            GC_HOOKS_STATS.steps += 42
+            GC_HOOKS_STATS.minors += 42
+
 GC_HOOKS_STATS = GcHooksStats()
 
 class MyGcHooks(GcHooks):
@@ -1473,14 +1483,7 @@
     def define_gc_hooks(cls):
         gchooks = cls.gchooks
         def f():
-            if NonConstant(False):
-                # this is needed to "fix" the annotation of GcHooksStats
-                # early; else, we change the annotation during the GC
-                # transform, when it's too late
-                GC_HOOKS_STATS.collects += 42
-                GC_HOOKS_STATS.steps += 42
-                GC_HOOKS_STATS.minors += 42
-
+            GC_HOOKS_STATS.fix_annotation()
             # trigger two major collections
             llop.gc__collect(lltype.Void)
             llop.gc__collect(lltype.Void)
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
@@ -94,7 +94,7 @@
 
 class RefcountingGcPolicy(BasicGcPolicy):
 
-    def gettransformer(self, translator):
+    def gettransformer(self, translator, gchooks):
         from rpython.memory.gctransform import refcounting
         return refcounting.RefcountingGCTransformer(translator)
 
@@ -175,7 +175,7 @@
 
 class BoehmGcPolicy(BasicGcPolicy):
 
-    def gettransformer(self, translator):
+    def gettransformer(self, translator, gchooks):
         from rpython.memory.gctransform import boehm
         return boehm.BoehmGCTransformer(translator)
 
@@ -439,9 +439,9 @@
 
 class ShadowStackFrameworkGcPolicy(BasicFrameworkGcPolicy):
 
-    def gettransformer(self, translator):
+    def gettransformer(self, translator, gchooks):
         from rpython.memory.gctransform import shadowstack
-        return shadowstack.ShadowStackFrameworkGCTransformer(translator)
+        return shadowstack.ShadowStackFrameworkGCTransformer(translator, 
gchooks)
 
     def enter_roots_frame(self, funcgen, (c_gcdata, c_numcolors)):
         numcolors = c_numcolors.value
@@ -484,9 +484,9 @@
 
 class AsmGcRootFrameworkGcPolicy(BasicFrameworkGcPolicy):
 
-    def gettransformer(self, translator):
+    def gettransformer(self, translator, gchooks):
         from rpython.memory.gctransform import asmgcroot
-        return asmgcroot.AsmGcRootFrameworkGCTransformer(translator)
+        return asmgcroot.AsmGcRootFrameworkGCTransformer(translator, gchooks)
 
     def GC_KEEPALIVE(self, funcgen, v):
         return 'pypy_asm_keepalive(%s);' % funcgen.expr(v)
diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py
--- a/rpython/translator/driver.py
+++ b/rpython/translator/driver.py
@@ -413,11 +413,12 @@
             translator.frozen = True
 
         standalone = self.standalone
+        gchooks = self.extra.get('gchooks', None)
 
         if standalone:
             from rpython.translator.c.genc import CStandaloneBuilder
             cbuilder = CStandaloneBuilder(self.translator, self.entry_point,
-                                          config=self.config,
+                                          config=self.config, gchooks=gchooks,
                       secondary_entrypoints=
                       self.secondary_entrypoints + annotated_jit_entrypoints)
         else:
@@ -426,7 +427,8 @@
             cbuilder = CLibraryBuilder(self.translator, self.entry_point,
                                        functions=functions,
                                        name='libtesting',
-                                       config=self.config)
+                                       config=self.config,
+                                       gchooks=gchooks)
         if not standalone:     # xxx more messy
             cbuilder.modulename = self.extmod_name
         database = cbuilder.build_database()
diff --git a/rpython/translator/goal/targetgcbench.py 
b/rpython/translator/goal/targetgcbench.py
--- a/rpython/translator/goal/targetgcbench.py
+++ b/rpython/translator/goal/targetgcbench.py
@@ -1,16 +1,23 @@
 from rpython.translator.goal import gcbench
+from rpython.memory.test.test_transformed_gc import MyGcHooks, GC_HOOKS_STATS
 
 # _____ Define and setup target ___
 
+def entry_point(argv):
+    GC_HOOKS_STATS.fix_annotation()
+    ret = gcbench.entry_point(argv)
+    minors = GC_HOOKS_STATS.minors
+    steps = GC_HOOKS_STATS.steps
+    collects = GC_HOOKS_STATS.collects
+    print 'GC hooks statistics'
+    print '    gc-minor:        ', minors
+    print '    gc-collect-step: ', steps
+    print '    gc-collect:      ', collects
+    return ret
+
+gchooks = MyGcHooks()
+
 def target(*args):
     gcbench.ENABLE_THREADS = False    # not RPython
-    return gcbench.entry_point, None
+    return entry_point, None
 
-"""
-Why is this a stand-alone target?
-
-The above target specifies None as the argument types list.
-This is a case treated specially in the driver.py . If the list
-of input types is empty, it is meant to be a list of strings,
-actually implementing argv of the executable.
-"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to