Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Missing overflow exception message in ocamlopt

3 views
Skip to first unread message

Jakob Lichtenberg

unread,
Oct 11, 2006, 2:53:45 PM10/11/06
to caml...@yquem.inria.fr
Using ocaml-3.09.3-win-msvc

When I compile the following program as byte code I see a stack overflow
(expected). When using ocamlopt it seems that the program dies and I do
not see the expected overflow exception?

>type overflow.ml

let array_1=Array.make 229376 42;;

let _ = Printf.printf "A\n";;

flush stdout;;

let array_2=Array.make 32768 43;;

let _ = Printf.printf "B\n";;

flush stdout;;

let list_1 = Array.to_list(array_1);;

let _ = Printf.printf "C\n";;

flush stdout;;

let list_2 = Array.to_list(array_2);;

let _ = Printf.printf "D\n";;

flush stdout;;

let list_3 = list_1@list_2;;

let _ = Printf.printf "E\n";;

flush stdout;;

>ocamlc overflow.ml -o overflow_ocamlc.exe

>overflow_ocamlc.exe

A

B

C

D

Fatal error: exception Stack_overflow

>echo %ERRORLEVEL%

2

>ocamlopt overflow.ml -o overflow_ocamlopt.exe

>overflow_ocamlopt.exe

A

B

C

D

>echo %ERRORLEVEL%

-1073741819

Is this a bug?

Thanks,

- Jakob Lichtenberg

Jon Harrop

unread,
Oct 11, 2006, 3:05:14 PM10/11/06
to caml...@yquem.inria.fr
On Wednesday 11 October 2006 19:46, Jakob Lichtenberg wrote:
> When I compile the following program as byte code I see a stack overflow
> (expected). When using ocamlopt it seems that the program dies and I do
> not see the expected overflow exception?

OCaml doesn't always throw the Stack_overflow exception from native code. On
some systems it seg faults.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Richard Jones

unread,
Oct 11, 2006, 3:20:03 PM10/11/06
to
On Wed, Oct 11, 2006 at 08:03:20PM +0100, Jon Harrop wrote:
> On Wednesday 11 October 2006 19:46, Jakob Lichtenberg wrote:
> > When I compile the following program as byte code I see a stack overflow
> > (expected). When using ocamlopt it seems that the program dies and I do
> > not see the expected overflow exception?
>
> OCaml doesn't always throw the Stack_overflow exception from native code. On
> some systems it seg faults.

Does it _ever_ throw a Stack_overflow in native code?? I've never
seen it.

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Internet Marketing and AdWords courses - http://merjis.com/courses - NEW!
Merjis blog - http://blog.merjis.com - NEW!

Gerd Stolpmann

unread,
Oct 11, 2006, 3:30:31 PM10/11/06
to Richard Jones
Am Mittwoch, den 11.10.2006, 20:17 +0100 schrieb Richard Jones:
> On Wed, Oct 11, 2006 at 08:03:20PM +0100, Jon Harrop wrote:
> > On Wednesday 11 October 2006 19:46, Jakob Lichtenberg wrote:
> > > When I compile the following program as byte code I see a stack overflow
> > > (expected). When using ocamlopt it seems that the program dies and I do
> > > not see the expected overflow exception?
> >
> > OCaml doesn't always throw the Stack_overflow exception from native code. On
> > some systems it seg faults.
>
> Does it _ever_ throw a Stack_overflow in native code?? I've never
> seen it.

Sometimes. Depends on the platform and how well-debugged the ocaml
runtime for the platform is. This is quite tricky because you need to
catch the segfault (that always happens), switch to an alternate stack,
and then unwind the original stack.

Gerd
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
ge...@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------

Jakob Lichtenberg

unread,
Oct 11, 2006, 3:48:57 PM10/11/06
to Jon Harrop, caml...@yquem.inria.fr
Is this a bug in ocamlopt?

- Jakob

Jon Harrop

unread,
Oct 11, 2006, 4:28:12 PM10/11/06
to caml...@yquem.inria.fr
On Wednesday 11 October 2006 20:17, Richard Jones wrote:
> Does it _ever_ throw a Stack_overflow in native code?? I've never
> seen it.

Sometimes. My x86 Debian box with swap on throws an exception.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

_______________________________________________

Robert Roessler

unread,
Oct 11, 2006, 9:08:31 PM10/11/06
to Caml-list
Jakob Lichtenberg wrote:
> Is this a bug in ocamlopt?

No - rather, it is the ugly intrusion of reality. ;)

As has been already pointed out, it isn't easy to generate code that
detects this at runtime under a widely varying set of environments and
conditions... to tighten it up further would likely start costing in
performance (and what is ocamlopt for?).

A related veiwpoint says that while you still don't understand your
app's logic and control paths well enough to predict/avoid things like
runaway stack usage - you use the interpreted version. THEN you
switch to the ocamlopt version when you think you are ready (and be
prepared to switch back if you are proven wrong).

> On Wednesday 11 October 2006 19:46, Jakob Lichtenberg wrote:
>> When I compile the following program as byte code I see a stack
> overflow
>> (expected). When using ocamlopt it seems that the program dies and I
> do
>> not see the expected overflow exception?
>
> OCaml doesn't always throw the Stack_overflow exception from native
> code. On
> some systems it seg faults.

Robert Roessler
roes...@rftp.com
http://www.rftp.com

Xavier Leroy

unread,
Oct 15, 2006, 12:31:08 PM10/15/06
to Jakob Lichtenberg
> When I compile the following program as byte code I see a stack overflow
> (expected). When using ocamlopt it seems that the program dies and I do
> not see the expected overflow exception?
> [under Windows]

Right. Given your e-mail address, you might actually understand
better than I why it is so. Let me explain:

The machine code generated by ocamlopt does not test explicitly for
stack overflows, relying instead on the operating system to detect and
report them. However, handling of stack overflow conditions varies
greatly between processors and operating systems. Currently:

- Under Linux/IA32 and Linux/AMD64, stack overflows are properly
turned into a Stack_overflow Caml exception. Similar handling is
in the CVS for MacOSX/PPC, and MacOSX/Intel might be feasible soon.

- Other Unix-like operating systems just report stack overflows
as a "segmentation violation" or "bus error" fatal signal.

- Windows, as you noticed, behaves strangely. Stack overflows are turned
into Win32 system exceptions, but apparently the structured
exception handling of Win32 just fails to handle them and silently
exits the program. That might be because the stack frames generated
by ocamlopt are nothing like what Win32 expects.

If you happen to know how to do better under Windows, you're most
welcome to let me know.

- Xavier Leroy

Jakob Lichtenberg

unread,
Oct 16, 2006, 12:00:53 AM10/16/06
to Xavier Leroy
Hi Xavier,

Thanks for letting me know about this. I am sorry to say that I do not have a deep understanding of the topic, but if I am able to dig anything up I'll let you know.

- Jakob

________________________________

From: Xavier Leroy [mailto:Xavier...@inria.fr]
Sent: Sun 10/15/2006 8:58 AM
To: Jakob Lichtenberg
Cc: caml...@yquem.inria.fr
Subject: Re: [Caml-list] Missing overflow exception message in ocamlopt

0 new messages