When should you use JNI with native code and when should you just let the JIT handle things?



If I'm starting a new JVM project and need a particular section of code to be really fast, should I write it in a naively compiled language or just let the JIT handle things?

What is even the point of the JNI if the JIT compiler exists?


Related to : When should you use JNI with native code and when should you just let the JIT handle things?
Java Native Interface(JNI): UnsatisfiedLinkError
Programming Languages
I have created a Java file "Dock.java" which uses JNI to access a C function called "setStruts." The C function needs two header files, Xlib.h and Xatom.h.
Whenever I try to run Dock's main function, which just calls setStruts, I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Dock.setStruts(III)V
at Dock.setStruts(Native Method)
at Dock.main(Dock.java:12)
I am assuming this is because System.loadLibrary is not loading the right library. I know that loadLibrary's string parameter doesn't need to have the directory path or the ".so" extension,
How to load native libraries using JNI
Programming Languages

How to load native libraries using JNI

I tried to load but i am getting error as

Native code library failed to load. java.lang.UnsatisfiedLinkError:


How does JIT compilation actually execute the machine code at runtime?
Programming Languages

I understand the gist of how JIT compilation works (after reading such resources as this SO question). However, I am still wondering how does it actually execute the machine code at runtime?

I don't have a deep background in operating systems or compiler optimizations, and haven't done anything with machine code directly, but am starting to explore it. I have started playing around in assembly, and see how something like NASM can take your assembly code and compile it to machine code (the executable), and then you can "invoke" it from the command line like ./my-executable.

But how is a JIT compiler actually doing that at runtime? Is it like streaming machine code into stdin or something, or how does it work? If you could provide an example or some pseudocode of how some assembly (or something along those lines, not as high level as C though) might look to demonstrate the basic flow, that would be amazing too.


How do you go about knowing what is happening in a JIT'ed code?
Programming Languages

I am working with Firefox on a research project. Firefox makes uses of lots of JIT'ed code during run time.

I instrumented Firefox using a custom PIN tool to find out locations(address) of some things I as looking for. The issue is that those location are in JIT'ed code. I want to know what is actually happening over there in the code.

To do this I dumped the corresponding memory region and used objdump to disassemble the dump. I used objdump -D -b binary -mi386 file.dump to see the instructions that would have been executed. To my surprise the only section listed is .data section (a very big one).

Either i am incorrectly disassembling it or something else is wrong with my understanding. I expect to see more sections like .text where actual executable instructions should be present and .data section should not be executable.

Am I correct in my understanding here?

Also If some one can please advise me on how to properly know what is happening in Jit'ed code.

Machine Linux 3.13.0-24-generic #47-Ubuntu SMP x86_64

Thanks


Java JNI Interface: Native functions relative file paths
Programming Languages

I am having problems with relative file paths that native functions use. When I call native C function from Java code, I get segmentation fault due to null file pointer. The only thing that works is to change these paths into absolute file paths, which is not solution for me. Is there any way to set root directory for native functions or to use Java project root folder to navigate through directories, or the absolute path is the only way?


When should you use JNI with native code and when should you just let the JIT handle things?
Programming Languages

If I'm starting a new JVM project and need a particular section of code to be really fast, should I write it in a naively compiled language or just let the JIT handle things?

What is even the point of the JNI if the JIT compiler exists?



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .