comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Beware: Rep spec on an enumeration type causes code explosion
Date: 1997/12/06
Date: 1997-12-06T00:00:00+00:00	[thread overview]
Message-ID: <dewar.881402137@merv> (raw)
In-Reply-To: gwinn-0512972303070001@dh5055063.res.ray.com


Joe Gwinn said

<<Exception handlers.  We were declaring a number of exception handlers at
  the beginning of each and every module, so every time the module was
  entered, the context had to be saved, and every time the module was
  exited, the context was popped off the exception stack and discarded,
  regardless of if an exception was ever raised.  This was easily solved;
  now, only tasks declare exception handlers, not modules.>>


Just so it is clear, this is by no means a necessary consequence of the
Ada language (and indeed the situation with exceptions is essentially
identical in C++).

The issue is how exceptions are implemented. It is indeed much easier
to handle exceptions by doing context saves on entry to an exception
frame, and then popping them off. Particularly in tasking environments
(where the current task context must be accessed to determine where
to store the context), and on RISC machines (where saving the context
can mean saving dozens of registers), this can be a very expensive
approach. With GNAT, we even discovered that Sun, for no good reason
at all, was doing a system call as part of setjmp!

In the case of GNAT, we used to use the system setjmp/longjmp for this
purpose, but, particularly because of the idiotically inefficient design
of setjmp in Solaris, we replaced this with our own builtin setjmp that
is much more efficient, but that is still only relative.

Really what is intended and expected by the Ada design is a "zero cost"
approach where the declaration of exception handlers costs nothing, and
you pay a price only when an exception is raised. This is done by building
appropriate data tables, so that the exception handler can figure out how
to restore the context without having wasted time saving it.

Such zero cost exception handling approaches are not science fiction, rather
they are pretty standard in the Ada world. I assume that the new Aonix
Object Ada has zero cost EH (the reason I assume this is that the runtime
is based on the old Alsys technology, and I helped write the zero cost
exception handling for this old technology :-) I certainly know that
Verdix Ada 83 technology uses a zero cost approach.

The difficulty with the zero cost approach is that it tends to be highly
machine dependent, and that is one of the reasons that it is been difficult
to do in the GNAT environment, which is so committed to machine independent
approaches. 

Nevertheless we regard switching to a zero cost exception scheme in GNAT to
be our highest priority technical improvement to the system, and indeed it
happens to be exactly what I am working on right now (I am answering this
while waiting for a new version to build that incorporates some of the 
necessary changes). This will first be built for the SGI version (that's
because SGI is funding some of the technical work for this modification),
but will be propagated to other versions soon after.

The bottom line here is that this is something you need to beat up on your
vendor about! Some of our customers have complained loudly at this problem
in GNAT, and as usual, the technical direction of GNAT, like any other
commercial compiler, is quite sensitive to user needs :-) :-) We know at
least one customer who would like to switch from Verdix (Rational)
technology, but this one inefficiency is holding them up (that's an SGI
customer, and hopefully the problem will be resolved very shortly, and
they will be able to do the switch they would like to).

If you have a style of programming which requires very large numbers of
exception handlers, then this is one of the aspects of compiler performance
that you need to carefuly evaluate. It is most certainly an issue that
you need to be aware of when using a language like Ad or C++ that supports
exceptions.

Robert Dewar
Ada Core Technologies





  parent reply	other threads:[~1997-12-06  0:00 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-05  0:00 Beware: Rep spec on an enumeration type causes code explosion Joe Gwinn
1997-12-06  0:00 ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-09  0:00     ` Stanley R. Allen
1997-12-06  0:00 ` Robert Dewar [this message]
1997-12-06  0:00 ` Ken Garlington
1997-12-06  0:00 ` Corey Minyard
1997-12-08  0:00   ` Joe Gwinn
1997-12-10  0:00     ` Robert Dewar
1997-12-06  0:00 ` Kevin D. Heatwole
     [not found]   ` <dewar.881478386@merv>
1997-12-07  0:00     ` Robert Dewar
1997-12-09  0:00   ` Jim Gleason
1997-12-06  0:00 ` David Marshall
1997-12-06  0:00 ` Tucker Taft
1997-12-06  0:00   ` Robert Dewar
1997-12-06  0:00   ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-08  0:00     ` Mats Weber
1997-12-09  0:00     ` Tucker Taft
1997-12-09  0:00       ` Matthew Heaney
1997-12-10  0:00         ` Charles Hixson
1997-12-10  0:00       ` Jean-Pierre Rosen
1997-12-10  0:00       ` Robert Dewar
1997-12-10  0:00       ` Stephen Leake
1997-12-14  0:00         ` Robert Dewar
1997-12-10  0:00       ` Stanley R. Allen
1997-12-14  0:00         ` Robert Dewar
1997-12-10  0:00       ` Ken Garlington
1997-12-11  0:00         ` John G. Volan
1997-12-11  0:00           ` Ken Garlington
1997-12-12  0:00             ` Matthew Heaney
1997-12-12  0:00               ` Ken Garlington
1997-12-16  0:00                 ` John G. Volan
1997-12-17  0:00                   ` Ken Garlington
1997-12-12  0:00           ` Alan E & Carmel J Brain
1997-12-12  0:00             ` Robert Dewar
1997-12-15  0:00               ` Tucker Taft
1997-12-16  0:00                 ` Brian Rogoff
1997-12-12  0:00           ` Joe Gwinn
1997-12-12  0:00             ` Robert Dewar
1997-12-16  0:00             ` John G. Volan
1997-12-17  0:00               ` Ken Garlington
1997-12-17  0:00               ` Joe Gwinn
1997-12-17  0:00                 ` John G. Volan
1997-12-18  0:00                   ` Joe Gwinn
1997-12-11  0:00       ` Rakesh Malhotra
1997-12-11  0:00         ` Matthew Heaney
1997-12-12  0:00           ` Rakesh Malhotra
1997-12-12  0:00           ` Samuel Tardieu
1997-12-12  0:00             ` Robert Dewar
1997-12-12  0:00           ` Robert Dewar
1997-12-14  0:00         ` Alan E & Carmel J Brain
1997-12-12  0:00       ` Joe Gwinn
1997-12-15  0:00         ` Robert Dewar
1997-12-16  0:00           ` Joe Gwinn
1997-12-16  0:00             ` Robert Dewar
1997-12-09  0:00     ` Geert Bosch
1997-12-10  0:00       ` Robert Dewar
1997-12-06  0:00 ` Robert Dewar
1997-12-06  0:00   ` Matthew Heaney
1997-12-10  0:00   ` GNORT information ( Was Re: Beware: Rep spec on an enumeration type causes code explosion ) Mark Bennison
1997-12-10  0:00     ` Robert Dewar
1997-12-06  0:00 ` Beware: Rep spec on an enumeration type causes code explosion Robert Dewar
1997-12-06  0:00 ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-07  0:00 ` Larry Kilgallen
  -- strict thread matches above, loose matches on Subject: below --
1997-12-09  0:00 tmoran
1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-11  0:00 ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox