diff --git a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java index 5e80aa794ed..ad63a0fc3c9 100644 --- a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java @@ -1239,7 +1239,7 @@ public class FileChannelImpl mapSize = size + pagePosition; try { // If map0 did not throw an exception, the address is valid - addr = map0(prot, mapPosition, mapSize, isSync); + addr = map0(fd, prot, mapPosition, mapSize, isSync); } catch (OutOfMemoryError x) { // An OutOfMemoryError may indicate that we've exhausted // memory so force gc and re-attempt map @@ -1250,7 +1250,7 @@ public class FileChannelImpl Thread.currentThread().interrupt(); } try { - addr = map0(prot, mapPosition, mapSize, isSync); + addr = map0(fd, prot, mapPosition, mapSize, isSync); } catch (OutOfMemoryError y) { // After a second OOME, fail throw new IOException("Map failed", y); @@ -1500,7 +1500,8 @@ public class FileChannelImpl // -- Native methods -- // Creates a new mapping - private native long map0(int prot, long position, long length, boolean isSync) + private native long map0(FileDescriptor fd, int prot, long position, + long length, boolean isSync) throws IOException; // Removes an existing mapping @@ -1514,12 +1515,12 @@ public class FileChannelImpl // Retrieves the maximum size of a transfer private static native int maxDirectTransferSize0(); - // Caches fieldIDs - private static native long initIDs(); + // Retrieves allocation granularity + private static native long allocationGranularity0(); static { IOUtil.load(); - allocationGranularity = initIDs(); + allocationGranularity = allocationGranularity0(); MAX_DIRECT_TRANSFER_SIZE = maxDirectTransferSize0(); } } diff --git a/src/java.base/unix/native/libnio/ch/FileChannelImpl.c b/src/java.base/unix/native/libnio/ch/FileChannelImpl.c index 6b310aca375..bb60b571a2a 100644 --- a/src/java.base/unix/native/libnio/ch/FileChannelImpl.c +++ b/src/java.base/unix/native/libnio/ch/FileChannelImpl.c @@ -50,13 +50,10 @@ #include "java_lang_Integer.h" #include -static jfieldID chan_fd; /* jobject 'fd' in sun.nio.ch.FileChannelImpl */ - JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_initIDs(JNIEnv *env, jclass clazz) +Java_sun_nio_ch_FileChannelImpl_allocationGranularity0(JNIEnv *env, jclass clazz) { jlong pageSize = sysconf(_SC_PAGESIZE); - chan_fd = (*env)->GetFieldID(env, clazz, "fd", "Ljava/io/FileDescriptor;"); return pageSize; } @@ -73,11 +70,10 @@ handle(JNIEnv *env, jlong rv, char *msg) JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_map0(JNIEnv *env, jobject this, +Java_sun_nio_ch_FileChannelImpl_map0(JNIEnv *env, jobject this, jobject fdo, jint prot, jlong off, jlong len, jboolean map_sync) { void *mapAddress = 0; - jobject fdo = (*env)->GetObjectField(env, this, chan_fd); jint fd = fdval(env, fdo); int protections = 0; int flags = 0; diff --git a/src/java.base/windows/native/libnio/ch/FileChannelImpl.c b/src/java.base/windows/native/libnio/ch/FileChannelImpl.c index 097ae004a1f..9dc8c3b3804 100644 --- a/src/java.base/windows/native/libnio/ch/FileChannelImpl.c +++ b/src/java.base/windows/native/libnio/ch/FileChannelImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,20 +36,16 @@ #include #pragma comment(lib, "Mswsock.lib") -static jfieldID chan_fd; /* id for jobject 'fd' in java.io.FileChannel */ - /************************************************************** - * static method to store field ID's in initializers - * and retrieve the allocation granularity + * static method to retrieve the allocation granularity */ JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_initIDs(JNIEnv *env, jclass clazz) +Java_sun_nio_ch_FileChannelImpl_allocationGranularity0(JNIEnv *env, jclass clazz) { SYSTEM_INFO si; jint align; GetSystemInfo(&si); align = si.dwAllocationGranularity; - chan_fd = (*env)->GetFieldID(env, clazz, "fd", "Ljava/io/FileDescriptor;"); return align; } @@ -59,7 +55,7 @@ Java_sun_nio_ch_FileChannelImpl_initIDs(JNIEnv *env, jclass clazz) */ JNIEXPORT jlong JNICALL -Java_sun_nio_ch_FileChannelImpl_map0(JNIEnv *env, jobject this, +Java_sun_nio_ch_FileChannelImpl_map0(JNIEnv *env, jobject this, jobject fdo, jint prot, jlong off, jlong len, jboolean map_sync) { void *mapAddress = 0; @@ -68,7 +64,6 @@ Java_sun_nio_ch_FileChannelImpl_map0(JNIEnv *env, jobject this, jlong maxSize = off + len; jint lowLen = (jint)(maxSize); jint highLen = (jint)(maxSize >> 32); - jobject fdo = (*env)->GetObjectField(env, this, chan_fd); HANDLE fileHandle = (HANDLE)(handleval(env, fdo)); HANDLE mapping; DWORD mapAccess = FILE_MAP_READ;