public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <rdsandiford@googlemail.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,  Martin Jambor <mjambor@suse.cz>
Subject: Re: [RFC, PATCH] Split pool_allocator and create a new object_allocator
Date: Thu, 02 Jul 2015 20:09:00 -0000	[thread overview]
Message-ID: <87mvze724k.fsf@googlemail.com> (raw)
In-Reply-To: <55914DB1.9000700@suse.cz> ("Martin \=\?utf-8\?Q\?Li\=C5\=A1ka\=22's\?\= message of "Mon, 29	Jun 2015 15:52:49 +0200")

Martin Liška <mliska@suse.cz> writes:
> @@ -136,18 +135,18 @@ private:
>  	int64_t align_i;
>        } u;
>  
> -    static inline allocation_object<U> *
> +    static inline allocation_object*

space before "*"

>      get_instance (void *data_ptr)
>      {
> -      return (allocation_object<U> *)(((char *)(data_ptr))
> -				      - offsetof (allocation_object<U>,
> +      return (allocation_object *)(((char *)(data_ptr))
> +				      - offsetof (allocation_object,
>  						  u.data));

space between ")" and "(".

>      }
>  
> -    static inline U *
> +    static inline void*
>      get_data (void *instance_ptr)
>      {
> -      return (U*)(((allocation_object<U> *) instance_ptr)->u.data);
> +      return (void*)(((allocation_object *) instance_ptr)->u.data);

same 2 comments here, although maybe dropping the cast would be better?

> @@ -387,11 +349,11 @@ pool_allocator<T>::allocate ()
>        /* We now know that we can take the first elt off the virgin list and
>  	 put it on the returned list.  */
>        block = m_virgin_free_list;
> -      header = (allocation_pool_list*) allocation_object<T>::get_data (block);
> +      header = (allocation_pool_list*) allocation_object::get_data (block);

Space before "*".  I'll not list out the others :-)

> @@ -408,36 +370,34 @@ pool_allocator<T>::allocate ()
>  
>  #ifdef ENABLE_CHECKING
>    /* Set the ID for element.  */
> -  allocation_object<T>::get_instance (header)->id = m_id;
> +  allocation_object::get_instance (header)->id = m_id;
>  #endif
>    VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (header, size));
>  
> -  /* Call default constructor.  */
> -  return (T *)(header);
> +  return (void *)(header);

Same comment about cast to void *.

> diff --git a/gcc/asan.c b/gcc/asan.c
> index e89817e..dabd6f1 100644
> --- a/gcc/asan.c
> +++ b/gcc/asan.c
> @@ -362,20 +362,20 @@ struct asan_mem_ref
>    /* Pool allocation new operator.  */
>    inline void *operator new (size_t)
>    {
> -    return pool.allocate ();
> +    return ::new (pool.allocate ()) asan_mem_ref ();
>    }
>  
>    /* Delete operator utilizing pool allocation.  */
>    inline void operator delete (void *ptr)
>    {
> -    pool.remove ((asan_mem_ref *) ptr);
> +    pool.remove (ptr);
>    }
>  
>    /* Memory allocation pool.  */
> -  static pool_allocator<asan_mem_ref> pool;
> +  static pool_allocator pool;
>  };

I'm probably going over old ground/wounds, sorry, but what's the benefit
of having this sort of pattern?  Why not simply have object_allocators
and make callers use pool.allocate () and pool.remove (x) (with pool.remove
calling the destructor) instead of new and delete?  It feels wrong to me
to tie the data type to a particular allocation object like this.
And using the pool allocator functions directly has the nice property
that you can tell when a delete/remove isn't necessary because the pool
itself is being cleared.

Thanks,
Richard

  reply	other threads:[~2015-07-02 20:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 14:01 Martin Liška
2015-07-02 20:09 ` Richard Sandiford [this message]
2015-07-02 21:08   ` Trevor Saunders
2015-07-03  8:56     ` Richard Sandiford
2015-07-03 10:11       ` Martin Liška
2015-07-03 12:22       ` Martin Jambor
2015-07-03 13:07         ` Richard Sandiford
2015-07-03 14:15           ` Martin Liška
2015-07-03 16:19             ` Richard Sandiford
2015-07-09 21:43               ` Martin Liška
2015-07-10 14:19                 ` Pat Haugen
2015-07-16 11:00                 ` Martin Liška
2015-07-16 11:03                   ` Richard Biener
2015-07-17 13:25                   ` Still crashes due to aliasing violation (Re: [RFC, PATCH] Split pool_allocator and create a new object_allocator) Ulrich Weigand
2015-07-17 13:44                     ` Richard Biener
2015-07-17 13:50                       ` Ulrich Weigand
2015-07-17 13:54                         ` Martin Liška
2015-07-17 15:37                           ` Richard Biener
2015-07-17 17:49                             ` Ulrich Weigand
2015-07-17 18:12                               ` Richard Biener
2015-07-17 21:57                                 ` Ulrich Weigand
2015-07-18 13:04                                   ` Richard Biener
2015-07-17 18:14                             ` Martin Liška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvze724k.fsf@googlemail.com \
    --to=rdsandiford@googlemail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mjambor@suse.cz \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).