RFR: 8306579: Consider building with /Zc:throwingNew [v2]

Kim Barrett kbarrett at openjdk.org
Thu Nov 21 08:18:17 UTC 2024


On Mon, 18 Nov 2024 05:48:57 GMT, Julian Waters <jwaters at openjdk.org> wrote:

>> [JDK-8305590](https://bugs.openjdk.org/browse/JDK-8305590) removed `-fcheck-new` when building with gcc. It turns out Visual Studio has a similar option, though inverted in behavior and default.
>> 
>> It seems like /Zc:throwingNew- (the default) corresponds to gcc -fcheck-new, and /Zc:throwingNew corresponds to -fno-check-new (the default).
>> 
>> The Visual Studio documentation strongly recommends using /Zc:throwingNew if possible, as turning it off (the default) seriously bloats code and inhibits optimizations.
>> https://learn.microsoft.com/en-us/cpp/build/reference/zc-throwingnew-assume-operator-new-throws?view=msvc-170
>> 
>> As mentioned in [JDK-8305590](https://bugs.openjdk.org/browse/JDK-8305590), the standard says that an allocation function can report allocation failure either by returning null (when it must have a nothrow exception specification), or by throwing `std::bad_alloc` (so obviously must not be declared as non-throwing). HotSpot allocation functions terminate the program instead of throwing on allocation failure, so similarly don't need the result checked for null.
>> 
>> The documentation for /Zc:throwingNew is somewhat vague and confusing, so some investigation is probably needed to verify it really has the desired effect for us.
>
> Julian Waters has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains three commits:
> 
>  - Merge branch 'master' into patch-15
>  - -Zc:throwingNew in flags-cflags.m4
>  - 8306579

> > > One thing I have a query on: Does this need the problem with the ADLC operator new to be fixed before it can be integrated?
> > 
> > 
> > For those following along, the bug being referred to is this: https://bugs.openjdk.org/browse/JDK-8342639 Global operator new in adlc has wrong exception spec
> > I think that's not a blocker for this change. [...[
> 
> Ah, alright. For exceptions ADLC is a strange case. ADLC has no exceptions on Linux, but does on every other platform. I couldn't tell you why this is the case
> 
> EDIT: Nevermind, I think I misunderstood "I don't think there's any exception handling in adlc", my bad

Right, there's no uses of try/catch or anything related.

I thought adlc had exceptions enabled, but you say not on linux, only on
everything else? (That's weird. It also would seriously uglify any exception
handling.) What does the "throwing" default global operator new do when
exceptions are disabled and allocation fails? I hope it terminates, rather
than returning null.

But I'm pretty sure it doesn't matter, because I think that function
definition is unused anywhere other than (possibly) Windows, and probably not
even there. (See discussion in the bug.)

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

PR Comment: https://git.openjdk.org/jdk/pull/22039#issuecomment-2490342881


More information about the build-dev mailing list