Heads up: Removing exit time destructors

3,512 views
Skip to first unread message

Nico Weber

unread,
Nov 9, 2011, 2:17:42 PM11/9/11
to Chromium-dev
Hi,

I'm trying to remove exit time destructors from chrome. A exit time
destructor is a destructor that runs on program shutdown. They are
used by global objects, and by function-local statics:

// Requires an exit time destructor,
// and probably also requires a static initializer:
MyClassWithDestructor g_my_object;

void f() {
// Requires an exit time destructor.
static MyClassWithDestructor s_my_local_object;
}

In almost all cases, object destructors don't do things that are
necessary at program shutdown and mostly slow down shutdown (in part
because they might require swapping in a piece of code that was
swapped out, just for running a destructor that nobody really cares
about). I think it's worth getting rid of them, and I started working
on this. As a side effect, I'm also removing static initializers (in
the "global objects" case).

clang has a warning, -Wexit-time-destructors, that detects these
destructors and warns about them. I turned that warning on for
content/ and ui/, and I'll try to turn it on for all other targets as
well as I clean them up. The Apple WebKit/mac port has been building
with this flag set for a few months already.

If you run into that warning,
http://code.google.com/p/chromium/issues/detail?id=101600#c15 has
examples of how to get rid of exit time destructors.

If you disagree with removing exit time destructors, please speak up now :-)

Thanks,
Nico

William Chan (陈智昌)

unread,
Nov 9, 2011, 2:30:27 PM11/9/11
to tha...@chromium.org, Chromium-dev
thakis++


--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-dev

Dominic Battre

unread,
Nov 9, 2011, 3:01:12 PM11/9/11
to tha...@chromium.org, Chromium-dev
Do you want to add this to http://dev.chromium.org/developers/coding-style?

Best regards,
Dominic

--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-dev



--
Dominic Battré | Software Engineer | bat...@google.com | +49 (0) 89 - 83 930 9152

Chris Bentzel

unread,
Nov 9, 2011, 3:48:10 PM11/9/11
to bat...@google.com, tha...@chromium.org, Chromium-dev
Why isn't shutdown as simple as

  - Run a few critical shutdown hooks which are registered in a DAG or other consistently ordered fashion.
  - Call _exit()
  - Profit

Is this due to memory bots?

Chris Bentzel

unread,
Nov 9, 2011, 3:51:46 PM11/9/11
to bat...@google.com, tha...@chromium.org, Chromium-dev
Oh - and thank you for making shutdown faster by removing the exit time destructors, just wondering if there's a different approach.

Nico Weber

unread,
Nov 9, 2011, 3:53:45 PM11/9/11
to Chris Bentzel, bat...@google.com, Chromium-dev
On Wed, Nov 9, 2011 at 12:48 PM, Chris Bentzel <cben...@chromium.org> wrote:
> Why isn't shutdown as simple as
>   - Run a few critical shutdown hooks which are registered in a DAG or other
> consistently ordered fashion.
>   - Call _exit()
>   - Profit
> Is this due to memory bots?

I think there are people working on this (http://crbug.com/97701), but
it's a bit out. For local statics, putting in CR_DEFINE_LOCAL_STATIC
is just as easy and will have the same effect now and after that work
is done, so there's little harm in it. Global statics need to be
prevented either way because they also require static initialization.
Hence, I think there isn't much harm in removing exit time destructors
anyway.

Nico

Marc-Antoine Ruel

unread,
Nov 9, 2011, 3:56:45 PM11/9/11
to tha...@chromium.org, Chris Bentzel, bat...@google.com, Chromium-dev
Will base::ShadowingAtExitManager continue to work for unit test isolation?

M-A

Nico Weber

unread,
Nov 9, 2011, 4:03:42 PM11/9/11
to Marc-Antoine Ruel, Chris Bentzel, bat...@google.com, Chromium-dev
On Wed, Nov 9, 2011 at 12:56 PM, Marc-Antoine Ruel <mar...@chromium.org> wrote:
> Will base::ShadowingAtExitManager continue to work for unit test isolation?

I believe it'll continue to work for stuff that's using an
AtExitManager. LazyInstances with LeakyLazyInstance aren't. Are you
worried about anything specific?

Nico

William Chan (陈智昌)

unread,
Nov 9, 2011, 4:05:14 PM11/9/11
to cben...@chromium.org, bat...@google.com, tha...@chromium.org, Chromium-dev
http://code.google.com/p/chromium/issues/detail?id=43782

Yes, memory bots are a concern.

On Wed, Nov 9, 2011 at 12:48 PM, Chris Bentzel <cben...@chromium.org> wrote:

Jochen Eisinger

unread,
Nov 9, 2011, 4:15:57 PM11/9/11
to will...@chromium.org, cben...@chromium.org, bat...@google.com, tha...@chromium.org, Chromium-dev
On Wed, Nov 9, 2011 at 10:05 PM, William Chan (陈智昌) <will...@chromium.org> wrote:
http://code.google.com/p/chromium/issues/detail?id=43782

Yes, memory bots are a concern.

Also, session-only support / delete on shutdown for site data is rather involved and at many places assumes that the respective systems are already shut down.

My guess is that you wouldn't only start those critical shutdown tasks, but also need to interrupt certain systems and put them into some consistent state.

-jochen

Timur Iskhodzhanov

unread,
Nov 10, 2011, 5:42:26 AM11/10/11
to will...@chromium.org, tha...@chromium.org, cben...@chromium.org, bat...@google.com, Chromium-dev
Why?

If the memory is still reachable from static objects, it's not counted as a leak

Thiago Farina

unread,
May 3, 2012, 5:35:40 PM5/3/12
to Dominic Battre, Dominic Battre, Nico Weber, Chromium-dev


On Nov 9 2011, 3:01 pm, Dominic Battre <bat...@google.com> wrote:
> Do you want to add this tohttp://dev.chromium.org/developers/coding-style?
>
That would be good. But it isn't there yet, is it worth adding it
somewhere else?

Nico Weber

unread,
May 3, 2012, 6:29:31 PM5/3/12
to Thiago Farina, Dominic Battre, Chromium-dev
It's caught at compile time by clang's -Wexit-time-destructors in almost all targets.

Nico

Thiago Farina

unread,
May 3, 2012, 6:39:04 PM5/3/12
to Nico Weber, Dominic Battre, Chromium-dev
I meant the best practices for avoiding exit time destructors. But it
may not be worth to document this though.

--
Thiago

William Chan (陈智昌)

unread,
May 3, 2012, 6:45:56 PM5/3/12
to tfa...@chromium.org, Nico Weber, Dominic Battre, Chromium-dev
I'd prefer to keep this out of coding-style if it's already enforced by our clang warning.

Reply all
Reply to author
Forward
0 new messages