среда, 4 мая 2011 г.

JNI

JNI(Java Native Interface) -- это фреймворк, который позволяет приложению, которое работает в виртуальной ява-машине, вызывать родные для данной платформы( ОС + хардвеа ), а также быть вызванным из этих родных приложений. Также это позволяет использовать ява-приложению библиотеки родные для данной платформы( написанные на языках С,С++ и ассемблер ).


Слабые строны такого подхода:
  • subtle errors in the use of JNI can destabilize the entire JVM in ways that are very difficult to reproduce and debug.
  • only applications and signed applets can invoke JNI.
  • an application that relies on JNI loses the platform portability Java offers (a workaround is to write a separate implementation of JNI code for each platform and have Java detect the operating system and load the correct one at runtime).
  • the JNI framework does not provide any automatic garbage collection for non-JVM memory resources allocated by code executing on the native side. Consequently, native side code (such as C, C++, or assembly language) must assume the responsibility for explicitly releasing any such memory resources that it itself acquires.
  • error checking is a MUST or it has the potential to crash the JNI side and the JVM.
  • on Linux and Solaris platforms, if the native code registers itself as a signal handler, it could intercept signals intended for the JVM. Signal chaining should be used to allow native code to better interoperate with JVM.[2]
  • on Windows platforms, Structured Exception Handling (SEH) may be employed to wrap native code in SEH try/catch blocks so as to capture machine (CPU/FPU) generated software interrupts (such as NULL pointer access violations and divide-by-zero operations), and to handle these situations before the interrupt is propagated back up into the JVM (i.e. Java side code), in all likelihood resulting in an unhandled exception.
  • The encoding used for the NewStringUTF, GetStringUTFLength, GetStringUTFChars, ReleaseStringUTFChars, GetStringUTFRegion functions is not standard UTF-8, but modified UTF-8. The null character (U+0000) and codepoints greater than or equal to U+10000 are encoded differently in modified UTF-8. Many programs actually use these functions incorrectly and treat the UTF-8 strings returned or passed into the functions as standard UTF-8 strings instead of modified UTF-8 strings. Programs should use the NewString, GetStringLength, GetStringChars, ReleaseStringChars, GetStringRegion, GetStringCritical, and ReleaseStringCritical functions, which use UTF-16LE encoding on little-endian architectures and UTF-16BE on big-endian architectures, and then use a UTF-16 to standard UTF-8 conversion routine.

Комментариев нет:

Отправить комментарий