caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Memory leak with native code.
@ 2002-12-05 18:48 David Brown
  2002-12-05 19:14 ` Markus Mottl
  2002-12-05 20:31 ` Basile STARYNKEVITCH
  0 siblings, 2 replies; 5+ messages in thread
From: David Brown @ 2002-12-05 18:48 UTC (permalink / raw)
  To: Caml List

I have a fairly complex program that has numerous callbacks between
Ocaml, C and back to Ocaml (I'm using Debian's 3.06).

If I compile my program byte-code, it works well.

However, if I compile it native, it seems to leak memory, just consuming
more and more memory as it runs.

I was wondering if anyone has any pointers on how to debug this kind of
issue.  I've checked the C stubs, and I think I'm using the macros
correctly.

I guess what would be helpful would be any pointers on what might be
different between bytecode and native.  I do use callbacks, but the main
program is in Ocaml.

Thanks,
David Brown
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Memory leak with native code.
  2002-12-05 18:48 [Caml-list] Memory leak with native code David Brown
@ 2002-12-05 19:14 ` Markus Mottl
  2002-12-05 20:31 ` Basile STARYNKEVITCH
  1 sibling, 0 replies; 5+ messages in thread
From: Markus Mottl @ 2002-12-05 19:14 UTC (permalink / raw)
  To: David Brown; +Cc: Caml List

On Thu, 05 Dec 2002, David Brown wrote:
> I guess what would be helpful would be any pointers on what might be
> different between bytecode and native.  I do use callbacks, but the
> main program is in Ocaml.

Have you made sure that stubs taking more than five arguments need to
be split up into two functions? E.g.:

C-file:

  CAMLprim value add_nat_native(value nat1, value ofs1, value len1,
                                value nat2, value ofs2, value len2,
                                value carry_in)
  {
    ...
  }

  CAMLprim value add_nat_bytecode(value * argv, int argn)
  {
    return add_nat_native(argv[0], argv[1], argv[2], argv[3],
                          argv[4], argv[5], argv[6]);
  }

OCaml-file:

  external add_nat: nat -> int -> int -> nat -> int -> int -> int -> int
                  = "add_nat_bytecode" "add_nat_native"

Notice that the external function needs to be declared such on the
OCaml-side that you name both entry points (for byte- and native code).

That's the only difference that comes to my mind...

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Memory leak with native code.
  2002-12-05 18:48 [Caml-list] Memory leak with native code David Brown
  2002-12-05 19:14 ` Markus Mottl
@ 2002-12-05 20:31 ` Basile STARYNKEVITCH
  2002-12-07 10:42   ` Xavier Leroy
  1 sibling, 1 reply; 5+ messages in thread
From: Basile STARYNKEVITCH @ 2002-12-05 20:31 UTC (permalink / raw)
  To: David Brown; +Cc: Caml List

>>>>> "David" == David Brown <caml-list@davidb.org> writes:

    David> I have a fairly complex program that has numerous callbacks
    David> between Ocaml, C and back to Ocaml (I'm using Debian's
    David> 3.06).

    David> If I compile my program byte-code, it works well.

    David> However, if I compile it native, it seems to leak memory,
    David> just consuming more and more memory as it runs.

I assume your plateform is x86 on Debian. Because of the small number
of registers, tail-recursion is limited to 5 arguments (if my memory
serves me well). For more arguments, a tail-rec is not a loop on
x86. Perhaps this could be your problem (just a guess, I encountered
it several years ago and reported to the mailing list). Then you might
merge several arguments into a tuple or record.  Or switch to
plateform with more registers!

Just a wild guess! The Caml team will confirm (or infirm) it.


-- 

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
alias: basile<at>tunes<dot>org 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Memory leak with native code.
  2002-12-05 20:31 ` Basile STARYNKEVITCH
@ 2002-12-07 10:42   ` Xavier Leroy
  2002-12-07 21:52     ` David Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Xavier Leroy @ 2002-12-07 10:42 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: David Brown, Caml List

>     David> I have a fairly complex program that has numerous callbacks
>     David> between Ocaml, C and back to Ocaml (I'm using Debian's
>     David> 3.06).
> 
>     David> If I compile my program byte-code, it works well.
> 
>     David> However, if I compile it native, it seems to leak memory,
>     David> just consuming more and more memory as it runs.
> 
> I assume your plateform is x86 on Debian. Because of the small number
> of registers, tail-recursion is limited to 5 arguments (if my memory
> serves me well). For more arguments, a tail-rec is not a loop on x86.

As of release 3.06, tail recursion (tail calls to the same function)
are properly implemented on all platforms regardless of the number of
arguments.  Tail cross-recursion, or more generally tail calls to
another function, are not supported if the number of arguments is
greater than a processor-dependent number: 5 for x86, more for RISC
processors.  

That would explain why a program compiled to native code uses more
stack space than when compiled to byte code.  However, there is no
evidence that David's problem is related to stack space.

You can track Caml heap space consumption by running both programs
(native and byte-code) with the OCAMLRUNPARAM environment variable set
to "v=4".  Normally, you should see roughly the same sequences of
"Growing heap to ..." messages.

A third source of leaks is the C code itself.  A good tool to track
these leaks is valgrind.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Memory leak with native code.
  2002-12-07 10:42   ` Xavier Leroy
@ 2002-12-07 21:52     ` David Brown
  0 siblings, 0 replies; 5+ messages in thread
From: David Brown @ 2002-12-07 21:52 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: Basile STARYNKEVITCH, David Brown, Caml List

On Sat, Dec 07, 2002 at 11:42:36AM +0100, Xavier Leroy wrote:

> That would explain why a program compiled to native code uses more
> stack space than when compiled to byte code.  However, there is no
> evidence that David's problem is related to stack space.

It gets even stranger.  After doing a make clean, and recompiling
everything, the memory leak now appears to be gone.

Dave
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-12-07 21:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-05 18:48 [Caml-list] Memory leak with native code David Brown
2002-12-05 19:14 ` Markus Mottl
2002-12-05 20:31 ` Basile STARYNKEVITCH
2002-12-07 10:42   ` Xavier Leroy
2002-12-07 21:52     ` David Brown

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).