Obtaining the JNIenv pointer from an arbitrary context

The JNIenv is only valid in its associated thread. So when we call
a Java callback from anywhere in the native code, we have to get JNIenv
from the JavaVM pointer. Indeed, the JavaVM pointer remains valid across
multiple threads so it can be cached in a global variable.
Some major modifications in JNI code

First step to correctly run native code from the JVM and cache method IDs