Unverified Commit 22788223 authored by Peter's avatar Peter Committed by GitHub

Merge pull request #1207 from ChristophKaser/android_bugfixes

Use android compatible way to unmap a ByteBuffer in java 9
parents 42e3ccc7 aff73774
......@@ -52,6 +52,7 @@ Here is an overview:
* Svantulden, improved documentation and nearest API
* thehereward, code cleanups like #620
* vvikas, ideas for many to many improvements and #616
* ChristophKaser, agrees to the [project's CLA](https://www.graphhopper.com/individual-contributor-license-agreement/), improved Android compatibility #1207
## Translations
......@@ -374,15 +374,13 @@ public class Helper {
if (Constants.JRE_IS_MINIMUM_JAVA9) {
// >=JDK9 class sun.misc.Unsafe { void invokeCleaner(ByteBuffer buf) }
final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
// we do not need to check for a specific class, we can call the Unsafe method with any buffer class
MethodHandle unmapper = MethodHandles.lookup().findVirtual(unsafeClass, "invokeCleaner",
MethodType.methodType(void.class, ByteBuffer.class));
// fetch the unsafe instance and bind it to the virtual MethodHandle
final Field f = unsafeClass.getDeclaredField("theUnsafe");
final Object theUnsafe = f.get(null);
final Method method = unsafeClass.getDeclaredMethod("invokeCleaner", ByteBuffer.class);
try {
method.invoke(theUnsafe, buffer);
return null;
} catch (Throwable t) {
throw new RuntimeException(t);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment