Skip to content

8337143: (fc, fs) Move filesystem-related native objects from libnio to libjava #20317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions make/modules/java.base/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -74,6 +76,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
NAME := nio, \
OPTIMIZATION := HIGH, \
EXTRA_HEADER_DIRS := \
libjava/nio/ch \
libnio/ch \
libnio/fs \
libjvm, \
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 @@ -53,19 +53,22 @@ 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, \
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 @@ -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, \
))
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 @@ -50,7 +50,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 @@ -80,7 +80,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 @@ -83,7 +83,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 @@ -289,7 +289,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 @@ -301,7 +301,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 @@ -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);
}
}
}
Expand All @@ -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;
Expand All @@ -1276,7 +1276,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 @@ -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
Expand Down Expand Up @@ -2089,6 +2089,6 @@ private static native int send0(FileDescriptor fd, long address, int len,
throws IOException;

static {
IOUtil.load();
NIOUtil.load();
}
}
42 changes: 3 additions & 39 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,22 @@ 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
*/
public static void load() { }

static {
jdk.internal.loader.BootLoader.loadLibrary("net");
jdk.internal.loader.BootLoader.loadLibrary("nio");
initIDs();

IOV_MAX = iovMax();
Expand Down
Loading