Consider these events in the socket code:
int read(byte b[], int off, int length, int timeout) throws IOException {
if (!VMJFR.socketReadToken.isEnabled()) {
return read(b, off, length, timeout);
}
SocketReadEvent event = new SocketReadEvent(VMJFR.socketReadToken);
int bytesRead = -1;
try {
event.begin();
bytesRead = read(b, off, length, timeout);
} 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.bytesRead = bytesRead;
event.timeout = timeout;
event.commit();
}
return bytesRead;
}
Before calling address.toString and doing manipulations of the string, it would be good if we could check if the duration of the event was above the threshold. That would make the cost of the instrumentation lower for short-duration events.
(Suggested by Tony Vlatas)
int read(byte b[], int off, int length, int timeout) throws IOException {
if (!VMJFR.socketReadToken.isEnabled()) {
return read(b, off, length, timeout);
}
SocketReadEvent event = new SocketReadEvent(VMJFR.socketReadToken);
int bytesRead = -1;
try {
event.begin();
bytesRead = read(b, off, length, timeout);
} 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.bytesRead = bytesRead;
event.timeout = timeout;
event.commit();
}
return bytesRead;
}
Before calling address.toString and doing manipulations of the string, it would be good if we could check if the duration of the event was above the threshold. That would make the cost of the instrumentation lower for short-duration events.
(Suggested by Tony Vlatas)
- relates to
-
JDK-8135800 Socket events should use event.shouldWrite() before adding data to event
-
- Resolved
-