-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
112fcbc
panamization of kqueue
DarraghClarke 5467408
merge master into branch
DarraghClarke 4fd27e9
removed unrelated change
DarraghClarke 0410db7
implementing feedback
DarraghClarke 109a656
Performance
DarraghClarke 0e39ef2
small refactoring
DarraghClarke 8d9a47a
general cleanup
DarraghClarke 4878d55
feedback
DarraghClarke e220788
implementing feedback, adding missing errno checks, cleanup
DarraghClarke 9de0789
moved repeating code into own method
DarraghClarke c66200c
merged master into branch
DarraghClarke cc5f558
fixed copyright header
DarraghClarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/java.base/macosx/classes/jdk/internal/ffi/generated/ErrnoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (c) 2024, 2025, 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 jdk.internal.ffi.generated; | ||
|
|
||
| import jdk.internal.ffi.generated.errno.errno_h; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.foreign.Arena; | ||
| import java.lang.foreign.MemorySegment; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| // Errno utility for macosx platform | ||
| public final class ErrnoUtils { | ||
| private ErrnoUtils() { | ||
| } | ||
|
|
||
| private static final long ERRNO_STRING_HOLDER_ARRAY_SIZE = 256L; | ||
|
|
||
| public static IOException IOExceptionWithErrnoString(int errno, String message) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming is a bit confusing here, minimally need a method description so we can quickly understand the relationship between "message" and strerror(errno). |
||
| try (Arena arena = Arena.ofConfined()) { | ||
| MemorySegment buf = arena.allocate(ERRNO_STRING_HOLDER_ARRAY_SIZE); | ||
| if (errno_h.strerror_r(errno, buf, ERRNO_STRING_HOLDER_ARRAY_SIZE) == 0) { | ||
| String errnoMsg = buf.getString(0, StandardCharsets.UTF_8); | ||
| return new IOException(message + " " + errnoMsg); | ||
| } else { | ||
| // failed to convert errno to string - output errno value | ||
| return new IOException(message + " Errno: " + errno); | ||
| } | ||
| } | ||
| } | ||
| } | ||
111 changes: 111 additions & 0 deletions
111
src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/errno_h.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| // Generated by jextract | ||
|
|
||
| package jdk.internal.ffi.generated.errno; | ||
|
|
||
| import jdk.internal.ffi.util.FFMUtils; | ||
|
|
||
| import java.lang.invoke.*; | ||
| import java.lang.foreign.*; | ||
|
|
||
| @SuppressWarnings("restricted") | ||
| public class errno_h { | ||
|
|
||
| errno_h() { | ||
| // Should not be called directly | ||
| } | ||
|
|
||
| private static final int EINTR = (int)4L; | ||
| /** | ||
| * {@snippet lang=c : | ||
| * #define EINTR 4 | ||
| * } | ||
| */ | ||
| public static int EINTR() { | ||
| return EINTR; | ||
| } | ||
|
|
||
| private static class strerror_r { | ||
| public static final FunctionDescriptor DESC = FunctionDescriptor.of( | ||
| FFMUtils.C_INT, | ||
| FFMUtils.C_INT, | ||
| FFMUtils.C_POINTER, | ||
| FFMUtils.C_LONG | ||
| ); | ||
|
|
||
| public static final MemorySegment ADDR = FFMUtils.findOrThrow("strerror_r"); | ||
|
|
||
| public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); | ||
| } | ||
|
|
||
| /** | ||
| * Function descriptor for: | ||
| * {@snippet lang=c : | ||
| * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) | ||
| * } | ||
| */ | ||
| public static FunctionDescriptor strerror_r$descriptor() { | ||
| return strerror_r.DESC; | ||
| } | ||
|
|
||
| /** | ||
| * Downcall method handle for: | ||
| * {@snippet lang=c : | ||
| * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) | ||
| * } | ||
| */ | ||
| public static MethodHandle strerror_r$handle() { | ||
| return strerror_r.HANDLE; | ||
| } | ||
|
|
||
| /** | ||
| * Address for: | ||
| * {@snippet lang=c : | ||
| * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) | ||
| * } | ||
| */ | ||
| public static MemorySegment strerror_r$address() { | ||
| return strerror_r.ADDR; | ||
| } | ||
|
|
||
| /** | ||
| * {@snippet lang=c : | ||
| * int strerror_r(int __errnum, char *__strerrbuf, size_t __buflen) | ||
| * } | ||
| */ | ||
| public static int strerror_r(int __errnum, MemorySegment __strerrbuf, long __buflen) { | ||
| var mh$ = strerror_r.HANDLE; | ||
| try { | ||
| if (FFMUtils.TRACE_DOWNCALLS) { | ||
| FFMUtils.traceDowncall("strerror_r", __errnum, __strerrbuf, __buflen); | ||
| } | ||
| return (int)mh$.invokeExact(__errnum, __strerrbuf, __buflen); | ||
| } catch (Throwable ex$) { | ||
| throw new AssertionError("should not reach here", ex$); | ||
| } | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
src/java.base/macosx/classes/jdk/internal/ffi/generated/errno/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (c) 2024, 2025, 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Defines native structures for errno APIs. | ||
| * Generated with the following jextract command: | ||
| * {@snippet lang = "Shell Script": | ||
| * | ||
| * HEADER_NAME=errno.h | ||
| * echo "#include <errno.h>" > $HEADER_NAME | ||
| * echo "#include <string.h>" >> $HEADER_NAME | ||
| * | ||
| * jextract --target-package jdk.internal.ffi.generated.errno \ | ||
| * --include-constant EINTR \ | ||
| * --include-function strerror_r \ | ||
| * $HEADER_NAME | ||
| * } | ||
| * | ||
| * After generation of native bindings, the layouts for the C builtin layouts and other | ||
| * variables/methods not specific to a component area are moved to the {@code BindingUtils} class | ||
| * for future reusability. | ||
| * | ||
| */ | ||
|
|
||
| package jdk.internal.ffi.generated.errno; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using jdk.internal.ffi.generated.** for jextract generated code is good. I'm not sure this is the right place for ErrnoUtils.