public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
* java to native code and Sun JVM alternatives
@ 2010-03-11 11:45 wagde
  2010-03-11 11:56 ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: wagde @ 2010-03-11 11:45 UTC (permalink / raw)
  To: java


Hi

I'm working on a project which have java code (and c++), and until ow I used
javac to compile the code and java to run the classes and JNI to call java
from c++ code.

I don't want to use javac, javah, and java, ...(sun stuff) because of
royalties issues...

I'm looking for alternatives.

What I see right now are two alternatives:
1. compile my java code to native code using gcj, and link it with the c++
code.
2. keep the classes and use the gij instead of java.

I start working on the two approaches in parallel and I'm having too many
problems in both them. So I need some REAL help here.

Problem with 1.
1. I succeeded to compile my java code (after chaning the syntax) using gcj
to linux "c" object files. But in the linkage to the binary, I got too many
"undefined reference to", ... because I use external "jars" (like axis)
which are not compiled to native. I try to compile the axis jar to c and get
too many compilation errors.

Problem with 2.
I compiled all my classes with gcj. and the C code uses JNI to call it. But
the JNI creates a JVM (JNI_CreateJavaVM)!!! which I don't want to use. I
want to use gij instead. So I wanted to know if there is anyway to let my
JNI code to ceate a gij VM and and java VM. is there anything like this ?!
If not, how can I use the classes I compiled with gcj from the c code
without using the JAVA VM?
CNI? does that mean that I should convert my jni code to cni?

Any idea/help/new approaches are welcome!

Thanx
Wagde
-- 
View this message in context: http://old.nabble.com/java-to-native-code-and-Sun-JVM-alternatives-tp27862420p27862420.html
Sent from the gcc - java mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: java to native code and Sun JVM alternatives
  2010-03-11 11:45 java to native code and Sun JVM alternatives wagde
@ 2010-03-11 11:56 ` Andrew Haley
  2010-03-14 15:36   ` wagde
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Haley @ 2010-03-11 11:56 UTC (permalink / raw)
  To: wagde; +Cc: java

On 03/11/2010 11:45 AM, wagde wrote:
> 
> I'm working on a project which have java code (and c++), and until ow I used
> javac to compile the code and java to run the classes and JNI to call java
> from c++ code.
> 
> I don't want to use javac, javah, and java, ...(sun stuff) because of
> royalties issues...

OpenJDK is free software, but let's press on...

> I'm looking for alternatives.
> 
> What I see right now are two alternatives:
> 1. compile my java code to native code using gcj, and link it with the c++
> code.
> 2. keep the classes and use the gij instead of java.
> 
> I start working on the two approaches in parallel and I'm having too many
> problems in both them. So I need some REAL help here.
> 
> Problem with 1.
> 1. I succeeded to compile my java code (after chaning the syntax) using gcj
> to linux "c" object files. But in the linkage to the binary, I got too many
> "undefined reference to", ... because I use external "jars" (like axis)
> which are not compiled to native. I try to compile the axis jar to c and get
> too many compilation errors.

Compiling Java code with -findirect-dispatch is probably your best
plan to solve this.  When an undefined class is discoveed, gcj's
runtime will try to load its class files.

> Problem with 2.
> I compiled all my classes with gcj. and the C code uses JNI to call it. But
> the JNI creates a JVM (JNI_CreateJavaVM)!!! which I don't want to use.

Why not?  This is fully supported by gcj, and doesn't hurt anything.

> I want to use gij instead. So I wanted to know if there is anyway to
> let my JNI code to ceate a gij VM and and java VM. is there anything
> like this ?!  If not, how can I use the classes I compiled with gcj
> from the c code without using the JAVA VM?  CNI? does that mean that
> I should convert my jni code to cni?

No, there's no need to do that.  JNI code should work with gcj just
fine.  

Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: java to native code and Sun JVM alternatives
  2010-03-11 11:56 ` Andrew Haley
@ 2010-03-14 15:36   ` wagde
  2010-03-14 15:49     ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: wagde @ 2010-03-14 15:36 UTC (permalink / raw)
  To: java


Hi

Thanx Andrew for the quick reply.

I'm trying to link my c code and I get:
undefined reference to `JNI_CreateJavaVM'
Although I have -lgcj in my ld command and it's the only undefined symbol in
my code.
Why is that?
I still don't understand how JNI_CreateJavaVM will create a gij VM and not
sun JAVA VM. can you explain this to me.

Thanx
Wagde


Andrew Haley wrote:
> 
> On 03/11/2010 11:45 AM, wagde wrote:
>> 
>> I'm working on a project which have java code (and c++), and until ow I
>> used
>> javac to compile the code and java to run the classes and JNI to call
>> java
>> from c++ code.
>> 
>> I don't want to use javac, javah, and java, ...(sun stuff) because of
>> royalties issues...
> 
> OpenJDK is free software, but let's press on...
> 
>> I'm looking for alternatives.
>> 
>> What I see right now are two alternatives:
>> 1. compile my java code to native code using gcj, and link it with the
>> c++
>> code.
>> 2. keep the classes and use the gij instead of java.
>> 
>> I start working on the two approaches in parallel and I'm having too many
>> problems in both them. So I need some REAL help here.
>> 
>> Problem with 1.
>> 1. I succeeded to compile my java code (after chaning the syntax) using
>> gcj
>> to linux "c" object files. But in the linkage to the binary, I got too
>> many
>> "undefined reference to", ... because I use external "jars" (like axis)
>> which are not compiled to native. I try to compile the axis jar to c and
>> get
>> too many compilation errors.
> 
> Compiling Java code with -findirect-dispatch is probably your best
> plan to solve this.  When an undefined class is discoveed, gcj's
> runtime will try to load its class files.
> 
>> Problem with 2.
>> I compiled all my classes with gcj. and the C code uses JNI to call it.
>> But
>> the JNI creates a JVM (JNI_CreateJavaVM)!!! which I don't want to use.
> 
> Why not?  This is fully supported by gcj, and doesn't hurt anything.
> 
>> I want to use gij instead. So I wanted to know if there is anyway to
>> let my JNI code to ceate a gij VM and and java VM. is there anything
>> like this ?!  If not, how can I use the classes I compiled with gcj
>> from the c code without using the JAVA VM?  CNI? does that mean that
>> I should convert my jni code to cni?
> 
> No, there's no need to do that.  JNI code should work with gcj just
> fine.  
> 
> Andrew.
> 
> 

-- 
View this message in context: http://old.nabble.com/java-to-native-code-and-Sun-JVM-alternatives-tp27862420p27895737.html
Sent from the gcc - java mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: java to native code and Sun JVM alternatives
  2010-03-14 15:36   ` wagde
@ 2010-03-14 15:49     ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2010-03-14 15:49 UTC (permalink / raw)
  To: java

On 03/14/2010 03:36 PM, wagde wrote:

> Thanx Andrew for the quick reply.
> 
> I'm trying to link my c code and I get:
> undefined reference to `JNI_CreateJavaVM'
> Although I have -lgcj in my ld command and it's the only undefined symbol in
> my code.
> Why is that?

You need to link with -ljvm.

> I still don't understand how JNI_CreateJavaVM will create a gij VM and not
> sun JAVA VM. can you explain this to me.

It's in gcj's libjvm.so, not Sun's.  You have to make sure you link with
gcj's version of libjvm by putting it in the path at link time.

Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-14 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 11:45 java to native code and Sun JVM alternatives wagde
2010-03-11 11:56 ` Andrew Haley
2010-03-14 15:36   ` wagde
2010-03-14 15:49     ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).