From e8e2aadd9ea302b7b448d0fda9d069d3813f31c5 Mon Sep 17 00:00:00 2001 From: Hamlin Li Date: Fri, 17 Oct 2025 11:22:23 +0000 Subject: [PATCH] 8369685: RISC-V: refactor code related to RVFeatureValue::enabled Reviewed-by: fyang, rehn --- src/hotspot/cpu/riscv/vm_version_riscv.cpp | 13 +----- src/hotspot/cpu/riscv/vm_version_riscv.hpp | 45 +++++++++---------- .../linux_riscv/vm_version_linux_riscv.cpp | 13 ++++-- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.cpp b/src/hotspot/cpu/riscv/vm_version_riscv.cpp index 9d6146a8389..6f4babc872f 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.cpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.cpp @@ -103,17 +103,6 @@ void VM_Version::common_initialize() { useRVA23U64Profile(); } - // Enable vendor specific features - - if (mvendorid.enabled()) { - // Rivos - if (mvendorid.value() == RIVOS) { - if (FLAG_IS_DEFAULT(UseConservativeFence)) { - FLAG_SET_DEFAULT(UseConservativeFence, false); - } - } - } - if (UseZic64b) { if (CacheLineSize != 64) { assert(!FLAG_IS_DEFAULT(CacheLineSize), "default cache line size should be 64 bytes"); @@ -199,7 +188,7 @@ void VM_Version::common_initialize() { FLAG_SET_DEFAULT(UsePopCountInstruction, false); } - if (UseZicboz && zicboz_block_size.enabled() && zicboz_block_size.value() > 0) { + if (UseZicboz && zicboz_block_size.value() > 0) { assert(is_power_of_2(zicboz_block_size.value()), "Sanity"); if (FLAG_IS_DEFAULT(UseBlockZeroing)) { FLAG_SET_DEFAULT(UseBlockZeroing, true); diff --git a/src/hotspot/cpu/riscv/vm_version_riscv.hpp b/src/hotspot/cpu/riscv/vm_version_riscv.hpp index 3d555d47e9f..f74992cbc37 100644 --- a/src/hotspot/cpu/riscv/vm_version_riscv.hpp +++ b/src/hotspot/cpu/riscv/vm_version_riscv.hpp @@ -52,24 +52,19 @@ class VM_Version : public Abstract_VM_Version { const char* const _pretty; const bool _feature_string; const uint64_t _linux_feature_bit; - int64_t _value; + public: RVFeatureValue(const char* pretty, int linux_bit_num, bool fstring) : - _pretty(pretty), _feature_string(fstring), _linux_feature_bit(nth_bit(linux_bit_num)), - _value(-1) { + _pretty(pretty), _feature_string(fstring), _linux_feature_bit(nth_bit(linux_bit_num)) { } - virtual void enable_feature(int64_t value = 0) { - _value = value; - } - virtual void disable_feature() { - _value = -1; - } - const char* pretty() { return _pretty; } - uint64_t feature_bit() { return _linux_feature_bit; } - bool feature_string() { return _feature_string; } - int64_t value() { return _value; } + virtual void enable_feature(int64_t value = 0) = 0; + virtual void disable_feature() = 0; + const char* pretty() { return _pretty; } + uint64_t feature_bit() { return _linux_feature_bit; } + bool feature_string() { return _feature_string; } virtual bool enabled() = 0; virtual void update_flag() = 0; + virtual void log_enabled() = 0; }; #define UPDATE_DEFAULT(flag) \ @@ -135,13 +130,12 @@ class VM_Version : public Abstract_VM_Version { return RVExtFeatures::current()->support_feature(_cpu_feature_index); } void enable_feature(int64_t value = 0) { - RVFeatureValue::enable_feature(value); RVExtFeatures::current()->set_feature(_cpu_feature_index); } void disable_feature() { - RVFeatureValue::disable_feature(); RVExtFeatures::current()->clear_feature(_cpu_feature_index); } + void log_enabled(); protected: bool deps_all_enabled(RVExtFeatureValue* dep0, ...) { @@ -196,21 +190,22 @@ class VM_Version : public Abstract_VM_Version { }; class RVNonExtFeatureValue : public RVFeatureValue { - bool _enabled; + static const int64_t DEFAULT_VALUE = -1; + int64_t _value; + public: RVNonExtFeatureValue(const char* pretty, int linux_bit_num, bool fstring) : RVFeatureValue(pretty, linux_bit_num, fstring), - _enabled(false) { + _value(DEFAULT_VALUE) { } - bool enabled() { return _enabled; } - void enable_feature(int64_t value = 0) { - RVFeatureValue::enable_feature(value); - _enabled = true; - } - void disable_feature() { - RVFeatureValue::disable_feature(); - _enabled = false; + bool enabled() { return _value != DEFAULT_VALUE; } + void enable_feature(int64_t value) { + assert(value != DEFAULT_VALUE, "Sanity"); + _value = value; } + void disable_feature() { _value = DEFAULT_VALUE; } + int64_t value() { return _value; } + void log_enabled(); }; public: diff --git a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp index e414a3889c2..0799de014a9 100644 --- a/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp +++ b/src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp @@ -103,6 +103,14 @@ uint32_t VM_Version::cpu_vector_length() { return (uint32_t)read_csr(CSR_VLENB); } +void VM_Version::RVExtFeatureValue::log_enabled() { + log_debug(os, cpu)("Enabled RV64 feature \"%s\"", pretty()); +} + +void VM_Version::RVNonExtFeatureValue::log_enabled() { + log_debug(os, cpu)("Enabled RV64 feature \"%s\" (%ld)", pretty(), value()); +} + void VM_Version::setup_cpu_available_features() { assert(ext_i.feature_bit() == HWCAP_ISA_I, "Bit for I must follow Linux HWCAP"); @@ -144,9 +152,8 @@ void VM_Version::setup_cpu_available_features() { continue; } - log_debug(os, cpu)("Enabled RV64 feature \"%s\" (%ld)", - _feature_list[i]->pretty(), - _feature_list[i]->value()); + _feature_list[i]->log_enabled(); + // The feature string if (_feature_list[i]->feature_string()) { const char* tmp = _feature_list[i]->pretty();