-
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. |
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.
src/hotspot/share/jvmci/jvmciEnv.cpp
Outdated
| // 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 |
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. |
|
@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. |
|
Just curious, how did you check that the “no omit frame pointer” option is needed? Did you see any test failures? |
gcc documentation states that you typically need to pass the same options to the link step from the compile step, since the linker when LTO is active is actually the compiler in disguise. |
|
@TheShermanTanker |
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