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