Ensure native access check can fold away

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P3
    • None
    • Affects Version/s: repo-panama
    • Component/s: core-libs

      Ensure that the native access check for restricted methods can fold away when it is found on the hot path.

      Given a simple method such as:

          public static byte payload(long addr) {
              return (byte) BYTE_HANDLE.get(addr);
          }

      Where BYTE_HANDLE constructs a MemorySegment out of the given address like so:

          static MemorySegment ofAddressUnsafe(long address) {
              return MemorySegment.ofAddress(address).reinterpret(8);
          }

      We see the following preamble in the generated assembly:

        0x0000017dddbc60ba: movabs r10, 0x44080a8d0 ; {oop(a 'java/lang/Class'{0x000000044080a8d0} = 'jdk/internal/access/SharedSecrets')}
        0x0000017dddbc60c4: mov r11d, dword ptr [r10 + 0x7c]
        0x0000017dddbc60c8: movabs r10, 0x440893d00 ; {oop(a 'java/lang/Class'{0x0000000440893d00} = 'Reinterpret')}
        0x0000017dddbc60d2: mov r8d, dword ptr [r10 + 0x30]
        0x0000017dddbc60d6: mov r10d, dword ptr [r12 + r11*8 + 8]
                                                                  ; implicit exception: dispatches to 0x0000017dddbc6144
        0x0000017dddbc60db: cmp r10d, 0x18128 ; {metadata('java/lang/System$2')}
        0x0000017dddbc60e2: jne 0x17dddbc6107
        0x0000017dddbc60e4: mov ebp, dword ptr [r12 + r8*8 + 0x1c]
                                                                  ; implicit exception: dispatches to 0x0000017dddbc615c
        0x0000017dddbc60e9: test ebp, ebp
        0x0000017dddbc60eb: jne 0x17dddbc6128

      From this we can draw 2 conclusions:

        1. The `module` field in java.lang.Class is not seen as a constant.
        2. The used of SharedSecrets generates some kind of type check.

      Both of these issues are easy to avoid, and would allow us to fold away all these additional checks.

            Assignee:
            Jorn Vernee
            Reporter:
            Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: