开发者

How does Java standard libraries comunicate with native code?

Do they use something like Mono's PInvoke? Or is it more like internal calls registered before the runtime is started? Does java have a base library for handling native calls like mscorlib.开发者_开发知识库dll? If I want to invoke a JVM in C code will it libraries look for the .so/.dll files? Does it make a difference to Java standard libraries if I statically link all of the JRE natives libraries?


They use JNI, exactly as it is publicly documented, to invoke native shared libraries for the specific platform.

As far as invoking a JVM from C code, the JVM uses shared libraries (DLL, SO, etc). A quick search of the JDK 6 source code does not reveal any System.loadLibrary() for the core native support (like native methods in Object, String, etc). That suggests to me that the native code for these methods, which appears to be in DLL's judging from the contents of the JRE/bin directory, is explicitly linked by java.exe (and javaw.exe in Windows).

When I last looked at this stuff, the requirements for invoking a JVM from C code was a well documented part of JNI - I strongly suggest you refer to that doco to proceed further. We even went so far as successfully writing a native C wrapper/loader for the IBM AS/400 Java 1.1 JVM.


They use the Java Native Interface (JNI).

I've never called the JVM from C, so I don't know about that.


There is an example here about how to start a JVM from inside your C program:

http://www.inonit.com/cygwin/jni/invocationApi/c.html


"Java Native Access (JNA) provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code" (quotation from their homepage).

Personally never tried it so far.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜