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

JFR: Remove use of thread-locals for java.base events

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 15
    • Component/s: hotspot
    • Subcomponent:
      jfr
    • Resolved In Build:
      b23

      Description

      The JFR events in java.base today rely on thread locals since the JIT (for some reason) is not able to remove the allocation of the event objects. See JDK-8187234 for details. Thread locals however don't work well with Loom and virtual threads due to memory bloat, so another approach is needed.

      One idea is to use the even handler directly:

          public int read(ByteBuffer dst) throws IOException {
              EventHandler handler = Handlers.SOCKET_READ;
              if (!handler.isEnabled()) {
                  return read(dst);
              }
              int bytesRead = 0;
              long start = 0;
              try {
                  start = EventHandler.timestamp();;
                  bytesRead = read(dst);
              } finally {
                  long duration = EventHandler.timestamp() - start;
                  if (handler.shouldCommit(duration)) {
                      String hostString = remoteAddress.getAddress().toString();
                      int delimiterIndex = hostString.lastIndexOf('/');

                      String eventHost = hostString.substring(0, delimiterIndex);
                      String eventAddress = hostString.substring(delimiterIndex + 1);
                      int eventPort = remoteAddress.getPort();
                      boolean eventEndOfStream = bytesRead < 0;
                      handler.write(start, duration, eventHost, eventAddress, eventPort, 0, bytesRead, eventEndOfStream);
                  }
              }
              return bytesRead;
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                egahlin Erik Gahlin
                Reporter:
                egahlin Erik Gahlin
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: