Class ImplLookupAccessor

java.lang.Object
dev.derklaro.reflexion.internal.handles.ImplLookupAccessor

final class ImplLookupAccessor extends Object
An accessor to get the IMPL_LOOKUP field using the unsafe field methods provided by the jvm.
Since:
1.0
  • Constructor Details

    • ImplLookupAccessor

      private ImplLookupAccessor()
  • Method Details

    • findImplLookup

      @Nullable public static @Nullable MethodHandles.Lookup findImplLookup()
      Tries to get the IMPL_LOOKUP using the either direct field access or the methods provided by sun.misc.Unsafe.
      Returns:
      the IMPL_LOOKUP field value or null if the lookup is not possible.
    • tryResolveUsingDirectAccess

      @Nullable private static @Nullable MethodHandles.Lookup tryResolveUsingDirectAccess()
      Tries to resolve the IMPL_LOOKUP field by direct access, only available on a modern jvm if unnamed modules were granted access to the java.lang.invoke module.
      Returns:
      the IMPL_LOOKUP instance, resolved via direct field access or null if not possible.
    • tryResolveUsingUnsafeGetObject

      @VisibleForTesting @Nullable static @Nullable MethodHandles.Lookup tryResolveUsingUnsafeGetObject()
      Tries to resolve the IMPL_LOOKUP field using the methods provided by sun.misc.unsafe. This method only works on a sun jvm and will most likely stop working in further releases of the jvm (20/21/22...) as all methods which are returning field offsets were deprecated and will be removed.
      Returns:
      the IMPL_LOOKUP instance, resolved using sun.misc.unsafe or null if not possible.
    • tryResolveUsingUnsafeAccessibleObject

      @VisibleForTesting @Nullable static @Nullable MethodHandles.Lookup tryResolveUsingUnsafeAccessibleObject()
      Tries to resolve the IMPL_LOOKUP field using the methods provided by sun.misc.unsafe. This method only works on a sun jvm and tries to force-override the accessible state of the IMPL_LOOKUP field.
      Returns:
      the IMPL_LOOKUP instance or null if not possible.
      Since:
      1.6