From owner-freebsd-java@FreeBSD.ORG Thu Jan 22 10:49:34 2015 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5898E59F for ; Thu, 22 Jan 2015 10:49:34 +0000 (UTC) Received: from mail-ob0-x22b.google.com (mail-ob0-x22b.google.com [IPv6:2607:f8b0:4003:c01::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1D6E5E06 for ; Thu, 22 Jan 2015 10:49:34 +0000 (UTC) Received: by mail-ob0-f171.google.com with SMTP id va2so743342obc.2 for ; Thu, 22 Jan 2015 02:49:33 -0800 (PST) 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=Q9pO8eQh7llQ62EHigZ/qp+tmJ85mRLBispxgZd567U=; b=awwG+xX+IXwPSm3kmQQyvnepoGc/mnPzAnbgy7X62DFwR3KJ5+ThoijHrgk14CaLsQ Ys81U8QNkFyNNq0ORyQ5qGGIbxksYYfWXg+12Q/2b7YB2kLu02mngIkfqzsLTgjfV+Bt eOCwa+3aXEcBAHbWdtP9SuqtrBMPFhoaezXkpBN/QOQBbOezKhGdnTXT4K+Fhz2ohNXL KZupCjIDGOfpfwvOrbKclvFGHdpgiEnCw0EiNhdndEyKO8HqPo6yuWskpJ3e077YVYYJ my163Plylj09hI6hGQsh6YO+MJFqLLeTrpjRmKMNfmhCiUaYLK+GGuSzOARBIZLDGLMx EcbQ== MIME-Version: 1.0 X-Received: by 10.202.7.142 with SMTP id 136mr364533oih.51.1421923773363; Thu, 22 Jan 2015 02:49:33 -0800 (PST) Received: by 10.202.105.7 with HTTP; Thu, 22 Jan 2015 02:49:33 -0800 (PST) In-Reply-To: <20150122102614.GA2046@c720-r276659> References: <20150122102614.GA2046@c720-r276659> Date: Thu, 22 Jan 2015 11:49:33 +0100 Message-ID: Subject: Re: executing Java written code from C pgm From: Johannes Dieterich To: Matthias Apitz , freebsd-java@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jan 2015 10:49:34 -0000 Dear Matthias, On Thu, Jan 22, 2015 at 11:26 AM, Matthias Apitz 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