RFR: 8374445: Fix -Wzero-as-null-pointer-constant warnings in JfrSet
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled. The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled. Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*). Testing: mach5 tier1-3 (tier3 is where most jfr tests are run) ------------- Commit messages: - fix -Wzero-as-null-poniter-constant warnings in jfrSet.hpp Changes: https://git.openjdk.org/jdk/pull/29022/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29022&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8374445 Stats: 10 lines in 1 file changed: 3 ins; 0 del; 7 mod Patch: https://git.openjdk.org/jdk/pull/29022.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/29022/head:pull/29022 PR: https://git.openjdk.org/jdk/pull/29022
On Sat, 3 Jan 2026 08:21:15 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
Will review this later Kim, sorry for the delay (26 stuff). ------------- PR Comment: https://git.openjdk.org/jdk/pull/29022#issuecomment-3719971111
On Wed, 7 Jan 2026 17:34:11 GMT, Markus Grönlund <mgronlun@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
Will review this later Kim, sorry for the delay (26 stuff).
Thanks for reviewing @mgronlun ------------- PR Comment: https://git.openjdk.org/jdk/pull/29022#issuecomment-3756446182
On Thu, 15 Jan 2026 19:13:47 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Will review this later Kim, sorry for the delay (26 stuff).
Thanks for reviewing @mgronlun
@kimbarrett don't you also need to adjust this for completeness: void clear() { memset(_table, 0, _table_size * sizeof(K)); } ------------- PR Comment: https://git.openjdk.org/jdk/pull/29022#issuecomment-3756916457
On Thu, 15 Jan 2026 19:13:47 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Will review this later Kim, sorry for the delay (26 stuff).
Thanks for reviewing @mgronlun
@kimbarrett don't you also need to adjust this for completeness:
``` void clear() { memset(_table, 0, _table_size * sizeof(K)); } ```
Drat! Missed that. https://bugs.openjdk.org/browse/JDK-8375544 ------------- PR Comment: https://git.openjdk.org/jdk/pull/29022#issuecomment-3760548998
On Sat, 3 Jan 2026 08:21:15 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
src/hotspot/share/jfr/utilities/jfrSet.hpp line 72:
70: } 71: for (unsigned i = 0; i < table_size; ++i) { 72: ::new (&table[i]) K{};
Is this the new (placement pun intended) way to do a placement new, using the outer scope operator ::? Or is it because we don't know what Hotspot type this is? src/hotspot/share/jfr/utilities/jfrSet.hpp line 142:
140: for (unsigned i = 0; i < old_table_size; ++i) { 141: const K k = old_table[i]; 142: if (k != K{}) {
Are these K{}'s compile constant expressions? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29022#discussion_r2690861905 PR Review Comment: https://git.openjdk.org/jdk/pull/29022#discussion_r2690859072
On Wed, 14 Jan 2026 15:11:59 GMT, Markus Grönlund <mgronlun@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
src/hotspot/share/jfr/utilities/jfrSet.hpp line 72:
70: } 71: for (unsigned i = 0; i < table_size; ++i) { 72: ::new (&table[i]) K{};
Is this the new (placement pun intended) way to do a placement new, using the outer scope operator ::? Or is it because we don't know what Hotspot type this is?
It's the same old way one should always do it. If one wants global placement new, one should say so. An unqualified `new` expression does a class-based lookup of `operator new`, so if the class has one (and lots of ours do), that will be used. We don't want that here, regardless of the type of `K`. As it happens, for all current uses `K` is a fundamental type, so it doesn't matter. But it's clearer and future proof to be explicit.
src/hotspot/share/jfr/utilities/jfrSet.hpp line 142:
140: for (unsigned i = 0; i < old_table_size; ++i) { 141: const K k = old_table[i]; 142: if (k != K{}) {
Are these K{}'s compile constant expressions?
For the types currently used, yes. This is a "value-initialized" (C++17 11.6/8) temporary. For fundamental types, that's a zero-initialized temporary. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29022#discussion_r2695057339 PR Review Comment: https://git.openjdk.org/jdk/pull/29022#discussion_r2695088728
On Thu, 15 Jan 2026 16:15:52 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
src/hotspot/share/jfr/utilities/jfrSet.hpp line 72:
70: } 71: for (unsigned i = 0; i < table_size; ++i) { 72: ::new (&table[i]) K{};
Is this the new (placement pun intended) way to do a placement new, using the outer scope operator ::? Or is it because we don't know what Hotspot type this is?
It's the same old way one should always do it. If one wants global placement new, one should say so. An unqualified `new` expression does a class-based lookup of `operator new`, so if the class has one (and lots of ours do), that will be used. We don't want that here, regardless of the type of `K`. As it happens, for all current uses `K` is a fundamental type, so it doesn't matter. But it's clearer and future proof to be explicit.
And the new location for global new is cppstdlib/new.hpp - ok. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29022#discussion_r2695233003
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
Kim Barrett has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision: - Merge branch 'master' into jfrset-zero-as-null-pointer-warnings - fix -Wzero-as-null-poniter-constant warnings in jfrSet.hpp ------------- Changes: - all: https://git.openjdk.org/jdk/pull/29022/files - new: https://git.openjdk.org/jdk/pull/29022/files/d2ee55ab..d54334e0 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=29022&range=01 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=29022&range=00-01 Stats: 55051 lines in 1117 files changed: 27415 ins; 10797 del; 16839 mod Patch: https://git.openjdk.org/jdk/pull/29022.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/29022/head:pull/29022 PR: https://git.openjdk.org/jdk/pull/29022
On Thu, 15 Jan 2026 16:50:14 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
Kim Barrett has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
- Merge branch 'master' into jfrset-zero-as-null-pointer-warnings - fix -Wzero-as-null-poniter-constant warnings in jfrSet.hpp
Look good, thanks Kim. ------------- Marked as reviewed by mgronlun (Reviewer). PR Review: https://git.openjdk.org/jdk/pull/29022#pullrequestreview-3666675208
On Sat, 3 Jan 2026 08:21:15 GMT, Kim Barrett <kbarrett@openjdk.org> wrote:
Please review this change to fix JfrSet to avoid triggering -Wzero-as-null-pointer-constant warnings when that warning is enabled.
The old code uses an entry value with representation 0 to indicate the entry doesn't have a value. It compares an entry value against literal 0 to check for that. If the key type is a pointer type, this involves an implicit 0 => null pointer constant conversion, so we get a warning when that warning is enabled.
Instead we initialize entry values to a value-initialized key, and compare against a value-initialized key. This changes the (currently undocumented) requirements on the key type. The key type is no longer required to be trivially constructible (to permit memset-based initialization), but is now required to be value-initializable. That's currently a wash, since all of the in-use key types are fundamental types (traceid (u8) and Klass*).
Testing: mach5 tier1-3 (tier3 is where most jfr tests are run)
This pull request has now been integrated. Changeset: a8b845e0 Author: Kim Barrett <kbarrett@openjdk.org> URL: https://git.openjdk.org/jdk/commit/a8b845e08ce2f1fbe7d807cd963cb6b5e4df5ce6 Stats: 10 lines in 1 file changed: 3 ins; 0 del; 7 mod 8374445: Fix -Wzero-as-null-pointer-constant warnings in JfrSet Reviewed-by: mgronlun ------------- PR: https://git.openjdk.org/jdk/pull/29022
participants (3)
-
David Holmes
-
Kim Barrett
-
Markus Grönlund