From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 507A3BBBB for ; Sat, 4 Mar 2006 15:01:38 +0100 (CET) Received: from kraid.nerim.net (smtp-106-saturday.nerim.net [62.4.16.106]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k24E1bs4015760 for ; Sat, 4 Mar 2006 15:01:38 +0100 Received: from hector.lesours (bstarynk.net8.nerim.net [213.41.176.170]) by kraid.nerim.net (Postfix) with ESMTP id 124FA40E23; Sat, 4 Mar 2006 15:01:37 +0100 (CET) Received: from basile by hector.lesours with local (Exim 4.60) (envelope-from ) id 1FFXKD-0004I9-Gj; Sat, 04 Mar 2006 15:01:37 +0100 Date: Sat, 4 Mar 2006 15:01:37 +0100 To: David MENTRE Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Looking for pointers regarding integration of OCaml plugins into OCaml native code Message-ID: <20060304140137.GA16267@ours.starynkevitch.net> References: <87ek1icotj.fsf@linux-france.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87ek1icotj.fsf@linux-france.org> User-Agent: Mutt/1.5.11+cvs20060126 From: Basile STARYNKEVITCH X-Miltered: at nez-perce with ID 44099DC2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 pointers:01 ocaml:01 ocaml:01 basile:01 basile:01 ecrivait:01 caml-list:01 bytecode:01 bytecode:01 dynlink:01 pointer:01 ocaml's:01 stack:01 stack:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Le Sat, Mar 04, 2006 at 02:38:32PM +0100, David MENTRE écrivait/wrote: > Hello, > > I would like to extend an OCaml native code application with plugins > written in OCaml (preferably native code). So, much like the C/OCaml > interface, I would like to have some dynamically loaded OCaml code > calling my application core code and vice versa. > > >>From my readings of the caml-list archives, I understand that: > > 1/ It is possible to load bytecode code into a bytecode application, > using the Dynlink module; > > 2/ It could be possible to load native code into a native code > application[1] but Xavier thinks this is no longer possible or too > difficult[2]. I haven't be able to find the explanation Xavier is > refering to. Has anybody a pointer to it? I would like to understand > the issue(s). I'm not an expert on Ocaml's GC, but I believe the issue is the local roots on the call stack. With bytecode, it is only on the VM stack, whose organisation is well understood. With native code, the pointers are on the machine's stack (the one usually used by C), and the Ocaml generated code contains extra information to describe it (IIRC some kind of hash tables mapping machine return addresses to stack frame descriptions). > 3/ With original OCaml, it is not possible to load a bytecode into a > native code application but that might be possible with the > Asmdynlink module of Fabrice Le Fessant[2]. If I remember correctly > (can't remember where I read that), the main issue is that native > and bytecode have not exactly the same memory representation (thus, > for example, the GC is different). Is that correct? I believe it is related to the previous point. There might be also another possibility. You might consider using Metaocaml see http://www.metaocaml.org/ with the following caveats First and above all, Metaocaml is much less mature than Ocaml is, and the team of people working on Metaocaml is much smaller. This means that Metaocaml is really a research prototype, not a full software product (there is no offense intended in stating this fact). MetaOcaml is native only on x86 (32 bits). IIRC, it is not native on x86_64 (aka AMD64) nor on all the other native targets of Ocaml. IIRC, there is not robust machinery to drop useless code, which is needed for long-time running programs in MetaOcaml. Basically, what is missing (both in MetaOcaml & in Ocaml) is the ability to garbage collect useless code. But this requirement has a major impact on the compiler, the runtime library and the performance of the GC, etc... Maybe Ocaml's successor would have the meta-programming abilities of MetaOcaml and a way to drop useless code, ie a GC handling machine code (old versions of SML/NJ did have it, and some CommonLisp implementations have it also). There are also some theoretical barriers (see all the work on safe module signatures, mixins, mobility, ....). I'm not sure that MetaOcaml has the ability to do exactly a module run-time linking; however, it is able to generate code at runtime which might be somehow equivalent. It could recieve some description of the code to generate... Maybe the easiest way is to stay within the bytecode... Do you really need the performance of native code? You might also try with ocamljitrun (but I admit that I don't have much time maintaining it). Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet aliases: basiletunesorg = bstarynknerimnet 8, rue de la Faïencerie, 92340 Bourg La Reine, France