Skip to content
Open
3 changes: 2 additions & 1 deletion make/modules/java.base/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
NAME := nio, \
OPTIMIZATION := HIGH, \
EXTRA_HEADER_DIRS := \
libjava/nio/ch \
libnio/ch \
libnio/fs \
libjvm, \
Expand All @@ -86,7 +87,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)
Expand Down
7 changes: 5 additions & 2 deletions make/modules/java.base/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,23 @@ endif
$(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
NAME := java, \
OPTIMIZATION := HIGH, \
EXTRA_HEADER_DIRS := \
libjava/nio/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, \
DISABLED_WARNINGS_clang_TimeZone_md.c := unused-variable, \
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 mswsock.lib ole32.lib shell32.lib version.lib ws2_32.lib, \
))

TARGETS += $(BUILD_LIBJAVA)
Expand Down
4 changes: 2 additions & 2 deletions make/modules/jdk.sctp/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,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), \
))
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/linux/classes/sun/nio/ch/EPoll.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/linux/classes/sun/nio/ch/EPollPort.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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;
Expand Down Expand Up @@ -79,7 +79,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);
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/linux/classes/sun/nio/ch/EventFD.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,7 +49,7 @@ void set() throws IOException {
}

void reset() throws IOException {
IOUtil.drain(efd);
NIOUtil.drain(efd);
}

void close() throws IOException {
Expand All @@ -68,6 +68,6 @@ void close() throws IOException {
private static native int set0(int efd) throws IOException;

static {
IOUtil.load();
NIOUtil.load();
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,7 +58,6 @@ static native long transferFrom0(FileDescriptor src, FileDescriptor dst,
static native void init0();

static {
IOUtil.load();
init0();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/java.base/macosx/classes/sun/nio/ch/KQueue.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/macosx/classes/sun/nio/ch/KQueuePort.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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) {
Expand Down Expand Up @@ -323,7 +323,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);
}
Expand All @@ -335,7 +335,7 @@ public Selector wakeup() {

private void clearInterrupt() throws IOException {
synchronized (interruptLock) {
IOUtil.drain(fd0);
NIOUtil.drain(fd0);
interruptTriggered = false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,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);
}
}
}
Expand All @@ -1157,7 +1157,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;
Expand All @@ -1174,7 +1174,7 @@ private void configureSocketNonBlocking() throws IOException {
if (!forcedNonBlocking) {
synchronized (stateLock) {
ensureOpen();
IOUtil.configureBlocking(fd, false);
NIOUtil.configureBlocking(fd, false);
forcedNonBlocking = true;
}
}
Expand Down Expand Up @@ -1412,7 +1412,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
Expand Down Expand Up @@ -1944,6 +1944,6 @@ private static native int send0(FileDescriptor fd, long address, int len,
throws IOException;

static {
IOUtil.load();
NIOUtil.load();
}
}
46 changes: 6 additions & 40 deletions src/java.base/share/classes/sun/nio/ch/IOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,58 +559,24 @@ 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
* Used to trigger initialization of static final fields and of
* FileDescriptor field IDs in the native layer
*/
public static void load() { }

static {
jdk.internal.loader.BootLoader.loadLibrary("net");
jdk.internal.loader.BootLoader.loadLibrary("nio");
// Initialize FileDescriptor field IDs in the native layer
initIDs();

IOV_MAX = iovMax();
Expand Down
Loading