50113
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
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;
|
57164
|
30 |
import java.net.Socket;
|
50113
|
31 |
|
|
32 |
import jdk.jfr.events.SocketWriteEvent;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* See {@link JITracer} for an explanation of this code.
|
|
36 |
*/
|
57164
|
37 |
@JIInstrumentationTarget("java.net.Socket$SocketOutputStream")
|
50113
|
38 |
final class SocketOutputStreamInstrumentor {
|
|
39 |
|
|
40 |
private SocketOutputStreamInstrumentor() {
|
|
41 |
}
|
|
42 |
|
|
43 |
@SuppressWarnings("deprecation")
|
|
44 |
@JIInstrumentationMethod
|
57164
|
45 |
public void write(byte b[], int off, int len) throws IOException {
|
50113
|
46 |
SocketWriteEvent event = SocketWriteEvent.EVENT.get();
|
|
47 |
if (!event.isEnabled()) {
|
57164
|
48 |
write(b, off, len);
|
50113
|
49 |
return;
|
|
50 |
}
|
|
51 |
int bytesWritten = 0;
|
|
52 |
try {
|
|
53 |
event.begin();
|
57164
|
54 |
write(b, off, len);
|
50113
|
55 |
bytesWritten = len;
|
|
56 |
} finally {
|
|
57 |
event.end() ;
|
|
58 |
if (event.shouldCommit()) {
|
57164
|
59 |
InetAddress remote = parent.getInetAddress();
|
|
60 |
event.host = remote.getHostName();
|
|
61 |
event.address = remote.getHostAddress();
|
|
62 |
event.port = parent.getPort();
|
57168
|
63 |
event.bytesWritten = bytesWritten;
|
50113
|
64 |
|
|
65 |
event.commit();
|
|
66 |
event.reset();
|
|
67 |
}
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
57168
|
71 |
// private field in java.net.Socket$SocketOutputStream
|
57164
|
72 |
private Socket parent;
|
50113
|
73 |
}
|