* [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container ()
@ 2021-10-05 22:37 Indu Bhagat
2021-10-07 7:58 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Indu Bhagat @ 2021-10-05 22:37 UTC (permalink / raw)
To: gcc-patches
Hello,
This patch fixes an outstanding issue with memory cleanup in the CTF container.
Earlier the two hash tables in the CTF container were not cleaned up in
ctfc_delete_container (). With this patch, we first free up the CTF type and
CTF variable entries in the hash_table slots, followed by emptying of the hash
tables.
Bootstrapped and regression tested on x86_64.
Thanks
------------------------
Free up the memory held by CTF type and CTF variable objects after CTF debug
information has been emitted. In ctfc_delete_container (), traverse the
hash_table of CTF types and CTF variables and free the memory held by the
respective objects.
gcc/ChangeLog:
* ctfc.c (free_ctf_dtdef_cb): New function.
(free_ctf_dvdef_cb): Likewise.
(ctfc_delete_container): Free hash table contents.
---
gcc/ctfc.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/ctfc.c b/gcc/ctfc.c
index 73c118e..1f961c9 100644
--- a/gcc/ctfc.c
+++ b/gcc/ctfc.c
@@ -179,6 +179,26 @@ ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die)
return NULL;
}
+/* Callback function to free the CTF type from hash table. */
+
+static int
+free_ctf_dtdef_cb (ctf_dtdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
+{
+ if (slot && *slot)
+ ggc_free (*slot);
+ return 1;
+}
+
+/* Callback function to free the CTF variable from hash table. */
+
+static int
+free_ctf_dvdef_cb (ctf_dvdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
+{
+ if (slot && *slot)
+ ggc_free (*slot);
+ return 1;
+}
+
/* Append member definition to the list. Member list is a singly-linked list
with list start pointing to the head. */
@@ -944,11 +964,16 @@ ctfc_delete_strtab (ctf_strtable_t * strtab)
void
ctfc_delete_container (ctf_container_ref ctfc)
{
- /* FIXME - CTF container can be cleaned up now.
- Will the ggc machinery take care of cleaning up the container structure
- including the hash_map members etc. ? */
if (ctfc)
{
+ ctfc->ctfc_types->traverse<void*, free_ctf_dtdef_cb> (NULL);
+ ctfc->ctfc_types->empty ();
+ ctfc->ctfc_types = NULL;
+
+ ctfc->ctfc_vars->traverse<void*, free_ctf_dvdef_cb> (NULL);
+ ctfc->ctfc_vars->empty ();
+ ctfc->ctfc_types = NULL;
+
ctfc_delete_strtab (&ctfc->ctfc_strtable);
ctfc_delete_strtab (&ctfc->ctfc_aux_strtable);
if (ctfc->ctfc_vars_list)
--
1.8.3.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container ()
2021-10-05 22:37 [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container () Indu Bhagat
@ 2021-10-07 7:58 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-10-07 7:58 UTC (permalink / raw)
To: Indu Bhagat; +Cc: GCC Patches
On Wed, Oct 6, 2021 at 12:38 AM Indu Bhagat via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
> This patch fixes an outstanding issue with memory cleanup in the CTF container.
> Earlier the two hash tables in the CTF container were not cleaned up in
> ctfc_delete_container (). With this patch, we first free up the CTF type and
> CTF variable entries in the hash_table slots, followed by emptying of the hash
> tables.
>
> Bootstrapped and regression tested on x86_64.
>
> Thanks
>
> ------------------------
>
> Free up the memory held by CTF type and CTF variable objects after CTF debug
> information has been emitted. In ctfc_delete_container (), traverse the
> hash_table of CTF types and CTF variables and free the memory held by the
> respective objects.
>
> gcc/ChangeLog:
>
> * ctfc.c (free_ctf_dtdef_cb): New function.
> (free_ctf_dvdef_cb): Likewise.
> (ctfc_delete_container): Free hash table contents.
> ---
> gcc/ctfc.c | 31 ++++++++++++++++++++++++++++---
> 1 file changed, 28 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/ctfc.c b/gcc/ctfc.c
> index 73c118e..1f961c9 100644
> --- a/gcc/ctfc.c
> +++ b/gcc/ctfc.c
> @@ -179,6 +179,26 @@ ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die)
> return NULL;
> }
>
> +/* Callback function to free the CTF type from hash table. */
> +
> +static int
> +free_ctf_dtdef_cb (ctf_dtdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
> +{
> + if (slot && *slot)
> + ggc_free (*slot);
> + return 1;
> +}
> +
> +/* Callback function to free the CTF variable from hash table. */
> +
> +static int
> +free_ctf_dvdef_cb (ctf_dvdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
> +{
> + if (slot && *slot)
> + ggc_free (*slot);
> + return 1;
> +}
> +
> /* Append member definition to the list. Member list is a singly-linked list
> with list start pointing to the head. */
>
> @@ -944,11 +964,16 @@ ctfc_delete_strtab (ctf_strtable_t * strtab)
> void
> ctfc_delete_container (ctf_container_ref ctfc)
> {
> - /* FIXME - CTF container can be cleaned up now.
> - Will the ggc machinery take care of cleaning up the container structure
> - including the hash_map members etc. ? */
> if (ctfc)
> {
> + ctfc->ctfc_types->traverse<void*, free_ctf_dtdef_cb> (NULL);
> + ctfc->ctfc_types->empty ();
> + ctfc->ctfc_types = NULL;
> +
> + ctfc->ctfc_vars->traverse<void*, free_ctf_dvdef_cb> (NULL);
> + ctfc->ctfc_vars->empty ();
> + ctfc->ctfc_types = NULL;
> +
it should be enough to set ctfc_types to NULL, in particular traversing
the table shouldn't be needed.
OK with that change.
Thanks,
Richard.
> ctfc_delete_strtab (&ctfc->ctfc_strtable);
> ctfc_delete_strtab (&ctfc->ctfc_aux_strtable);
> if (ctfc->ctfc_vars_list)
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-07 7:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 22:37 [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container () Indu Bhagat
2021-10-07 7:58 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).