Hi, As I mentioned on the Haskell mailing list a few days ago, a few of us at Yale are developing a system that allows Haskell code to invoke Java methods via GreenCard and the Java Native Interface. The system works quite reliably at this point, including integration of the Java and Haskell garbage collectors, and we have succesfully run a number of interesting test programs under Hugs98 on both Windows and Linux. We are currently working on a novel mechanism for mapping Java method names to Haskell function names; when that is complete, we plan to make this system available to the community. However, because the Java VM is multi-threaded, I had to rebuild Hugs from sources under Linux to use the multi-threaded version of the C library. The changes were very minor: - Pass the -D_REENTRANT flag to CC - Add -lpthread to LIBS for linking - #define DONT_PANIC to avoid catching signals used by the user-space LinuxThreads implementation. To make it as painless as possible for users to be able to use the Java/Haskell bridge, whilst minimizing the impact on others, I have made modified my local copy of hugs so that the above changes only take effect if the --with-pthreads option is given to configure. Attached is a patch with the mods. to src/Makefile.in and src/unix/configure.in to add the --with-pthreads option. Since this change is completely invisible unless hugs is built from sources using --with-pthreads, I hope that you won't object to including this in the hugs distribution. The patch is in unified diff format. If you have any problems applying the patch from the diff. file or there is anything I can do to make this patch more acceptable, please let me know. Thanks! -Antony Courtney -- Antony Courtney Grad. Student, Dept. of Computer Science, Yale University antony@apocalypse.org http://www.apocalypse.org/pub/u/antony diff -u -r src/Makefile.in /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/Makefile.in --- src/Makefile.in Tue Jan 30 21:52:13 2001 +++ /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/Makefile.in Sat Jul 7 16:35:19 2001 @@ -25,7 +25,7 @@ default :: hugs@EXE@ runhugs@EXE@ CC = @CC@ -CFLAGS = @CFLAGS@ @DEBUGFLAGS@ +CFLAGS = @CFLAGS@ @DEBUGFLAGS@ @MTCFLAGS@ OPTFLAGS = @OPTFLAGS@ LD = @LD@ diff -u -r src/unix/configure.in /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/unix/configure.in --- src/unix/configure.in Wed Jan 17 18:30:36 2001 +++ /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/unix/configure.in Sat Jul 7 16:51:57 2001 @@ -240,6 +240,7 @@ AC_ARG_ENABLE(tag-checks, [ --enable-tag-checks runtime tag checking (for debugging use)],AC_DEFINE(CHECK_TAGS)) AC_ARG_ENABLE(lint, [ --enable-lint enable "lint" flags (for debugging use)]) AC_ARG_ENABLE(only98, [ --enable-only98 make Hugs Haskell 98 only], AC_DEFINE(HASKELL_98_ONLY)) +AC_ARG_WITH(pthreads, [ --with-pthreads build Hugs using pthreads C library], AC_DEFINE(DONT_PANIC) MTCFLAGS="-D_REENTRANT"; LIBS="$LIBS -lpthread") dnl Disabled for now because the plugin-code can't handle the change. dnl If you're not using plugins, you could turn this on manually @@ -343,6 +344,7 @@ AC_SUBST(OPTFLAGS) AC_SUBST(DEBUGFLAGS) AC_SUBST(LDDEBUGFLAGS) +AC_SUBST(MTCFLAGS) dnl Figure out sizes of objects and decide which version of Hugs to build
Antony Courtney wrote:
[...] We are currently working on a novel mechanism for mapping Java method names to Haskell function names; when that is complete, we plan to make this system available to the community.
It might be a good idea to join the Haskell Foreign Function Interface (FFI) mailing list (http://haskell.org/mailman/listinfo/ffi) for anybody interested in this kind of stuff. Apart from some occasional syntactic Jihads, it's quite low-volume. The new design is intended to accommodate various languages apart from C, e.g. SPJ is working on a .NET binding IIRC, which probably has very similar problems as a one for Java (overloading, exceptions, etc.). A draft document is available at http://www.cse.unsw.edu.au/~chak/haskell/ffi.ps.gz and http://www.cse.unsw.edu.au/~chak/haskell/ffi.tex The Java part is almost nonexistent yet and has only been discussed very superficially, so any help and suggestions are highly appreciated.
However, because the Java VM is multi-threaded, I had to rebuild Hugs from sources under Linux to use the multi-threaded version of the C library. The changes were very minor: - Pass the -D_REENTRANT flag to CC - Add -lpthread to LIBS for linking - #define DONT_PANIC to avoid catching signals used by the user-space LinuxThreads implementation.
Hmmm, things are a little bit different on Solaris IIRC, but I don't have the relevant man pages at hand. I'll have a look tomorrow... Cheers, Sven.
Hi,
just to let you know that I've folded this change into the CVS tree.
Many thanks for the contribution, keep them coming! :)
--sigbjorn
----- Original Message -----
From: "Antony Courtney"
Hi,
As I mentioned on the Haskell mailing list a few days ago, a few of us at Yale are developing a system that allows Haskell code to invoke Java methods via GreenCard and the Java Native Interface. The system works quite reliably at this point, including integration of the Java and Haskell garbage
collectors, > and we have succesfully run a number of interesting test programs under Hugs98 > on both Windows and Linux. We are currently working on a novel mechanism for > mapping Java method names to Haskell function names; when that is complete, we > plan to make this system available to the community. > > However, because the Java VM is multi-threaded, I had to rebuild Hugs from > sources under Linux to use the multi-threaded version of the C library. The > changes were very minor: > - Pass the -D_REENTRANT flag to CC > - Add -lpthread to LIBS for linking > - #define DONT_PANIC to avoid catching signals used by the user-space > LinuxThreads implementation. > > To make it as painless as possible for users to be able to use the Java/Haskell > bridge, whilst minimizing the impact on others, I have made modified my local > copy of hugs so that the above changes only take effect if the --with-pthreads > option is given to configure. > > Attached is a patch with the mods. to src/Makefile.in and src/unix/configure.in > to add the --with-pthreads option. Since this change is completely invisible > unless hugs is built from sources using --with-pthreads, I hope that you won't > object to including this in the hugs distribution. > > The patch is in unified diff format. If you have any problems applying the > patch from the diff. file or there is anything I can do to make this patch more > acceptable, please let me know. > > Thanks! > > -Antony Courtney > > -- > Antony Courtney > Grad. Student, Dept. of Computer Science, Yale University > antony@apocalypse.org http://www.apocalypse.org/pub/u/antony
diff -u -r src/Makefile.in /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/Makefile.in --- src/Makefile.in Tue Jan 30 21:52:13 2001 +++ /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/Makefile.in Sat Jul 7 16:35:19 2001 @@ -25,7 +25,7 @@ default :: hugs@EXE@ runhugs@EXE@
CC = @CC@ -CFLAGS = @CFLAGS@ @DEBUGFLAGS@ +CFLAGS = @CFLAGS@ @DEBUGFLAGS@ @MTCFLAGS@ OPTFLAGS = @OPTFLAGS@
LD = @LD@ diff -u -r src/unix/configure.in /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/unix/configure.in --- src/unix/configure.in Wed Jan 17 18:30:36 2001 +++ /usr/local/src/hugs98-Feb2001-MT/hugs98-Feb2001/src/unix/configure.in Sat Jul 7 16:51:57 2001 @@ -240,6 +240,7 @@ AC_ARG_ENABLE(tag-checks, [ --enable-tag-checks runtime tag checking (for debugging use)],AC_DEFINE(CHECK_TAGS)) AC_ARG_ENABLE(lint, [ --enable-lint enable "lint" flags (for debugging use)]) AC_ARG_ENABLE(only98, [ --enable-only98 make Hugs Haskell 98 only], AC_DEFINE(HASKELL_98_ONLY)) +AC_ARG_WITH(pthreads, [ --with-pthreads build Hugs using
---------------------------------------------------------------------------- ---- pthreads C library], AC_DEFINE(DONT_PANIC) MTCFLAGS="-D_REENTRANT"; LIBS="$LIBS -lpthread")
dnl Disabled for now because the plugin-code can't handle the change. dnl If you're not using plugins, you could turn this on manually @@ -343,6 +344,7 @@ AC_SUBST(OPTFLAGS) AC_SUBST(DEBUGFLAGS) AC_SUBST(LDDEBUGFLAGS) +AC_SUBST(MTCFLAGS)
dnl Figure out sizes of objects and decide which version of Hugs to build
participants (3)
-
Antony Courtney -
Sigbjorn Finne -
Sven Panne