--- a/src/java.base/share/classes/java/net/Socket.java Tue Feb 05 18:53:19 2019 +0000
+++ b/src/java.base/share/classes/java/net/Socket.java Fri Feb 08 16:49:25 2019 +0000
@@ -934,7 +934,9 @@
}
@Override
public int read() throws IOException {
- return in.read();
+ byte[] a = new byte[1];
+ int n = read(a, 0, 1);
+ return (n > 0) ? (a[0] & 0xff) : -1;
}
@Override
public int read(byte b[], int off, int len) throws IOException {
@@ -988,7 +990,8 @@
}
@Override
public void write(int b) throws IOException {
- out.write(b);
+ byte[] a = new byte[] { (byte) b };
+ write(a, 0, 1);
}
@Override
public void write(byte b[], int off, int len) throws IOException {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java Tue Feb 05 18:53:19 2019 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketInputStreamInstrumentor.java Fri Feb 08 16:49:25 2019 +0000
@@ -27,15 +27,15 @@
import java.io.IOException;
import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
import jdk.jfr.events.SocketReadEvent;
/**
* See {@link JITracer} for an explanation of this code.
*/
-@JIInstrumentationTarget("java.net.SocketInputStream")
-@JITypeMapping(from = "jdk.jfr.internal.instrument.SocketInputStreamInstrumentor$AbstractPlainSocketImpl",
- to = "java.net.AbstractPlainSocketImpl")
+@JIInstrumentationTarget("java.net.Socket$SocketInputStream")
final class SocketInputStreamInstrumentor {
private SocketInputStreamInstrumentor() {
@@ -43,30 +43,28 @@
@SuppressWarnings("deprecation")
@JIInstrumentationMethod
- int read(byte b[], int off, int length, int timeout) throws IOException {
+ public int read(byte b[], int off, int length) throws IOException {
SocketReadEvent event = SocketReadEvent.EVENT.get();
if (!event.isEnabled()) {
- return read(b, off, length, timeout);
+ return read(b, off, length);
}
int bytesRead = 0;
try {
event.begin();
- bytesRead = read(b, off, length, timeout);
+ bytesRead = read(b, off, length);
} finally {
event.end();
if (event.shouldCommit()) {
- 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;
+ InetAddress remote = parent.getInetAddress();
+ event.host = remote.getHostName();
+ event.address = remote.getHostAddress();
+ event.port = parent.getPort();
if (bytesRead < 0) {
event.endOfStream = true;
} else {
event.bytesRead = bytesRead;
}
- event.timeout = timeout;
+ event.timeout = parent.getSoTimeout();
event.commit();
event.reset();
@@ -75,14 +73,17 @@
return bytesRead;
}
- private AbstractPlainSocketImpl impl = null;
+ private Socket parent;
- void silenceFindBugsUnwrittenField(InetAddress dummy) {
- impl.address = dummy;
+ InetAddress getInetAddress() {
+ throw new RuntimeException();
}
- static class AbstractPlainSocketImpl {
- InetAddress address;
- int port;
+ int getPort() {
+ throw new RuntimeException();
+ }
+
+ int getSoTimeout() throws SocketException {
+ throw new RuntimeException();
}
}
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java Tue Feb 05 18:53:19 2019 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/SocketOutputStreamInstrumentor.java Fri Feb 08 16:49:25 2019 +0000
@@ -27,15 +27,14 @@
import java.io.IOException;
import java.net.InetAddress;
+import java.net.Socket;
import jdk.jfr.events.SocketWriteEvent;
/**
* See {@link JITracer} for an explanation of this code.
*/
-@JIInstrumentationTarget("java.net.SocketOutputStream")
-@JITypeMapping(from = "jdk.jfr.internal.instrument.SocketOutputStreamInstrumentor$AbstractPlainSocketImpl",
- to = "java.net.AbstractPlainSocketImpl")
+@JIInstrumentationTarget("java.net.Socket$SocketOutputStream")
final class SocketOutputStreamInstrumentor {
private SocketOutputStreamInstrumentor() {
@@ -43,26 +42,24 @@
@SuppressWarnings("deprecation")
@JIInstrumentationMethod
- private void socketWrite(byte b[], int off, int len) throws IOException {
+ public void write(byte b[], int off, int len) throws IOException {
SocketWriteEvent event = SocketWriteEvent.EVENT.get();
if (!event.isEnabled()) {
- socketWrite(b, off, len);
+ write(b, off, len);
return;
}
int bytesWritten = 0;
try {
event.begin();
- socketWrite(b, off, len);
+ write(b, off, len);
bytesWritten = len;
} finally {
event.end() ;
if (event.shouldCommit()) {
- 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;
+ InetAddress remote = parent.getInetAddress();
+ event.host = remote.getHostName();
+ event.address = remote.getHostAddress();
+ event.port = parent.getPort();
event.bytesWritten = bytesWritten < 0 ? 0 : bytesWritten;
event.commit();
@@ -71,14 +68,13 @@
}
}
- private AbstractPlainSocketImpl impl = null;
+ private Socket parent;
- void silenceFindBugsUnwrittenField(InetAddress dummy) {
- impl.address = dummy;
+ InetAddress getInetAddress() {
+ throw new RuntimeException();
}
- static class AbstractPlainSocketImpl {
- InetAddress address;
- int port;
+ int getPort() {
+ throw new RuntimeException();
}
}
--- a/test/jdk/jdk/jfr/event/io/TestInstrumentation.java Tue Feb 05 18:53:19 2019 +0000
+++ b/test/jdk/jdk/jfr/event/io/TestInstrumentation.java Fri Feb 08 16:49:25 2019 +0000
@@ -105,14 +105,14 @@
"java/io/FileOutputStream::write::(I)V",
"java/io/FileOutputStream::write::([B)V",
"java/io/FileOutputStream::write::([BII)V",
- "java/net/SocketInputStream::read::()I",
- "java/net/SocketInputStream::read::([B)I",
- "java/net/SocketInputStream::read::([BII)I",
- "java/net/SocketInputStream::close::()V",
- "java/net/SocketOutputStream::write::(I)V",
- "java/net/SocketOutputStream::write::([B)V",
- "java/net/SocketOutputStream::write::([BII)V",
- "java/net/SocketOutputStream::close::()V",
+ "java/net/Socket$SocketInputStream::read::()I",
+ "java/net/Socket$SocketInputStream::read::([B)I",
+ "java/net/Socket$SocketInputStream::read::([BII)I",
+ "java/net/Socket$SocketInputStream::close::()V",
+ "java/net/Socket$SocketOutputStream::write::(I)V",
+ "java/net/Socket$SocketOutputStream::write::([B)V",
+ "java/net/Socket$SocketOutputStream::write::([BII)V",
+ "java/net/Socket$SocketOutputStream::close::()V",
"java/nio/channels/FileChannel::read::([Ljava/nio/ByteBuffer;)J",
"java/nio/channels/FileChannel::write::([Ljava/nio/ByteBuffer;)J",
"java/nio/channels/SocketChannel::open::()Ljava/nio/channels/SocketChannel;",