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