caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Missing overflow exception message in ocamlopt
@ 2006-10-11 18:46 Jakob Lichtenberg
  2006-10-11 19:03 ` [Caml-list] " Jon Harrop
  2006-10-15 15:58 ` Xavier Leroy
  0 siblings, 2 replies; 9+ messages in thread
From: Jakob Lichtenberg @ 2006-10-11 18:46 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]

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

 

 


[-- Attachment #2: Type: text/html, Size: 10760 bytes --]

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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 18:46 Missing overflow exception message in ocamlopt Jakob Lichtenberg
@ 2006-10-11 19:03 ` Jon Harrop
  2006-10-11 19:17   ` Richard Jones
  2006-10-11 19:45   ` Jakob Lichtenberg
  2006-10-15 15:58 ` Xavier Leroy
  1 sibling, 2 replies; 9+ messages in thread
From: Jon Harrop @ 2006-10-11 19:03 UTC (permalink / raw)
  To: caml-list

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


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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 19:03 ` [Caml-list] " Jon Harrop
@ 2006-10-11 19:17   ` Richard Jones
  2006-10-11 19:25     ` Gerd Stolpmann
  2006-10-11 20:26     ` Jon Harrop
  2006-10-11 19:45   ` Jakob Lichtenberg
  1 sibling, 2 replies; 9+ messages in thread
From: Richard Jones @ 2006-10-11 19:17 UTC (permalink / raw)
  Cc: caml-list

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!


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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 19:17   ` Richard Jones
@ 2006-10-11 19:25     ` Gerd Stolpmann
  2006-10-11 20:26     ` Jon Harrop
  1 sibling, 0 replies; 9+ messages in thread
From: Gerd Stolpmann @ 2006-10-11 19:25 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

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 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


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

* RE: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 19:03 ` [Caml-list] " Jon Harrop
  2006-10-11 19:17   ` Richard Jones
@ 2006-10-11 19:45   ` Jakob Lichtenberg
  2006-10-12  1:04     ` Robert Roessler
  1 sibling, 1 reply; 9+ messages in thread
From: Jakob Lichtenberg @ 2006-10-11 19:45 UTC (permalink / raw)
  To: Jon Harrop, caml-list

Is this a bug in ocamlopt?

- Jakob


-----Original Message-----
From: caml-list-bounces@yquem.inria.fr
[mailto:caml-list-bounces@yquem.inria.fr] On Behalf Of Jon Harrop
Sent: Wednesday, October 11, 2006 12:03 PM
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Missing overflow exception message in ocamlopt

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


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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 19:17   ` Richard Jones
  2006-10-11 19:25     ` Gerd Stolpmann
@ 2006-10-11 20:26     ` Jon Harrop
  1 sibling, 0 replies; 9+ messages in thread
From: Jon Harrop @ 2006-10-11 20:26 UTC (permalink / raw)
  To: caml-list

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


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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 19:45   ` Jakob Lichtenberg
@ 2006-10-12  1:04     ` Robert Roessler
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Roessler @ 2006-10-12  1:04 UTC (permalink / raw)
  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
roessler@rftp.com
http://www.rftp.com


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

* Re: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-11 18:46 Missing overflow exception message in ocamlopt Jakob Lichtenberg
  2006-10-11 19:03 ` [Caml-list] " Jon Harrop
@ 2006-10-15 15:58 ` Xavier Leroy
  2006-10-16  3:50   ` Jakob Lichtenberg
  1 sibling, 1 reply; 9+ messages in thread
From: Xavier Leroy @ 2006-10-15 15:58 UTC (permalink / raw)
  To: Jakob Lichtenberg; +Cc: caml-list

> 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


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

* RE: [Caml-list] Missing overflow exception message in ocamlopt
  2006-10-15 15:58 ` Xavier Leroy
@ 2006-10-16  3:50   ` Jakob Lichtenberg
  0 siblings, 0 replies; 9+ messages in thread
From: Jakob Lichtenberg @ 2006-10-16  3:50 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1839 bytes --]

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.Leroy@inria.fr]
Sent: Sun 10/15/2006 8:58 AM
To: Jakob Lichtenberg
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Missing overflow exception message in ocamlopt



> 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




[-- Attachment #2: Type: text/html, Size: 2669 bytes --]

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

end of thread, other threads:[~2006-10-16  3:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-11 18:46 Missing overflow exception message in ocamlopt Jakob Lichtenberg
2006-10-11 19:03 ` [Caml-list] " Jon Harrop
2006-10-11 19:17   ` Richard Jones
2006-10-11 19:25     ` Gerd Stolpmann
2006-10-11 20:26     ` Jon Harrop
2006-10-11 19:45   ` Jakob Lichtenberg
2006-10-12  1:04     ` Robert Roessler
2006-10-15 15:58 ` Xavier Leroy
2006-10-16  3:50   ` Jakob Lichtenberg

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 NNTP newsgroup(s).