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
136 static VirtualizationType get_detected_virtualization() {
137 return _detected_virtualization;
138 }
139
140 // platforms that need to specialize this
141 // define VM_Version::print_platform_virtualization_info()
142 static void print_platform_virtualization_info(outputStream*) { }
143
144 // does HW support an 8-byte compare-exchange operation?
145 // Required to be true but still dynamically checked at runtime
146 // for platforms that don't set SUPPORTS_NATIVE_CX8
147 static bool supports_cx8() {
148 #ifdef SUPPORTS_NATIVE_CX8
149 return true;
150 #else
151 return _supports_cx8;
152 #endif
153 }
154 // does HW support atomic get-and-set or atomic get-and-add? Used
155 // to guide intrinsification decisions for Unsafe atomic ops
156 static bool supports_atomic_getset4() {return _supports_atomic_getset4;}
157 static bool supports_atomic_getset8() {return _supports_atomic_getset8;}
158 static bool supports_atomic_getadd4() {return _supports_atomic_getadd4;}
159 static bool supports_atomic_getadd8() {return _supports_atomic_getadd8;}
160
161 static unsigned int logical_processors_per_package() {
162 return _logical_processors_per_package;
163 }
164
165 static unsigned int L1_data_cache_line_size() {
166 return _L1_data_cache_line_size;
167 }
168
169 // the size in bytes of a data cache line flushed by a flush
170 // operation which should be a power of two or zero if cache line
171 // writeback is not supported by the current os_cpu combination
172 static unsigned int data_cache_line_flush_size() {
173 return _data_cache_line_flush_size;
174 }
175
176 // returns true if and only if cache line writeback is supported
177 static bool supports_data_cache_line_flush() {
178 return _data_cache_line_flush_size != 0;
179 }
180
181 // Denominator for computing default ParallelGCThreads for machines with
182 // a large number of cores.
183 static uint parallel_worker_threads_denominator() { return 8; }
184
185 // Does this CPU support spin wait instruction?
186 static bool supports_on_spin_wait() { return false; }
187
188 // Does platform support fast class initialization checks for static methods?
189 static bool supports_fast_class_init_checks() { return false; }
190
191 // Does platform support stack watermark barriers for concurrent stack processing?
192 constexpr static bool supports_stack_watermark_barrier() { return false; }
193
194 // Is recursive lightweight locking implemented for this platform?
195 constexpr static bool supports_recursive_lightweight_locking() { return false; }
196
197 // Does platform support secondary supers table lookup?
198 constexpr static bool supports_secondary_supers_table() { return false; }
199
200 // Does platform support float16 instructions?
201 static bool supports_float16() { return false; }
202
203 // Does this CPU support this intrinsic?
204 static bool is_intrinsic_supported(vmIntrinsicID id) { return true; }
205
206 static bool profile_all_receivers_at_type_check() { return true; }
207
208 static bool print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]);
209
210 protected:
211 // VM_Version statics
212 static const size_t CPU_TYPE_DESC_BUF_SIZE = 256;
213 static const size_t CPU_DETAILED_DESC_BUF_SIZE = 4096;
214
215 static int _no_of_threads;
216 static int _no_of_cores;
217 static int _no_of_sockets;
218 static bool _initialized;
219 static char _cpu_name[CPU_TYPE_DESC_BUF_SIZE];
220 static char _cpu_desc[CPU_DETAILED_DESC_BUF_SIZE];
221
222 public:
223 static int number_of_threads(void);
224 static int number_of_cores(void);
225 static int number_of_sockets(void);
226
227 static const char* cpu_name(void);
228 static const char* cpu_description(void);
229 };
230
231 #endif // SHARE_RUNTIME_ABSTRACT_VM_VERSION_HPP