Skip to content

8360025: (se) Convert kqueue Selector Implementation to use FFM APIs #25546

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 8 commits into
base: master
Choose a base branch
from

Conversation

DarraghClarke
Copy link
Contributor

@DarraghClarke DarraghClarke commented May 30, 2025

This PR aims to Panamize the Java Kqueue implementation, This is based on the work that was previously shared in #22307 , The main change since then is that this branch takes advantage of the changes made in #25043 to allow for better performance during errno handling.

These changes feature a lot of Jextract generated files, though alterations have been made in relation to Errno handling and performance improvements.

I will update this description soon to include performance metrics on a few microbenchmarks, though currently it's roughly 2% to 3% slower with the changes, which is somewhat expected, though there are still a few ideas of possible performance improvements that could be tried. Any suggestions or comments in that area are more than welcome however.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Error

 ⚠️ Found copyright format issue for oracle in [src/java.base/macosx/classes/jdk/internal/ffi/generated/ErrnoUtils.java]

Issue

  • JDK-8360025: (se) Convert kqueue Selector Implementation to use FFM APIs (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25546/head:pull/25546
$ git checkout pull/25546

Update a local copy of the PR:
$ git checkout pull/25546
$ git pull https://git.openjdk.org/jdk.git pull/25546/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25546

View PR using the GUI difftool:
$ git pr show -t 25546

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25546.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 30, 2025

👋 Welcome back dclarke! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 30, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented May 30, 2025

@DarraghClarke The following labels will be automatically applied to this pull request:

  • core-libs
  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added nio nio-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels May 30, 2025
* questions.
*/

package jdk.internal.ffi.util;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is some general ffm utils for using ffm, you can put it in jdk.internal.foreign.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are only intended to be used for "panamization" and are not for general use. So, this is the reason we propose to have them here. But maybe some of them might be of general interest?


// filters
static final int EVFILT_READ = -1;
static final int EVFILT_WRITE = -2;
static final int EVFILT_READ = kqueue_h.EVFILT_READ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove these constants and use kqueue_h constants directly?

public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE;
public static final AddressLayout C_POINTER = ValueLayout.ADDRESS
.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, JAVA_BYTE));
public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG;
Copy link
Contributor

@minborg minborg Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is int on Windows. So, we could perhaps use Linker.nativeLinker().canonicalLayouts().get("long") here? "size_t" and "wchar_t" are other canonical layouts that may differ across platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea and would allow us to make BindingUtils shared,
Though I wonder if it's best to move BindingUtils to be shared, or if its worth merging it into FFMUtils. I'd favour the second option

@minborg
Copy link
Contributor

minborg commented Jun 19, 2025

Some of the files are missing a blank line at the end.

@@ -34,13 +38,13 @@ class KQueuePoller extends Poller {
private final int kqfd;
private final int filter;
private final int maxEvents;
private final long address;
private final MemorySegment pollArrayRegions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a poll array so I think very confusing to see "Regions" in the name.

result = kqueue_h.kevent(
kqfd, keventMS, 1, NULL,
0, NULL);
} while ((result == KQUEUE_ERROR_VALUE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only case where the syscall should be restarted is EINTR.

if (result == -errno_h.EINTR()) {
return IOStatus.INTERRUPTED;
} else {
throw new IOException("kqueue_poll failed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syscall is "kqueue" rather than "kqueue_poll".

@DarraghClarke DarraghClarke marked this pull request as ready for review July 8, 2025 11:04
@DarraghClarke DarraghClarke changed the title WIP: Panamize KQueue selector implementation JDK-8360025: (se) Convert kqueue Selector Implementation to use FFM APIs Jul 8, 2025
@openjdk openjdk bot changed the title JDK-8360025: (se) Convert kqueue Selector Implementation to use FFM APIs 8360025: (se) Convert kqueue Selector Implementation to use FFM APIs Jul 8, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 8, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 8, 2025

Webrevs

@AlanBateman
Copy link
Contributor

/reviewer 2

@openjdk
Copy link

openjdk bot commented Jul 8, 2025

@AlanBateman Only the author (@DarraghClarke) is allowed to issue the reviewer command.

@AlanBateman
Copy link
Contributor

I plan to review this but may be a week or two before I can get to it.

@AlanBateman
Copy link
Contributor

/reviewers 2

@openjdk
Copy link

openjdk bot commented Jul 8, 2025

@AlanBateman
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org nio nio-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants