RFR: 8324048: (fc) Make FileKey fields final [v2]

Jaikiran Pai jpai at openjdk.org
Thu Aug 22 07:28:06 UTC 2024


On Wed, 21 Aug 2024 19:31:04 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Something must be loading the library but I don't know what. I did some testing which does not use any NIO classes other than `FileKey`, and the class worked without the explicit load, on both Unix and Windows. I think, however, that I need to add it on Unix and restore it on Windows to be safe.
>
> Added / reinstated `IOUtil.load()` in 378d700.

> Something must be loading the library but I don't know what.

I was curious, so gave this program a try against a JDK version which doesn't have this PR's change:


import java.nio.file.*;
import java.nio.channels.*;

public class FileChannelTest {
    public static void main(final String[] args) throws Exception {
        try(FileChannel fc = FileChannel.open(Path.of("/tmp/foo.txt"), StandardOpenOption.WRITE)) {
            System.out.println("opened filechannel " + fc);
            try(final FileLock lock = fc.lock()) {
                System.out.println("obtained lock " + lock);
            }
        }
    }
}


Launched it as follows with `-Xlog` logging:


java "-Xlog:class+init=trace,library=trace" FileChannelTest.java


The generated log (snippet) looks like:


[0.103s][debug][class,init] Thread "main" is initializing sun.nio.ch.FileDispatcherImpl
[0.103s][debug][class,init] Thread "main" is initializing sun.nio.ch.UnixFileDispatcherImpl
[0.103s][debug][class,init] Thread "main" is initializing sun.nio.ch.FileDispatcher
[0.103s][debug][class,init] Thread "main" is initializing sun.nio.ch.NativeDispatcher
[0.103s][info ][class,init] 618 Initializing 'sun/nio/ch/NativeDispatcher'(no method) (0x000001f001046d90) by thread "main"
[0.103s][info ][class,init] 619 Initializing 'sun/nio/ch/FileDispatcher'(no method) (0x000001f001046fe0) by thread "main"
[0.103s][info ][class,init] 620 Initializing 'sun/nio/ch/UnixFileDispatcherImpl' (0x000001f0010472b8) by thread "main"
[0.104s][debug][class,init] Thread "main" linking sun.nio.ch.IOUtil
[0.104s][debug][class,init] Thread "main" is initializing sun.nio.ch.IOUtil
[0.104s][info ][class,init] 621 Initializing 'sun/nio/ch/IOUtil' (0x000001f001047a00) by thread "main"
[0.104s][debug][class,init] Thread "main" recursively initializing sun.nio.ch.IOUtil
[0.104s][debug][class,init] Thread "main" recursively initializing sun.nio.ch.IOUtil
[0.104s][info ][library   ] Failed to find JNI_OnLoad_net in library with handle 0xfffffffffffffffb
[0.104s][info ][library   ] Loaded library /jdk-22.jdk/Contents/Home/lib/libnet.dylib, handle 0x0000000099b0b070
[0.104s][info ][library   ] Found JNI_OnLoad in library with handle 0x0000000099b0b070
[0.104s][info ][library   ] Found inet_pton in library with handle 0xfffffffffffffffe
[0.104s][info ][library   ] Failed to find JNI_OnLoad_nio in library with handle 0xfffffffffffffffb
[0.104s][debug][class,init] Thread "main" recursively initializing sun.nio.ch.IOUtil
[0.104s][info ][library   ] Found Java_sun_nio_ch_IOUtil_initIDs in library with handle 0x0000000099b0ae10

So it looks like `IOUtil.load()` gets called from the static initializer of `sun.nio.ch.UnixFileDispatcherImpl` here https://github.com/openjdk/jdk/blob/master/src/java.base/unix/classes/sun/nio/ch/UnixFileDispatcherImpl.java#L40 which then triggers the loading of the net and nio libraries.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20429#discussion_r1726498606


More information about the nio-dev mailing list