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

Reduce JNI overhead of accessing FileDescriptor

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 15
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b24

      Description

      Various methods in libjava use this macro in io_util_md.h:

      #define GET_FD(this, fid) \
          (*env)->GetObjectField(env, (this), (fid)) == NULL ? \
              -1 : (*env)->GetIntField(env, (*env)->GetObjectField(env, (this), (fid)), IO_fd_fdID)

      Problem: compilers can't fold the repeated GetObjectField into one call

      Solution: Turn the macros into functions which call GetObjectField only once:

      FD getFD(JNIEnv *env, jobject this, jfieldID fid) {
        jobject fd = (*env)->GetObjectField(env, this, fid);
        if (fd == NULL) {
          return -1;
        }
        return (*env)->GetIntField(env, fd, IO_fd_fdID);
      }

      On existing micro RandomAccessRead:

      Before:
      Benchmark (fileSize) Mode Cnt Score Error Units
      RandomAccessRead.test 1000000 avgt 25 0.832 ± 0.001 us/op

      After:
      Benchmark (fileSize) Mode Cnt Score Error Units
      RandomAccessRead.test 1000000 avgt 25 0.771 ± 0.005 us/op

      ~60 ns/op reduction, or an 8% speed-up. (Relative gain diminishes for larger operations, e.g., reading an 8kb buffer).

      Startup label added since this has an effect on opening and reading small entries from jar/zip files.

        Attachments

          Activity

            People

            • Assignee:
              redestad Claes Redestad
              Reporter:
              redestad Claes Redestad
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: