< prev index next >
src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
Print this page
rev 53271 : 8216981: Per thread IO statistics in JFR
@@ -75,64 +75,114 @@
close(sp[1]);
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz,
- jobject fdo, jlong address, jint len)
+ jobject fdo, jlong address, jint len, jboolean socket)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
- return convertReturnVal(env, read(fd, buf, len), JNI_TRUE);
+ jint readBytes = read(fd, buf, len);
+
+ if (readBytes > 0) {
+ if (socket) {
+ JVM_callNetworkReadBytes(env, (jint) readBytes);
+ } else {
+ JVM_callFileReadBytes(env, (jint)readBytes);
+ }
+ }
+
+ return convertReturnVal(env, readBytes, JNI_TRUE);
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject fdo,
jlong address, jint len, jlong offset)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
- return convertReturnVal(env, pread64(fd, buf, len, offset), JNI_TRUE);
+ jint readBytes = pread64(fd, buf, len, offset);
+
+ if (readBytes > 0) {
+ JVM_callFileReadBytes(env, (jint)readBytes);
+ }
+
+ return convertReturnVal(env, readBytes, JNI_TRUE);
}
JNIEXPORT jlong JNICALL
Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz,
- jobject fdo, jlong address, jint len)
+ jobject fdo, jlong address, jint len, jboolean socket)
{
jint fd = fdval(env, fdo);
struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
- return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE);
+ jint readBytes = readv(fd, iov, len);
+
+ if (readBytes > 0) {
+ if (socket) {
+ JVM_callNetworkReadBytes(env, (jint) readBytes);
+ } else {
+ JVM_callFileReadBytes(env, (jint)readBytes);
+ }
+ }
+
+ return convertLongReturnVal(env, readBytes, JNI_TRUE);
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz,
- jobject fdo, jlong address, jint len)
+ jobject fdo, jlong address, jint len, jboolean socket)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
+ jint writtenBytes = write(fd, buf, len);
+
+ if (writtenBytes > 0) {
+ if (socket) {
+ JVM_callNetworkWriteBytes(env, (jint) writtenBytes);
+ } else {
+ JVM_callFileWriteBytes(env, (jint) writtenBytes);
+ }
+ }
- return convertReturnVal(env, write(fd, buf, len), JNI_FALSE);
+ return convertReturnVal(env, writtenBytes, JNI_FALSE);
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_FileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobject fdo,
jlong address, jint len, jlong offset)
{
jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address);
+ jint writtenBytes = pwrite64(fd, buf, len, offset);
+
+ if (writtenBytes > 0) {
+ JVM_callFileWriteBytes(env, (jint) writtenBytes);
+ }
- return convertReturnVal(env, pwrite64(fd, buf, len, offset), JNI_FALSE);
+ return convertReturnVal(env, writtenBytes, JNI_FALSE);
}
JNIEXPORT jlong JNICALL
Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz,
- jobject fdo, jlong address, jint len)
+ jobject fdo, jlong address, jint len, jboolean socket)
{
jint fd = fdval(env, fdo);
struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
- return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE);
+ jint writtenBytes = writev(fd, iov, len);
+
+ if (writtenBytes > 0) {
+ if (socket) {
+ JVM_callNetworkWriteBytes(env, (jint) writtenBytes);
+ } else {
+ JVM_callFileWriteBytes(env, (jint) writtenBytes);
+ }
+ }
+
+ return convertLongReturnVal(env, writtenBytes, JNI_FALSE);
}
static jlong
handle(JNIEnv *env, jlong rv, char *msg)
{
< prev index next >