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 enum class vmIntrinsicID; 46 47 // Abstract_VM_Version provides information about the VM. 48 49 class Abstract_VM_Version: AllStatic { 50 friend class VMStructs; 51 friend class JVMCIVMStructs; 52 53 protected: 54 static const char* _s_vm_release; 55 static const char* _s_internal_vm_info_string; 56 57 // CPU feature flags, can be affected by VM settings. 58 static uint64_t _features; 59 60 static const char* _features_string; 61 62 static const char* _cpu_info_string; 63 64 // Original CPU feature flags, not affected by VM settings. 65 static uint64_t _cpu_features; 66 67 // These are set by machine-dependent initializations 68 #ifndef SUPPORTS_NATIVE_CX8 69 static bool _supports_cx8; 70 #endif 71 static bool _supports_atomic_getset4; 72 static bool _supports_atomic_getset8; 73 static bool _supports_atomic_getadd4; 74 static bool _supports_atomic_getadd8; 75 static unsigned int _logical_processors_per_package; 76 static unsigned int _L1_data_cache_line_size; 77 static int _vm_major_version; 78 static int _vm_minor_version; 79 static int _vm_security_version; 80 static int _vm_patch_version; 81 static int _vm_build_number; 82 static unsigned int _data_cache_line_flush_size; 83 84 public: 85 86 static VirtualizationType _detected_virtualization; 87 88 // Called as part of the runtime services initialization which is 89 // called from the management module initialization (via init_globals()) 90 // after argument parsing and attaching of the main thread has 91 // occurred. Examines a variety of the hardware capabilities of 92 // the platform to determine which features can be used to execute the 93 // program. 94 static void initialize() { } 95 96 // This allows for early initialization of VM_Version information 97 // that may be needed later in the initialization sequence but before 98 // full VM_Version initialization is possible. It can not depend on any 99 // other part of the VM being initialized when called. Platforms that 100 // need to specialize this define VM_Version::early_initialize(). 101 static void early_initialize() { } 102 103 // Called to initialize VM variables needing initialization 104 // after command line parsing. Platforms that need to specialize 105 // this should define VM_Version::init_before_ergo(). 106 static void init_before_ergo() {} 107 108 // Name 109 static const char* vm_name(); 110 // Vendor 111 static const char* vm_vendor(); 112 // VM version information string printed by launcher (java -version) 113 static const char* vm_info_string(); 114 static const char* vm_release(); 115 static const char* vm_platform_string(); 116 static const char* vm_variant(); 117 118 static int vm_major_version() { return _vm_major_version; } 119 static int vm_minor_version() { return _vm_minor_version; } 120 static int vm_security_version() { return _vm_security_version; } 121 static int vm_patch_version() { return _vm_patch_version; } 122 static int vm_build_number() { return _vm_build_number; } 123 124 // Gets the jvm_version_info.jvm_version 125 static unsigned int jvm_version(); 126 127 // Internal version providing additional build information 128 static const char* internal_vm_info_string(); 129 static const char* jdk_debug_level(); 130 static const char* printable_jdk_debug_level(); 131 132 static const char* features_string() { return _features_string; } 133 134 static const char* cpu_info_string() { return _cpu_info_string; } 135 static const char* extract_features_string(const char* cpu_info_string, 136 size_t cpu_info_string_len, 137 size_t features_offset); 138 139 static VirtualizationType get_detected_virtualization() { 140 return _detected_virtualization; 141 } 142 143 // platforms that need to specialize this 144 // define VM_Version::print_platform_virtualization_info() 145 static void print_platform_virtualization_info(outputStream*) { } 146 147 // does HW support an 8-byte compare-exchange operation? 148 // Required to be true but still dynamically checked at runtime 149 // for platforms that don't set SUPPORTS_NATIVE_CX8 150 static bool supports_cx8() { 151 #ifdef SUPPORTS_NATIVE_CX8 152 return true; 153 #else 154 return _supports_cx8; 155 #endif 156 } 157 // does HW support atomic get-and-set or atomic get-and-add? Used 158 // to guide intrinsification decisions for Unsafe atomic ops 159 static bool supports_atomic_getset4() {return _supports_atomic_getset4;} 160 static bool supports_atomic_getset8() {return _supports_atomic_getset8;} 161 static bool supports_atomic_getadd4() {return _supports_atomic_getadd4;} 162 static bool supports_atomic_getadd8() {return _supports_atomic_getadd8;} 163 164 static unsigned int logical_processors_per_package() { 165 return _logical_processors_per_package; 166 } 167 168 static unsigned int L1_data_cache_line_size() { 169 return _L1_data_cache_line_size; 170 } 171 172 // the size in bytes of a data cache line flushed by a flush 173 // operation which should be a power of two or zero if cache line 174 // writeback is not supported by the current os_cpu combination 175 static unsigned int data_cache_line_flush_size() { 176 return _data_cache_line_flush_size; 177 } 178 179 // returns true if and only if cache line writeback is supported 180 static bool supports_data_cache_line_flush() { 181 return _data_cache_line_flush_size != 0; 182 } 183 184 // Denominator for computing default ParallelGCThreads for machines with 185 // a large number of cores. 186 static uint parallel_worker_threads_denominator() { return 8; } 187 188 // Does this CPU support spin wait instruction? 189 static bool supports_on_spin_wait() { return false; } 190 191 // Does platform support fast class initialization checks for static methods? 192 static bool supports_fast_class_init_checks() { return false; } 193 194 // Does platform support stack watermark barriers for concurrent stack processing? 195 constexpr static bool supports_stack_watermark_barrier() { return false; } 196 197 // Is recursive lightweight locking implemented for this platform? 198 constexpr static bool supports_recursive_lightweight_locking() { return false; } 199 200 // Does platform support secondary supers table lookup? 201 constexpr static bool supports_secondary_supers_table() { return false; } 202 203 // Does platform support float16 instructions? 204 static bool supports_float16() { return false; } 205 206 // Does this CPU support this intrinsic? 207 static bool is_intrinsic_supported(vmIntrinsicID id) { return true; } 208 209 static bool profile_all_receivers_at_type_check() { return true; } 210 211 static bool print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]); 212 213 protected: 214 // VM_Version statics 215 static const size_t CPU_TYPE_DESC_BUF_SIZE = 256; 216 static const size_t CPU_DETAILED_DESC_BUF_SIZE = 4096; 217 218 static int _no_of_threads; 219 static int _no_of_cores; 220 static int _no_of_sockets; 221 static bool _initialized; 222 static char _cpu_name[CPU_TYPE_DESC_BUF_SIZE]; 223 static char _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE]; 224 225 public: 226 static int number_of_threads(void); 227 static int number_of_cores(void); 228 static int number_of_sockets(void); 229 230 static const char* cpu_name(void); 231 static const char* cpu_description(void); 232 }; 233 234 #endif // SHARE_RUNTIME_ABSTRACT_VM_VERSION_HPP