aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Unable to execute JNI in a 64 bit machine. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Unable to execute JNI in a 64 bit machine." Watch "Unable to execute JNI in a 64 bit machine." New topic
Author

Unable to execute JNI in a 64 bit machine.

Aparna Sree
Greenhorn

Joined: Jul 21, 2010
Posts: 28
Hi,
I am trying to execute a dll through JNI.
I have 32 bit dll and 64 bit dll

My code works fine in a 32 bit machine(using 32 bit dll).
but it doesnt work on a 64 bit machine. I tried executing it with both 32 bit and 64 bit dll.

I also tried installing 64 bit JDK,JRE and tried to run the 64 bit dll through java.
I am getting the following error.

# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006d451528, pid=956, ti
d=4240
#
# JRE version: 6.0_21-b07
# Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0-b17 mixed mode windows-amd64
)
# Problematic frame:
# C [java.dll+0x1528]
#
# An error report file with more information is saved as:
# C:\Program Files\Java\jdk1.6.0_21\bin\hs_err_pid956.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Any idea what could be the problem.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

Moving to Other JSE/JEE APIs.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Rob Prime wrote:Moving to Other JSE/JEE APIs.
When ?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

Now. And thanks for pointing out my forgetfulness
Aparna Sree
Greenhorn

Joined: Jul 21, 2010
Posts: 28
Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0-b17 mixed mode windows-amd64 )


I am pretty sure my machine is Intel. Any idea what
mixed mode windows-amd64
means?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"amd64" is just the name for the instruction set used by all consumer 64-bit Intel processors, because AMD were the first to define it, and Intel later had to play catch-up.

You need to use a 32-bit library with a 32-bit JVM, and a 64-bit library with a 64-bit JVM. If you're getting an access violation, then there's a bug in the native code. If the bug only shows up in the 64-bit version and not the 32-bit, then you're probably just lucky that it works on 32-bit. The hs_err crash report might give you a hint where the problem occurs, or it might not.

Who wrote the native code, and how big is it?


[Jess in Action][AskingGoodQuestions]
Aparna Sree
Greenhorn

Joined: Jul 21, 2010
Posts: 28
Thanks! for the reply.
My native code is very small.


I had generated a .h file and included it in WrapperforTHEDLL.dll
WrapperforTHEDLL.dll works fine because I tried executing the exe version and it works fine everywhere(64 bit and 32 bit machine).

But as I said before my java code crashes on a 64 bit machine.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"The native code" refers to the C language code that's in the DLL itself -- i.e., the implementation of Java_myJNIClass_myNativeEx().

I don't know what you mean by "the exe version" -- how would you test the JNI code without the JVM? If there's some underlying functionality which you tested in C and that works fine, that's great -- but it's the JNI wrapper code that I'm more concerned about.
Aparna Sree
Greenhorn

Joined: Jul 21, 2010
Posts: 28
You are absolutely right!
I actually have a 3rd party dll which has to be executed/called though java. Since i am using JNI, we created a C wrapper which will inturn call the 3rd party DLL.

I just have to call the wrapper, and it takes care of the rest. When I said "exe"; I meant, WrapperforTHEDLL.exe. I ran this in 64 bit machine and it worked fine. Of course, it wasn't the JNI code.

Since you said that problem is in wrapper; and I am not very good at C, I used JNA thus eliminating the need for wrapper. And YES!!! the code worked fine.

With a little help I was able to resolve issue in C code too.

Thanks alot!
Ahmed Gawad
Greenhorn

Joined: Nov 19, 2011
Posts: 2
Hello,
I have the same problem with a 3rd party dll. The DLL is loaded successfully under a 32-bit machine. But under 64-bit the jvm crashes. I have tested on both 32-bit && 64-bit JVMs. Any suggestions?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You can't load a 32-bit DLL into a 64-bit JVM; you need to get a 64-bit version from the vendor.
Ahmed Gawad
Greenhorn

Joined: Nov 19, 2011
Posts: 2
Ernest Friedman-Hill wrote:You can't load a 32-bit DLL into a 64-bit JVM; you need to get a 64-bit version from the vendor.


Thanks for your response,
As I mentioned earlier I tried to load it from 32-bit JVM on 64-bit machine without success. When run on 32-bit JVM on 32-bit machine, it worked like charm.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to execute JNI in a 64 bit machine.