comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Dynamic allocation in the predefined language environment
Date: Fri, 10 Jul 2015 16:58:49 -0500
Date: 2015-07-10T16:58:49-05:00	[thread overview]
Message-ID: <mnpf6q$tju$1@loke.gir.dk> (raw)
In-Reply-To: 87bnfmuzl0.fsf@theworld.com

"Bob Duff" <bobduff@theworld.com> wrote in message 
news:87bnfmuzl0.fsf@theworld.com...
...
> Here's what I have in mind: The programmer may mark a procedure (or
> region of code?) as "doesn't run out of stack memory".  The
> implementation calculates a worst-case (compile-time-known) stack usage
> for that procedure (including everything it calls that has the same
> property).  This is always possible, because it can never be bigger than
> the size of the address space.

Interesting.

...
> This wouldn't fit in well with the usual Ada compilation model,
> which wants to generate code without looking at the transitive
> closure of the call graph.  I can think of various designs,
> suitable for a from-scratch compiler implementation -- I
> wouldn't want to retrofit this feature into an existing
> compiler.

You could implement it rather like inlining. The effect would be the same.

For Janus/Ada, which aggresively tries to avoid unnecessary dependence on 
other units (the primary reason we used generic code sharing, for example), 
this would be a lousy model. But one could argue that such avoidance isn't 
as necessary as it once was.

Or one could use link-time fill-ins of the memory sizes in the pre-checks 
(that would be much more in keeping with Janus/Ada). Anyway, I agree: not 
that easy to retrofit.

...
>> We added a one-time hack to the runtime to make that a bit less of a
>> problem -- we added a "leeway" setting that triggered Storage_Error a bit
>> too early (if the distance between the top of the heap and top of the 
>> stack
>> (stacks growing downwards on Intel machines) is less than Leeway, then
>> Storage_Error is raised), and the setting was decreased after the first
>> triggering of Storage_Error. Of course, that only works once; it's hardly
>> worthwhile for programs that run a long time (like a web server).
>
> I don't see why it should work only once.  You reserve enough stack
> space so that S_E can be raised.  The "raise S_E" uses that reserve,
> then when it jumps to the handler, the reserved space is again
> reserved.

The extra space is needed so that the handlers execute without raising S_E 
(mainly so Put_Line would work). We don't have any runtime call at the end 
of handlers (they return using the normal subprogram mechanism), so there 
isn't any sensible way to know when to reset the leeway value. I spent a 
looonnnngggg time thinking about this problem before I gave up (adding 
runtime overhead to fix that was a non-starter).

[For instance, I considered using the next registration of an exception 
handler to reset the leeway. But that didn't work because the handler could 
call something that uses an exception handler internally. Indeed, Put_Line 
does that, so that didn't work at all.]

...
>>...I recall one Ada person (Dave
>> Emery, I think) saying the Storage_Error is like a parachute that opens 
>> on
>> impact -- it works, but it's very useful.
>
> ;-)
>
> I'll assume a missing "not" there.

Yup. Too fast writing CLA messages, I guess.

> Anyway, it's better than languages that allow running out of stack to
> overwrite arbitary memory locations (like stacks belonging to other
> tasks).

Surely.

                   Randy.


  reply	other threads:[~2015-07-10 21:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 11:13 Dynamic allocation in the predefined language environment Matthias-Christian Ott
2015-07-06 13:04 ` G.B.
2015-07-06 14:21   ` Matthias-Christian Ott
2015-07-06 14:06 ` Bob Duff
2015-07-06 14:16   ` Matthias-Christian Ott
2015-07-06 14:23     ` G.B.
2015-07-06 14:43       ` Matthias-Christian Ott
2015-07-06 14:56         ` Bob Duff
2015-07-07  8:46           ` Matthias-Christian Ott
2015-07-07 22:32             ` Bob Duff
2015-07-08 19:47               ` Randy Brukardt
2015-07-08 21:08                 ` Bob Duff
2015-07-10 21:58                   ` Randy Brukardt [this message]
2015-07-08 21:16                 ` Dmitry A. Kazakov
2015-07-06 14:45     ` Bob Duff
2015-07-06 20:28       ` Randy Brukardt
2015-07-07  8:49       ` Matthias-Christian Ott
2015-07-07 22:14         ` Bob Duff
2015-07-06 15:29   ` Simon Wright
2015-07-06 20:31     ` Randy Brukardt
2015-07-06 21:35       ` Simon Wright
2015-07-07 18:29         ` Randy Brukardt
2015-07-06 20:22   ` Randy Brukardt
2015-07-06 18:45 ` Jeffrey R. Carter
2015-07-07  7:42 ` Dmitry A. Kazakov
2015-07-07  8:23   ` Matthias-Christian Ott
2015-07-07  8:46     ` Dmitry A. Kazakov
replies disabled

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