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

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P3
    • 15
    • Affects Version/s: 15
    • Component/s: hotspot
    • jfr
    • b23

      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;
      }

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

              Created:
              Updated:
              Resolved: