On Tue, 27 Oct 2020 23:08:13 GMT, Ioi Lam <ik...@openjdk.org> wrote: >> Claes Redestad 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 three additional >> commits since the last revision: >> >> - Merge branch 'master' into threadHeapSampler_constexpr >> - Remove _log_table_initialized assert >> - Refactor ThreadHeapSampler::_log_table as constexpr > > src/hotspot/share/runtime/threadHeapSampler.cpp line 48: > >> 46: }; >> 47: >> 48: const FastLogTable<ThreadHeapSampler::FastLogCount> >> ThreadHeapSampler::_log_table; > > To guarantee that `_log_table` is evaluated at C++ compile time, it's best to > change the code to > > constexpr FastLogTable<ThreadHeapSampler::FastLogCount> _log_table; > > There are 2 reasons: > > 1. C++ guarantees compile-time evaluation only if the expression is used in a > "constexpr context". You can read more from > [here](https://isocpp.org/blog/2013/01/when-does-a-constexpr-function-get-evaluated-at-compile-time-stackoverflow). > 2. In the future, if the `FastLogTable` constructor is modified in a way that > cannot be evaluated at compile time, (e.g., someone removes `constexpr` from > the constructor's declaration by mistake, the C++ compiler will catch that > and tell you that `_log_table` cannot be `constexpr`. > > Unfortunately, you cannot use `constexpr` in forward declarations, so you > should either move the definition of `FastLogTable` to the hpp file, or > remove the declaration of `_log_table` from the hpp file.
Ok, makes sense. I went with removing the `_log_table` declaration from the hpp file. I think things came out a bit cleaner as a result, too. ------------- PR: https://git.openjdk.java.net/jdk/pull/880