executing Java written code from C pgm

Ronald Klop ronald-lists at klop.ws
Thu Jan 22 11:25:14 UTC 2015


On Thu, 22 Jan 2015 11:49:33 +0100, Johannes Dieterich  
<dieterich.joh at gmail.com> wrote:

> Dear Matthias,
>
> On Thu, Jan 22, 2015 at 11:26 AM, Matthias Apitz <guru at 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

This would be my advise also.

Ronald.


More information about the freebsd-java mailing list