Detecting JNI Architecture Is A Pain In The

It sounds like a simple problem: if I want JBoss Modules to choose a directory to read a Java native (JNI) library from, such that each platform (which is comprised of OS, CPU architecture, and ABI variations) gets a separate directory, I should just be able to probe a system property and thus know right where to go, right? Wrong. Until Java 8, the JDK only defines “os.arch” and “os.name” to go on; and these names are far from uniform or standardized.  CPU names for equivalent architectures can vary (e.g. “x86_64” versus”AMD64”); CPUs may evolve linearly (e.g. “i586” becomes “i686”) or non-linearly (e.g. ARM instruction set offshoots and extended instruction sets like Wireless MMX).  In the end you might be able to load, say, a linux-i386 native library on linux-i686, or linux-armv6 on linux-armv7a.  And detecting ABI variation is (at least until Java 8) a black art. In the end I’ve wound up with this monstrosity. Without a doubt, I will have to fiddle with it as more weird variations are reported.  (By the way, if you discover more weird variations, please reportthem!)

Written on February 28, 2014