This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Compiling Scala-generated bytecode
- From: Bryce McKinlay <bmckinlay at gmail dot com>
- To: Marko DimjaÅeviÄ <marko at dimjasevic dot net>
- Cc: GCC Java <java at gcc dot gnu dot org>
- Date: Fri, 24 Oct 2014 14:32:56 +0100
- Subject: Re: Compiling Scala-generated bytecode
- Authentication-results: sourceware.org; auth=none
- References: <1413785951 dot 4798 dot 12 dot camel at neelix> <CALUNu-qQ-k-F8w5ekc+GXOhyo-V=Ppsxe7wmEXtahOxK6-d7Fw at mail dot gmail dot com> <1414126365 dot 4574 dot 13 dot camel at neelix>
On Fri, Oct 24, 2014 at 5:52 AM, Marko DimjaÅeviÄ <marko@dimjasevic.net> wrote:
> Have you actually executed this on a machine? If so, I'd like to know
> which version of GCJ you used for this.
>
> As I've reported in one of my previous mails, the first command fails.
> This happens with GCC 4.7.2. I've tried to build GCC 4.9.1 because
> Andrew Hughes pointed out I might have a too old GCJ version to include
> Pattern.quote(String), but something was failing with the build process,
> so I can't really give it a shot with 4.9.1.
I just built GCC 4.9.1 and gave it a try on a fresh EC2 instance.
$ uname -a
Linux ip-172-30-1-126 3.14.20-20.44.amzn1.x86_64 #1 SMP Mon Oct 6
22:52:46 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ sudo yum install gcc-c++ libmpc-devel mpfr-devel gmp-devel
$ curl -O http://mirrors-uk.go-parts.com/gcc/releases/gcc-4.9.1/gcc-4.9.1.tar.bz2
$ tar jxvf gcc-4.9.1.tar.bz2
$ mkdir gcc-build; cd gcc-build
$ ../gcc-4.9.1/configure --enable-java --disable-multilib --prefix=$HOME/gcc-bin
$ make -j35
$ make install
$ cd $HOME
$ curl -O http://www.scala-lang.org/files/archive/scala-2.9.2.tgz
$ tar zxvf scala-2.9.2.tgz
$ export PATH=$PATH:$HOME/gcc-bin/bin:$HOME/scala-2.9.2/bin
$ mkdir lib
$ gcj --indirect-dispatch -O2 --shared
scala-2.9.2/lib/scala-library.jar -o lib/libscala.so
$ scalac HelloWorld.scala
$ gcj HelloWorld$.class HelloWorld.class
--classpath=/home/ec2-user/scala-2.9.2/lib/scala-library.jar -lscala
-L$HOME/lib --indirect-dispatch --main=HelloWorld
$ export LD_LIBRARY_PATH=$HOME/lib:$HOME/gcc-bin/lib64
$ ./a.out
Hello, Scala World!
The "--indirect-dispatch" option is the key here. This defers class
and method resolution to runtime, so any missing ones will be runtime
errors, not compile time errors.
Even in 4.9.1, the scala-library.jar references a few methods (e.g. in
sun.misc.Unsafe, and java.math.BigInteger) that libgcj doesn't have,
but it doesn't need them to run. At least for this simple example.
Bryce