From c79f43ee97815d50d6f13867bfe280032d34add8 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Sun, 17 Aug 2025 11:34:00 +0200 Subject: [PATCH 01/11] use copy ctor --- src/hotspot/share/oops/resolvedFieldEntry.hpp | 20 --------------- .../share/oops/resolvedMethodEntry.hpp | 25 ------------------- 2 files changed, 45 deletions(-) diff --git a/src/hotspot/share/oops/resolvedFieldEntry.hpp b/src/hotspot/share/oops/resolvedFieldEntry.hpp index c98d5f54d1e97..d61cbf1999283 100644 --- a/src/hotspot/share/oops/resolvedFieldEntry.hpp +++ b/src/hotspot/share/oops/resolvedFieldEntry.hpp @@ -55,17 +55,6 @@ class ResolvedFieldEntry { u1 _flags; // Flags: [0000|00|is_final|is_volatile] u1 _get_code, _put_code; // Get and Put bytecodes of the field - void copy_from(const ResolvedFieldEntry& other) { - _field_holder = other._field_holder; - _field_offset = other._field_offset; - _field_index = other._field_index; - _cpool_index = other._cpool_index; - _tos_state = other._tos_state; - _flags = other._flags; - _get_code = other._get_code; - _put_code = other._put_code; - } - public: ResolvedFieldEntry(u2 cpi) : _field_holder(nullptr), @@ -80,15 +69,6 @@ class ResolvedFieldEntry { ResolvedFieldEntry() : ResolvedFieldEntry(0) {} - ResolvedFieldEntry(const ResolvedFieldEntry& other) { - copy_from(other); - } - - ResolvedFieldEntry& operator=(const ResolvedFieldEntry& other) { - copy_from(other); - return *this; - } - // Bit shift to get flags // Note: Only two flags exists at the moment but more could be added enum { diff --git a/src/hotspot/share/oops/resolvedMethodEntry.hpp b/src/hotspot/share/oops/resolvedMethodEntry.hpp index 8f49608127fbe..e84452236006a 100644 --- a/src/hotspot/share/oops/resolvedMethodEntry.hpp +++ b/src/hotspot/share/oops/resolvedMethodEntry.hpp @@ -82,21 +82,6 @@ class ResolvedMethodEntry { bool _has_table_index; #endif - void copy_from(const ResolvedMethodEntry& other) { - _method = other._method; - _entry_specific = other._entry_specific; - _cpool_index = other._cpool_index; - _number_of_parameters = other._number_of_parameters; - _tos_state = other._tos_state; - _flags = other._flags; - _bytecode1 = other._bytecode1; - _bytecode2 = other._bytecode2; -#ifdef ASSERT - _has_interface_klass = other._has_interface_klass; - _has_table_index = other._has_table_index; -#endif - } - // Constructors public: ResolvedMethodEntry(u2 cpi) : @@ -114,16 +99,6 @@ class ResolvedMethodEntry { ResolvedMethodEntry() : ResolvedMethodEntry(0) {} - ResolvedMethodEntry(const ResolvedMethodEntry& other) { - copy_from(other); - } - - ResolvedMethodEntry& operator=(const ResolvedMethodEntry& other) { - copy_from(other); - return *this; - } - - // Bit shift to get flags enum { is_vfinal_shift = 0, From dc4fa3ac5719bdac042af8e21001e335d04d1f14 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 00:45:43 +0000 Subject: [PATCH 02/11] fix --- src/hotspot/share/compiler/compilerEvent.cpp | 4 +++- src/hotspot/share/opto/phasetype.hpp | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/compiler/compilerEvent.cpp b/src/hotspot/share/compiler/compilerEvent.cpp index 4bc859ef0d642..88699c8d870ef 100644 --- a/src/hotspot/share/compiler/compilerEvent.cpp +++ b/src/hotspot/share/compiler/compilerEvent.cpp @@ -56,7 +56,9 @@ class PhaseTypeGuard : public StackObj { Semaphore PhaseTypeGuard::_mutex_semaphore(1); // Table for mapping compiler phases names to int identifiers. -static GrowableArray* phase_names = nullptr; +namespace { +GrowableArray* phase_names = nullptr; +} class CompilerPhaseTypeConstant : public JfrSerializer { public: diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index 942850cf89225..74408d99acfcd 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -138,13 +138,13 @@ enum CompilerPhaseType { }; #undef table_entry -static const char* phase_descriptions[] = { +static constexpr const char* compiler_phase_descriptions[] = { #define array_of_labels(name, description) description, COMPILER_PHASES(array_of_labels) #undef array_of_labels }; -static const char* phase_names[] = { +static constexpr const char* compiler_phase_names[] = { #define array_of_labels(name, description) #name, COMPILER_PHASES(array_of_labels) #undef array_of_labels @@ -153,16 +153,16 @@ static const char* phase_names[] = { class CompilerPhaseTypeHelper { public: static const char* to_name(CompilerPhaseType cpt) { - return phase_names[cpt]; + return compiler_phase_names[cpt]; } static const char* to_description(CompilerPhaseType cpt) { - return phase_descriptions[cpt]; + return compiler_phase_descriptions[cpt]; } }; static CompilerPhaseType find_phase(const char* str) { for (int i = 0; i < PHASE_NUM_TYPES; i++) { - if (strcmp(phase_names[i], str) == 0) { + if (strcmp(compiler_phase_names[i], str) == 0) { return (CompilerPhaseType)i; } } From d9a82a368b7c7a7d89952da6d45f24ce918fe1b8 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 08:15:52 +0000 Subject: [PATCH 03/11] revert --- src/hotspot/share/oops/resolvedFieldEntry.hpp | 20 +++++++++++++++ .../share/oops/resolvedMethodEntry.hpp | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/hotspot/share/oops/resolvedFieldEntry.hpp b/src/hotspot/share/oops/resolvedFieldEntry.hpp index d61cbf1999283..c98d5f54d1e97 100644 --- a/src/hotspot/share/oops/resolvedFieldEntry.hpp +++ b/src/hotspot/share/oops/resolvedFieldEntry.hpp @@ -55,6 +55,17 @@ class ResolvedFieldEntry { u1 _flags; // Flags: [0000|00|is_final|is_volatile] u1 _get_code, _put_code; // Get and Put bytecodes of the field + void copy_from(const ResolvedFieldEntry& other) { + _field_holder = other._field_holder; + _field_offset = other._field_offset; + _field_index = other._field_index; + _cpool_index = other._cpool_index; + _tos_state = other._tos_state; + _flags = other._flags; + _get_code = other._get_code; + _put_code = other._put_code; + } + public: ResolvedFieldEntry(u2 cpi) : _field_holder(nullptr), @@ -69,6 +80,15 @@ class ResolvedFieldEntry { ResolvedFieldEntry() : ResolvedFieldEntry(0) {} + ResolvedFieldEntry(const ResolvedFieldEntry& other) { + copy_from(other); + } + + ResolvedFieldEntry& operator=(const ResolvedFieldEntry& other) { + copy_from(other); + return *this; + } + // Bit shift to get flags // Note: Only two flags exists at the moment but more could be added enum { diff --git a/src/hotspot/share/oops/resolvedMethodEntry.hpp b/src/hotspot/share/oops/resolvedMethodEntry.hpp index e84452236006a..8f49608127fbe 100644 --- a/src/hotspot/share/oops/resolvedMethodEntry.hpp +++ b/src/hotspot/share/oops/resolvedMethodEntry.hpp @@ -82,6 +82,21 @@ class ResolvedMethodEntry { bool _has_table_index; #endif + void copy_from(const ResolvedMethodEntry& other) { + _method = other._method; + _entry_specific = other._entry_specific; + _cpool_index = other._cpool_index; + _number_of_parameters = other._number_of_parameters; + _tos_state = other._tos_state; + _flags = other._flags; + _bytecode1 = other._bytecode1; + _bytecode2 = other._bytecode2; +#ifdef ASSERT + _has_interface_klass = other._has_interface_klass; + _has_table_index = other._has_table_index; +#endif + } + // Constructors public: ResolvedMethodEntry(u2 cpi) : @@ -99,6 +114,16 @@ class ResolvedMethodEntry { ResolvedMethodEntry() : ResolvedMethodEntry(0) {} + ResolvedMethodEntry(const ResolvedMethodEntry& other) { + copy_from(other); + } + + ResolvedMethodEntry& operator=(const ResolvedMethodEntry& other) { + copy_from(other); + return *this; + } + + // Bit shift to get flags enum { is_vfinal_shift = 0, From 44aabc0a8c3115cf5f0559ee2ecc6ca1d42b2464 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 08:16:04 +0000 Subject: [PATCH 04/11] review sugg --- src/hotspot/share/opto/phasetype.cpp | 37 ++++++++++++++++++++++++++++ src/hotspot/share/opto/phasetype.hpp | 29 ++++++++-------------- 2 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 src/hotspot/share/opto/phasetype.cpp diff --git a/src/hotspot/share/opto/phasetype.cpp b/src/hotspot/share/opto/phasetype.cpp new file mode 100644 index 0000000000000..530f5f5cfa7f4 --- /dev/null +++ b/src/hotspot/share/opto/phasetype.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "phasetype.hpp" + +const char* CompilerPhaseTypeHelper::phase_descriptions[] = { +#define array_of_labels(name, description) description, + COMPILER_PHASES(array_of_labels) +#undef array_of_labels +}; + +const char* CompilerPhaseTypeHelper::phase_names[] = { +#define array_of_labels(name, description) #name, + COMPILER_PHASES(array_of_labels) +#undef array_of_labels +}; diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index 74408d99acfcd..a718c84726b66 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -138,31 +138,22 @@ enum CompilerPhaseType { }; #undef table_entry -static constexpr const char* compiler_phase_descriptions[] = { -#define array_of_labels(name, description) description, - COMPILER_PHASES(array_of_labels) -#undef array_of_labels -}; - -static constexpr const char* compiler_phase_names[] = { -#define array_of_labels(name, description) #name, - COMPILER_PHASES(array_of_labels) -#undef array_of_labels -}; - class CompilerPhaseTypeHelper { public: - static const char* to_name(CompilerPhaseType cpt) { - return compiler_phase_names[cpt]; - } - static const char* to_description(CompilerPhaseType cpt) { - return compiler_phase_descriptions[cpt]; - } + static const char* phase_descriptions[]; + static const char* phase_names[]; + + static const char* to_name(CompilerPhaseType cpt) { + return phase_names[cpt]; + } + static const char* to_description(CompilerPhaseType cpt) { + return phase_descriptions[cpt]; + } }; static CompilerPhaseType find_phase(const char* str) { for (int i = 0; i < PHASE_NUM_TYPES; i++) { - if (strcmp(compiler_phase_names[i], str) == 0) { + if (strcmp(CompilerPhaseTypeHelper::phase_names[i], str) == 0) { return (CompilerPhaseType)i; } } From dd01d9dfd246fafac450c9ecdea140ba2f7287c3 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 08:17:14 +0000 Subject: [PATCH 05/11] indent --- src/hotspot/share/opto/phasetype.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index a718c84726b66..dc4807e4c6573 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -140,15 +140,15 @@ enum CompilerPhaseType { class CompilerPhaseTypeHelper { public: - static const char* phase_descriptions[]; - static const char* phase_names[]; + static const char* phase_descriptions[]; + static const char* phase_names[]; - static const char* to_name(CompilerPhaseType cpt) { - return phase_names[cpt]; - } - static const char* to_description(CompilerPhaseType cpt) { - return phase_descriptions[cpt]; - } + static const char* to_name(CompilerPhaseType cpt) { + return phase_names[cpt]; + } + static const char* to_description(CompilerPhaseType cpt) { + return phase_descriptions[cpt]; + } }; static CompilerPhaseType find_phase(const char* str) { From e7122cd679682d4550c5c1b18949a1d072e440df Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 08:18:16 +0000 Subject: [PATCH 06/11] nn --- src/hotspot/share/compiler/compilerEvent.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hotspot/share/compiler/compilerEvent.cpp b/src/hotspot/share/compiler/compilerEvent.cpp index 88699c8d870ef..6e075feac0d54 100644 --- a/src/hotspot/share/compiler/compilerEvent.cpp +++ b/src/hotspot/share/compiler/compilerEvent.cpp @@ -56,9 +56,7 @@ class PhaseTypeGuard : public StackObj { Semaphore PhaseTypeGuard::_mutex_semaphore(1); // Table for mapping compiler phases names to int identifiers. -namespace { GrowableArray* phase_names = nullptr; -} class CompilerPhaseTypeConstant : public JfrSerializer { public: From a2183a2ca36dd81830a92f3b6d62f8742e8517a3 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 08:18:44 +0000 Subject: [PATCH 07/11] static --- src/hotspot/share/compiler/compilerEvent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/compiler/compilerEvent.cpp b/src/hotspot/share/compiler/compilerEvent.cpp index 6e075feac0d54..4bc859ef0d642 100644 --- a/src/hotspot/share/compiler/compilerEvent.cpp +++ b/src/hotspot/share/compiler/compilerEvent.cpp @@ -56,7 +56,7 @@ class PhaseTypeGuard : public StackObj { Semaphore PhaseTypeGuard::_mutex_semaphore(1); // Table for mapping compiler phases names to int identifiers. -GrowableArray* phase_names = nullptr; +static GrowableArray* phase_names = nullptr; class CompilerPhaseTypeConstant : public JfrSerializer { public: From a66abc051fe6f640930cbcca9ab8240b6ca97aeb Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 14:22:33 +0000 Subject: [PATCH 08/11] const --- src/hotspot/share/opto/phasetype.cpp | 4 ++-- src/hotspot/share/opto/phasetype.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hotspot/share/opto/phasetype.cpp b/src/hotspot/share/opto/phasetype.cpp index 530f5f5cfa7f4..e46c14bcda91d 100644 --- a/src/hotspot/share/opto/phasetype.cpp +++ b/src/hotspot/share/opto/phasetype.cpp @@ -24,13 +24,13 @@ #include "phasetype.hpp" -const char* CompilerPhaseTypeHelper::phase_descriptions[] = { +const char* const CompilerPhaseTypeHelper::phase_descriptions[] = { #define array_of_labels(name, description) description, COMPILER_PHASES(array_of_labels) #undef array_of_labels }; -const char* CompilerPhaseTypeHelper::phase_names[] = { +const char* const CompilerPhaseTypeHelper::phase_names[] = { #define array_of_labels(name, description) #name, COMPILER_PHASES(array_of_labels) #undef array_of_labels diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index dc4807e4c6573..bd60ca75d534c 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -140,8 +140,8 @@ enum CompilerPhaseType { class CompilerPhaseTypeHelper { public: - static const char* phase_descriptions[]; - static const char* phase_names[]; + static const char* const phase_descriptions[]; + static const char* const phase_names[]; static const char* to_name(CompilerPhaseType cpt) { return phase_names[cpt]; From 4db623eae0e6633889d1c9d571a06489258e39f5 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 14:23:32 +0000 Subject: [PATCH 09/11] 2012 --- src/hotspot/share/opto/phasetype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/opto/phasetype.cpp b/src/hotspot/share/opto/phasetype.cpp index e46c14bcda91d..40d7655b96000 100644 --- a/src/hotspot/share/opto/phasetype.cpp +++ b/src/hotspot/share/opto/phasetype.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it From 90e9c537709ad4c384f7efd2ed18c63a4c21b51b Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Wed, 20 Aug 2025 14:45:29 +0000 Subject: [PATCH 10/11] underscore --- src/hotspot/share/opto/phasetype.cpp | 4 ++-- src/hotspot/share/opto/phasetype.hpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/opto/phasetype.cpp b/src/hotspot/share/opto/phasetype.cpp index 40d7655b96000..f1940c014e8f9 100644 --- a/src/hotspot/share/opto/phasetype.cpp +++ b/src/hotspot/share/opto/phasetype.cpp @@ -24,13 +24,13 @@ #include "phasetype.hpp" -const char* const CompilerPhaseTypeHelper::phase_descriptions[] = { +const char* const CompilerPhaseTypeHelper::_phase_descriptions[] = { #define array_of_labels(name, description) description, COMPILER_PHASES(array_of_labels) #undef array_of_labels }; -const char* const CompilerPhaseTypeHelper::phase_names[] = { +const char* const CompilerPhaseTypeHelper::_phase_names[] = { #define array_of_labels(name, description) #name, COMPILER_PHASES(array_of_labels) #undef array_of_labels diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index bd60ca75d534c..98b1d74a196b8 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -140,20 +140,20 @@ enum CompilerPhaseType { class CompilerPhaseTypeHelper { public: - static const char* const phase_descriptions[]; - static const char* const phase_names[]; + static const char* const _phase_descriptions[]; + static const char* const _phase_names[]; static const char* to_name(CompilerPhaseType cpt) { - return phase_names[cpt]; + return _phase_names[cpt]; } static const char* to_description(CompilerPhaseType cpt) { - return phase_descriptions[cpt]; + return _phase_descriptions[cpt]; } }; static CompilerPhaseType find_phase(const char* str) { for (int i = 0; i < PHASE_NUM_TYPES; i++) { - if (strcmp(CompilerPhaseTypeHelper::phase_names[i], str) == 0) { + if (strcmp(CompilerPhaseTypeHelper::_phase_names[i], str) == 0) { return (CompilerPhaseType)i; } } From cc7da3adeea447ee8c108f0179943de785a6e239 Mon Sep 17 00:00:00 2001 From: Francesco Andreuzzi Date: Thu, 21 Aug 2025 08:12:43 +0000 Subject: [PATCH 11/11] make find_phase a member --- src/hotspot/share/opto/phasetype.cpp | 9 +++++++++ src/hotspot/share/opto/phasetype.hpp | 16 +++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/opto/phasetype.cpp b/src/hotspot/share/opto/phasetype.cpp index f1940c014e8f9..3e18bd089baf1 100644 --- a/src/hotspot/share/opto/phasetype.cpp +++ b/src/hotspot/share/opto/phasetype.cpp @@ -35,3 +35,12 @@ const char* const CompilerPhaseTypeHelper::_phase_names[] = { COMPILER_PHASES(array_of_labels) #undef array_of_labels }; + +CompilerPhaseType CompilerPhaseTypeHelper::find_phase(const char* str) { + for (int i = 0; i < PHASE_NUM_TYPES; i++) { + if (strcmp(CompilerPhaseTypeHelper::_phase_names[i], str) == 0) { + return (CompilerPhaseType)i; + } + } + return PHASE_NONE; +} diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index 98b1d74a196b8..5c733c7dc0ab9 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -139,26 +139,20 @@ enum CompilerPhaseType { #undef table_entry class CompilerPhaseTypeHelper { - public: + private: static const char* const _phase_descriptions[]; static const char* const _phase_names[]; + public: static const char* to_name(CompilerPhaseType cpt) { return _phase_names[cpt]; } static const char* to_description(CompilerPhaseType cpt) { return _phase_descriptions[cpt]; } -}; -static CompilerPhaseType find_phase(const char* str) { - for (int i = 0; i < PHASE_NUM_TYPES; i++) { - if (strcmp(CompilerPhaseTypeHelper::_phase_names[i], str) == 0) { - return (CompilerPhaseType)i; - } - } - return PHASE_NONE; -} + static CompilerPhaseType find_phase(const char* str); +}; class PhaseNameValidator { private: @@ -174,7 +168,7 @@ class PhaseNameValidator { { for (StringUtils::CommaSeparatedStringIterator iter(option); *iter != nullptr && _valid; ++iter) { - CompilerPhaseType cpt = find_phase(*iter); + CompilerPhaseType cpt = CompilerPhaseTypeHelper::find_phase(*iter); if (PHASE_NONE == cpt) { const size_t len = MIN2(strlen(*iter), 63) + 1; // cap len to a value we know is enough for all phase descriptions _bad = NEW_C_HEAP_ARRAY(char, len, mtCompiler);