-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8355080: java.base/jdk.internal.foreign.SystemLookup.find() doesn't work on static JDK #24801
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
Conversation
… on both regular and static JDK.
|
👋 Welcome back jiangli! A progress list of the required criteria for merging this PR into |
|
@jianglizhou This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 144 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@jianglizhou The following labels will be automatically applied to this pull request:
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. |
Webrevs
|
liach
left a comment
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.
sysLookup does look much cleaner compared to jdkLibraryPath.
src/java.base/share/classes/jdk/internal/foreign/SystemLookup.java
Outdated
Show resolved
Hide resolved
…java Thanks. I used `jdk.internal.loader.NativeLibraries` as a quick change before adding adding import. I neglected to to clean up that part. Co-authored-by: Chen Liang <liach@openjdk.org>
@liach Thanks for the quick review! |
| // Adding at least one #include removes unwanted warnings on some platforms. | ||
| #include <stdlib.h> | ||
|
|
||
| #include <jni.h> |
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.
Do we need this include? DEF_STATIC_JNI_OnLoad is defined by jni_util.h, which should include jni.h?
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.
Do we need this include? DEF_STATIC_JNI_OnLoad is defined by jni_util.h, which should include jni.h?
Removed, thanks!
- Remove '#include <jni.h>'.
|
|
|
|
||
| @SuppressWarnings("restricted") | ||
| private static SymbolLookup sysLookup() { | ||
| NativeLibraries libs = NativeLibraries.newInstance(null); |
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.
I would consult @mcimadamore or @JornVernee look at this for the native function call permission requirements.
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.
@mcimadamore or @JornVernee Can you help take a look of this? Thanks!
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.
Unfortunately, I believe both of them are on vacation, yet they have the required expertise to review this PR. You might need to wait a bit, sorry!
|
Hello Jiangli, if I understand this change correctly, then this is forcing a non-JNI library to be a JNI library for it to work on static JDK. Is that a requirement for static JDK builds? Or is it just a convenient way to use existing library loading mechanism in the Are there other similar libraries shipped in JAVA_HOME/lib that would require a similar change/treatment? |
Hi @jaikiran Good questions. I kind of expected questions like those might be raised with the addition of The original static built-in JNI library support in JDK was added by JEP 178 (https://openjdk.org/jeps/178) "Statically-Linked JNI Libraries" work. It's on top of the JNI library support. Both spec & implementation expected You are right that this PR change turns the
Yes. Our current static/hermetic work has found any missing |
|
The changes here look good. Essentially, if The loaded library is associated with the boot classloader. This could be problematic, in principle. However, since the requests to Having to upgrade to JNI is a bit sad -- although I get that it is required as a workaround for now. For the longer term I'd prefer a better way to integrate static lookups in the FFM API. For instance, all |
|
/reviewers 2 |
|
@mcimadamore |
mcimadamore
left a comment
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.
Looks good to me -- but also risky. I'd prefer if @JornVernee could also take a look.
I remember this wasn't quite as elegant on Windows, but I suppose there is already some solution in place to look up symbols that are statically linked into the same executable? |
|
I had a look at the implementation, and see how it works now. The JNI_OnLoad_XXX function is essentially being used as a marker to indicate that this library was statically linked into the VM binary, so we can create a I think the current solution is probably fine. I think alternatively we could keep track of a table with statically linked libraries to determine where/how symbols should be looked up for a particular library. Or, the symbol doesn't necessarily have to be JNI_OnLoad_XXX, but could be some other, non-JNI-specific, marker symbol. |
With the current effort for enhancing/completing static JDK support, the system is able to detect if it's running on static using checks like jdk/src/hotspot/share/runtime/os.cpp Line 516 in 2f84480
load_zip_library retrieve the os::get_default_process_handle without doing dlopen (e.g. on Linux) to load the native libraries. For longer term, we can make the solution more coherent/general for handling the various cases in the system.
|
|
@mcimadamore @JornVernee Thanks for the in-depth thoughts and reviews! |
|
/integrate |
|
Going to push as commit acd93df.
Your commit was automatically rebased without conflicts. |
|
@jianglizhou Pushed as commit acd93df. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
I'm not quite sure what you mean that "upgrades" the library to a "JNI library"? Nor why this is sad? What we do is that we add a marker to identify the library as a built-in library. The name of the marker contains the letters |
JNI libraries are more restrictive than non-JNI libraries, as JNI libraries can only be loaded by a single class loader. The lifetime of the class loader is re-used as the lifetime of the library, and tells us when OnLoad and OnUnload should be called. This is in particular not needed in this case, and gets us away from the loaded-by-single-class-loader restricted, but as Maurizio says, making this library a JNI library is probably okay, since this class should always be loaded by the boot loader. |
|
This was news to me. I'm thinking about what this means in terms of the static build, where all native JDK libraries are "loaded" as soon as the application starts executing. Do we have native libraries in the JDK that are not loaded by the boot loader? If so, have we introduced some corner case effects by marking them with the static JNI symbol? 🤔 |
There are few, e.g. java.security.jgss, jdk.security.auth and jdk.crypto.cryptoki are mapped to the platform class loader, and jdk.attach mapped to the application class loader. |
|
@magicus For existing JDK JNI native libraries, I think adding The reason why boot loader question/consideration brought up in this thread was because |
Please review this PR that changes to use
NativeLibraries.loadLibrary()for loading thelibsyslookupinjdk.internal.foreign.SystemLookupclass.NativeLibraries.loadLibrary()handles both the shared library and (static) built-in library loading properly. Onstatic-jdk, callingNativeLibraries.loadLibrary()forsystlookuplibrary can find the built-in library by looking up usingJNI_OnLoad_syslookup. The current change addsDEF_STATIC_JNI_OnLoadin syslookup.c (in shared, windows and aix versions) for that purpose.In addition to GHA testing, I tested the change on static-jdk with jdk tier1 tests on linux-x64 locally. All java/foreign/* jdk tier1 tests pass with the change. Without the change, there are about 60 java/foreign/* jdk tier1 tests fail on static-jdk.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24801/head:pull/24801$ git checkout pull/24801Update a local copy of the PR:
$ git checkout pull/24801$ git pull https://git.openjdk.org/jdk.git pull/24801/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24801View PR using the GUI difftool:
$ git pr show -t 24801Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24801.diff
Using Webrev
Link to Webrev Comment