From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 7BA417EFCD for ; Sat, 18 Oct 2014 12:04:44 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of kennethadammiller@gmail.com) identity=pra; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="kennethadammiller@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of kennethadammiller@gmail.com designates 209.85.218.52 as permitted sender) identity=mailfrom; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="kennethadammiller@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oi0-f52.google.com) identity=helo; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="postmaster@mail-oi0-f52.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al4BAN86QlTRVdo0m2dsb2JhbABbg2FYBIMCyQSHTgKBCwcWAREBAQEBAQYLCwkULoQCAQEBAwESEQQZARsPDwMBCwYFCw0qAgIhAQERAQUBHBkbB4gIAQMJCA2sKG6LMIFygxCIMAoZJw1nhUoBCgEBARgBAQQOikGDSoFcVAuCd4FUBYRikWSCRIF9QYIRgTCDRooQQoRlGCmFRyEvgQaBRQEBAQ X-IPAS-Result: Al4BAN86QlTRVdo0m2dsb2JhbABbg2FYBIMCyQSHTgKBCwcWAREBAQEBAQYLCwkULoQCAQEBAwESEQQZARsPDwMBCwYFCw0qAgIhAQERAQUBHBkbB4gIAQMJCA2sKG6LMIFygxCIMAoZJw1nhUoBCgEBARgBAQQOikGDSoFcVAuCd4FUBYRikWSCRIF9QYIRgTCDRooQQoRlGCmFRyEvgQaBRQEBAQ X-IronPort-AV: E=Sophos;i="5.04,745,1406584800"; d="scan'208";a="101788991" Received: from mail-oi0-f52.google.com ([209.85.218.52]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Oct 2014 12:04:43 +0200 Received: by mail-oi0-f52.google.com with SMTP id a3so1699262oib.11 for ; Sat, 18 Oct 2014 03:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=dAcGZ8IXtgGmHiAOBJner6lfFSlrwL52J0UV4MpPUI4=; b=hvDsDTPRaII8Jl3Yq4l5LGtInxw7s7CuRuHqAryCzlFQw/SuJztK26vLXwAkMKQ/b9 ZIDgldrFGgieOxBHjllyDW279B+OUVBjBgUxErcu2K6qgDYr2VHmz4a+CdwBI01+f7Sx 0pg71M9/GxVCCaNj9Jj6PudiQq/efTHvo5yUZDZ7YMIjUveouuYD6HvYlo3ypBJt8wv3 YJv7a/aNqfH3sukpJjNJeypFaLAXmR6FZQn7XAywgU3xYTDZPP/iF3Spv7Edfawxup3D 5kJdculVeDSIlSzwxs3S7VkEYwXSwlVvKLL2U70wqn/KMb2JSyEiKCNae5wVDqxtSXQ8 oi0A== MIME-Version: 1.0 X-Received: by 10.182.95.9 with SMTP id dg9mr1179597obb.44.1413626681978; Sat, 18 Oct 2014 03:04:41 -0700 (PDT) Received: by 10.182.97.137 with HTTP; Sat, 18 Oct 2014 03:04:41 -0700 (PDT) In-Reply-To: References: Date: Sat, 18 Oct 2014 06:04:41 -0400 Message-ID: From: Kenneth Adam Miller To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=089e01538a123976200505af9ca8 Subject: Re: [Caml-list] Library recompilation with OCamljava --089e01538a123976200505af9ca8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Ok, to replicate the bug, just go to https://github.com/KennethAdamMiller/ocaml-makefile where I'm updating the fork of ocamlmakefile in order to allow a target to compile for ocamljava. Once I update (I've committed, but haven't pushed yet, will within a matter of hours hours), you can clone or pull, and cd to the threads subdirectory, which is an example project that consumes the ocamlmakefile. Then just do make jbc #or make java-byte-code ex1 and ex2 crashe with uncaught under/overflow exception and some other overflow errors (not reliable); I think it's because the synchronization that is expressed in the ocaml code isn't very well followed at java's level; there seems to be some very great imbalance in thread scheduling (possibly slow signal handling). In java, there's a long pause where the output doesn't make it to the screen until the uncaught exception hits, when it does, the numbers being passed have a huge difference. In contrast, ocamlopt or ocamlc compiled code executes rather evenly, with each event receiving scheduler attention pretty much equally. That's my jest. Agreed! I'd much much rather construct some method of automatic (or even just expedient manual intervention!) that offers ocaml -> C sublibrary : java -> C sublibrary support! I've already started down the path of ocamljava, and right now, even ocaml-RPC with protocol buffers looks like a long haul as well! ocamljava is just a much better solution. Precisely! ocaml-ctypes is exactly what's being used by the library that I'm porting to call into C sub libraries. It would be really sweet if the ocamljava compiler could detect the ocaml-ctypes and generate these mappings automatically. This would eliminate a lot of error prone code, since C code tends to interpret data raw at some point... How might I got about writing this to boot? I'm moderately new to ocaml, lacking deep expertise in it, but I'm an aggressive learner. Please explain the best path forward, I want to create a robust and reusable solution. On Sat, Oct 18, 2014 at 5:09 AM, forum@x9c.fr wrote: > Hi Kenneth, > > > Le 17 oct. 2014 =C3=A0 23:33, Kenneth Adam Miller > a =C3=A9crit : > > So, after doing some more work, I think the answer to 2) is no/no. After > looking more into piqi, I now just need to find a way to do protocol > buffers based RPC to an ocaml service... > > Anybody know how to do that? > > On Thu, Oct 16, 2014 at 4:08 AM, Kenneth Adam Miller < > kennethadammiller@gmail.com> wrote: > >> So, I'm attempting a large library recompile with ocamljava. It's pretty >> audacious, because some people in my workplace are rather unwilling to >> learn ocaml, yet a very well respected and needed library is authored in >> it. Everyone knows java, so we hope very much to recompile the library j= ust >> with ocamljava. >> >> Two important things that make me nervous in pursuing this effort are: >> >> 1) once fully recompiled, will the library work in java as it did with >> native/ocaml byte code? >> >> I've already started modifying the popular OCamlMakefile project to add a >> java-byte-code target, and I've found that a threaded example is admitted >> by the compiler produces an uncaught exception when run on the JVM... Th= at >> example may fall out of what the ocamljava docs has been safely implemen= ted >> under ocamljava, I'm not sure... >> >> > This sounds like a bug... It would be nice to report it at > https://github.com/xclerc/ocamljava, > particularly if you have a (small) reproduction case. The "thread" library > is indeed only lightly > tested, mainly because the "concurrent" library (which is specific to > OCaml-Java) includes > another implementation of threads, that is much closer to Java threads. > > > 2) I've noticed that the rather large library that I need to compile, as >> my final target, and aside from the toy targets I'm testing ocamljava wi= th, >> actually consumes some other C libraries and functions in it's dependency >> path... >> >> This is difficult; the traditional OCamlMakefile builds traditional c >> stubs to .o files, correctly compiled with ocamlc. But when put on the >> ocamljava command line, but ocamljava doesn't know what to do about it. >> Would there be any way that I can have support for this ocaml feature as >> well, or facilitate some way to link in or enable ocaml code that calls >> into C being compiled down to java? >> >> > OCaml-Java does not know how to handle C files, as additional primitives > should be implemented > through Java files. As a consequence, when porting a project from > ocamlc/ocamlopt to ocamljava, > you have to port C files to Java files. > > > >> 3) What if the answer to 2) is no/no? >> >> If I can't use ocamljava, which is the most desired and elegant way, >> allowing beautiful language inter-operation, how can I *best* facilitate >> calls to the ocaml library? Is there a fast way to generate callbacks to >> ocaml in java or any other language? It's very highly preferable not to >> have to delegate back through the JNI due to type safety and fragility. >> Alternatively, I looked at the OCaml library Restful, and wondered to >> myself if there could be any kind of fast definition between ocaml types >> and an exchange language, like json or something. Ideally, I'd like to be >> able to generate a url per function in a very very simple declarative >> manner, so that I can take ocaml libraries, and make them operate as a >> service, where ocaml library functions correspond to URLs. >> >> > I think a neat way to use a C library from an ocamljava-compiled program > would be to have a > Java "backend" for Jeremy Yallop's ctypes ( > https://github.com/ocamllabs/ocaml-ctypes). > I never had the time to implement that, but toyed with this idea and think > the best way to > implement it would be to go through JNA (https://github.com/twall/jna) > rather than JNI. > JNA includes a "dlopen"-like mechanism, and automatically maps simple > types from Java > to C. My knowledge of ctypes is quite limited, but I see no showstopper. > > > Regards, > > Xavier > --089e01538a123976200505af9ca8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ok, to replicate the bug, just go to=C2=A0https://github.com/Ken= nethAdamMiller/ocaml-makefile where I'm updating the fork of ocamlm= akefile in order to allow a target to compile for ocamljava. Once I update = (I've committed, but haven't pushed yet, will within a matter of ho= urs hours), you can clone or pull, and cd to the threads subdirectory, whic= h is an example project that consumes the ocamlmakefile. Then just do=C2=A0=

make jbc =C2=A0#or make java-byte-code=C2=A0

ex1 and ex2 crashe with uncaught under/overflow except= ion and some other overflow errors (not reliable); I think it's because= the synchronization that is expressed in the ocaml code isn't very wel= l followed at java's level; there seems to be some very great imbalance= in thread scheduling (possibly slow signal handling). In java, there's= a long pause where the output doesn't make it to the screen until the = uncaught exception hits, when it does, the numbers being passed have a huge= difference. In contrast, ocamlopt or ocamlc compiled code executes rather = evenly, with each event receiving scheduler attention pretty much equally. = That's my jest.

Agreed! I'd much much rather co= nstruct some method of automatic (or even just expedient manual interventio= n!) that offers ocaml -> C sublibrary : java -> C sublibrary support!= I've already started down the path of ocamljava, and right now, even o= caml-RPC with protocol buffers looks like a long haul as well! ocamljava is= just a much better solution.

Precisely! ocaml-ctype= s is exactly what's being used by the library that I'm porting to c= all into C sub libraries. It would be really sweet if the ocamljava compile= r could detect the ocaml-ctypes and generate these mappings automatically. = This would eliminate a lot of error prone code, since C code tends to inter= pret data raw at some point... How might I got about writing this to boot? = I'm moderately new to ocaml, lacking deep expertise in it, but I'm = an aggressive learner. Please explain the best path forward, I want to crea= te a robust and reusable solution.
On Sat, Oct 18, 2014 at 5:09 AM, forum@x9c.fr <forum@x9c.fr> wrote:
Hi Kenneth,<= div>

Le 17 oct. 2014 =C3=A0 23:33, Kenneth Adam= Miller <kennethadammiller@gmail.com> a =C3=A9crit :
=
So, after doing some more wo= rk, I think the answer to 2) is no/no. After looking more into piqi, I now = just need to find a way to do protocol buffers based RPC to an ocaml servic= e...

Anybody know how to do that?

On Thu, Oct 16, 2014 at 4:0= 8 AM, Kenneth Adam Miller <kennethadammiller@gmail.com> wrote:
So, I'm attempting a = large library recompile with ocamljava. It's pretty audacious, because = some people in my workplace are rather unwilling to learn ocaml, yet a very= well respected and needed library is authored in it. Everyone knows java, = so we hope very much to recompile the library just with ocamljava.=C2=A0
Two important things that make me nervous in pursuing this= effort are:

1) once fully recompiled, will the li= brary work in java as it did with native/ocaml byte code?
I've alre= ady started modifying the popular OCamlMakefile project to add a java-byte-= code target, and I've found that a threaded example is admitted by the = compiler produces an uncaught exception when run on the JVM... That example= may fall out of what the ocamljava docs has been safely implemented under = ocamljava, I'm not sure...
<= /div>

This sounds =C2=A0like a= bug... It would be nice to report it at=C2=A0https://github.com/xclerc/ocamljava,


2) I've noticed that the rather large libr= ary that I need to compile, as my final target, and aside from the toy targ= ets I'm testing ocamljava with, actually consumes some other C librarie= s and functions in it's dependency path...
This = is difficult; the traditional OCamlMakefile builds traditional c stubs to .= o files, correctly compiled with ocamlc. But when put on the ocamljava comm= and line, but ocamljava doesn't know what to do about it. Would there b= e any way that I can have support for this ocaml feature as well, or facili= tate some way to link in or enable ocaml code that calls into C being compi= led down to java?=C2=A0

OCaml-Java does not know how to= handle C files, as additional primitives should be implemented
t= hrough Java files. As a consequence, when porting a project from ocamlc/oca= mlopt to ocamljava,
you have to port C files to Java files.
=


=
<= br>
3) What if the answer to 2) is no/no?
If I can't u= se ocamljava, which is the most desired and elegant way, allowing beautiful= language inter-operation, how can I best facilitate calls to the oc= aml library? Is there a fast way to generate callbacks to ocaml in java or = any other language? It's very highly preferable not to have to delegate= back through the JNI due to type safety and fragility. Alternatively, I lo= oked at the OCaml library Restful, and wondered to myself if there could be= any kind of fast definition between ocaml types and an exchange language, = like json or something. Ideally, I'd like to be able to generate a url = per function in a very very simple declarative manner, so that I can take o= caml libraries, and make them operate as a service, where ocaml library fun= ctions correspond to URLs.

I never had the time to implement that, but t= oyed with this idea and think the best way to
implement it would = be to go through JNA (https://github.com/twall/jna) rather than JNI.
JNA incl= udes a "dlopen"-like mechanism, and automatically maps simple typ= es from Java
to C. My knowledge of ctypes is quite limited, but I= see no showstopper.


Regards,
=

Xavier

--089e01538a123976200505af9ca8--