RFR: 8349214: Improve size optimization flags for MSVC builds

Magnus Ihse Bursie ihse at openjdk.org
Tue Feb 4 21:06:16 UTC 2025


On Tue, 4 Feb 2025 08:51:43 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

> Looks like the binary size optimization flags are not ideal when compiling with MSVC.
> On other compilers (gcc/clang) the current size optimization flags lead in most cases to smaller libraries. On MSVC this seems to be not the case, the libs often get larger when optimizing for SIZE.
> 
> For example jvm.dll (build with VS2022) with current -Os size optimization
> 20M images/jdk/bin/server/jvm.dll
> 
> with -O1 set for size optimization
> 13M images/jdk/bin/server/jvm.dll
> 
> See the doc from MSVC about "optimize for size"
> https://learn.microsoft.com/en-us/cpp/build/reference/o1-o2-minimize-size-maximize-speed?view=msvc-170
> "The /O1 option sets the individual optimization options that create the smallest code in the majority of cases."
> The Os option is only a part of the size minimization flag set :
> /O1 (Minimize Size) equivalent to /Og /Os /Oy /Ob2 /GF /Gy

Marked as reviewed by ihse (Reviewer).

Sounds good then. 

The optimization levels were kind of a mess that we "inherited" from the old build system, were they had just agglutinated over the years, probably dating back to Java 1.0, with nobody left around to remember why they were the way they were.

So it is definitely ripe for an overhaul. Anything you can do in this area is much appreciated, as long as it does not cause any regressions.

-------------

PR Review: https://git.openjdk.org/jdk/pull/23432#pullrequestreview-2594062927
PR Comment: https://git.openjdk.org/jdk/pull/23432#issuecomment-2635070522


More information about the build-dev mailing list