From 744fa3594da8c5cdf8544797a00fbc532aaf92b3 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Mon, 22 Jul 2024 11:25:20 -0700 Subject: [PATCH 1/6] 8337143: (fc, fs) Move filesystem-related native objects from libnio to libjava --- make/modules/java.base/lib/CoreLibraries.gmk | 7 +- .../linux/classes/sun/nio/ch/EPoll.java | 4 +- .../linux/classes/sun/nio/ch/EPollPort.java | 8 +- .../classes/sun/nio/ch/EPollSelectorImpl.java | 4 +- .../linux/classes/sun/nio/ch/EventFD.java | 6 +- .../sun/nio/ch/FileDispatcherImpl.java | 3 +- .../sun/nio/fs/LinuxNativeDispatcher.java | 1 - .../ch => libjava}/FileDispatcherImpl.c | 0 .../fs => libjava}/LinuxNativeDispatcher.c | 0 .../fs => libjava}/LinuxWatchService.c | 0 .../macosx/classes/sun/nio/ch/KQueue.java | 4 +- .../macosx/classes/sun/nio/ch/KQueuePort.java | 8 +- .../sun/nio/ch/KQueueSelectorImpl.java | 6 +- .../{libnio/fs => libjava}/BsdFileSystem.c | 0 .../fs => libjava}/BsdNativeDispatcher.c | 0 .../ch => libjava}/FileDispatcherImpl.c | 0 .../fs => libjava}/MacOSXNativeDispatcher.c | 0 .../fs => libjava}/UTIFileTypeDetector.c | 0 .../classes/java/net/Inet6AddressImpl.java | 6 +- .../sun/nio/ch/DatagramChannelImpl.java | 10 +- .../share/classes/sun/nio/ch/IOUtil.java | 42 +----- .../share/classes/sun/nio/ch/NIOUtil.java | 81 +++++++++++ .../sun/nio/ch/NativeSocketAddress.java | 4 +- .../share/classes/sun/nio/ch/Net.java | 8 +- .../classes/sun/nio/ch/NioSocketImpl.java | 6 +- .../sun/nio/ch/ServerSocketChannelImpl.java | 8 +- .../classes/sun/nio/ch/SocketChannelImpl.java | 6 +- .../classes/sun/nio/ch/UnixDomainSockets.java | 6 +- .../sun/nio/ch/DatagramDispatcher.java | 6 +- .../classes/sun/nio/ch/InheritedChannel.java | 4 +- .../unix/classes/sun/nio/ch/NativeThread.java | 2 +- .../unix/classes/sun/nio/ch/PipeImpl.java | 4 +- .../classes/sun/nio/ch/PollSelectorImpl.java | 8 +- .../classes/sun/nio/ch/SinkChannelImpl.java | 4 +- .../classes/sun/nio/ch/SocketDispatcher.java | 6 +- .../classes/sun/nio/ch/SourceChannelImpl.java | 4 +- ...ixAsynchronousServerSocketChannelImpl.java | 4 +- .../ch/UnixAsynchronousSocketChannelImpl.java | 8 +- .../classes/sun/nio/ch/UnixDispatcher.java | 4 +- .../sun/nio/fs/UnixNativeDispatcher.java | 1 - .../native/{libnio/ch => libjava}/FileKey.c | 0 .../native/{libnio/ch => libjava}/IOUtil.c | 130 ++--------------- .../{libnio => libjava}/MappedMemoryUtils.c | 0 .../{libnio/ch => libjava}/NativeThread.c | 0 .../ch => libjava}/UnixFileDispatcherImpl.c | 0 .../{libnio/fs => libjava}/UnixFileSystem.c | 0 .../fs => libjava}/UnixNativeDispatcher.c | 0 src/java.base/unix/native/libnio/ch/NIOUtil.c | 136 ++++++++++++++++++ .../sun/nio/ch/DatagramDispatcher.java | 4 +- .../classes/sun/nio/ch/SocketDispatcher.java | 4 +- .../windows/classes/sun/nio/ch/WEPoll.java | 4 +- .../sun/nio/ch/WEPollSelectorImpl.java | 4 +- ...wsAsynchronousServerSocketChannelImpl.java | 4 +- .../WindowsAsynchronousSocketChannelImpl.java | 4 +- .../sun/nio/ch/WindowsSelectorImpl.java | 4 +- .../sun/nio/fs/RegistryFileTypeDetector.java | 6 - .../sun/nio/fs/WindowsNativeDispatcher.java | 2 - .../ch => libjava}/FileDispatcherImpl.c | 0 .../native/{libnio/ch => libjava}/FileKey.c | 0 .../native/{libnio/ch => libjava}/IOUtil.c | 81 +---------- .../native/{libnio/ch => libjava}/Iocp.c | 0 .../{libnio => libjava}/MappedMemoryUtils.c | 0 .../fs => libjava}/RegistryFileTypeDetector.c | 0 .../WindowsAsynchronousFileChannelImpl.c | 0 .../fs => libjava}/WindowsNativeDispatcher.c | 0 .../windows/native/libnio/ch/NIOUtil.c | 109 ++++++++++++++ .../windows/native/libnio/ch/nio_util.h | 12 +- .../share/classes/jdk/nio/Channels.java | 5 +- .../sun/nio/ch/sctp/SctpChannelImpl.java | 7 +- .../sun/nio/ch/sctp/SctpMultiChannelImpl.java | 5 +- .../unix/classes/sun/nio/ch/sctp/SctpNet.java | 9 +- .../nio/ch/sctp/SctpServerChannelImpl.java | 7 +- test/jdk/jdk/nio/Basic.java | 6 +- 73 files changed, 467 insertions(+), 359 deletions(-) rename src/java.base/linux/native/{libnio/ch => libjava}/FileDispatcherImpl.c (100%) rename src/java.base/linux/native/{libnio/fs => libjava}/LinuxNativeDispatcher.c (100%) rename src/java.base/linux/native/{libnio/fs => libjava}/LinuxWatchService.c (100%) rename src/java.base/macosx/native/{libnio/fs => libjava}/BsdFileSystem.c (100%) rename src/java.base/macosx/native/{libnio/fs => libjava}/BsdNativeDispatcher.c (100%) rename src/java.base/macosx/native/{libnio/ch => libjava}/FileDispatcherImpl.c (100%) rename src/java.base/macosx/native/{libnio/fs => libjava}/MacOSXNativeDispatcher.c (100%) rename src/java.base/macosx/native/{libnio/fs => libjava}/UTIFileTypeDetector.c (100%) create mode 100644 src/java.base/share/classes/sun/nio/ch/NIOUtil.java rename src/java.base/unix/native/{libnio/ch => libjava}/FileKey.c (100%) rename src/java.base/unix/native/{libnio/ch => libjava}/IOUtil.c (55%) rename src/java.base/unix/native/{libnio => libjava}/MappedMemoryUtils.c (100%) rename src/java.base/unix/native/{libnio/ch => libjava}/NativeThread.c (100%) rename src/java.base/unix/native/{libnio/ch => libjava}/UnixFileDispatcherImpl.c (100%) rename src/java.base/unix/native/{libnio/fs => libjava}/UnixFileSystem.c (100%) rename src/java.base/unix/native/{libnio/fs => libjava}/UnixNativeDispatcher.c (100%) create mode 100644 src/java.base/unix/native/libnio/ch/NIOUtil.c rename src/java.base/windows/native/{libnio/ch => libjava}/FileDispatcherImpl.c (100%) rename src/java.base/windows/native/{libnio/ch => libjava}/FileKey.c (100%) rename src/java.base/windows/native/{libnio/ch => libjava}/IOUtil.c (65%) rename src/java.base/windows/native/{libnio/ch => libjava}/Iocp.c (100%) rename src/java.base/windows/native/{libnio => libjava}/MappedMemoryUtils.c (100%) rename src/java.base/windows/native/{libnio/fs => libjava}/RegistryFileTypeDetector.c (100%) rename src/java.base/windows/native/{libnio/ch => libjava}/WindowsAsynchronousFileChannelImpl.c (100%) rename src/java.base/windows/native/{libnio/fs => libjava}/WindowsNativeDispatcher.c (100%) create mode 100644 src/java.base/windows/native/libnio/ch/NIOUtil.c diff --git a/make/modules/java.base/lib/CoreLibraries.gmk b/make/modules/java.base/lib/CoreLibraries.gmk index 7fed18491d1f8..619ab5f3749b2 100644 --- a/make/modules/java.base/lib/CoreLibraries.gmk +++ b/make/modules/java.base/lib/CoreLibraries.gmk @@ -53,19 +53,22 @@ endif $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \ NAME := java, \ OPTIMIZATION := HIGH, \ + EXTRA_HEADER_DIRS := \ + libnio/ch, \ jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \ ProcessImpl_md.c_CFLAGS := $(VERSION_CFLAGS), \ java_props_md.c_CFLAGS := \ -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"', \ DISABLED_WARNINGS_gcc_ProcessImpl_md.c := unused-result, \ JDK_LIBS := libjvm, \ - LIBS_linux := $(LIBDL), \ + LIBS_linux := $(LIBDL) -lpthread, \ LIBS_aix := $(LIBDL) $(LIBM),\ LIBS_macosx := \ -framework CoreFoundation \ + -framework CoreServices \ -framework Foundation \ -framework SystemConfiguration, \ - LIBS_windows := advapi32.lib ole32.lib shell32.lib version.lib, \ + LIBS_windows := advapi32.lib ole32.lib shell32.lib version.lib mswsock.lib ws2_32.lib, \ )) TARGETS += $(BUILD_LIBJAVA) diff --git a/src/java.base/linux/classes/sun/nio/ch/EPoll.java b/src/java.base/linux/classes/sun/nio/ch/EPoll.java index d96582ad90f21..bf17b09ec299e 100644 --- a/src/java.base/linux/classes/sun/nio/ch/EPoll.java +++ b/src/java.base/linux/classes/sun/nio/ch/EPoll.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -51,7 +51,7 @@ private EPoll() { } * } */ static { - IOUtil.load(); + NIOUtil.load(); } private static final int SIZEOF_EPOLLEVENT = eventSize(); private static final int OFFSETOF_EVENTS = eventsOffset(); diff --git a/src/java.base/linux/classes/sun/nio/ch/EPollPort.java b/src/java.base/linux/classes/sun/nio/ch/EPollPort.java index f2a4649d6f8e1..217237e654726 100644 --- a/src/java.base/linux/classes/sun/nio/ch/EPollPort.java +++ b/src/java.base/linux/classes/sun/nio/ch/EPollPort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -95,7 +95,7 @@ static class Event { // create socket pair for wakeup mechanism try { - long fds = IOUtil.makePipe(true); + long fds = NIOUtil.makePipe(true); this.sp = new int[]{(int) (fds >>> 32), (int) fds}; } catch (IOException ioe) { EPoll.freePollArray(address); @@ -136,7 +136,7 @@ private void wakeup() { if (wakeupCount.incrementAndGet() == 1) { // write byte to socketpair to force wakeup try { - IOUtil.write1(sp[1], (byte)0); + NIOUtil.write1(sp[1], (byte)0); } catch (IOException x) { throw new AssertionError(x); } @@ -219,7 +219,7 @@ private Event poll() throws IOException { // a wakeup byte queued to wake each thread int nread; do { - nread = IOUtil.drain1(sp[0]); + nread = NIOUtil.drain1(sp[0]); } while (nread == IOStatus.INTERRUPTED); } diff --git a/src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java b/src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java index cb55932fd7e99..f27160afe61d5 100644 --- a/src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java +++ b/src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java @@ -51,7 +51,7 @@ class EPollSelectorImpl extends SelectorImpl { // maximum number of events to poll in one call to epoll_wait - private static final int NUM_EPOLLEVENTS = Math.min(IOUtil.fdLimit(), 1024); + private static final int NUM_EPOLLEVENTS = Math.min(NIOUtil.fdLimit(), 1024); // epoll file descriptor private final int epfd; @@ -81,7 +81,7 @@ class EPollSelectorImpl extends SelectorImpl { try { this.eventfd = new EventFD(); - IOUtil.configureBlocking(IOUtil.newFD(eventfd.efd()), false); + NIOUtil.configureBlocking(NIOUtil.newFD(eventfd.efd()), false); } catch (IOException ioe) { EPoll.freePollArray(pollArrayAddress); FileDispatcherImpl.closeIntFD(epfd); diff --git a/src/java.base/linux/classes/sun/nio/ch/EventFD.java b/src/java.base/linux/classes/sun/nio/ch/EventFD.java index adc41d04ece25..152a375c500d5 100644 --- a/src/java.base/linux/classes/sun/nio/ch/EventFD.java +++ b/src/java.base/linux/classes/sun/nio/ch/EventFD.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024, 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 @@ -49,7 +49,7 @@ void set() throws IOException { } void reset() throws IOException { - IOUtil.drain(efd); + NIOUtil.drain(efd); } void close() throws IOException { @@ -68,6 +68,6 @@ void close() throws IOException { private static native int set0(int efd) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/linux/classes/sun/nio/ch/FileDispatcherImpl.java b/src/java.base/linux/classes/sun/nio/ch/FileDispatcherImpl.java index a69f240a608ff..78d440c16645b 100644 --- a/src/java.base/linux/classes/sun/nio/ch/FileDispatcherImpl.java +++ b/src/java.base/linux/classes/sun/nio/ch/FileDispatcherImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -58,7 +58,6 @@ static native long transferFrom0(FileDescriptor src, FileDescriptor dst, static native void init0(); static { - IOUtil.load(); init0(); } } diff --git a/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java b/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java index af42c245c1c7b..08ec6658f3f64 100644 --- a/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java +++ b/src/java.base/linux/classes/sun/nio/fs/LinuxNativeDispatcher.java @@ -90,7 +90,6 @@ static native int directCopy0(int dst, int src, long addressToPollForCancel) private static native void init(); static { - jdk.internal.loader.BootLoader.loadLibrary("nio"); init(); } } diff --git a/src/java.base/linux/native/libnio/ch/FileDispatcherImpl.c b/src/java.base/linux/native/libjava/FileDispatcherImpl.c similarity index 100% rename from src/java.base/linux/native/libnio/ch/FileDispatcherImpl.c rename to src/java.base/linux/native/libjava/FileDispatcherImpl.c diff --git a/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c b/src/java.base/linux/native/libjava/LinuxNativeDispatcher.c similarity index 100% rename from src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c rename to src/java.base/linux/native/libjava/LinuxNativeDispatcher.c diff --git a/src/java.base/linux/native/libnio/fs/LinuxWatchService.c b/src/java.base/linux/native/libjava/LinuxWatchService.c similarity index 100% rename from src/java.base/linux/native/libnio/fs/LinuxWatchService.c rename to src/java.base/linux/native/libjava/LinuxWatchService.c diff --git a/src/java.base/macosx/classes/sun/nio/ch/KQueue.java b/src/java.base/macosx/classes/sun/nio/ch/KQueue.java index 30ad9ca92fe1d..64719a3254967 100644 --- a/src/java.base/macosx/classes/sun/nio/ch/KQueue.java +++ b/src/java.base/macosx/classes/sun/nio/ch/KQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -48,7 +48,7 @@ private KQueue() { } * }; */ static { - IOUtil.load(); + NIOUtil.load(); } private static final int SIZEOF_KQUEUEEVENT = keventSize(); private static final int OFFSET_IDENT = identOffset(); diff --git a/src/java.base/macosx/classes/sun/nio/ch/KQueuePort.java b/src/java.base/macosx/classes/sun/nio/ch/KQueuePort.java index e6c0e09ad3465..4b24f1dda72c0 100644 --- a/src/java.base/macosx/classes/sun/nio/ch/KQueuePort.java +++ b/src/java.base/macosx/classes/sun/nio/ch/KQueuePort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -91,7 +91,7 @@ static class Event { // create socket pair for wakeup mechanism try { - long fds = IOUtil.makePipe(true); + long fds = NIOUtil.makePipe(true); this.sp = new int[]{(int) (fds >>> 32), (int) fds}; } catch (IOException ioe) { KQueue.freePollArray(address); @@ -133,7 +133,7 @@ private void wakeup() { if (wakeupCount.incrementAndGet() == 1) { // write byte to socketpair to force wakeup try { - IOUtil.write1(sp[1], (byte)0); + NIOUtil.write1(sp[1], (byte)0); } catch (IOException x) { throw new AssertionError(x); } @@ -220,7 +220,7 @@ private Event poll() throws IOException { // a wakeup byte queued to wake each thread int nread; do { - nread = IOUtil.drain1(sp[0]); + nread = NIOUtil.drain1(sp[0]); } while (nread == IOStatus.INTERRUPTED); } diff --git a/src/java.base/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java b/src/java.base/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java index 6c84984f515d4..d565af932ba6a 100644 --- a/src/java.base/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java +++ b/src/java.base/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java @@ -84,7 +84,7 @@ class KQueueSelectorImpl extends SelectorImpl { this.pollArrayAddress = KQueue.allocatePollArray(MAX_KEVENTS); try { - long fds = IOUtil.makePipe(false); + long fds = NIOUtil.makePipe(false); this.fd0 = (int) (fds >>> 32); this.fd1 = (int) fds; } catch (IOException ioe) { @@ -296,7 +296,7 @@ public Selector wakeup() { synchronized (interruptLock) { if (!interruptTriggered) { try { - IOUtil.write1(fd1, (byte)0); + NIOUtil.write1(fd1, (byte)0); } catch (IOException ioe) { throw new InternalError(ioe); } @@ -308,7 +308,7 @@ public Selector wakeup() { private void clearInterrupt() throws IOException { synchronized (interruptLock) { - IOUtil.drain(fd0); + NIOUtil.drain(fd0); interruptTriggered = false; } } diff --git a/src/java.base/macosx/native/libnio/fs/BsdFileSystem.c b/src/java.base/macosx/native/libjava/BsdFileSystem.c similarity index 100% rename from src/java.base/macosx/native/libnio/fs/BsdFileSystem.c rename to src/java.base/macosx/native/libjava/BsdFileSystem.c diff --git a/src/java.base/macosx/native/libnio/fs/BsdNativeDispatcher.c b/src/java.base/macosx/native/libjava/BsdNativeDispatcher.c similarity index 100% rename from src/java.base/macosx/native/libnio/fs/BsdNativeDispatcher.c rename to src/java.base/macosx/native/libjava/BsdNativeDispatcher.c diff --git a/src/java.base/macosx/native/libnio/ch/FileDispatcherImpl.c b/src/java.base/macosx/native/libjava/FileDispatcherImpl.c similarity index 100% rename from src/java.base/macosx/native/libnio/ch/FileDispatcherImpl.c rename to src/java.base/macosx/native/libjava/FileDispatcherImpl.c diff --git a/src/java.base/macosx/native/libnio/fs/MacOSXNativeDispatcher.c b/src/java.base/macosx/native/libjava/MacOSXNativeDispatcher.c similarity index 100% rename from src/java.base/macosx/native/libnio/fs/MacOSXNativeDispatcher.c rename to src/java.base/macosx/native/libjava/MacOSXNativeDispatcher.c diff --git a/src/java.base/macosx/native/libnio/fs/UTIFileTypeDetector.c b/src/java.base/macosx/native/libjava/UTIFileTypeDetector.c similarity index 100% rename from src/java.base/macosx/native/libnio/fs/UTIFileTypeDetector.c rename to src/java.base/macosx/native/libjava/UTIFileTypeDetector.c diff --git a/src/java.base/share/classes/java/net/Inet6AddressImpl.java b/src/java.base/share/classes/java/net/Inet6AddressImpl.java index 87fefbe37ba32..f576227b30b24 100644 --- a/src/java.base/share/classes/java/net/Inet6AddressImpl.java +++ b/src/java.base/share/classes/java/net/Inet6AddressImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -148,4 +148,8 @@ public synchronized InetAddress loopbackAddress() { private InetAddress anyLocalAddress; private InetAddress loopbackAddress; + + static { + jdk.internal.loader.BootLoader.loadLibrary("net"); + } } diff --git a/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java index 5c06ac7d9be02..c6c26ab0dd735 100644 --- a/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java @@ -1246,7 +1246,7 @@ private void lockedConfigureBlocking(boolean block) throws IOException { ensureOpen(); // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } } } @@ -1259,7 +1259,7 @@ private boolean tryLockedConfigureBlocking(boolean block) throws IOException { assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread(); synchronized (stateLock) { if (!forcedNonBlocking && isOpen()) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); return true; } else { return false; @@ -1276,7 +1276,7 @@ private void configureSocketNonBlocking() throws IOException { if (!forcedNonBlocking) { synchronized (stateLock) { ensureOpen(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); forcedNonBlocking = true; } } @@ -1529,7 +1529,7 @@ private void repairSocket(InetSocketAddress target) // copy the blocking mode if (!isBlocking() || forcedNonBlocking) { - IOUtil.configureBlocking(newfd, false); + NIOUtil.configureBlocking(newfd, false); } // dup this channel's socket to the new socket. If this succeeds then @@ -2089,6 +2089,6 @@ private static native int send0(FileDescriptor fd, long address, int len, throws IOException; static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/share/classes/sun/nio/ch/IOUtil.java b/src/java.base/share/classes/sun/nio/ch/IOUtil.java index d86d6decb14e7..cc9f62911727b 100644 --- a/src/java.base/share/classes/sun/nio/ch/IOUtil.java +++ b/src/java.base/share/classes/sun/nio/ch/IOUtil.java @@ -559,49 +559,15 @@ static long bufferAddress(ByteBuffer buf) { return NIO_ACCESS.getBufferAddress(buf); } - public static FileDescriptor newFD(int i) { - FileDescriptor fd = new FileDescriptor(); - setfdVal(fd, i); - return fd; - } - - static native boolean randomBytes(byte[] someBytes); - - /** - * Returns two file descriptors for a pipe encoded in a long. - * The read end of the pipe is returned in the high 32 bits, - * while the write end is returned in the low 32 bits. - */ - static native long makePipe(boolean blocking) throws IOException; - - static native int write1(int fd, byte b) throws IOException; - - /** - * Read and discard all bytes. - */ - static native boolean drain(int fd) throws IOException; - - /** - * Read and discard at most one byte - * @return the number of bytes read or IOS_INTERRUPTED - */ - static native int drain1(int fd) throws IOException; - - public static native void configureBlocking(FileDescriptor fd, - boolean blocking) - throws IOException; - public static native int fdVal(FileDescriptor fd); static native void setfdVal(FileDescriptor fd, int value); - static native int fdLimit(); - - static native int iovMax(); + private static native int iovMax(); - static native long writevMax(); + private static native long writevMax(); - static native void initIDs(); + private static native void initIDs(); /** * Used to trigger loading of native libraries @@ -609,8 +575,6 @@ public static native void configureBlocking(FileDescriptor fd, public static void load() { } static { - jdk.internal.loader.BootLoader.loadLibrary("net"); - jdk.internal.loader.BootLoader.loadLibrary("nio"); initIDs(); IOV_MAX = iovMax(); diff --git a/src/java.base/share/classes/sun/nio/ch/NIOUtil.java b/src/java.base/share/classes/sun/nio/ch/NIOUtil.java new file mode 100644 index 0000000000000..9cc9fa37139b9 --- /dev/null +++ b/src/java.base/share/classes/sun/nio/ch/NIOUtil.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.nio.ch; + +import java.io.FileDescriptor; +import java.io.IOException; + +/** + * File-descriptor based I/O utilities that are shared by NIO classes. + */ + +public final class NIOUtil { + + private NIOUtil() { } // No instantiation + + public static FileDescriptor newFD(int i) { + FileDescriptor fd = new FileDescriptor(); + IOUtil.setfdVal(fd, i); + return fd; + } + + /** + * Returns two file descriptors for a pipe encoded in a long. + * The read end of the pipe is returned in the high 32 bits, + * while the write end is returned in the low 32 bits. + */ + static native long makePipe(boolean blocking) throws IOException; + + static native int write1(int fd, byte b) throws IOException; + + /** + * Read and discard all bytes. + */ + static native boolean drain(int fd) throws IOException; + + /** + * Read and discard at most one byte + * @return the number of bytes read or IOS_INTERRUPTED + */ + static native int drain1(int fd) throws IOException; + + public static native void configureBlocking(FileDescriptor fd, + boolean blocking) + throws IOException; + + static native int fdLimit(); + + /** + * Used to trigger loading of native libraries + */ + public static void load() { } + + static { + jdk.internal.loader.BootLoader.loadLibrary("net"); + jdk.internal.loader.BootLoader.loadLibrary("nio"); + } + +} diff --git a/src/java.base/share/classes/sun/nio/ch/NativeSocketAddress.java b/src/java.base/share/classes/sun/nio/ch/NativeSocketAddress.java index c1f813ec5249a..223ff5ffbb914 100644 --- a/src/java.base/share/classes/sun/nio/ch/NativeSocketAddress.java +++ b/src/java.base/share/classes/sun/nio/ch/NativeSocketAddress.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -341,6 +341,6 @@ private static void putAddress(long address, Inet6Address ia) { private static native int offsetSin6FlowInfo(); static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/share/classes/sun/nio/ch/Net.java b/src/java.base/share/classes/sun/nio/ch/Net.java index 49814ae6bf294..b294df5489bfd 100644 --- a/src/java.base/share/classes/sun/nio/ch/Net.java +++ b/src/java.base/share/classes/sun/nio/ch/Net.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -531,7 +531,7 @@ static FileDescriptor socket(boolean stream) throws IOException { static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK)); + return NIOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK)); } static FileDescriptor serverSocket(boolean stream) { @@ -541,7 +541,7 @@ static FileDescriptor serverSocket(boolean stream) { static FileDescriptor serverSocket(ProtocolFamily family, boolean stream) { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, stream, true, FAST_LOOPBACK)); + return NIOUtil.newFD(socket0(preferIPv6, stream, true, FAST_LOOPBACK)); } // Due to oddities SO_REUSEADDR on Windows reuse is ignored @@ -813,7 +813,7 @@ static native int blockOrUnblock6(boolean block, FileDescriptor fd, byte[] group static native short pollconnValue(); static { - IOUtil.load(); + NIOUtil.load(); initIDs(); POLLIN = pollinValue(); diff --git a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java index b9885a36fa896..69783b36427ca 100644 --- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -212,7 +212,7 @@ private void configureNonBlockingIfNeeded(FileDescriptor fd, boolean timed) if (!nonBlocking && (timed || Thread.currentThread().isVirtual())) { assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); nonBlocking = true; } } @@ -763,7 +763,7 @@ protected void accept(SocketImpl si) throws IOException { InetSocketAddress localAddress; try { localAddress = Net.localAddress(newfd); - IOUtil.configureBlocking(newfd, true); + NIOUtil.configureBlocking(newfd, true); } catch (IOException ioe) { nd.close(newfd); throw ioe; diff --git a/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java index 0bd72bacf0b08..804e24fbc33b7 100644 --- a/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/ServerSocketChannelImpl.java @@ -494,7 +494,7 @@ private SocketChannel finishAccept(FileDescriptor newfd, SocketAddress sa) { try { // newly accepted socket is initially in blocking mode - IOUtil.configureBlocking(newfd, true); + NIOUtil.configureBlocking(newfd, true); // check permitted to accept connections from the remote address if (isNetSocket()) { @@ -531,7 +531,7 @@ private void lockedConfigureBlocking(boolean block) throws IOException { ensureOpen(); // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } } } @@ -545,7 +545,7 @@ private boolean tryLockedConfigureBlocking(boolean block) throws IOException { synchronized (stateLock) { // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking && isOpen()) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); return true; } else { return false; @@ -561,7 +561,7 @@ private void configureSocketNonBlockingIfVirtualThread() throws IOException { if (!forcedNonBlocking && Thread.currentThread().isVirtual()) { synchronized (stateLock) { ensureOpen(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); forcedNonBlocking = true; } } diff --git a/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java index ebbf55acd9711..8703b43750a35 100644 --- a/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -729,7 +729,7 @@ private void lockedConfigureBlocking(boolean block) throws IOException { ensureOpen(); // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } } } @@ -743,7 +743,7 @@ private boolean tryLockedConfigureBlocking(boolean block) throws IOException { synchronized (stateLock) { // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking && isOpen()) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); return true; } else { return false; @@ -759,7 +759,7 @@ private void configureSocketNonBlockingIfVirtualThread() throws IOException { if (!forcedNonBlocking && Thread.currentThread().isVirtual()) { synchronized (stateLock) { ensureOpen(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); forcedNonBlocking = true; } } diff --git a/src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java b/src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java index 251e79c6ecc69..334b86ee907d1 100644 --- a/src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java +++ b/src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -104,7 +104,7 @@ static byte[] getPathBytes(Path path) { } static FileDescriptor socket() throws IOException { - return IOUtil.newFD(socket0()); + return NIOUtil.newFD(socket0()); } static void bind(FileDescriptor fd, Path addr) throws IOException { @@ -185,7 +185,7 @@ private static native int accept0(FileDescriptor fd, FileDescriptor newfd, Objec static { // Load all required native libs - IOUtil.load(); + NIOUtil.load(); supported = init(); } } diff --git a/src/java.base/unix/classes/sun/nio/ch/DatagramDispatcher.java b/src/java.base/unix/classes/sun/nio/ch/DatagramDispatcher.java index 10a2098a04014..32bbbfc198ad2 100644 --- a/src/java.base/unix/classes/sun/nio/ch/DatagramDispatcher.java +++ b/src/java.base/unix/classes/sun/nio/ch/DatagramDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -35,10 +35,6 @@ class DatagramDispatcher extends UnixDispatcher { - static { - IOUtil.load(); - } - int read(FileDescriptor fd, long address, int len) throws IOException { return read0(fd, address, len); } diff --git a/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java b/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java index 868e859da29a7..212a5d2eaaeca 100644 --- a/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java +++ b/src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -282,7 +282,7 @@ private static String unixPeerAddress(int fd) throws IOException { private static native boolean isConnected(int fd); static { - IOUtil.load(); + NIOUtil.load(); initIDs(); } } diff --git a/src/java.base/unix/classes/sun/nio/ch/NativeThread.java b/src/java.base/unix/classes/sun/nio/ch/NativeThread.java index 2ec67cc7d5c47..6e585be2fb0f9 100644 --- a/src/java.base/unix/classes/sun/nio/ch/NativeThread.java +++ b/src/java.base/unix/classes/sun/nio/ch/NativeThread.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 diff --git a/src/java.base/unix/classes/sun/nio/ch/PipeImpl.java b/src/java.base/unix/classes/sun/nio/ch/PipeImpl.java index f4ef6ce147191..bf5516cd95756 100644 --- a/src/java.base/unix/classes/sun/nio/ch/PipeImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/PipeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -39,7 +39,7 @@ class PipeImpl private final SinkChannel sink; PipeImpl(SelectorProvider sp) throws IOException { - long pipeFds = IOUtil.makePipe(true); + long pipeFds = NIOUtil.makePipe(true); int readFd = (int) (pipeFds >>> 32); int writeFd = (int) pipeFds; FileDescriptor sourcefd = new FileDescriptor(); diff --git a/src/java.base/unix/classes/sun/nio/ch/PollSelectorImpl.java b/src/java.base/unix/classes/sun/nio/ch/PollSelectorImpl.java index a3bff8d1e6523..9891f4d884077 100644 --- a/src/java.base/unix/classes/sun/nio/ch/PollSelectorImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/PollSelectorImpl.java @@ -74,7 +74,7 @@ class PollSelectorImpl extends SelectorImpl { this.pollArray = new AllocatedNativeObject(size, false); try { - long fds = IOUtil.makePipe(false); + long fds = NIOUtil.makePipe(false); this.fd0 = (int) (fds >>> 32); this.fd1 = (int) fds; } catch (IOException ioe) { @@ -242,7 +242,7 @@ public Selector wakeup() { synchronized (interruptLock) { if (!interruptTriggered) { try { - IOUtil.write1(fd1, (byte)0); + NIOUtil.write1(fd1, (byte)0); } catch (IOException ioe) { throw new InternalError(ioe); } @@ -254,7 +254,7 @@ public Selector wakeup() { private void clearInterrupt() throws IOException { synchronized (interruptLock) { - IOUtil.drain(fd0); + NIOUtil.drain(fd0); interruptTriggered = false; } } @@ -385,6 +385,6 @@ private int getReventOps(int i) { private static native int poll(long pollAddress, int numfds, int timeout); static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java b/src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java index bc15d8d156b8f..12b44d1405f04 100644 --- a/src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java @@ -108,7 +108,7 @@ private void configureSocketNonBlockingIfVirtualThread() throws IOException { if (!forcedNonBlocking && Thread.currentThread().isVirtual()) { synchronized (stateLock) { ensureOpen(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); forcedNonBlocking = true; } } @@ -219,7 +219,7 @@ protected void implConfigureBlocking(boolean block) throws IOException { ensureOpen(); // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } } } finally { diff --git a/src/java.base/unix/classes/sun/nio/ch/SocketDispatcher.java b/src/java.base/unix/classes/sun/nio/ch/SocketDispatcher.java index 5b262fb58b7ad..c0fb5567e4e64 100644 --- a/src/java.base/unix/classes/sun/nio/ch/SocketDispatcher.java +++ b/src/java.base/unix/classes/sun/nio/ch/SocketDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -87,8 +87,4 @@ static native int write0(FileDescriptor fd, long address, int len) static native long writev0(FileDescriptor fd, long address, int len) throws IOException; - - static { - IOUtil.load(); - } } diff --git a/src/java.base/unix/classes/sun/nio/ch/SourceChannelImpl.java b/src/java.base/unix/classes/sun/nio/ch/SourceChannelImpl.java index 2990d35b51695..41b181e7e0a7d 100644 --- a/src/java.base/unix/classes/sun/nio/ch/SourceChannelImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/SourceChannelImpl.java @@ -108,7 +108,7 @@ private void configureSocketNonBlockingIfVirtualThread() throws IOException { if (!forcedNonBlocking && Thread.currentThread().isVirtual()) { synchronized (stateLock) { ensureOpen(); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); forcedNonBlocking = true; } } @@ -219,7 +219,7 @@ protected void implConfigureBlocking(boolean block) throws IOException { ensureOpen(); // do nothing if virtual thread has forced the socket to be non-blocking if (!forcedNonBlocking) { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } } } finally { diff --git a/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java b/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java index d8e6ed1a21a85..b0ddc2b149607 100644 --- a/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -75,7 +75,7 @@ private void enableAccept() { super(port); try { - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); } catch (IOException x) { nd.close(fd); // prevent leak throw x; diff --git a/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java b/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java index 49960b7ed219c..bc74085498ff4 100644 --- a/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java +++ b/src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -101,7 +101,7 @@ private static enum OpType { CONNECT, READ, WRITE }; // set non-blocking try { - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); } catch (IOException x) { nd.close(fd); throw x; @@ -123,7 +123,7 @@ private static enum OpType { CONNECT, READ, WRITE }; super(port, fd, remote); this.fdVal = IOUtil.fdVal(fd); - IOUtil.configureBlocking(fd, false); + NIOUtil.configureBlocking(fd, false); try { port.register(fdVal, this); @@ -771,6 +771,6 @@ Future implWrite(boolean isGatheringWrite, private static native void checkConnect(int fdVal) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/unix/classes/sun/nio/ch/UnixDispatcher.java b/src/java.base/unix/classes/sun/nio/ch/UnixDispatcher.java index bc643100f9d78..88b803aae06ea 100644 --- a/src/java.base/unix/classes/sun/nio/ch/UnixDispatcher.java +++ b/src/java.base/unix/classes/sun/nio/ch/UnixDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -45,7 +45,7 @@ void preClose(FileDescriptor fd) throws IOException { static native void init(); static { - IOUtil.load(); + NIOUtil.load(); init(); } } diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java b/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java index a069a9a04bac8..3ddce1659cb93 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java @@ -605,7 +605,6 @@ static boolean xattrSupported() { private static native int init(); static { - jdk.internal.loader.BootLoader.loadLibrary("nio"); capabilities = init(); } } diff --git a/src/java.base/unix/native/libnio/ch/FileKey.c b/src/java.base/unix/native/libjava/FileKey.c similarity index 100% rename from src/java.base/unix/native/libnio/ch/FileKey.c rename to src/java.base/unix/native/libjava/FileKey.c diff --git a/src/java.base/unix/native/libnio/ch/IOUtil.c b/src/java.base/unix/native/libjava/IOUtil.c similarity index 55% rename from src/java.base/unix/native/libnio/ch/IOUtil.c rename to src/java.base/unix/native/libjava/IOUtil.c index dfa99658fa667..22d34c79f72e4 100644 --- a/src/java.base/unix/native/libnio/ch/IOUtil.c +++ b/src/java.base/unix/native/libjava/IOUtil.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -47,14 +47,6 @@ Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I")); } -JNIEXPORT jboolean JNICALL -Java_sun_nio_ch_IOUtil_randomBytes(JNIEnv *env, jclass clazz, - jbyteArray randArray) -{ - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", NULL); - return JNI_FALSE; -} - JNIEXPORT jint JNICALL Java_sun_nio_ch_IOUtil_fdVal(JNIEnv *env, jclass clazz, jobject fdo) { @@ -67,104 +59,6 @@ Java_sun_nio_ch_IOUtil_setfdVal(JNIEnv *env, jclass clazz, jobject fdo, jint val setfdval(env, fdo, val); } -static int -configureBlocking(int fd, jboolean blocking) -{ - int flags = fcntl(fd, F_GETFL); - int newflags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK); - - return (flags == newflags) ? 0 : fcntl(fd, F_SETFL, newflags); -} - -JNIEXPORT void JNICALL -Java_sun_nio_ch_IOUtil_configureBlocking(JNIEnv *env, jclass clazz, - jobject fdo, jboolean blocking) -{ - if (configureBlocking(fdval(env, fdo), blocking) < 0) - JNU_ThrowIOExceptionWithLastError(env, "Configure blocking failed"); -} - -JNIEXPORT jlong JNICALL -Java_sun_nio_ch_IOUtil_makePipe(JNIEnv *env, jobject this, jboolean blocking) -{ - int fd[2]; - - if (pipe(fd) < 0) { - JNU_ThrowIOExceptionWithLastError(env, "Pipe failed"); - return 0; - } - if (blocking == JNI_FALSE) { - if ((configureBlocking(fd[0], JNI_FALSE) < 0) - || (configureBlocking(fd[1], JNI_FALSE) < 0)) { - JNU_ThrowIOExceptionWithLastError(env, "Configure blocking failed"); - close(fd[0]); - close(fd[1]); - return 0; - } - } - return ((jlong) fd[0] << 32) | (jlong) fd[1]; -} - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_IOUtil_write1(JNIEnv *env, jclass cl, jint fd, jbyte b) -{ - char c = (char)b; - return convertReturnVal(env, write(fd, &c, 1), JNI_FALSE); -} - -JNIEXPORT jboolean JNICALL -Java_sun_nio_ch_IOUtil_drain(JNIEnv *env, jclass cl, jint fd) -{ - char buf[16]; - int tn = 0; - - for (;;) { - int n = read(fd, buf, sizeof(buf)); - tn += n; - if ((n < 0) && (errno != EAGAIN && errno != EWOULDBLOCK)) - JNU_ThrowIOExceptionWithLastError(env, "Drain"); - if (n == (int)sizeof(buf)) - continue; - return (tn > 0) ? JNI_TRUE : JNI_FALSE; - } -} - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_IOUtil_drain1(JNIEnv *env, jclass cl, jint fd) -{ - int res; - char buf[1]; - - res = read(fd, buf, 1); - if (res < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { - res = 0; - } else if (errno == EINTR) { - return IOS_INTERRUPTED; - } else { - JNU_ThrowIOExceptionWithLastError(env, "read"); - return IOS_THROWN; - } - } - return res; -} - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_IOUtil_fdLimit(JNIEnv *env, jclass this) -{ - struct rlimit rlp; - if (getrlimit(RLIMIT_NOFILE, &rlp) < 0) { - JNU_ThrowIOExceptionWithLastError(env, "getrlimit failed"); - return -1; - } - if (rlp.rlim_max == RLIM_INFINITY || - rlp.rlim_max > (rlim_t)java_lang_Integer_MAX_VALUE) { - return java_lang_Integer_MAX_VALUE; - } else { - return (jint)rlp.rlim_max; - } -} - JNIEXPORT jint JNICALL Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this) { @@ -197,16 +91,16 @@ Java_sun_nio_ch_IOUtil_writevMax(JNIEnv *env, jclass this) #endif } -/* Declared in nio_util.h for use elsewhere in NIO */ +// Declared in nio_util.h for use elsewhere in NIO -jint +JNIEXPORT jint convertReturnVal(JNIEnv *env, jint n, jboolean reading) { - if (n > 0) /* Number of bytes written */ + if (n > 0) // Number of bytes written return n; else if (n == 0) { if (reading) { - return IOS_EOF; /* EOF is -1 in javaland */ + return IOS_EOF; // EOF is -1 in javaland } else { return 0; } @@ -222,16 +116,16 @@ convertReturnVal(JNIEnv *env, jint n, jboolean reading) } } -/* Declared in nio_util.h for use elsewhere in NIO */ +// Declared in nio_util.h for use elsewhere in NIO -jlong +JNIEXPORT jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading) { - if (n > 0) /* Number of bytes written */ + if (n > 0) // Number of bytes written return n; else if (n == 0) { if (reading) { - return IOS_EOF; /* EOF is -1 in javaland */ + return IOS_EOF; // EOF is -1 in javaland } else { return 0; } @@ -247,15 +141,13 @@ convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading) } } -jint +JNIEXPORT jint fdval(JNIEnv *env, jobject fdo) { return (*env)->GetIntField(env, fdo, fd_fdID); } -void +JNIEXPORT void setfdval(JNIEnv *env, jobject fdo, jint val) { (*env)->SetIntField(env, fdo, fd_fdID, val); } - - diff --git a/src/java.base/unix/native/libnio/MappedMemoryUtils.c b/src/java.base/unix/native/libjava/MappedMemoryUtils.c similarity index 100% rename from src/java.base/unix/native/libnio/MappedMemoryUtils.c rename to src/java.base/unix/native/libjava/MappedMemoryUtils.c diff --git a/src/java.base/unix/native/libnio/ch/NativeThread.c b/src/java.base/unix/native/libjava/NativeThread.c similarity index 100% rename from src/java.base/unix/native/libnio/ch/NativeThread.c rename to src/java.base/unix/native/libjava/NativeThread.c diff --git a/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c b/src/java.base/unix/native/libjava/UnixFileDispatcherImpl.c similarity index 100% rename from src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c rename to src/java.base/unix/native/libjava/UnixFileDispatcherImpl.c diff --git a/src/java.base/unix/native/libnio/fs/UnixFileSystem.c b/src/java.base/unix/native/libjava/UnixFileSystem.c similarity index 100% rename from src/java.base/unix/native/libnio/fs/UnixFileSystem.c rename to src/java.base/unix/native/libjava/UnixFileSystem.c diff --git a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/src/java.base/unix/native/libjava/UnixNativeDispatcher.c similarity index 100% rename from src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c rename to src/java.base/unix/native/libjava/UnixNativeDispatcher.c diff --git a/src/java.base/unix/native/libnio/ch/NIOUtil.c b/src/java.base/unix/native/libnio/ch/NIOUtil.c new file mode 100644 index 0000000000000..b9d3d3060e676 --- /dev/null +++ b/src/java.base/unix/native/libnio/ch/NIOUtil.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2000, 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include + +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" +#include "sun_nio_ch_IOUtil.h" +#include "java_lang_Integer.h" +#include "java_lang_Long.h" +#include "nio.h" +#include "nio_util.h" + +static int +configureBlocking(int fd, jboolean blocking) +{ + int flags = fcntl(fd, F_GETFL); + int newflags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK); + + return (flags == newflags) ? 0 : fcntl(fd, F_SETFL, newflags); +} + +JNIEXPORT void JNICALL +Java_sun_nio_ch_NIOUtil_configureBlocking(JNIEnv *env, jclass clazz, + jobject fdo, jboolean blocking) +{ + if (configureBlocking(fdval(env, fdo), blocking) < 0) + JNU_ThrowIOExceptionWithLastError(env, "Configure blocking failed"); +} + +JNIEXPORT jlong JNICALL +Java_sun_nio_ch_NIOUtil_makePipe(JNIEnv *env, jobject this, jboolean blocking) +{ + int fd[2]; + + if (pipe(fd) < 0) { + JNU_ThrowIOExceptionWithLastError(env, "Pipe failed"); + return 0; + } + if (blocking == JNI_FALSE) { + if ((configureBlocking(fd[0], JNI_FALSE) < 0) + || (configureBlocking(fd[1], JNI_FALSE) < 0)) { + JNU_ThrowIOExceptionWithLastError(env, "Configure blocking failed"); + close(fd[0]); + close(fd[1]); + return 0; + } + } + return ((jlong) fd[0] << 32) | (jlong) fd[1]; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_NIOUtil_write1(JNIEnv *env, jclass cl, jint fd, jbyte b) +{ + char c = (char)b; + return convertReturnVal(env, write(fd, &c, 1), JNI_FALSE); +} + +JNIEXPORT jboolean JNICALL +Java_sun_nio_ch_NIOUtil_drain(JNIEnv *env, jclass cl, jint fd) +{ + char buf[16]; + int tn = 0; + + for (;;) { + int n = read(fd, buf, sizeof(buf)); + tn += n; + if ((n < 0) && (errno != EAGAIN && errno != EWOULDBLOCK)) + JNU_ThrowIOExceptionWithLastError(env, "Drain"); + if (n == (int)sizeof(buf)) + continue; + return (tn > 0) ? JNI_TRUE : JNI_FALSE; + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_NIOUtil_drain1(JNIEnv *env, jclass cl, jint fd) +{ + int res; + char buf[1]; + + res = read(fd, buf, 1); + if (res < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + res = 0; + } else if (errno == EINTR) { + return IOS_INTERRUPTED; + } else { + JNU_ThrowIOExceptionWithLastError(env, "read"); + return IOS_THROWN; + } + } + return res; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_NIOUtil_fdLimit(JNIEnv *env, jclass this) +{ + struct rlimit rlp; + if (getrlimit(RLIMIT_NOFILE, &rlp) < 0) { + JNU_ThrowIOExceptionWithLastError(env, "getrlimit failed"); + return -1; + } + if (rlp.rlim_max == RLIM_INFINITY || + rlp.rlim_max > (rlim_t)java_lang_Integer_MAX_VALUE) { + return java_lang_Integer_MAX_VALUE; + } else { + return (jint)rlp.rlim_max; + } +} diff --git a/src/java.base/windows/classes/sun/nio/ch/DatagramDispatcher.java b/src/java.base/windows/classes/sun/nio/ch/DatagramDispatcher.java index c59dfabbcedd1..5e7cddaac6eb0 100644 --- a/src/java.base/windows/classes/sun/nio/ch/DatagramDispatcher.java +++ b/src/java.base/windows/classes/sun/nio/ch/DatagramDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -71,6 +71,6 @@ private static native long writev0(FileDescriptor fd, long address, int len) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/windows/classes/sun/nio/ch/SocketDispatcher.java b/src/java.base/windows/classes/sun/nio/ch/SocketDispatcher.java index 6ce751bddf717..d3c751b06af36 100644 --- a/src/java.base/windows/classes/sun/nio/ch/SocketDispatcher.java +++ b/src/java.base/windows/classes/sun/nio/ch/SocketDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -90,6 +90,6 @@ private static native long writev0(FileDescriptor fd, long address, int len) private static native void close0(int fdVal) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/windows/classes/sun/nio/ch/WEPoll.java b/src/java.base/windows/classes/sun/nio/ch/WEPoll.java index 93e25e55f7cf4..af24ff77278bd 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WEPoll.java +++ b/src/java.base/windows/classes/sun/nio/ch/WEPoll.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -53,7 +53,7 @@ private WEPoll() { } * } */ static { - IOUtil.load(); + NIOUtil.load(); } private static final int SIZEOF_EPOLLEVENT = eventSize(); private static final int OFFSETOF_EVENTS = eventsOffset(); diff --git a/src/java.base/windows/classes/sun/nio/ch/WEPollSelectorImpl.java b/src/java.base/windows/classes/sun/nio/ch/WEPollSelectorImpl.java index bbcfab9bbf19c..999a4c2e44343 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WEPollSelectorImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WEPollSelectorImpl.java @@ -239,7 +239,7 @@ public Selector wakeup() { synchronized (interruptLock) { if (!interruptTriggered) { try { - IOUtil.write1(fd1Val, (byte) 0); + NIOUtil.write1(fd1Val, (byte) 0); } catch (IOException ioe) { throw new InternalError(ioe); } @@ -251,7 +251,7 @@ public Selector wakeup() { private void clearInterrupt() throws IOException { synchronized (interruptLock) { - IOUtil.drain(fd0Val); + NIOUtil.drain(fd0Val); interruptTriggered = false; } } diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java index 53c2219368c0e..02b7cb6bb74d1 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousServerSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -362,7 +362,7 @@ private static native void updateAcceptContext(long listenSocket, private static native void closesocket0(long socket) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); initIDs(); } } diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java index 20fdfc46ae312..231223720cde7 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -940,7 +940,7 @@ private static native int write0(long socket, int count, long address, private static native void closesocket0(long socket) throws IOException; static { - IOUtil.load(); + NIOUtil.load(); initIDs(); } } diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java index 977a1653fdd31..fb3159891acde 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -624,6 +624,6 @@ public Selector wakeup() { } static { - IOUtil.load(); + NIOUtil.load(); } } diff --git a/src/java.base/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java b/src/java.base/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java index 485d99eae00d5..1a7037d65d4df 100644 --- a/src/java.base/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java +++ b/src/java.base/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java @@ -62,10 +62,4 @@ public String implProbeContentType(Path file) throws IOException { } private static native String queryStringValue(long subKey, long name); - - static { - // nio.dll has dependency on net.dll - jdk.internal.loader.BootLoader.loadLibrary("net"); - jdk.internal.loader.BootLoader.loadLibrary("nio"); - } } diff --git a/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java b/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java index 8e351b7e0effa..5e923aa2a0d27 100644 --- a/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java +++ b/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java @@ -1094,9 +1094,7 @@ static NativeBuffer asNativeBuffer(String s) throws WindowsException { private static native void initIDs(); static { - // nio.dll has dependency on net.dll jdk.internal.loader.BootLoader.loadLibrary("net"); - jdk.internal.loader.BootLoader.loadLibrary("nio"); initIDs(); } diff --git a/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c b/src/java.base/windows/native/libjava/FileDispatcherImpl.c similarity index 100% rename from src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c rename to src/java.base/windows/native/libjava/FileDispatcherImpl.c diff --git a/src/java.base/windows/native/libnio/ch/FileKey.c b/src/java.base/windows/native/libjava/FileKey.c similarity index 100% rename from src/java.base/windows/native/libnio/ch/FileKey.c rename to src/java.base/windows/native/libjava/FileKey.c diff --git a/src/java.base/windows/native/libnio/ch/IOUtil.c b/src/java.base/windows/native/libjava/IOUtil.c similarity index 65% rename from src/java.base/windows/native/libnio/ch/IOUtil.c rename to src/java.base/windows/native/libjava/IOUtil.c index 850c237d9e908..01d9532c724ac 100644 --- a/src/java.base/windows/native/libnio/ch/IOUtil.c +++ b/src/java.base/windows/native/libjava/IOUtil.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -34,7 +34,7 @@ #include "java_lang_Long.h" #include "nio.h" #include "nio_util.h" -#include "net_util.h" +/* #include "net_util.h" */ #include "sun_nio_ch_IOUtil.h" /* field id for jlong 'handle' in java.io.FileDescriptor used for file fds */ @@ -62,16 +62,6 @@ Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) /************************************************************** * IOUtil.c */ -JNIEXPORT jboolean JNICALL -Java_sun_nio_ch_IOUtil_randomBytes(JNIEnv *env, jclass clazz, - jbyteArray randArray) -{ - return - Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed(env, - clazz, - randArray); -} - JNIEXPORT jint JNICALL Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this) { @@ -84,7 +74,7 @@ Java_sun_nio_ch_IOUtil_writevMax(JNIEnv *env, jclass this) return java_lang_Long_MAX_VALUE; } -jint +JNIEXPORT jint convertReturnVal(JNIEnv *env, jint n, jboolean reading) { if (n > 0) /* Number of bytes written */ @@ -100,7 +90,7 @@ convertReturnVal(JNIEnv *env, jint n, jboolean reading) return IOS_THROWN; } -jlong +JNIEXPORT jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading) { if (n > 0) /* Number of bytes written */ @@ -128,79 +118,22 @@ Java_sun_nio_ch_IOUtil_setfdVal(JNIEnv *env, jclass clazz, jobject fdo, jint val setfdval(env, fdo, val); } - -#define SET_BLOCKING 0 -#define SET_NONBLOCKING 1 - -JNIEXPORT void JNICALL -Java_sun_nio_ch_IOUtil_configureBlocking(JNIEnv *env, jclass clazz, - jobject fdo, jboolean blocking) -{ - u_long argp; - int result = 0; - jint fd = fdval(env, fdo); - - if (blocking == JNI_FALSE) { - argp = SET_NONBLOCKING; - } else { - argp = SET_BLOCKING; - /* Blocking fd cannot be registered with EventSelect */ - WSAEventSelect(fd, NULL, 0); - } - result = ioctlsocket(fd, FIONBIO, &argp); - if (result == SOCKET_ERROR) { - NET_ThrowNew(env, WSAGetLastError(), "ioctlsocket"); - } -} - -JNIEXPORT jboolean JNICALL -Java_sun_nio_ch_IOUtil_drain(JNIEnv *env, jclass cl, jint fd) -{ - char buf[16]; - jboolean readBytes = JNI_FALSE; - for (;;) { - int n = recv((SOCKET) fd, buf, sizeof(buf), 0); - if (n == SOCKET_ERROR) { - if (WSAGetLastError() != WSAEWOULDBLOCK) { - JNU_ThrowIOExceptionWithLastError(env, "recv failed"); - } - return readBytes; - } - if (n <= 0) - return readBytes; - if (n < (int)sizeof(buf)) - return JNI_TRUE; - readBytes = JNI_TRUE; - } -} - -JNIEXPORT jint JNICALL -Java_sun_nio_ch_IOUtil_write1(JNIEnv *env, jclass cl, jint fd, jbyte b) -{ - int n = send((SOCKET) fd, &b, 1, 0); - if (n == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) { - JNU_ThrowIOExceptionWithLastError(env, "send failed"); - return IOS_THROWN; - } - return (n == 1) ? 1 : 0; -} - /* Note: This function returns the int fd value from file descriptor. It is mostly used for sockets which should use the int fd value. */ -jint +JNIEXPORT jint fdval(JNIEnv *env, jobject fdo) { return (*env)->GetIntField(env, fdo, fd_fdID); } -void +JNIEXPORT void setfdval(JNIEnv *env, jobject fdo, jint val) { (*env)->SetIntField(env, fdo, fd_fdID, val); } -jlong +JNIEXPORT jlong handleval(JNIEnv *env, jobject fdo) { return (*env)->GetLongField(env, fdo, handle_fdID); diff --git a/src/java.base/windows/native/libnio/ch/Iocp.c b/src/java.base/windows/native/libjava/Iocp.c similarity index 100% rename from src/java.base/windows/native/libnio/ch/Iocp.c rename to src/java.base/windows/native/libjava/Iocp.c diff --git a/src/java.base/windows/native/libnio/MappedMemoryUtils.c b/src/java.base/windows/native/libjava/MappedMemoryUtils.c similarity index 100% rename from src/java.base/windows/native/libnio/MappedMemoryUtils.c rename to src/java.base/windows/native/libjava/MappedMemoryUtils.c diff --git a/src/java.base/windows/native/libnio/fs/RegistryFileTypeDetector.c b/src/java.base/windows/native/libjava/RegistryFileTypeDetector.c similarity index 100% rename from src/java.base/windows/native/libnio/fs/RegistryFileTypeDetector.c rename to src/java.base/windows/native/libjava/RegistryFileTypeDetector.c diff --git a/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c b/src/java.base/windows/native/libjava/WindowsAsynchronousFileChannelImpl.c similarity index 100% rename from src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c rename to src/java.base/windows/native/libjava/WindowsAsynchronousFileChannelImpl.c diff --git a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c b/src/java.base/windows/native/libjava/WindowsNativeDispatcher.c similarity index 100% rename from src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c rename to src/java.base/windows/native/libjava/WindowsNativeDispatcher.c diff --git a/src/java.base/windows/native/libnio/ch/NIOUtil.c b/src/java.base/windows/native/libnio/ch/NIOUtil.c new file mode 100644 index 0000000000000..b5b14a7865f23 --- /dev/null +++ b/src/java.base/windows/native/libnio/ch/NIOUtil.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2000, 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include +#include +#include +#include "jni.h" +#include "jni_util.h" +#include "jvm.h" +#include "jlong.h" + +#include "java_lang_Long.h" +#include "nio.h" +#include "nio_util.h" +#include "net_util.h" +#include "sun_nio_ch_NIOUtil.h" + +JNIEXPORT jboolean JNICALL +Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed +(JNIEnv *env, jclass clazz, jbyteArray randArray); + +/************************************************************** + * NIOUtil.c + */ + +#define SET_BLOCKING 0 +#define SET_NONBLOCKING 1 + +JNIEXPORT void JNICALL +Java_sun_nio_ch_NIOUtil_configureBlocking(JNIEnv *env, jclass clazz, + jobject fdo, jboolean blocking) +{ + u_long argp; + int result = 0; + jint fd = fdval(env, fdo); + + if (blocking == JNI_FALSE) { + argp = SET_NONBLOCKING; + } else { + argp = SET_BLOCKING; + /* Blocking fd cannot be registered with EventSelect */ + WSAEventSelect(fd, NULL, 0); + } + result = ioctlsocket(fd, FIONBIO, &argp); + if (result == SOCKET_ERROR) { + NET_ThrowNew(env, WSAGetLastError(), "ioctlsocket"); + } +} + +JNIEXPORT jboolean JNICALL +Java_sun_nio_ch_NIOUtil_drain(JNIEnv *env, jclass cl, jint fd) +{ + char buf[16]; + jboolean readBytes = JNI_FALSE; + for (;;) { + int n = recv((SOCKET) fd, buf, sizeof(buf), 0); + if (n == SOCKET_ERROR) { + if (WSAGetLastError() != WSAEWOULDBLOCK) { + JNU_ThrowIOExceptionWithLastError(env, "recv failed"); + } + return readBytes; + } + if (n <= 0) + return readBytes; + if (n < (int)sizeof(buf)) + return JNI_TRUE; + readBytes = JNI_TRUE; + } +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_NIOUtil_drain1(JNIEnv *env, jclass cl, jint fd) +{ + JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "drain1"); + return IOS_THROWN; +} + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_NIOUtil_write1(JNIEnv *env, jclass cl, jint fd, jbyte b) +{ + int n = send((SOCKET) fd, &b, 1, 0); + if (n == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) { + JNU_ThrowIOExceptionWithLastError(env, "send failed"); + return IOS_THROWN; + } + return (n == 1) ? 1 : 0; +} diff --git a/src/java.base/windows/native/libnio/ch/nio_util.h b/src/java.base/windows/native/libnio/ch/nio_util.h index b90e0ac63d5c2..e6034b2787d2b 100644 --- a/src/java.base/windows/native/libnio/ch/nio_util.h +++ b/src/java.base/windows/native/libnio/ch/nio_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -40,11 +40,11 @@ #define MAX_UNIX_DOMAIN_PATH_LEN \ (int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2) -jint fdval(JNIEnv *env, jobject fdo); -void setfdval(JNIEnv *env, jobject fdo, jint val); -jlong handleval(JNIEnv *env, jobject fdo); -jint convertReturnVal(JNIEnv *env, jint n, jboolean r); -jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r); +JNIEXPORT jint fdval(JNIEnv *env, jobject fdo); +JNIEXPORT void setfdval(JNIEnv *env, jobject fdo, jint val); +JNIEXPORT jlong handleval(JNIEnv *env, jobject fdo); +JNIEXPORT jint convertReturnVal(JNIEnv *env, jint n, jboolean r); +JNIEXPORT jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r); jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd); #ifdef _WIN64 diff --git a/src/jdk.net/share/classes/jdk/nio/Channels.java b/src/jdk.net/share/classes/jdk/nio/Channels.java index e59acdbc654e0..91dd6fc826b94 100644 --- a/src/jdk.net/share/classes/jdk/nio/Channels.java +++ b/src/jdk.net/share/classes/jdk/nio/Channels.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -34,6 +34,7 @@ import java.util.Objects; import sun.nio.ch.IOUtil; +import sun.nio.ch.NIOUtil; import sun.nio.ch.Net; import sun.nio.ch.SelChImpl; import sun.nio.ch.SelectionKeyImpl; @@ -248,7 +249,7 @@ public int translateInterestOps(int ops) { @Override protected void implConfigureBlocking(boolean block) throws IOException { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } @Override diff --git a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java index 4355605e25815..4615f02e63f0d 100644 --- a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java +++ b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -63,6 +63,7 @@ import sun.nio.ch.IOUtil; import sun.nio.ch.NativeThread; import sun.nio.ch.Net; +import sun.nio.ch.NIOUtil; import sun.nio.ch.SelChImpl; import sun.nio.ch.SelectionKeyImpl; import sun.nio.ch.Util; @@ -543,7 +544,7 @@ public boolean finishConnect() throws IOException { @Override protected void implConfigureBlocking(boolean block) throws IOException { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } @Override @@ -1096,7 +1097,7 @@ static native int send0(int fd, long address, int length, @SuppressWarnings("removal") private static void loadSctpLibrary() { - IOUtil.load(); /* loads nio & net native libraries */ + NIOUtil.load(); /* loads nio & net native libraries */ AccessController.doPrivileged( new PrivilegedAction<>() { public Void run() { diff --git a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java index b1b721c99762c..bdd68372c6e91 100644 --- a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java +++ b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpMultiChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -62,6 +62,7 @@ import sun.nio.ch.IOStatus; import sun.nio.ch.IOUtil; import sun.nio.ch.Net; +import sun.nio.ch.NIOUtil; import sun.nio.ch.SelChImpl; import sun.nio.ch.SelectionKeyImpl; import sun.nio.ch.Util; @@ -284,7 +285,7 @@ private void senderCleanup() throws IOException { @Override protected void implConfigureBlocking(boolean block) throws IOException { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } @Override diff --git a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java index 239e09837f7a9..b50df1e9c1b8a 100644 --- a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java +++ b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpNet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -37,6 +37,7 @@ import sun.net.util.IPAddressUtil; import sun.nio.ch.IOUtil; import sun.nio.ch.Net; +import sun.nio.ch.NIOUtil; import com.sun.nio.sctp.SctpSocketOption; import static com.sun.nio.sctp.SctpStandardSocketOptions.*; @@ -76,7 +77,7 @@ static void preClose(int fd) throws IOException { */ static FileDescriptor socket(boolean oneToOne) throws IOException { int nativefd = socket0(oneToOne); - return IOUtil.newFD(nativefd); + return NIOUtil.newFD(nativefd); } static void bindx(int fd, InetAddress[] addrs, int port, boolean add) @@ -280,7 +281,7 @@ static void shutdown(int fd, int assocId) static FileDescriptor branch(int fd, int assocId) throws IOException { int nativefd = branch0(fd, assocId); - return IOUtil.newFD(nativefd); + return NIOUtil.newFD(nativefd); } /* Native Methods */ @@ -335,7 +336,7 @@ static native void setInitMsgOption0(int fd, int arg1, int arg2) @SuppressWarnings("removal") private static void loadSctpLibrary() { - IOUtil.load(); // loads nio & net native libraries + NIOUtil.load(); // loads nio & net native libraries java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Void run() { diff --git a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java index 0f710a4c67048..09f42b85c9437 100644 --- a/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java +++ b/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpServerChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -45,6 +45,7 @@ import sun.nio.ch.IOStatus; import sun.nio.ch.IOUtil; import sun.nio.ch.Net; +import sun.nio.ch.NIOUtil; import sun.nio.ch.SelChImpl; import sun.nio.ch.SelectionKeyImpl; @@ -243,7 +244,7 @@ public SctpChannel accept() throws IOException { if (n < 1) return null; - IOUtil.configureBlocking(newfd, true); + NIOUtil.configureBlocking(newfd, true); InetSocketAddress isa = isaa[0]; sc = new SctpChannelImpl(provider(), newfd); @@ -259,7 +260,7 @@ public SctpChannel accept() throws IOException { @Override protected void implConfigureBlocking(boolean block) throws IOException { - IOUtil.configureBlocking(fd, block); + NIOUtil.configureBlocking(fd, block); } @Override diff --git a/test/jdk/jdk/nio/Basic.java b/test/jdk/jdk/nio/Basic.java index 02fcfbc4a4d5a..769f7cba3d662 100644 --- a/test/jdk/jdk/nio/Basic.java +++ b/test/jdk/jdk/nio/Basic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -46,7 +46,7 @@ import jdk.nio.Channels; import jdk.nio.Channels.SelectableChannelCloser; -import sun.nio.ch.IOUtil; +import sun.nio.ch.NIOUtil; import org.testng.annotations.Test; import static org.testng.Assert.*; @@ -237,7 +237,7 @@ public void testImplReleaseChannel() throws IOException { @Test(expectedExceptions = IllegalArgumentException.class) public void testInvalidFileDescriptor() throws IOException { - FileDescriptor fd = IOUtil.newFD(-1); + FileDescriptor fd = NIOUtil.newFD(-1); Channels.readWriteSelectableChannel(fd, new SelectableChannelCloser() { @Override public void implCloseChannel(SelectableChannel sc) { } From 485197374fd0c0a6ad6911d81348d57ea91dd7ca Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 26 Jul 2024 12:35:59 -0700 Subject: [PATCH 2/6] 8337143: Move natives to /native/libjava/nio/{ch,fs} as a function of their original location in libnio --- .../linux/native/libjava/{ => nio/ch}/FileDispatcherImpl.c | 0 .../linux/native/libjava/{ => nio/fs}/LinuxNativeDispatcher.c | 0 .../linux/native/libjava/{ => nio/fs}/LinuxWatchService.c | 0 .../macosx/native/libjava/{ => nio/ch}/FileDispatcherImpl.c | 0 src/java.base/macosx/native/libjava/{ => nio/fs}/BsdFileSystem.c | 0 .../macosx/native/libjava/{ => nio/fs}/BsdNativeDispatcher.c | 0 .../macosx/native/libjava/{ => nio/fs}/MacOSXNativeDispatcher.c | 0 .../macosx/native/libjava/{ => nio/fs}/UTIFileTypeDetector.c | 0 src/java.base/unix/native/libjava/{ => nio}/MappedMemoryUtils.c | 0 src/java.base/unix/native/libjava/{ => nio/ch}/FileKey.c | 0 src/java.base/unix/native/libjava/{ => nio/ch}/NativeThread.c | 0 .../unix/native/libjava/{ => nio/ch}/UnixFileDispatcherImpl.c | 0 src/java.base/unix/native/libjava/{ => nio/fs}/UnixFileSystem.c | 0 .../unix/native/libjava/{ => nio/fs}/UnixNativeDispatcher.c | 0 .../windows/native/libjava/{ => nio}/MappedMemoryUtils.c | 0 .../windows/native/libjava/{ => nio/ch}/FileDispatcherImpl.c | 0 src/java.base/windows/native/libjava/{ => nio/ch}/FileKey.c | 0 src/java.base/windows/native/libjava/{ => nio/ch}/Iocp.c | 0 .../libjava/{ => nio/ch}/WindowsAsynchronousFileChannelImpl.c | 0 .../native/libjava/{ => nio/fs}/RegistryFileTypeDetector.c | 0 .../windows/native/libjava/{ => nio/fs}/WindowsNativeDispatcher.c | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename src/java.base/linux/native/libjava/{ => nio/ch}/FileDispatcherImpl.c (100%) rename src/java.base/linux/native/libjava/{ => nio/fs}/LinuxNativeDispatcher.c (100%) rename src/java.base/linux/native/libjava/{ => nio/fs}/LinuxWatchService.c (100%) rename src/java.base/macosx/native/libjava/{ => nio/ch}/FileDispatcherImpl.c (100%) rename src/java.base/macosx/native/libjava/{ => nio/fs}/BsdFileSystem.c (100%) rename src/java.base/macosx/native/libjava/{ => nio/fs}/BsdNativeDispatcher.c (100%) rename src/java.base/macosx/native/libjava/{ => nio/fs}/MacOSXNativeDispatcher.c (100%) rename src/java.base/macosx/native/libjava/{ => nio/fs}/UTIFileTypeDetector.c (100%) rename src/java.base/unix/native/libjava/{ => nio}/MappedMemoryUtils.c (100%) rename src/java.base/unix/native/libjava/{ => nio/ch}/FileKey.c (100%) rename src/java.base/unix/native/libjava/{ => nio/ch}/NativeThread.c (100%) rename src/java.base/unix/native/libjava/{ => nio/ch}/UnixFileDispatcherImpl.c (100%) rename src/java.base/unix/native/libjava/{ => nio/fs}/UnixFileSystem.c (100%) rename src/java.base/unix/native/libjava/{ => nio/fs}/UnixNativeDispatcher.c (100%) rename src/java.base/windows/native/libjava/{ => nio}/MappedMemoryUtils.c (100%) rename src/java.base/windows/native/libjava/{ => nio/ch}/FileDispatcherImpl.c (100%) rename src/java.base/windows/native/libjava/{ => nio/ch}/FileKey.c (100%) rename src/java.base/windows/native/libjava/{ => nio/ch}/Iocp.c (100%) rename src/java.base/windows/native/libjava/{ => nio/ch}/WindowsAsynchronousFileChannelImpl.c (100%) rename src/java.base/windows/native/libjava/{ => nio/fs}/RegistryFileTypeDetector.c (100%) rename src/java.base/windows/native/libjava/{ => nio/fs}/WindowsNativeDispatcher.c (100%) diff --git a/src/java.base/linux/native/libjava/FileDispatcherImpl.c b/src/java.base/linux/native/libjava/nio/ch/FileDispatcherImpl.c similarity index 100% rename from src/java.base/linux/native/libjava/FileDispatcherImpl.c rename to src/java.base/linux/native/libjava/nio/ch/FileDispatcherImpl.c diff --git a/src/java.base/linux/native/libjava/LinuxNativeDispatcher.c b/src/java.base/linux/native/libjava/nio/fs/LinuxNativeDispatcher.c similarity index 100% rename from src/java.base/linux/native/libjava/LinuxNativeDispatcher.c rename to src/java.base/linux/native/libjava/nio/fs/LinuxNativeDispatcher.c diff --git a/src/java.base/linux/native/libjava/LinuxWatchService.c b/src/java.base/linux/native/libjava/nio/fs/LinuxWatchService.c similarity index 100% rename from src/java.base/linux/native/libjava/LinuxWatchService.c rename to src/java.base/linux/native/libjava/nio/fs/LinuxWatchService.c diff --git a/src/java.base/macosx/native/libjava/FileDispatcherImpl.c b/src/java.base/macosx/native/libjava/nio/ch/FileDispatcherImpl.c similarity index 100% rename from src/java.base/macosx/native/libjava/FileDispatcherImpl.c rename to src/java.base/macosx/native/libjava/nio/ch/FileDispatcherImpl.c diff --git a/src/java.base/macosx/native/libjava/BsdFileSystem.c b/src/java.base/macosx/native/libjava/nio/fs/BsdFileSystem.c similarity index 100% rename from src/java.base/macosx/native/libjava/BsdFileSystem.c rename to src/java.base/macosx/native/libjava/nio/fs/BsdFileSystem.c diff --git a/src/java.base/macosx/native/libjava/BsdNativeDispatcher.c b/src/java.base/macosx/native/libjava/nio/fs/BsdNativeDispatcher.c similarity index 100% rename from src/java.base/macosx/native/libjava/BsdNativeDispatcher.c rename to src/java.base/macosx/native/libjava/nio/fs/BsdNativeDispatcher.c diff --git a/src/java.base/macosx/native/libjava/MacOSXNativeDispatcher.c b/src/java.base/macosx/native/libjava/nio/fs/MacOSXNativeDispatcher.c similarity index 100% rename from src/java.base/macosx/native/libjava/MacOSXNativeDispatcher.c rename to src/java.base/macosx/native/libjava/nio/fs/MacOSXNativeDispatcher.c diff --git a/src/java.base/macosx/native/libjava/UTIFileTypeDetector.c b/src/java.base/macosx/native/libjava/nio/fs/UTIFileTypeDetector.c similarity index 100% rename from src/java.base/macosx/native/libjava/UTIFileTypeDetector.c rename to src/java.base/macosx/native/libjava/nio/fs/UTIFileTypeDetector.c diff --git a/src/java.base/unix/native/libjava/MappedMemoryUtils.c b/src/java.base/unix/native/libjava/nio/MappedMemoryUtils.c similarity index 100% rename from src/java.base/unix/native/libjava/MappedMemoryUtils.c rename to src/java.base/unix/native/libjava/nio/MappedMemoryUtils.c diff --git a/src/java.base/unix/native/libjava/FileKey.c b/src/java.base/unix/native/libjava/nio/ch/FileKey.c similarity index 100% rename from src/java.base/unix/native/libjava/FileKey.c rename to src/java.base/unix/native/libjava/nio/ch/FileKey.c diff --git a/src/java.base/unix/native/libjava/NativeThread.c b/src/java.base/unix/native/libjava/nio/ch/NativeThread.c similarity index 100% rename from src/java.base/unix/native/libjava/NativeThread.c rename to src/java.base/unix/native/libjava/nio/ch/NativeThread.c diff --git a/src/java.base/unix/native/libjava/UnixFileDispatcherImpl.c b/src/java.base/unix/native/libjava/nio/ch/UnixFileDispatcherImpl.c similarity index 100% rename from src/java.base/unix/native/libjava/UnixFileDispatcherImpl.c rename to src/java.base/unix/native/libjava/nio/ch/UnixFileDispatcherImpl.c diff --git a/src/java.base/unix/native/libjava/UnixFileSystem.c b/src/java.base/unix/native/libjava/nio/fs/UnixFileSystem.c similarity index 100% rename from src/java.base/unix/native/libjava/UnixFileSystem.c rename to src/java.base/unix/native/libjava/nio/fs/UnixFileSystem.c diff --git a/src/java.base/unix/native/libjava/UnixNativeDispatcher.c b/src/java.base/unix/native/libjava/nio/fs/UnixNativeDispatcher.c similarity index 100% rename from src/java.base/unix/native/libjava/UnixNativeDispatcher.c rename to src/java.base/unix/native/libjava/nio/fs/UnixNativeDispatcher.c diff --git a/src/java.base/windows/native/libjava/MappedMemoryUtils.c b/src/java.base/windows/native/libjava/nio/MappedMemoryUtils.c similarity index 100% rename from src/java.base/windows/native/libjava/MappedMemoryUtils.c rename to src/java.base/windows/native/libjava/nio/MappedMemoryUtils.c diff --git a/src/java.base/windows/native/libjava/FileDispatcherImpl.c b/src/java.base/windows/native/libjava/nio/ch/FileDispatcherImpl.c similarity index 100% rename from src/java.base/windows/native/libjava/FileDispatcherImpl.c rename to src/java.base/windows/native/libjava/nio/ch/FileDispatcherImpl.c diff --git a/src/java.base/windows/native/libjava/FileKey.c b/src/java.base/windows/native/libjava/nio/ch/FileKey.c similarity index 100% rename from src/java.base/windows/native/libjava/FileKey.c rename to src/java.base/windows/native/libjava/nio/ch/FileKey.c diff --git a/src/java.base/windows/native/libjava/Iocp.c b/src/java.base/windows/native/libjava/nio/ch/Iocp.c similarity index 100% rename from src/java.base/windows/native/libjava/Iocp.c rename to src/java.base/windows/native/libjava/nio/ch/Iocp.c diff --git a/src/java.base/windows/native/libjava/WindowsAsynchronousFileChannelImpl.c b/src/java.base/windows/native/libjava/nio/ch/WindowsAsynchronousFileChannelImpl.c similarity index 100% rename from src/java.base/windows/native/libjava/WindowsAsynchronousFileChannelImpl.c rename to src/java.base/windows/native/libjava/nio/ch/WindowsAsynchronousFileChannelImpl.c diff --git a/src/java.base/windows/native/libjava/RegistryFileTypeDetector.c b/src/java.base/windows/native/libjava/nio/fs/RegistryFileTypeDetector.c similarity index 100% rename from src/java.base/windows/native/libjava/RegistryFileTypeDetector.c rename to src/java.base/windows/native/libjava/nio/fs/RegistryFileTypeDetector.c diff --git a/src/java.base/windows/native/libjava/WindowsNativeDispatcher.c b/src/java.base/windows/native/libjava/nio/fs/WindowsNativeDispatcher.c similarity index 100% rename from src/java.base/windows/native/libjava/WindowsNativeDispatcher.c rename to src/java.base/windows/native/libjava/nio/fs/WindowsNativeDispatcher.c From 7e8a02e39526847ca799e2b32846da24aa0a23c6 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Mon, 5 Aug 2024 15:58:24 -0700 Subject: [PATCH 3/6] 8337143: Removed dependency of libjava on headers in libnio/ch --- make/modules/java.base/Lib.gmk | 3 ++ make/modules/java.base/lib/CoreLibraries.gmk | 4 +-- make/modules/jdk.sctp/Lib.gmk | 4 +-- .../native/{libnio => libjava/nio}/ch/nio.h | 0 .../{libnio => libjava/nio}/ch/nio_util.h | 33 ------------------- .../native/libnio/ch/DatagramChannelImpl.c | 4 ++- .../unix/native/libnio/ch/InheritedChannel.c | 7 +++- src/java.base/unix/native/libnio/ch/Net.c | 4 ++- src/java.base/unix/native/libnio/ch/Net.h | 31 +++++++++++++++++ .../ch/UnixAsynchronousSocketChannelImpl.c | 3 +- .../unix/native/libnio/ch/UnixDomainSockets.c | 10 +++++- .../{libnio => libjava/nio}/ch/nio_util.h | 19 +---------- .../native/libnio/ch/DatagramDispatcher.c | 5 ++- .../native/libnio/ch/SocketDispatcher.c | 11 ++++++- .../native/libnio/ch/UnixDomainSockets.c | 8 ++++- 15 files changed, 83 insertions(+), 63 deletions(-) rename src/java.base/share/native/{libnio => libjava/nio}/ch/nio.h (100%) rename src/java.base/unix/native/{libnio => libjava/nio}/ch/nio_util.h (65%) create mode 100644 src/java.base/unix/native/libnio/ch/Net.h rename src/java.base/windows/native/{libnio => libjava/nio}/ch/nio_util.h (69%) diff --git a/make/modules/java.base/Lib.gmk b/make/modules/java.base/Lib.gmk index 3f4b1c73e89b9..807da45d9e36e 100644 --- a/make/modules/java.base/Lib.gmk +++ b/make/modules/java.base/Lib.gmk @@ -44,6 +44,8 @@ include lib/CoreLibraries.gmk $(eval $(call SetupJdkLibrary, BUILD_LIBNET, \ NAME := net, \ OPTIMIZATION := LOW, \ + EXTRA_HEADER_DIRS := \ + libjava/nio/ch, \ DISABLED_WARNINGS_gcc_net_util_md.c := format-nonliteral, \ DISABLED_WARNINGS_gcc_NetworkInterface.c := unused-function, \ DISABLED_WARNINGS_clang_net_util_md.c := format-nonliteral, \ @@ -74,6 +76,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \ NAME := nio, \ OPTIMIZATION := HIGH, \ EXTRA_HEADER_DIRS := \ + libjava/nio/ch \ libnio/ch \ libnio/fs \ libjvm, \ diff --git a/make/modules/java.base/lib/CoreLibraries.gmk b/make/modules/java.base/lib/CoreLibraries.gmk index 619ab5f3749b2..dbe31a89cc4c8 100644 --- a/make/modules/java.base/lib/CoreLibraries.gmk +++ b/make/modules/java.base/lib/CoreLibraries.gmk @@ -54,7 +54,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \ NAME := java, \ OPTIMIZATION := HIGH, \ EXTRA_HEADER_DIRS := \ - libnio/ch, \ + libjava/nio/ch, \ jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \ ProcessImpl_md.c_CFLAGS := $(VERSION_CFLAGS), \ java_props_md.c_CFLAGS := \ @@ -68,7 +68,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \ -framework CoreServices \ -framework Foundation \ -framework SystemConfiguration, \ - LIBS_windows := advapi32.lib ole32.lib shell32.lib version.lib mswsock.lib ws2_32.lib, \ + LIBS_windows := advapi32.lib mswsock.lib ole32.lib shell32.lib version.lib ws2_32.lib, \ )) TARGETS += $(BUILD_LIBJAVA) diff --git a/make/modules/jdk.sctp/Lib.gmk b/make/modules/jdk.sctp/Lib.gmk index a6d95a25154bd..4b160af555b31 100644 --- a/make/modules/jdk.sctp/Lib.gmk +++ b/make/modules/jdk.sctp/Lib.gmk @@ -36,8 +36,8 @@ ifeq ($(call isTargetOs, linux), true) EXTRA_HEADER_DIRS := \ $(call GetJavaHeaderDir, java.base) \ java.base:libjvm \ - java.base:libnio \ - java.base:libnio/ch, \ + java.base:libjava/nio \ + java.base:libjava/nio/ch, \ JDK_LIBS := java.base:libjava java.base:libnet, \ LIBS_linux := $(LIBDL) -lpthread, \ )) diff --git a/src/java.base/share/native/libnio/ch/nio.h b/src/java.base/share/native/libjava/nio/ch/nio.h similarity index 100% rename from src/java.base/share/native/libnio/ch/nio.h rename to src/java.base/share/native/libjava/nio/ch/nio.h diff --git a/src/java.base/unix/native/libnio/ch/nio_util.h b/src/java.base/unix/native/libjava/nio/ch/nio_util.h similarity index 65% rename from src/java.base/unix/native/libnio/ch/nio_util.h rename to src/java.base/unix/native/libjava/nio/ch/nio_util.h index 6cd3c858a7bd7..73aab03bd293d 100644 --- a/src/java.base/unix/native/libnio/ch/nio_util.h +++ b/src/java.base/unix/native/libjava/nio/ch/nio_util.h @@ -31,23 +31,6 @@ #include #include -/* Defines SO_REUSEPORT */ -#ifndef SO_REUSEPORT -#ifdef __linux__ -#define SO_REUSEPORT 15 -#elif defined(AIX) || defined(MACOSX) -#define SO_REUSEPORT 0x0200 -#else -#define SO_REUSEPORT 0 -#endif -#endif - -/* 2 bytes to allow for null at end of string and null at start of string - * for abstract name - */ -#define MAX_UNIX_DOMAIN_PATH_LEN \ - (int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2) - /* NIO utility procedures */ @@ -59,19 +42,3 @@ void setfdval(JNIEnv *env, jobject fdo, jint value); jint convertReturnVal(JNIEnv *env, jint n, jboolean reading); jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading); - -/* Defined in Net.c */ - -jint handleSocketError(JNIEnv *env, jint errorValue); - -/* Defined in UnixDomainSockets.c */ - -jbyteArray sockaddrToUnixAddressBytes(JNIEnv *env, - struct sockaddr_un *sa, - socklen_t len); - -jint unixSocketAddressToSockaddr(JNIEnv *env, - jbyteArray uaddr, - struct sockaddr_un *sa, - int *len); - diff --git a/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c b/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c index 902a816419db7..4f2ec0c74f179 100644 --- a/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c +++ b/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -41,6 +41,8 @@ #include "nio.h" #include "nio_util.h" +#include "Net.h" + #include "sun_nio_ch_DatagramChannelImpl.h" JNIEXPORT void JNICALL diff --git a/src/java.base/unix/native/libnio/ch/InheritedChannel.c b/src/java.base/unix/native/libnio/ch/InheritedChannel.c index d56625627930d..8f341c4e87810 100644 --- a/src/java.base/unix/native/libnio/ch/InheritedChannel.c +++ b/src/java.base/unix/native/libnio/ch/InheritedChannel.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -38,6 +38,11 @@ #include "sun_nio_ch_InheritedChannel.h" +/* Defined in UnixDomainSockets.c */ +extern jbyteArray sockaddrToUnixAddressBytes(JNIEnv *env, + struct sockaddr_un *sa, + socklen_t len); + JNIEXPORT void JNICALL Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla) { diff --git a/src/java.base/unix/native/libnio/ch/Net.c b/src/java.base/unix/native/libnio/ch/Net.c index 578c38a3b2fde..5dac58ba312f6 100644 --- a/src/java.base/unix/native/libnio/ch/Net.c +++ b/src/java.base/unix/native/libnio/ch/Net.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -42,6 +42,8 @@ #include "nio_util.h" #include "nio.h" +#include "Net.h" + #ifdef _AIX #include #include diff --git a/src/java.base/unix/native/libnio/ch/Net.h b/src/java.base/unix/native/libnio/ch/Net.h new file mode 100644 index 0000000000000..75b1acefecb46 --- /dev/null +++ b/src/java.base/unix/native/libnio/ch/Net.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jni.h" + + +/* Defined in Net.c */ + +jint handleSocketError(JNIEnv *env, jint errorValue); diff --git a/src/java.base/unix/native/libnio/ch/UnixAsynchronousSocketChannelImpl.c b/src/java.base/unix/native/libnio/ch/UnixAsynchronousSocketChannelImpl.c index 6aa4adbf5d9d1..cdad353cd9749 100644 --- a/src/java.base/unix/native/libnio/ch/UnixAsynchronousSocketChannelImpl.c +++ b/src/java.base/unix/native/libnio/ch/UnixAsynchronousSocketChannelImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -34,6 +34,7 @@ #include "nio_util.h" #include "nio.h" +#include "Net.h" JNIEXPORT void JNICALL Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect(JNIEnv *env, diff --git a/src/java.base/unix/native/libnio/ch/UnixDomainSockets.c b/src/java.base/unix/native/libnio/ch/UnixDomainSockets.c index 73db22a917620..092d03e484fbd 100644 --- a/src/java.base/unix/native/libnio/ch/UnixDomainSockets.c +++ b/src/java.base/unix/native/libnio/ch/UnixDomainSockets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -41,6 +41,14 @@ #include "nio_util.h" #include "nio.h" +#include "Net.h" + +/* 2 bytes to allow for null at end of string and null at start of string + * for abstract name + */ +#define MAX_UNIX_DOMAIN_PATH_LEN \ + (int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2) + /* Subtle platform differences in how unnamed sockets (empty path) * are returned from getsockname() */ diff --git a/src/java.base/windows/native/libnio/ch/nio_util.h b/src/java.base/windows/native/libjava/nio/ch/nio_util.h similarity index 69% rename from src/java.base/windows/native/libnio/ch/nio_util.h rename to src/java.base/windows/native/libjava/nio/ch/nio_util.h index e6034b2787d2b..a9d5381a5b0d4 100644 --- a/src/java.base/windows/native/libnio/ch/nio_util.h +++ b/src/java.base/windows/native/libjava/nio/ch/nio_util.h @@ -29,23 +29,13 @@ #include "jni.h" -/** - * The maximum buffer size for WSASend/WSARecv. Microsoft recommendation for - * blocking operations is to use buffers no larger than 64k. We need the - * maximum to be less than 128k to support asynchronous close on Windows - * Server 2003 and newer editions of Windows. - */ -#define MAX_BUFFER_SIZE ((128*1024)-1) - -#define MAX_UNIX_DOMAIN_PATH_LEN \ - (int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2) +/* Defined in IOUtil.c */ JNIEXPORT jint fdval(JNIEnv *env, jobject fdo); JNIEXPORT void setfdval(JNIEnv *env, jobject fdo, jint val); JNIEXPORT jlong handleval(JNIEnv *env, jobject fdo); JNIEXPORT jint convertReturnVal(JNIEnv *env, jint n, jboolean r); JNIEXPORT jlong convertLongReturnVal(JNIEnv *env, jlong n, jboolean r); -jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd); #ifdef _WIN64 @@ -63,10 +53,3 @@ struct iovec { #endif -/* Defined in UnixDomainSockets.c */ - -jbyteArray sockaddrToUnixAddressBytes(JNIEnv *env, struct sockaddr_un *sa, socklen_t len); - -jint unixSocketAddressToSockaddr(JNIEnv *env, jbyteArray uaddr, - struct sockaddr_un *sa, int *len); - diff --git a/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c b/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c index 8d3a14ffd91bb..1dbff362c9df4 100644 --- a/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c +++ b/src/java.base/windows/native/libnio/ch/DatagramDispatcher.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -41,6 +41,9 @@ * DatagramDispatcher.c */ +/* Defined in DatagramChannelImpl.c */ +extern jboolean purgeOutstandingICMP(JNIEnv *env, jclass clazz, jint fd); + JNIEXPORT jint JNICALL Java_sun_nio_ch_DatagramDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) diff --git a/src/java.base/windows/native/libnio/ch/SocketDispatcher.c b/src/java.base/windows/native/libnio/ch/SocketDispatcher.c index ff74a0abf10af..02b14d8a09efc 100644 --- a/src/java.base/windows/native/libnio/ch/SocketDispatcher.c +++ b/src/java.base/windows/native/libnio/ch/SocketDispatcher.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -39,6 +39,15 @@ * SocketDispatcher.c */ +/** + * The maximum buffer size for WSASend/WSARecv. Microsoft recommendation for + * blocking operations is to use buffers no larger than 64k. We need the + * maximum to be less than 128k to support asynchronous close on Windows + * Server 2003 and newer editions of Windows. + */ +#define MAX_BUFFER_SIZE ((128*1024)-1) + + JNIEXPORT jint JNICALL Java_sun_nio_ch_SocketDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) diff --git a/src/java.base/windows/native/libnio/ch/UnixDomainSockets.c b/src/java.base/windows/native/libnio/ch/UnixDomainSockets.c index bc185b3aa185b..8b04ea0bc9660 100644 --- a/src/java.base/windows/native/libnio/ch/UnixDomainSockets.c +++ b/src/java.base/windows/native/libnio/ch/UnixDomainSockets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -38,6 +38,12 @@ #include "sun_nio_ch_Net.h" #include "sun_nio_ch_PollArrayWrapper.h" +/* 2 bytes to allow for null at end of string and null at start of string + * for abstract name + */ +#define MAX_UNIX_DOMAIN_PATH_LEN \ + (int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2) + /* The winsock provider ID of the Microsoft AF_UNIX implementation */ static GUID MS_PROVIDER_ID = {0xA00943D9,0x9C2E,0x4633,{0x9B,0x59,0,0x57,0xA3,0x16,0x09,0x94}}; From f57b6f13e9f375bfd2e8a05afd2b900a4d42285e Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 9 Aug 2024 10:39:57 -0700 Subject: [PATCH 4/6] 8337143: Remove loading libnet from Inet6AddressImpl; delete commented out #include in Windows IOUtil.c --- src/java.base/share/classes/java/net/Inet6AddressImpl.java | 6 +----- src/java.base/windows/native/libjava/IOUtil.c | 1 - .../InetAddress/java.base/java/net/NullCharInHostname.java | 6 +++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/java.base/share/classes/java/net/Inet6AddressImpl.java b/src/java.base/share/classes/java/net/Inet6AddressImpl.java index f576227b30b24..87fefbe37ba32 100644 --- a/src/java.base/share/classes/java/net/Inet6AddressImpl.java +++ b/src/java.base/share/classes/java/net/Inet6AddressImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2021, 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 @@ -148,8 +148,4 @@ public synchronized InetAddress loopbackAddress() { private InetAddress anyLocalAddress; private InetAddress loopbackAddress; - - static { - jdk.internal.loader.BootLoader.loadLibrary("net"); - } } diff --git a/src/java.base/windows/native/libjava/IOUtil.c b/src/java.base/windows/native/libjava/IOUtil.c index 01d9532c724ac..946065d31c325 100644 --- a/src/java.base/windows/native/libjava/IOUtil.c +++ b/src/java.base/windows/native/libjava/IOUtil.c @@ -34,7 +34,6 @@ #include "java_lang_Long.h" #include "nio.h" #include "nio_util.h" -/* #include "net_util.h" */ #include "sun_nio_ch_IOUtil.h" /* field id for jlong 'handle' in java.io.FileDescriptor used for file fds */ diff --git a/test/jdk/java/net/InetAddress/java.base/java/net/NullCharInHostname.java b/test/jdk/java/net/InetAddress/java.base/java/net/NullCharInHostname.java index a78c41398ce51..84d3e58b130ed 100644 --- a/test/jdk/java/net/InetAddress/java.base/java/net/NullCharInHostname.java +++ b/test/jdk/java/net/InetAddress/java.base/java/net/NullCharInHostname.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -27,6 +27,10 @@ public class NullCharInHostname { public static void main(String[] args) { + // Manually load the "net" library which is needed for Inet6AddressImpl. + // In normal scenarios this library is loaded automatically. + jdk.internal.loader.BootLoader.loadLibrary("net"); + var name = "foo\u0000bar"; System.out.println("file.encoding = " + System.getProperty("file.encoding")); System.out.println("native.encoding = " + System.getProperty("native.encoding")); From 853d34912dee7523a291536743158f6b8ed74378 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Wed, 11 Sep 2024 12:34:22 -0700 Subject: [PATCH 5/6] 8337143: Clean up to address reviewer comments --- make/modules/java.base/Lib.gmk | 2 +- src/java.base/share/classes/sun/nio/ch/IOUtil.java | 4 +++- src/java.base/unix/classes/sun/nio/ch/NativeThread.java | 1 - src/java.base/unix/native/libnio/ch/NIOUtil.c | 2 +- .../sun/net/www/protocol/http/ntlm/NTLMAuthentication.java | 4 +++- src/java.base/windows/classes/sun/nio/ch/Iocp.java | 3 +-- .../sun/nio/ch/WindowsAsynchronousFileChannelImpl.java | 4 ---- .../windows/classes/sun/nio/fs/WindowsNativeDispatcher.java | 1 - src/java.base/windows/native/libnio/ch/NIOUtil.c | 4 ---- 9 files changed, 9 insertions(+), 16 deletions(-) diff --git a/make/modules/java.base/Lib.gmk b/make/modules/java.base/Lib.gmk index 094c96de7d42a..b73618f98d044 100644 --- a/make/modules/java.base/Lib.gmk +++ b/make/modules/java.base/Lib.gmk @@ -88,7 +88,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \ LIBS_macosx := \ -framework CoreFoundation \ -framework CoreServices, \ - LIBS_windows := advapi32.lib mswsock.lib ws2_32.lib, \ + LIBS_windows := advapi32.lib ws2_32.lib, \ )) TARGETS += $(BUILD_LIBNIO) diff --git a/src/java.base/share/classes/sun/nio/ch/IOUtil.java b/src/java.base/share/classes/sun/nio/ch/IOUtil.java index cc9f62911727b..cb27b14c179b5 100644 --- a/src/java.base/share/classes/sun/nio/ch/IOUtil.java +++ b/src/java.base/share/classes/sun/nio/ch/IOUtil.java @@ -570,11 +570,13 @@ static long bufferAddress(ByteBuffer buf) { private static native void initIDs(); /** - * Used to trigger loading of native libraries + * Used to trigger initialization of static final fields and of + * FileDescriptor field IDs in the native layer */ public static void load() { } static { + // Initialize FileDescriptor field IDs in the native layer initIDs(); IOV_MAX = iovMax(); diff --git a/src/java.base/unix/classes/sun/nio/ch/NativeThread.java b/src/java.base/unix/classes/sun/nio/ch/NativeThread.java index 6e585be2fb0f9..5a72357472fe8 100644 --- a/src/java.base/unix/classes/sun/nio/ch/NativeThread.java +++ b/src/java.base/unix/classes/sun/nio/ch/NativeThread.java @@ -93,7 +93,6 @@ static boolean isVirtualThread(long tid) { private static native void init(); static { - IOUtil.load(); init(); } diff --git a/src/java.base/unix/native/libnio/ch/NIOUtil.c b/src/java.base/unix/native/libnio/ch/NIOUtil.c index b9d3d3060e676..fd2c3c31680b0 100644 --- a/src/java.base/unix/native/libnio/ch/NIOUtil.c +++ b/src/java.base/unix/native/libnio/ch/NIOUtil.c @@ -31,7 +31,7 @@ #include "jni_util.h" #include "jvm.h" #include "jlong.h" -#include "sun_nio_ch_IOUtil.h" +#include "sun_nio_ch_NIOUtil.h" #include "java_lang_Integer.h" #include "java_lang_Long.h" #include "nio.h" diff --git a/src/java.base/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java b/src/java.base/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java index d3b60daad7440..a6d0dabb46083 100644 --- a/src/java.base/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java +++ b/src/java.base/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -68,6 +68,8 @@ enum TransparentAuth { private static final TransparentAuth authMode; static { + jdk.internal.loader.BootLoader.loadLibrary("net"); + Properties props = GetPropertyAction.privilegedGetProperties(); defaultDomain = props.getProperty("http.auth.ntlm.domain", "domain"); String ntlmCacheProp = props.getProperty("jdk.ntlm.cache", "true"); diff --git a/src/java.base/windows/classes/sun/nio/ch/Iocp.java b/src/java.base/windows/classes/sun/nio/ch/Iocp.java index 9a6a5c66b4432..58932356db0a5 100644 --- a/src/java.base/windows/classes/sun/nio/ch/Iocp.java +++ b/src/java.base/windows/classes/sun/nio/ch/Iocp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -433,7 +433,6 @@ private static native void postQueuedCompletionStatus(long completionPort, private static native String getErrorMessage(int error); static { - IOUtil.load(); initIDs(); } } diff --git a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java index 15ae425850ed6..d146db15a4105 100644 --- a/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java @@ -745,8 +745,4 @@ private static native int writeFile(long handle, long address, int len, private static native int lockFile(long handle, long position, long size, boolean shared, long overlapped) throws IOException; - - static { - IOUtil.load(); - } } diff --git a/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java b/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java index 5e923aa2a0d27..7248a17a39fab 100644 --- a/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java +++ b/src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java @@ -1094,7 +1094,6 @@ static NativeBuffer asNativeBuffer(String s) throws WindowsException { private static native void initIDs(); static { - jdk.internal.loader.BootLoader.loadLibrary("net"); initIDs(); } diff --git a/src/java.base/windows/native/libnio/ch/NIOUtil.c b/src/java.base/windows/native/libnio/ch/NIOUtil.c index b5b14a7865f23..ee8e763cb06c7 100644 --- a/src/java.base/windows/native/libnio/ch/NIOUtil.c +++ b/src/java.base/windows/native/libnio/ch/NIOUtil.c @@ -37,10 +37,6 @@ #include "net_util.h" #include "sun_nio_ch_NIOUtil.h" -JNIEXPORT jboolean JNICALL -Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed -(JNIEnv *env, jclass clazz, jbyteArray randArray); - /************************************************************** * NIOUtil.c */ From b54b1683813a977e0a4b0ac229ade6ee033c8b1a Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 13 Sep 2024 13:35:54 -0700 Subject: [PATCH 6/6] 8337143: Minor makefile tweak --- make/modules/java.base/lib/CoreLibraries.gmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make/modules/java.base/lib/CoreLibraries.gmk b/make/modules/java.base/lib/CoreLibraries.gmk index a32247ef9c8a1..40046144888f4 100644 --- a/make/modules/java.base/lib/CoreLibraries.gmk +++ b/make/modules/java.base/lib/CoreLibraries.gmk @@ -65,7 +65,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \ DISABLED_WARNINGS_clang_TimeZone_md.c := unused-variable, \ JDK_LIBS := libjvm, \ LIBS_linux := $(LIBDL) -lpthread, \ - LIBS_aix := $(LIBDL) $(LIBM),\ + LIBS_aix := $(LIBDL) $(LIBM), \ LIBS_macosx := \ -framework CoreFoundation \ -framework CoreServices \