Unsafe Accessor is a bridge to access Unsafe (sun.misc.Unsafe
or jdk.internal.misc.Unsafe
)
Maven group:
moe.karla.unsafe
Module | Description |
---|---|
unsafe-accessor-root |
The main module for unsafe access. This module provides the minimal API for: AccessibleObject.setAccessible Unsafe.allocateObject MethodHandles.Lookup.IMPL_LOOKUP |
unsafe-accessor-security |
The module for controlling the direct access for unsafe api. |
unsafe-accessor-unsafe |
Provide the bridge for accessing jdk.internal.misc.Unsafe or sun.misc.Unsafe |
Unsafe accessor is compatible with the Java module system. When you're packing your application with jlink, you may need define unsafe-accessor's module.
Module name | Description |
---|---|
moe.karla.unsafe.security |
Required. The security layer of UnsafeAccessor |
moe.karla.unsafe.root |
Required. The basic API of UnsafeAccessor |
jdk.unsupported |
Suggested. You have to add --add-opens java.base/java.base.invoke=moe.karla.unsafe.root if you dont include this JDK module. |
moe.karla.unsafe.unsafe |
Optional. This is a optional module that provide API view of jdk.internal.misc.Unsafe |
moe.karla.unsafe.unsafe.j9 |
Required. This module is the implementation of Java9+ unsafe object api bridge. |
Note: If you are using Compose Multiplatform, you may include unsafe-accessor modules via compose configuration too.
See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-native-distribution.html#including-jdk-modules
Warning
NOT SUPPORTED ON ANDROID.
Just like the name of the project, unsafe accessor is UNSAFE. It relies heavily on the high degree of freedom of the JVM platform, which may unsupported on Android platform.
Integration of UnsafeAccessor into Android is untested and unsupported.
The unsafe accessor is highly dependent on
java.lang.invoke
(API Level 26, Android 8)
The core of UnsafeAccessor is getting the private protected field java.lang.invoke.MethodHandles$Lookup#IMPL_LOOKUP
,
which can be got via reflection (java 8).