Patchwork [pph] More GC fixes (issue5606049)

login
register
mail settings
Submitter Diego Novillo
Date Feb. 2, 2012, 2:56 a.m.
Message ID <20120202025633.258E2AE1D7@tobiano.tor.corp.google.com>
Download mbox | patch
Permalink /patch/139063/
State New
Headers show

Comments

Diego Novillo - Feb. 2, 2012, 2:56 a.m.
This patch extends the hack I added in
http://gcc.gnu.org/ml/gcc-patches/2012-01/msg01031.html to pacify the garbage
collector.

I have to keep using the same fake GC root because these trees are
added to structures that I can't seem to get properly annotated for
GC.  In particular, I'm having trouble with 'FILE' pointers.  I will
try to figure this out at some point, but we've got bigger issues to
address at the moment.

The specific problem this time was that bitsizetype was being
GC'd out while we were reading a PPH image.  This was causing
ICEs when we were trying to read many PPH images.

2012-02-01   Diego Novillo  <dnovillo@google.com>

	* config-lang.in (gtfiles): Remove pph-out.c.  Add pph-core.c.
	* pph-core.c: Include gt-cp-pph-core.h.
	(pph_cached_trees): Declare.
	(pph_cache_insert_at): If adding a tree to the cache, also
	add it to pph_cached_trees.
	(pph_streamer_init): Set pph_cached_trees to NULL.
	(pph_streamer_finish): Likewise.
	Call ggc_collect.
	* pph-out.c (pph_decls_in_symtab): Remove.  Update all users.
---
 gcc/cp/ChangeLog.pph  |   12 ++++++++++++
 gcc/cp/config-lang.in |    2 +-
 gcc/cp/pph-core.c     |   25 +++++++++++++++++++++++++
 gcc/cp/pph-out.c      |   22 ----------------------
 4 files changed, 38 insertions(+), 23 deletions(-)

Patch

diff --git a/gcc/cp/ChangeLog.pph b/gcc/cp/ChangeLog.pph
index 8e8080d..ec80b56 100644
--- a/gcc/cp/ChangeLog.pph
+++ b/gcc/cp/ChangeLog.pph
@@ -1,3 +1,15 @@ 
+2012-02-01   Diego Novillo  <dnovillo@google.com>
+
+	* config-lang.in (gtfiles): Remove pph-out.c.  Add pph-core.c.
+	* pph-core.c: Include gt-cp-pph-core.h.
+	(pph_cached_trees): Declare.
+	(pph_cache_insert_at): If adding a tree to the cache, also
+	add it to pph_cached_trees.
+	(pph_streamer_init): Set pph_cached_trees to NULL.
+	(pph_streamer_finish): Likewise.
+	Call ggc_collect.
+	* pph-out.c (pph_decls_in_symtab): Remove.  Update all users.
+
 2012-02-01   Lawrence Crowl  <crowl@google.com>
 
 	* pph-streamer.h (pph_trace_tree):  Add name parameter.  Adjust callers
diff --git a/gcc/cp/config-lang.in b/gcc/cp/config-lang.in
index ab8e686..7dbfe95 100644
--- a/gcc/cp/config-lang.in
+++ b/gcc/cp/config-lang.in
@@ -30,4 +30,4 @@  compilers="cc1plus\$(exeext)"
 
 target_libs="target-libstdc++-v3"
 
-gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.h \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c \$(srcdir)/cp/except.c \$(srcdir)/cp/pph-out.c"
+gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.h \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c \$(srcdir)/cp/except.c \$(srcdir)/cp/pph-core.c"
diff --git a/gcc/cp/pph-core.c b/gcc/cp/pph-core.c
index d20d45b..814060f 100644
--- a/gcc/cp/pph-core.c
+++ b/gcc/cp/pph-core.c
@@ -90,6 +90,19 @@  struct pph_stream_registry_d {
 static struct pph_stream_registry_d pph_stream_registry;
 
 
+/* List of all the trees added to PPH pickle caches.
+
+   FIXME pph, the *only* purpose of this list is to act as a GC root
+   to avoid these trees from being garbage collected.
+
+   The parser will invoke garbage collection, which may clobber some
+   trees in the pickle caches (because the pickle caches are stored on
+   the heap).  Ideally, we would put all these data structures on GC
+   memory.  */
+static GTY(()) VEC(tree,gc) *pph_cached_trees;
+
+
+
 /*************************************************************** pph logging */
 
 
@@ -540,6 +553,11 @@  pph_cache_insert_at (pph_cache *cache, void *data, unsigned ix,
     VEC_safe_grow_cleared (pph_cache_entry, heap, cache->v, ix + 1);
   VEC_replace (pph_cache_entry, cache->v, ix, &e);
 
+  /* FIXME pph.  Hack to prevent cached trees from being garbage
+     collected.  */
+  if ((unsigned) tag <= (unsigned) PPH_any_tree)
+    VEC_safe_push (tree, gc, pph_cached_trees, (tree) data);
+
   return pph_cache_get_entry (cache, ix);
 }
 
@@ -1337,6 +1355,7 @@  pph_streamer_init (void)
 {
   pph_hooks_init ();
   pph_init_preloaded_cache ();
+  pph_cached_trees = NULL;
 }
 
 
@@ -1433,6 +1452,10 @@  pph_streamer_finish (void)
   VEC_free (pph_stream_ptr, heap, pph_stream_registry.v);
   pointer_map_destroy (pph_stream_registry.image_ix);
   htab_delete (pph_stream_registry.name_ix);
+
+  /* Get rid of all the dead trees we may have had in caches.  */
+  pph_cached_trees = NULL;
+  ggc_collect ();
 }
 
 
@@ -1455,3 +1478,5 @@  pph_finish (void)
   if (flag_pph_logfile)
     fclose (pph_logfile);
 }
+
+#include "gt-cp-pph-core.h"
diff --git a/gcc/cp/pph-out.c b/gcc/cp/pph-out.c
index 4fb1f7c..203b111 100644
--- a/gcc/cp/pph-out.c
+++ b/gcc/cp/pph-out.c
@@ -54,19 +54,6 @@  static void pph_out_merge_key_tree (pph_stream *, tree);
 static pph_stream *pph_out_stream = NULL;
 
 
-/* List of all the symbols added to the PPH symbol table.
-
-   FIXME pph, the *only* purpose of this list is to act as a GC root
-   to avoid these DECLs from being garbage collected.
-
-   The parser will invoke garbage collection, which may clobber some
-   DECLs in the symbol table (because the symbol table is stored on
-   the heap).  Ideally, we would notice when DECLs go unused, but for
-   now this will just keep these DECLs around until we finalize PPH
-   processing.  */
-static GTY(()) VEC(tree,gc) *pph_decls_in_symtab;
-
-
 /* Return the stream we are currently generating.  We declare this function
    with external linkage so it can be accessed from pph_include_handler,
    but this really should be private to this file.  */
@@ -109,7 +96,6 @@  pph_writer_init (void)
   pph_out_stream = pph_stream_open (pph_out_file, "wb");
   if (pph_out_stream == NULL)
     fatal_error ("Cannot open PPH file %s for writing: %m", pph_out_file);
-  pph_decls_in_symtab = NULL;
 }
 
 
@@ -2551,7 +2537,6 @@  pph_add_decl_to_symtab (tree decl, enum pph_symtab_action action,
   entry.top_level = top_level;
   entry.at_end = at_end;
   VEC_safe_push (pph_symtab_entry, heap, pph_out_stream->symtab.v, &entry);
-  VEC_safe_push (tree, gc, pph_decls_in_symtab, decl);
 }
 
 
@@ -2838,11 +2823,6 @@  pph_writer_finish (void)
 
   pph_stream_close (pph_out_stream);
   pph_out_stream = NULL;
-
-  /* Get rid of all the dead DECLs we may have had in the symbol
-     table.  */
-  pph_decls_in_symtab = NULL;
-  ggc_collect ();
 }
 
 
@@ -2871,5 +2851,3 @@  pph_disable_output (void)
      of disabling PPH generation we may want to simply abort compilation.  */
   pph_disable_reader ();
 }
-
-#include "gt-cp-pph-out.h"