-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8346394: Bundled freetype library needs to have JNI_OnLoad for static builds #22791
Conversation
👋 Welcome back ihse! A progress list of the required criteria for merging this PR into |
@magicus 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 8 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
If I understand correctly, this is a "new" requirement because of the need to support static builds ? Seems odd if the library doesn't actually use JNI. And what if the JDK is trying to load a library that is not part of the JDK ?
We bundle it on mac too .. |
Do not integrate this until I have approved. |
Yes.
So what this means is that the code executing
Then it will not find the special marker method, and assume it will have to load it normally, as it then is a user-supplied or 3rd party dll.
Oh, that's right. But the macOS bundling is done purely at link time, so we do not have this problem, as far as I can tell. |
I see (I think) |
/integrate |
Going to push as commit f3e2f88.
Your commit was automatically rebased without conflicts. |
A bit late but why do we presume that just because this library is bundled that it has to be part of the static image? This static build stuff continues to leave me with a "bad taste in my mouth". |
No? The library can be bundled as a dynamic library as well, that has always been and still is the case.
I agree that the static build stuff is still not up to normal JDK standards. It was originally "tacked on" from the side, with a lot of kludges to get it to work. I am trying to work through these problematic cases and clean up the code. This current kludge is that there is a lot of code doing System.loadLibrary(someInternalLibrary), and for static builds these calls should really be a no-op. But how do you know? The solution chosen by the original implementors of static builds was to look for a symbol JNI_OnLoad_someInternalLibrary, and if it was found, skip loading the dynamic library. It can certainly be discussed if this was a good way of doing things, but that is how it currently works. (It does have the advantage that users can add static libraries of their own in this way.) |
Is that necessary? Presumably if you try to dynamically load a statically linked library it will fail. Does the failure indicate the reason? If so then just ignore it.
Is this intended to be a supported mechanism? That needs to be specified and documented somewhere if so. |
It is perhaps not necessary, but this is the way it is implemented, and had been for years. Just as you like to be conservative and don't change things that's been working for years, so am I a bit reluctant to change this behavior. Doing so would be a massive undertaking, on a completely different scale than just fixing a few issues to get the Windows static launcher to work properly.
Yes it is. It is documented in the JNI specification: https://docs.oracle.com/en/java/javase/23/docs/specs/jni/invocation.html#jni_onload_l |
Thanks for the memory jolt, I had forgotten about that. |
All JDK native libraries needs to have a proper
JNI_OnLoad
, set either byDEF_STATIC_JNI_OnLoad
orDEF_JNI_OnLoad
. This is so that in a static build, the JVM can recognize that the library is already loaded, and does not try to load a (non-existent) external library.Our bundled version of freetype is missing such a marker.
This turns out to be a problem just on Windows, since the
System.loadLibrary("freetype")
code inFontManagerNativeLibrary
is only executed on Windows. However, the cost of including this in the bundled versions on all platforms is very small, and it is a safeguard for any future changes. In practice, freetype bundling is only enabled on Windows anyways.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22791/head:pull/22791
$ git checkout pull/22791
Update a local copy of the PR:
$ git checkout pull/22791
$ git pull https://git.openjdk.org/jdk.git pull/22791/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22791
View PR using the GUI difftool:
$ git pr show -t 22791
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22791.diff
Using Webrev
Link to Webrev Comment