-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8345265: Minor improvements for LTO across all compilers #22464
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back jwaters! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
@TheShermanTanker 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
|
kimbarrett
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.
I only noticed this had been changed back to Draft after I was mostly done looking
at it. But I don't think this should be done this way, esp. since it didn't seem to work
(as in suppressing warnings from LTO) for me.
| // The memory allocated in libjvmci was not allocated with os::malloc | ||
| // so must not be freed with os::free. | ||
| ALLOW_C_FUNCTION(::free((void*) _init_error_msg)); | ||
| ALLOW_C_FUNCTION(::free, ::free((void*) _init_error_msg);) |
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.
Please do this bug fix change under a separate JBS issue & PR. I've created a JBS issue for it:
https://bugs.openjdk.org/browse/JDK-8345267
Fix memory leak in JVMCIEnv dtor
| // forbidden warnings in such builds. | ||
| #define FORBID_C_FUNCTION(signature, alternative) \ | ||
| extern "C" __attribute__((__warning__(alternative))) signature; | ||
| [[gnu::warning(alternative)]] signature noexcept; |
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.
Why are you making this change at all, let alone under this JBS issue?
Among other problems, noexcept is mostly irrelevant in HotSpot, since we build with
exceptions disabled. (There are a few places where noexcept affects semantics, like for
operator new, but otherwise there is no point.)
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 was thinking about the extern "C" and I think it might not be needed. A method that was already declared extern "C" in a C library header will keep that linkage when it is declared again, even without extern "C". There's also the issue that this forbidding macro could declare methods that don't actually exist on the current platform, which I think(?) removing extern "C" helps prevent. There's also the strange case that not all platforms have C library methods that are extern "C" (Windows is a notable example), so this helps declaring things with conflicting linkages and causing an error. The noexcept was just to match the declarations in standard library headers, since they are supposed to be noexcept according to the Standard
src/hotspot/share/runtime/os.cpp
Outdated
| */ | ||
|
|
||
| // Stopgap fix until FORBID_C_FUNCTION can work properly with LTO | ||
| #define DISABLE_POISONING_STOPGAP |
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.
This isn't needed if not using LTO.
src/hotspot/share/runtime/os.cpp
Outdated
| */ | ||
|
|
||
| // Stopgap fix until FORBID_C_FUNCTION can work properly with LTO | ||
| #define DISABLE_POISONING_STOPGAP |
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.
So far as I can tell, this doesn't work. I still get tons of -Wattribute-warnings when building
with LTO, because of similar problem from other files.
src/hotspot/share/runtime/os.cpp
Outdated
| */ | ||
|
|
||
| // Stopgap fix until FORBID_C_FUNCTION can work properly with LTO | ||
| #define DISABLE_POISONING_STOPGAP |
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.
This prevents precompiled headers from being used for this file. -Winvalid-pch will warn if enabled.
Yeah, I had noticed that it didn't work too, which is why I returned it to draft. It also causes VC to explode when compiling the Windows HotSpot, so that isn't ideal. I guess returning g1ParScanThreadState.cpp to LTO status will have to wait until FORBID_C_FUNCTION is properly fixed up to be LTO proof |
|
This needs a name and description change, I'll do so later. @MBaesken does this fix LTO on your end? Kim also reports that LTO hangs indefinitely alongside several warning messages, do you have similar issues when you try to enable LTO? |
When I try to build with this change (with and without lto enabled) I run into (maybe it is related to the devkit, maybe to pch I don't know) |
It's related to the subtle change in FORBID_C_FUNCTION, I think unistd.h is being included before compilerWarnings.hpp somewhere. Well, at least I now know the current approach has this issue |
|
/touch |
|
@TheShermanTanker The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
@TheShermanTanker This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
|
/touch |
|
@TheShermanTanker The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
@TheShermanTanker This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
|
/touch |
|
@TheShermanTanker The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
@TheShermanTanker This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
|
/touch |
|
@TheShermanTanker The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
@TheShermanTanker This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a |
|
/touch |
|
Please give me more time, the flatten issue on my end is still causing problems |
|
@TheShermanTanker The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
After trying and failing and trying and failing countless hours and days... I admit I'm nowhere close to solving this problem. I just can't figure out what the slow paths and external methods not local to the g1ParScanThreadState.cpp source file are. Every attempt at using a tool to discern this has failed catastrophically, and the call hierarchy is enormous, meaning manually trying to do this myself is out of the question. @kimbarrett if I could ask, what are the slow paths that should not be inlined, and what are the methods that are not local to the source file in question? If I just knew what to look at, maybe I could begin to start tackling this problem properly. |
|
Paging with the mailing list bridge to restart discussion, which I need in order to be able to continue working on this |
|
Mailing list message from Kim Barrett on hotspot-dev: On 10/8/25 8:06 AM, Julian Waters wrote:
As I've said before, we (Oracle) think LTO support is a substantial project, Some of the issues that make it a substantial project include: The LTO vs flattening problem. There are functions that assume (or even rely upon) implicit noinline via Build time issues, and their impact on development time and testing resources. Is LTO an alternative mode, different from how things are "normally" done? There might be others that I'm not remembering or I'm completely unaware of. |
Currently that seems to be the biggest problem, I do have solutions for other smaller issues with LTO, but from what I witness the flattening problem has to be solved first before any more work can be done with LTO. While I fortunately do have time to spare to try working on the issue (I'm that "Someone else", more or less), I less fortunately don't have the knowledge required to fix that problem, as even though only G1 uses flattening, the call hierarchy is too massive to actually meaningfully discern which calls need to be flattened and which calls shouldn't be flattened. Not very sure if anyone knows which code paths shouldn't be inlined within g1ParScanThreadState.cpp, actually. If anyone knew, I could fast track the flattening issue on my end and have it solved pretty quickly. |
|
@magicus In JBS, I see a long conversation about LTO optimization for libraries aiming to cover all use cases. Maybe it's better to start with something smaller? For example, provide a way to enable it per library and per platform, so it can be incrementally adopted. Initial results for some libraries in the java.desktop look promising. |
Hi, at the moment this is HotSpot only; We're unfortunately facing a very severe issue in G1 that can't seem to be solved. I'm currently focusing on making it work for HotSpot before introducing this for the native libraries. |
But as far I understand it will be much easy to implement for libs, do you know any blockers? |
Yes, the LTO build worked for the other JDK native libs when I enabled it there some months ago as a test. With GCC and LTO enabled, some libs get smaller e.g. for libfontmanager I saw a while ago 1.7M (without) to 1.1M (with LTO). |
Currently we have OPTIMIZATION levels NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE for the native libs we build in OpenJDK. We could easily add also LTO or LTOHIGH + LTOSIZE if we want to distinguish even more. So should we still offer LTO for more libs as an option to enable for the lib, even with the mentioned issues? |
Provide an option for library owners to opt-in, which can be enabled per-library, per-platform and per-compiler after appropriate testing for performance, functionality, and footprint. So it will be possible to mix size/perf and lto optimizations. Then later we can decide what to use by default. |
|
FWIW, I'm prototyping a possible change in g1ParScanThreadState.cpp that might |
Yeah, maybe something like LINK_TIME_OPTIMIZATION := YES that can be set by lib owners and passed as an optional parameter to SetupJdkLibrary / SetupNativeCompilation or similar. I created |
I created a draft PR #27976 to support enabling LTO on library level. |
|
For Linux x86_64 / gcc 13 here are the sizes of the libs and debuginfos before (without) and WITH lto enabled on LIB level For the debug info one can see a good size effect ; but not always the lib size decreases, for libfreetype.so it increases slightly. |
This is a general cleanup and improvement of LTO, as well as a quick fix to remove a workaround in the Makefiles that disabled LTO for g1ParScanThreadState.cpp due to the old poisoning mechanism causing trouble. The -Wno-attribute-warning change here can be removed once Kim's new poisoning solution is integrated.
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22464/head:pull/22464$ git checkout pull/22464Update a local copy of the PR:
$ git checkout pull/22464$ git pull https://git.openjdk.org/jdk.git pull/22464/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22464View PR using the GUI difftool:
$ git pr show -t 22464Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22464.diff
Using Webrev
Link to Webrev Comment