Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350519

Some FFM VarHandles should return false for isAccessModeSupported

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      `isAccessModeSupported` is likely rarely used. A previous NPE JDK-8307508 completely preventing the usage of this API on all FFM VarHandles was not reported by any user, but discovered by me during my work on other code.
      Show
      `isAccessModeSupported` is likely rarely used. A previous NPE JDK-8307508 completely preventing the usage of this API on all FFM VarHandles was not reported by any user, but discovered by me during my work on other code.
    • Java API
    • SE

      Summary

      Some VarHandles created by the Foreign Function & Memory (FFM) API now consistently return false on VarHandle::isAccessModeSupported for access modes that they do not support.

      Problem

      Some VarHandles returned by FFM APIs, including MemoryLayout::varHandle, arrayElementVarHandle, and ValueLayout::varHandle, may or may not support access modes other than plain get and set, such as getOpaque setVolatile, depending on the byte alignment property of the layout and the path elements passed to construct the handle.

      When these access modes are not supported, the implementation methods currently simply throw an UnsupportedOperationException. However, they do not correctly report this lack of support in VarHandle::isAccessModeSupported.

      Solution

      Update those VarHandle implementations to return false upon isAccessModeSupported query for non-plain access modes when they are not supported by these VarHandle.

      Specification

      No change. The fact that some access modes are not supported by all var handles created by FFM is already documented here:

      https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/foreign/MemoryLayout.html#access-mode-restrictions

      As such, this change is purely behavioral.

            liach Chen Liang
            liach Chen Liang
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: