summaryrefslogtreecommitdiff
path: root/gcc/ggc-common.c
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2009-05-26 17:33:33 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2009-05-26 17:33:33 +0000
commit740cd0bed10b436b5ab592163341464e25a5fef7 (patch)
tree878cbdf019958acd271cdf6e396a37afeaf98aa4 /gcc/ggc-common.c
parent165c158a4782dde25b9020d34ae522b4fe431903 (diff)
downloadgcc-740cd0bed10b436b5ab592163341464e25a5fef7.tar.gz
2009-05-26 Basile Starynkevitch <basile@starynkevitch.net>
* gcc/doc/plugins.texi (Loading plugins): typo. (Plugin callbacks): Documented PLUGIN_INFO, PLUGIN_GGC_START, PLUGIN_GGC_MARKING, PLUGIN_GGC_END, PLUGIN_REGISTER_GGC_ROOTS. (Interacting with the GCC Garbage Collector): Added new section. (Giving information about a plugin): Added new section for PLUGIN_INFO. * gcc/testsuite/gcc.dg/plugin/plugin.exp: Added ggcplug.c test plugin with ggcplug-test-1.c for testing PLUGIN_GGC_MARKING etc... * gcc/testsuite/gcc.dg/plugin/ggcplug-test-1.c: Added new file. * gcc/testsuite/gcc.dg/plugin/ggcplug.c: Added new file. * gcc/ggc.h (ggc_register_root_tab): Added declaration. * gcc/gcc-plugin.h (PLUGIN_GGC_START, PLUGIN_GGC_MARKING) (PLUGIN_GGC_END, PLUGIN_REGISTER_GGC_ROOTS): Added new events. (register_callback): Improved comment in declaration. * gcc/ggc-common.c (const_ggc_root_tab_t) Added new typedef for vectors. (extra_root_vec) Added static variable for dynamic roots registration. (ggc_register_root_tab) Added new routine. (ggc_mark_roots) Added iteration inside extra_root_vec, and invoke PLUGIN_GGC_MARKING event. * gcc/ggc-zone.c: Include plugin.h. (ggc_collect): Invoke PLUGIN_GGC_START & PLUGIN_GGC_END events. * gcc/ggc-page.c: Include plugin.h. (ggc_collect): Invoke PLUGIN_GGC_START & PLUGIN_GGC_END events. * gcc/plugin.c (plugin_event_name): added names of PLUGIN_GGC_START, PLUGIN_GGC_MARKING, PLUGIN_GGC_END, PLUGIN_REGISTER_GGC_ROOTS (register_callback): check lack of callbacks for pseudo-events. Added handling of PLUGIN_REGISTER_GGC_ROOTS, PLUGIN_GGC_START, PLUGIN_GGC_MARKING, PLUGIN_GGC_END. (invoke_plugin_callbacks): Handle PLUGIN_GGC_START, PLUGIN_GGC_MARKING, PLUGIN_GGC_END, PLUGIN_REGISTER_GGC_ROOTS. * gcc/Makefile.in (ggc-common.o, ggc-zone.o, ggc-page.o): Added dependency on plugin.h. (plugin.o): Added dependency on ggc.h... git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147878 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ggc-common.c')
-rw-r--r--gcc/ggc-common.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index b6b9e1e3400..2499ff51cd7 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -30,6 +30,8 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "hosthooks.h"
#include "hosthooks-def.h"
+#include "plugin.h"
+#include "vec.h"
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
@@ -86,6 +88,34 @@ ggc_htab_delete (void **slot, void *info)
return 1;
}
+
+/* This extra vector of dynamically registered root_tab-s is used by
+ ggc_mark_roots and gives the ability to dynamically add new GGC root
+ tables, for instance from some plugins; this vector is a heap one
+ [since it is used by GGC internally!] */
+typedef const struct ggc_root_tab* const_ggc_root_tab_t;
+DEF_VEC_P(const_ggc_root_tab_t);
+DEF_VEC_ALLOC_P(const_ggc_root_tab_t, heap);
+static VEC(const_ggc_root_tab_t, heap) *extra_root_vec;
+
+
+/* Dynamically register a new GGC root table RT. This is useful for
+ plugins. */
+
+void
+ggc_register_root_tab (const struct ggc_root_tab* rt)
+{
+ if (!rt)
+ return;
+ if (!extra_root_vec)
+ {
+ int vlen = 32;
+ extra_root_vec = VEC_alloc (const_ggc_root_tab_t, heap, vlen);
+ }
+ VEC_safe_push (const_ggc_root_tab_t, heap, extra_root_vec, rt);
+}
+
+
/* Iterate through all registered roots and mark each element. */
void
@@ -104,7 +134,21 @@ ggc_mark_roots (void)
for (rt = gt_ggc_rtab; *rt; rt++)
for (rti = *rt; rti->base != NULL; rti++)
for (i = 0; i < rti->nelt; i++)
- (*rti->cb)(*(void **)((char *)rti->base + rti->stride * i));
+ (*rti->cb) (*(void **)((char *)rti->base + rti->stride * i));
+
+ if (extra_root_vec
+ && VEC_length(const_ggc_root_tab_t,extra_root_vec) > 0)
+ {
+ const_ggc_root_tab_t rtp = NULL;
+ for (i=0;
+ VEC_iterate(const_ggc_root_tab_t, extra_root_vec, i, rtp);
+ i++)
+ {
+ for (rti = rtp; rti->base != NULL; rti++)
+ for (i = 0; i < rti->nelt; i++)
+ (*rti->cb) (*(void **) ((char *)rti->base + rti->stride * i));
+ }
+ }
if (ggc_protect_identifiers)
ggc_mark_stringpool ();
@@ -123,6 +167,9 @@ ggc_mark_roots (void)
if (! ggc_protect_identifiers)
ggc_purge_stringpool ();
+
+ /* Some plugins may call ggc_set_mark from here. */
+ invoke_plugin_callbacks (PLUGIN_GGC_MARKING, NULL);
}
/* Allocate a block of memory, then clear it. */