Summary
-------
Propose `JNI_OnLoad` to use the class loader that requests to load this native library
and `JNI_OnUnload` to use the system class loader as the class loading context
respectively.
Problem
-------
The current JNI spec does not specify the class loading context used for `JNI_OnLoad`
hooks whereas the implementation uses the class loader that requests to load the
native library as the class loading context which is very reasonable. On the other hand,
the JNI spec specifies that `JNI_OnUnload` is called in an unknown context whereas
the implementation uses the class loader being unloaded as the context.
Solution
--------
Use the system class loader as the class loading context for `JNI_OnUnload` hook,
that is consistent with `FindClass` currently specified when there is no context.
No change in the class loading context for `JNI_OnLoad` hook but clarify it in
`JNI_OnLoad` spec.
Specification
-------------
1) jni.h will define a new JNI version constant for JDK 10:
+#define JNI_VERSION_10 0x000a0000
(Note: the name may be revised per the decision about the version string for
the new release cadence discussion [1])
2) The spec of `FindClass` is updated to specify the behavior when called from the
library lifecycle hooks as follows:
<pre>
+Since JDK 10, when `FindClass` is called from a library lifecycle function
+hook the class loader is determined as follows:
+
+ * for `JNI_OnLoad` and `JNI_OnLoad_L` the class loader of the class that
+ is loading the native library is used
+ * for `JNI_OnUnload` and `JNI_OnUnload_L` the class loader returned by
+ `ClassLoader.getSystemClassLoader` is used (as the class loader used
+ at on-load time may no longer exist)
</pre>
3) The spec change for the `GetVersion` function:
+In JDK/JRE 10, `GetVersion()` returns `JNI_VERSION_10`.
[1] http://mail.openjdk.java.net/pipermail/discuss/2017-September/004281.html