public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Mark Mitchell <mark@codesourcery.com>
Cc: gcc@gcc.gnu.org, Jason Merrill <jason@redhat.com>
Subject: Re: __attribute__((cleanup(function)) versus try/finally
Date: Wed, 07 May 2003 23:01:00 -0000	[thread overview]
Message-ID: <wvlsmrq744t.fsf@prospero.boston.redhat.com> (raw)
In-Reply-To: <1052345885.5665.64.camel@doubledemon.codesourcery.com> (Mark Mitchell's message of "07 May 2003 15:18:01 -0700")

On 07 May 2003 15:18:01 -0700, Mark Mitchell <mark@codesourcery.com> wrote:

> Now, with my scheme this function has no handler code; i.e, the EH
> run-time library will never transfer control back to this function.  

Yes.  With the alternative look-aside optimization I mentioned, the same
would be true.  And it wouldn't even require a library call to register the
cleanup.

> Even when using setjmp/longjmp the cost is just one setjmp at the start
> of the function, so that the stack can be unwound.

I think the longjmp_unwind scheme uses multiple setjmps, though I'm not
sure; it doesn't have the benefit of the whole-function analysis that the
compiler can do when inserting EH code.

> If pthread_cleanup_push uses try/finally, it's my understanding that
> there will be multiple calls to setjmp, before each of the calls to g.

I'm pretty sure there's just one at the beginning of the function, emitted
if needed.

The parallel look-aside optimization for the setjmp case could be to
register EH cleanups via a call into the EH runtime much like
pthread_cleanup_push; this would avoid the need for any setjmps if a
function only has cleanups.

> And in the non-setjmp case, there will be landing pads and unwind
> information for each of the exception regions, rather than just one for
> the entire function.

Landing pads, yes, but they're just one instruction unless an optimizer has
moved code there, in which case it's presumably beneficial.

Unwind info is always per-function.  There is, however, an entry in the
LSDA for each region, typically 4 bytes in a small function.  The
look-aside optimization would make this larger, of course.

> Adding EH to C is a very dramatic change.  The spirit of C is "no hidden
> stuff."  Calling exceptions "zero-cost" is a lie; we say that because
> they require no additional instructions be executed unless an exception
> is thrown, not because they actually have no cost.  The unwind tables
> are a significant cost, for example.

Significant, but not unreasonable IMO.  As I mentioned, Irix and Tru64
always emit them.  We always emit them for S/390 and x86-64.  Always
emitting them for pthreads code seems appropriate to me, and much easier
than creating a whole new system to deal with what is basically an already
solved problem.

> To that end, I've toyed with the following idea:
>
> - When building a library written in C, provide two sets of entry points
> for the globally visible functions
>[...]

This sounds like a rather heavy weight solution to this problem.  I'd much
rather re-use mechanisms we already have.

> This kind of solution is awfully attractive if you're on an embedded
> system.  (I want pthreads on my cell-phone, but I sure don't want to have
> extra unwind info around.  I want to be able to support C++, but if it's
> not in use, I don't want to have to pay the cost of supporting C++ by my
> making my C libraries bigger.)

Then you probably want to use setjmp/longjmp exceptions.  With the
optimization described above, it would be no more expensive than the old
mechanism.

Jason

  reply	other threads:[~2003-05-07 23:01 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.BSF.4.55.0305061457450.57349@acrux.dbai.tuwien.ac.at>
     [not found] ` <1052245742.2583.315.camel@doubledemon.codesourcery.com>
     [not found]   ` <wvlissnc2e3.fsf@prospero.boston.redhat.com>
     [not found]     ` <1052249890.31850.338.camel@doubledemon.codesourcery.com>
2003-05-06 21:04       ` Jason Merrill
2003-05-06 21:24         ` Mark Mitchell
2003-05-07 21:21           ` Jason Merrill
2003-05-07 22:18             ` Mark Mitchell
2003-05-07 23:01               ` Jason Merrill [this message]
2003-05-08 12:05               ` Gabriel Dos Reis
2003-05-09  5:46               ` Kai Henningsen
2003-05-06 21:52         ` Anthony Green
2003-05-08 17:44         ` Mike Stump
2003-05-08 17:45           ` Jason Merrill
2003-05-08 18:40             ` Mark Mitchell
2003-05-08 19:06               ` Alexandre Oliva
2003-05-08 19:47                 ` Mark Mitchell
2003-05-08 20:19                   ` Alexandre Oliva
2003-05-08 21:18                   ` Jason Merrill
2003-05-13 21:10                     ` Mark Mitchell
2003-05-13 21:25                       ` Richard Henderson
2003-05-13 21:41                         ` Mark Mitchell
2003-05-13 22:16                           ` Richard Henderson
2003-05-13 21:31                       ` Gabriel Dos Reis
2003-05-15 17:00                       ` Jason Merrill
2003-05-15 17:23                         ` Mark Mitchell
2003-05-09 19:41                   ` Kai Henningsen
2003-05-08 19:37               ` Jason Merrill
2003-05-07  0:14   ` Richard Henderson
2003-05-07  2:32     ` Mark Mitchell
2003-05-13 21:33 Richard Kenner
2003-05-13 22:11 ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2003-05-09  9:54 Ranjit Mathew
2003-05-09 10:16 ` Andrew Haley
2003-05-09 12:08   ` Fergus Henderson
2003-05-09 12:49   ` Jamie Lokier
2003-05-09  9:23 Ranjit Mathew
2003-05-09  9:31 ` Andrew Haley
2003-05-08  7:49 Ranjit Mathew
2003-05-08 21:21 ` Richard Henderson
2003-05-07 10:18 Ranjit Mathew
2003-05-07 13:54 ` Jason Merrill
2003-05-07 18:23 ` Richard Henderson
2003-05-08 18:02 ` Mike Stump
2003-05-06 19:56 Jason Merrill
2003-05-08 11:59 ` Gabriel Dos Reis
2003-05-08 15:02   ` Jason Merrill
2003-05-08 18:30 ` Mike Stump
2003-05-08 20:49   ` Richard Henderson
2003-05-08 22:29     ` Mike Stump
2003-05-13  0:07       ` Geoff Keating
2003-05-13 21:27         ` Richard Henderson
2003-05-14  1:14           ` Geoff Keating
2003-05-14  7:41             ` Richard Henderson
2003-05-14 21:11               ` Geoff Keating
2003-05-14 22:20                 ` Richard Henderson

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=wvlsmrq744t.fsf@prospero.boston.redhat.com \
    --to=jason@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    /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).