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

Socket events should use event.shouldWrite() before adding data to event

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u60, 9
    • hotspot
    • jfr
    • b84

      Consider:

          private void socketWrite(byte b[], int off, int len) throws IOException {
              if (!VMJFR.socketWriteToken.isEnabled()) {
                  socketWrite(b, off, len);
                  return;
              }
              SocketWriteEvent event = new SocketWriteEvent(VMJFR.socketWriteToken);
              int bytesWritten = -1;
              try {
                  event.begin();
                  socketWrite(b, off, len);
                  bytesWritten = len;
              } finally {
                  String hostString = impl.address.toString();
                  int delimiterIndex = hostString.lastIndexOf('/');

                  event.host = hostString.substring(0, delimiterIndex);
                  event.address = hostString.substring(delimiterIndex + 1);
                  event.port = impl.port;
                  event.bytesWritten = bytesWritten;

                  event.commit();
              }
          }

      We can avoid the address.toString() and String manipulations if we check event.shouldWrite() before.

            sla Staffan Larsen (Inactive)
            sla Staffan Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: