comp.lang.ada
 help / color / mirror / Atom feed
* Beware: Rep spec on an enumeration type causes code explosion
@ 1997-12-05  0:00 Joe Gwinn
  1997-12-06  0:00 ` Robert Dewar
                   ` (10 more replies)
  0 siblings, 11 replies; 70+ messages in thread
From: Joe Gwinn @ 1997-12-05  0:00 UTC (permalink / raw)



We just ran into a real zinger with the Green Hills Ada95 compiler
(Solaris host, 68060 target, VxWorks 5.2 target OS), although it appears
that the issue may be common to all Ada95 compilers.  

The symptom at presentation was that the code was at least two orders of
magnitude too slow, although it did appear to work correctly, and didn't
crash.  This system is supposed to run at 64 Hz (with 50% CPU load), but
was barely making 4 Hz (at 96% CPU load) while doing a fraction of the
full workload, so we are at least a factor of 30 too slow, and more likely
a factor of 100 too slow.  As they say, this is a problem.  Projects have
died for less.

After the usual round of pointless finger-pointing (and helpful
suggestions that we recode the whole thing in C), we built an
interrupt-driven system execution profiler and used it to figure out what
the hell was going on.  

Basically, it was spending all of its time in VxWorks, because the Ada RTE
was calling on VxWorks at an astounding rate.  This was in turn due to two
things, the handling of enumeration types, and the registration and
deregistration of user-defined exception handlers at every turn.

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.

Enumeration Types.  This is the zinger.  A 29-line Ada95 program expanded
into 1,090 lines of assembly code, a static expansion ratio of 38:1, not
the usual 3:1 or 4:1.  In this 1,090 lines of assembly, there were
multiple calls to the Ada RTE routine "_rts_holey_enumeration" (or the
like), which is reported to handle enumeration types that may contain gaps
in the mapping sequence, or whose base value (zero or one) isn't known at
compile time.  

At first, we though that the bloat was caused by the use of subranges of
enumeration types, but soon discovered that the real problem was caused by
the use of representation specifications on enumeration types, and that
use of subranges appears to be irrelevant.  

We have now removed the bulk of the rep specs on enumeration types, just
trusting for now that the compiler will always start enumerations at zero,
just like C/C++.  Ada95 does not specify the base value of an enumeration,
so compilers vary. We were using rep specs to govern the representation of
Ada records used to generate and understand messages exchanged with
display consoles coded in C++.  This idiom is used extensively.   For
portability, we will eventually change the code to remove all ungoverned
enumerations.


The code now runs something like ten times faster.  Fortunately, this one
wasn't too hard to fix.  Profiling and digging continues; we haven't heard
the last of performance problems.


Memory Management.  The Ada Runtime System makes extensive calls to the C
functions malloc() and free(), a cause for worry.  Variable-block
allocators such as malloc and free are generally unsuited for nonstop
heavy use, and will generally either leak memory or fragment their memory
pool, causing the application to run slower and slower until it eventually
jams.   The use of free() in a realtime system is generally forbidden;
it's OK to allocate a bunch of memory during startup, and explicitly
manage it yourself during operation, but it is not OK to use malloc and
free for realtime memory management.  The claim is that Wind River's
version of malloc/free is stable in realtime use.  It's hard to see how
this could be true.   This will need further research.  



Summary.  One wonders where the other beartraps are.  Some compiler gurus
seemed to know all about this one, long before we blundered into it, but
for some reason could not give timely advance warning.  It would have
saved considerable travail and fright, and deprived the just-do-it-in-C
crowd of a horror story.

In the early 1990s, when implementing a communications core in Ada83, we
had all manner of problems with similar beartraps.  You simply could not
tell from the manuals and books which idioms would blow up on you.  One
assumes that the compiler writers knew what they struggled with, but that
information was never published in a useable form, one assumes for PC
reasons.  The then solution was to try to stay in the Pascal subset of
Ada, and to read the generated assembly code to detect code explosions. 
Ugly, but effective.  Not that there was a practical alternative.  Even
so, we reimplemented the core three or four times before we achieved a
stable and reasonable Ada to assembly code expansion ratio.  

In communications cores, performance is very much the issue, so it was
possible to spend that kind of effort getting it just right.  Not all
projects can afford this.

The good news was that the resulting code ported to a new compiler without
provoking another code explosion, implying that the explosions were
properties of Ada83 the language, and were not due to the vagaries of 
design of this or that compiler.  (Generics did cause problems though.) 
As the descendant of Ada83, one would expect some of the same behaviour
from Ada95, plus the usual new-compiler and new-language teething effects.


Question.  Is there an Ada95 FAQ or the like, full of suitably dire
warnings?  I have seen very useful and widely used published books of such
things for C and C++, but have never seen anything like it for Ada95.  If
there isn't yet one, perhaps we should develop one, for our mutual
protection.  

I suppose that the writers of Ada95 compilers know where they struggled
with Ada95, as well as Ada83 before it.  If it was hard for them to write,
it will likely generate lots of code.


Joe Gwinn




^ permalink raw reply	[flat|nested] 70+ messages in thread
* Re: Beware: Rep spec on an enumeration type causes code explosion
@ 1997-12-09  0:00 tmoran
  0 siblings, 0 replies; 70+ messages in thread
From: tmoran @ 1997-12-09  0:00 UTC (permalink / raw)



>By and large, vendors (not just compiler vendors) don't seem to be
>comfortable coming forth with sufficiently specific, pointed, and timely
>warnings to allow the unwashed users to avoid blunders.  The rule seems to
  The RR manual has a chapter "Limitations and Precautions" that addresses
at least some of the dangers.  I have no paper docs for either of my
other Ada compilers.




^ permalink raw reply	[flat|nested] 70+ messages in thread
* Re: Beware: Rep spec on an enumeration type causes code explosion
@ 1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  0 siblings, 0 replies; 70+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1997-12-11  0:00 UTC (permalink / raw)



"Stanley R. Allen" <s_allen@HSO.LINK.COM> writes:
>Joe Gwinn wrote:
>
>> What has in the past worked is lists of general issues and warnings,
>> without the naming of specific vendors, even though some issues may not be
>> universal, so at least we know under which rocks to look.  One way of
>> looking at this is that the list gives the relative size, weight, and
>> power of various idioms, so users have some idea what things cost.
>
>You need something like PIWG or ACES.
>
    I think its important to note that, while it is a good idea to
    identify language features which may have implementation problems,
    that no other language definition that I know of does this now. No
    language I am aware of includes in its definition any assessment
    of the relative size/speed for a construct and I would suspect
    this would be extremely difficult to do because it would vary so
    much from one target to another.

    All languages have corner cases or difficult features which may be
    subject to inefficient or erroneous implementation. Ada does
    better than most at trying to make sure that no given feature is
    of necessity difficult to implement efficiently. Certainly things
    like the PIWG are very useful in benchmarking various features.
    I think Ada has done better than most in compiling statistics on
    performance issues for various implementations and making that
    information generally available. But it seems to me that it is
    inherently something that must be done at the implementation
    level - not at a language definition level.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
===============================================================================
    Glendower: "I can call spirits from the vasty deep."
    Hotspur: "Why so can I, or so can any man; but will they come when
    you do call for them?"
        -- Shakespeare, "Henry IV"
===============================================================================




^ permalink raw reply	[flat|nested] 70+ messages in thread
* Re: Beware: Rep spec on an enumeration type causes code explosion
@ 1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  1997-12-11  0:00 ` Robert Dewar
  0 siblings, 1 reply; 70+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1997-12-11  0:00 UTC (permalink / raw)



Tucker Taft <stt@HOUDINI.CAMB.INMET.COM> writes:
>language design principles.  Your enumeration rep clause simply reconfirmed
>the default representation, but suppose it didn't?  You would be
>stuck with the overhead you managed to eliminate by simply commenting
>out the rep clause.  Of course, the compiler could recognize various
>other specials cases, such as contiguous representation starting at
>something other than zero, or evenly distributed "holey" representation
>(e.g., even numbers only), or simply not "too" sparse, or ...
>
    I'll give you a good reason why getting too smart about rep clause
    implementation might be a Bad Thing. Suppose I implement an
    enumeral type with a "confirming" rep clause because I know I'm
    dealing with a real live hardware interface or message format and
    want to make it clear that the representation for this given
    enumeration is critical. I compile & run and my timing comes out a
    given way because your compiler was smart enough to detect that my
    representation was conveniently matching the positions. So far, so
    good. At a later date the hardware or message format changes to
    include some new bit patterns which create holes in the
    representation and now when I compile I get a significantly
    different implementation for the enumeration and a corresponding
    change in performance. This is a satisfactory definition of the
    technical term: "Bad Thing".

    Sometimes poor performance isn't as bad a Bad Thing as
    inconsistent performance can be.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
===============================================================================
    Glendower: "I can call spirits from the vasty deep."
    Hotspur: "Why so can I, or so can any man; but will they come when
    you do call for them?"
        -- Shakespeare, "Henry IV"
===============================================================================




^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~1997-12-18  0:00 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-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 ` 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 ` 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 David Marshall
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 ` 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     ` Geert Bosch
1997-12-10  0:00       ` Robert Dewar
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       ` Robert Dewar
1997-12-10  0:00       ` Jean-Pierre Rosen
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           ` 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-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-10  0:00       ` Stanley R. Allen
1997-12-14  0:00         ` Robert Dewar
1997-12-10  0:00       ` Stephen Leake
1997-12-14  0:00         ` Robert Dewar
1997-12-11  0:00       ` Rakesh Malhotra
1997-12-11  0:00         ` Matthew Heaney
1997-12-12  0:00           ` Robert Dewar
1997-12-12  0:00           ` Rakesh Malhotra
1997-12-12  0:00           ` Samuel Tardieu
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-06  0:00 ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-06  0:00 ` Robert Dewar
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

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