Skip to main content

How to use JNI Invocation API using CDC ?

4 replies [Last post]
sam_ankur
Offline
Joined: 2008-07-21
Points: 0

Hello,

I am working on Java application which needs to be deployed on Linux environment with strict memory footprint constraints (2-4MB). So I have tried the prototype of the application with CDC (phoneME Advanced) and got the desired results (with some modification). But the problem is that I need to use the JNI to invoke my Java application and I am unable to achieve that. I need to invoke the Java APIs from the C++ code.

So could someone please suggest me how to achieve the same using phoneME Advanced? If not, could you suggest me some other low memory-footprint JVM with JNI support?

Looking forward to your suggestions/advise.

Thanks in advance.

Regards,
Ankur

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sam_ankur
Offline
Joined: 2008-07-21
Points: 0

Chris,

Now I have tried to build the CDC runtime using linux-x86-generic. The build was successful and all the required directory structure got created. But still when I searched for the "jni.h" in linux-x86-generic directory, I couldn't found it.

Then I tried building the CDC for installation, it failed after sometime as it was not able to connect to the "https://phoneme.dev.java.net". So my question is does it try to download something during "make bin"?

Isn't the jni.h required by the CDC for JNI support?

Could you please suggest me something to overcome this issue?

Looking forward to hear from you.

Thanks
Ankur

cjplummer
Offline
Joined: 2006-10-16
Points: 0

jni.h is in cdc/src/share/javavm/export/jni.h

As for libjvm.so, historically cvm has not built as a shared library and requires you to build and link your main() as part of the cvm build process, resulting in linking your main with bin/cvm. To do this, replace cdc/src/linux/bin/java_md.c with your own main(), or modify the makefiles to pickup up your main() instead of the one in java_md.c.

There is some support for building cvm as a shared library. I'm not sure of it's current state of completeness, but I believe it works. Try building with CVM_BUILD_SO=true. However, if it doesn't work or there are further issues, I probably won't be able to help much.

Chris

cjplummer
Offline
Joined: 2006-10-16
Points: 0

CDC has JNI support so I don't understand what problem you are having. If you just don't know how to use JNI, I'm sure there's plenty of existing documentation out there already you could google for.

Chris

sam_ankur
Offline
Joined: 2008-07-21
Points: 0

Chris,

Thanks for the response.

I understand that CDC specification supports JNI and even I have the hands-on experience of using JNI, but what I am trying to ask is that I am unable to achieve the same using the phoneME Advanced (as using for the first time).

I have created a small test C (CProductStub.c) program which invokes the Java class and execute the main method of it. This test program works fine with the IBM J9 JVM with the expected output. To compile the C code on J9 on linux environment, I am using the following command :

[b]gcc -I/J9/ibm-java2-i386-50/include -L/J9/ibm-java2-i386-50/jre/bin/j9vm -ljvm -L/J9/ibm-java2-i386-50/jre/bin -ljsig -lj9thr23 -ldl -lpthread CProductStub.c -o CProductStub[/b]

As the -I option suggests that where to search for the header files (in this case jni.h), so I want to know where can I find the header files in phoneME Advanced? Even I am unable to locate the libjvm.so shared object.

So could you please suggest me if I need to have a separate patch for this? Or maybe I am overlooking something in phoneME Advanced.

I would really appreciate any help in this regard.

Thanks
Ankur