Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Jan 2015 11:49:33 +0100
From:      Johannes Dieterich <dieterich.joh@gmail.com>
To:        Matthias Apitz <guru@unixarea.de>, freebsd-java@freebsd.org
Subject:   Re: executing Java written code from C pgm
Message-ID:  <CABquGzVqV-kOVXkNdp9d=DQHEA=Of5tccmwo_vMCSFK8-Fo5nA@mail.gmail.com>
In-Reply-To: <20150122102614.GA2046@c720-r276659>
References:  <20150122102614.GA2046@c720-r276659>

next in thread | previous in thread | raw e-mail | index | archive | help
Dear Matthias,

On Thu, Jan 22, 2015 at 11:26 AM, Matthias Apitz <guru@unixarea.de> wrote:
>
> Hello,
>
> I have some C/C++ written servers and want to use code (classes) written
> in Java. I figured out how the load the JVM and to reference into the
> class as C function calls. I can post the details if someone is
> interested it this.
>
> The problem is that the a.out must be linked against the JVM (libjvm.so)
> and the resulting process is around 300 MByte (text, data and bss),
> which makes it unusable in production (where some 200-300 processes of
> this are running).
>
> Is there some way to compile the Java code to machine code with needing
> a JVM to execute this?
You can try gcj from the GNU compilers. It can compile some Java code
to binary. That being said: last I tried, it failed for me for any
non-trivial code. Additionally, I believe it is stuck at around Java5
which (fortunately, from my perspective) becomes rarer to use in the
Java world so odds are your classes will not compile. I recall also
seeing something llvm based lately, but I unfortunately cannot
remember the details anymore.

Your best bet, in my opinion, is either into looking what exactly is
consuming so much memory, potentially optimizing it and coming up with
a different linking scheme (we all probably need more information on
your current setup to make an educated guess) or you could look into
porting your Java classes to C.

You could look into having a standalone Java-server that communicated
with all the C servers via some interface. Again, this would require
some more details on your use case if this is a feasible way of
dealing with things. Personally, I would favor this route though.

Sorry to not be able to be of more help,

Johannes



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CABquGzVqV-kOVXkNdp9d=DQHEA=Of5tccmwo_vMCSFK8-Fo5nA>