author | alanb |
Sat, 16 Mar 2019 19:44:12 +0000 | |
changeset 54155 | b5a73f22b2bd |
parent 50113 | caf115bb98ad |
child 57268 | adcdd45830a0 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jfr.internal.instrument; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.net.InetAddress; |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
30 |
import java.net.Socket; |
50113 | 31 |
|
32 |
import jdk.jfr.events.SocketReadEvent; |
|
33 |
||
34 |
/** |
|
35 |
* See {@link JITracer} for an explanation of this code. |
|
36 |
*/ |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
37 |
@JIInstrumentationTarget("java.net.Socket$SocketInputStream") |
50113 | 38 |
final class SocketInputStreamInstrumentor { |
39 |
||
40 |
private SocketInputStreamInstrumentor() { |
|
41 |
} |
|
42 |
||
43 |
@SuppressWarnings("deprecation") |
|
44 |
@JIInstrumentationMethod |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
45 |
public int read(byte b[], int off, int length) throws IOException { |
50113 | 46 |
SocketReadEvent event = SocketReadEvent.EVENT.get(); |
47 |
if (!event.isEnabled()) { |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
48 |
return read(b, off, length); |
50113 | 49 |
} |
50 |
int bytesRead = 0; |
|
51 |
try { |
|
52 |
event.begin(); |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
53 |
bytesRead = read(b, off, length); |
50113 | 54 |
} finally { |
55 |
event.end(); |
|
56 |
if (event.shouldCommit()) { |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
57 |
InetAddress remote = parent.getInetAddress(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
58 |
event.host = remote.getHostName(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
59 |
event.address = remote.getHostAddress(); |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
60 |
event.port = parent.getPort(); |
50113 | 61 |
if (bytesRead < 0) { |
62 |
event.endOfStream = true; |
|
63 |
} else { |
|
64 |
event.bytesRead = bytesRead; |
|
65 |
} |
|
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
66 |
event.timeout = parent.getSoTimeout(); |
50113 | 67 |
|
68 |
event.commit(); |
|
69 |
event.reset(); |
|
70 |
} |
|
71 |
} |
|
72 |
return bytesRead; |
|
73 |
} |
|
74 |
||
54155
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
75 |
// private field in java.net.Socket$SocketInputStream |
b5a73f22b2bd
8220493: Prepare Socket/ServerSocket for alternative platform SocketImpl
alanb
parents:
50113
diff
changeset
|
76 |
private Socket parent; |
50113 | 77 |
} |