1 /* 2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_RUNTIME_ABSTRACT_VM_VERSION_HPP 26 #define SHARE_RUNTIME_ABSTRACT_VM_VERSION_HPP 27 28 #include "memory/allStatic.hpp" // For declaration of class AllStatic 29 #include "utilities/globalDefinitions.hpp" 30 31 typedef enum { 32 NoDetectedVirtualization, 33 XenHVM, 34 XenPVHVM, // mix-mode on Linux aarch64 35 KVM, 36 VMWare, 37 HyperV, 38 HyperVRole, 39 PowerVM, // on AIX or Linux ppc64(le) 40 PowerFullPartitionMode, // on Linux ppc64(le) 41 PowerKVM 42 } VirtualizationType; 43 44 class outputStream; 45 class stringStream; 46 enum class vmIntrinsicID; 47 48 // Abstract_VM_Version provides information about the VM. 49 50 class Abstract_VM_Version: AllStatic { 51 friend class VMStructs; 52 friend class JVMCIVMStructs; 53 54 protected: 55 static const char* _s_vm_release; 56 static const char* _s_internal_vm_info_string; 57 58 // CPU feature flags, can be affected by VM settings. 59 static uint64_t _features; 60 61 static const char* _features_string; 62 63 static const char* _cpu_info_string; 64 65 // Original CPU feature flags, not affected by VM settings. 66 static uint64_t _cpu_features; 67 68 // These are set by machine-dependent initializations 69 #ifndef SUPPORTS_NATIVE_CX8 70 static bool _supports_cx8; 71 #endif 72 static bool _supports_atomic_getset4; 73 static bool _supports_atomic_getset8; 74 static bool _supports_atomic_getadd4; 75 static bool _supports_atomic_getadd8; 76 static unsigned int _logical_processors_per_package; 77 static unsigned int _L1_data_cache_line_size; 78 static int _vm_major_version; 79 static int _vm_minor_version; 80 static int _vm_security_version; 81 static int _vm_patch_version; 82 static int _vm_build_number; 83 static unsigned int _data_cache_line_flush_size; 84 85 public: 86 87 static VirtualizationType _detected_virtualization; 88 89 // Called as part of the runtime services initialization which is 90 // called from the management module initialization (via init_globals()) 91 // after argument parsing and attaching of the main thread has 92 // occurred. Examines a variety of the hardware capabilities of 93 // the platform to determine which features can be used to execute the 94 // program. 95 static void initialize() { } 96 97 // This allows for early initialization of VM_Version information 98 // that may be needed later in the initialization sequence but before 99 // full VM_Version initialization is possible. It can not depend on any 100 // other part of the VM being initialized when called. Platforms that 101 // need to specialize this define VM_Version::early_initialize(). 102 static void early_initialize() { } 103 104 // Called to initialize VM variables needing initialization 105 // after command line parsing. Platforms that need to specialize 106 // this should define VM_Version::init_before_ergo(). 107 static void init_before_ergo() {} 108 109 // Name 110 static const char* vm_name(); 111 // Vendor 112 static const char* vm_vendor(); 113 // VM version information string printed by launcher (java -version) 114 static const char* vm_info_string(); 115 static const char* vm_release(); 116 static const char* vm_platform_string(); 117 static const char* vm_variant(); 118 119 static int vm_major_version() { return _vm_major_version; } 120 static int vm_minor_version() { return _vm_minor_version; } 121 static int vm_security_version() { return _vm_security_version; } 122 static int vm_patch_version() { return _vm_patch_version; } 123 static int vm_build_number() { return _vm_build_number; } 124 125 // Gets the jvm_version_info.jvm_version 126 static unsigned int jvm_version(); 127 128 // Internal version providing additional build information 129 static const char* internal_vm_info_string(); 130 static const char* jdk_debug_level(); 131 static const char* printable_jdk_debug_level(); 132 133 static const char* features_string() { return _features_string; } 134 135 static const char* cpu_info_string() { return _cpu_info_string; } 136 137 static VirtualizationType get_detected_virtualization() { 138 return _detected_virtualization; 139 } 140 141 // platforms that need to specialize this 142 // define VM_Version::print_platform_virtualization_info() 143 static void print_platform_virtualization_info(outputStream*) { } 144 145 // does HW support an 8-byte compare-exchange operation? 146 // Required to be true but still dynamically checked at runtime 147 // for platforms that don't set SUPPORTS_NATIVE_CX8 148 static bool supports_cx8() { 149 #ifdef SUPPORTS_NATIVE_CX8 150 return true; 151 #else 152 return _supports_cx8; 153 #endif 154 } 155 // does HW support atomic get-and-set or atomic get-and-add? Used 156 // to guide intrinsification decisions for Unsafe atomic ops 157 static bool supports_atomic_getset4() {return _supports_atomic_getset4;} 158 static bool supports_atomic_getset8() {return _supports_atomic_getset8;} 159 static bool supports_atomic_getadd4() {return _supports_atomic_getadd4;} 160 static bool supports_atomic_getadd8() {return _supports_atomic_getadd8;} 161 162 static unsigned int logical_processors_per_package() { 163 return _logical_processors_per_package; 164 } 165 166 static unsigned int L1_data_cache_line_size() { 167 return _L1_data_cache_line_size; 168 } 169 170 // the size in bytes of a data cache line flushed by a flush 171 // operation which should be a power of two or zero if cache line 172 // writeback is not supported by the current os_cpu combination 173 static unsigned int data_cache_line_flush_size() { 174 return _data_cache_line_flush_size; 175 } 176 177 // returns true if and only if cache line writeback is supported 178 static bool supports_data_cache_line_flush() { 179 return _data_cache_line_flush_size != 0; 180 } 181 182 // Denominator for computing default ParallelGCThreads for machines with 183 // a large number of cores. 184 static uint parallel_worker_threads_denominator() { return 8; } 185 186 // Does this CPU support spin wait instruction? 187 static bool supports_on_spin_wait() { return false; } 188 189 // Does platform support fast class initialization checks for static methods? 190 static bool supports_fast_class_init_checks() { return false; } 191 192 // Does platform support stack watermark barriers for concurrent stack processing? 193 constexpr static bool supports_stack_watermark_barrier() { return false; } 194 195 // Is recursive lightweight locking implemented for this platform? 196 constexpr static bool supports_recursive_lightweight_locking() { return false; } 197 198 // Does platform support secondary supers table lookup? 199 constexpr static bool supports_secondary_supers_table() { return false; } 200 201 // Does platform support float16 instructions? 202 static bool supports_float16() { return false; } 203 204 // Does this CPU support this intrinsic? 205 static bool is_intrinsic_supported(vmIntrinsicID id) { return true; } 206 207 static bool profile_all_receivers_at_type_check() { return true; } 208 209 static bool print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]); 210 211 protected: 212 // VM_Version statics 213 static const size_t CPU_TYPE_DESC_BUF_SIZE = 256; 214 static const size_t CPU_DETAILED_DESC_BUF_SIZE = 4096; 215 216 static int _no_of_threads; 217 static int _no_of_cores; 218 static int _no_of_sockets; 219 static bool _initialized; 220 static char _cpu_name[CPU_TYPE_DESC_BUF_SIZE]; 221 static char _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE]; 222 223 public: 224 static int number_of_threads(void); 225 static int number_of_cores(void); 226 static int number_of_sockets(void); 227 228 static const char* cpu_name(void); 229 static const char* cpu_description(void); 230 231 static void get_cpu_features_name(void* features_buffer, stringStream& ss) { return; } 232 static void get_missing_features_name(void* features_buffer, stringStream& ss) { return; } 233 234 // Returns number of bytes required to store cpu features representation 235 static int cpu_features_size() { return 0; } 236 237 // Stores arch dependent cpu features representation in the provided buffer. 238 // Size of the buffer must be same as returned by cpu_features_size() 239 static void store_cpu_features(void* buf) { return; } 240 241 // features_to_test is an opaque object that stores arch specific representation of cpu features 242 static bool supports_features(void* features_to_test) { return false; }; 243 }; 244 245 #endif // SHARE_RUNTIME_ABSTRACT_VM_VERSION_HPP