1 /*
   2  * Copyright (c) 1997, 2020, 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_VM_RUNTIME_VM_VERSION_HPP
  26 #define SHARE_VM_RUNTIME_VM_VERSION_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/ostream.hpp"
  30 #include "utilities/macros.hpp"
  31 
  32 typedef enum {
  33   NoDetectedVirtualization,
  34   XenHVM,
  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 // VM_Version provides information about the VM.
  45 
  46 class Abstract_VM_Version: AllStatic {
  47   friend class VMStructs;
  48   friend class JVMCIVMStructs;
  49 
  50  protected:
  51   static const char*  _s_vm_release;
  52   static const char*  _s_internal_vm_info_string;
  53 
  54   // CPU feature flags.
  55   static uint64_t _features;
  56   static const char* _features_string;
  57 
  58   // These are set by machine-dependent initializations
  59   static bool         _supports_cx8;
  60   static bool         _supports_atomic_getset4;
  61   static bool         _supports_atomic_getset8;
  62   static bool         _supports_atomic_getadd4;
  63   static bool         _supports_atomic_getadd8;
  64   static unsigned int _logical_processors_per_package;
  65   static unsigned int _L1_data_cache_line_size;
  66   static int          _vm_major_version;
  67   static int          _vm_minor_version;
  68   static int          _vm_security_version;
  69   static int          _vm_patch_version;
  70   static int          _vm_build_number;
  71 
  72   static VirtualizationType _detected_virtualization;
  73 
  74   static unsigned int _parallel_worker_threads;
  75   static bool         _parallel_worker_threads_initialized;
  76 
  77   static unsigned int nof_parallel_worker_threads(unsigned int num,
  78                                                   unsigned int dem,
  79                                                   unsigned int switch_pt);
  80  public:
  81   // Called as part of the runtime services initialization which is
  82   // called from the management module initialization (via init_globals())
  83   // after argument parsing and attaching of the main thread has
  84   // occurred.  Examines a variety of the hardware capabilities of
  85   // the platform to determine which features can be used to execute the
  86   // program.
  87   static void initialize();
  88 
  89   // This allows for early initialization of VM_Version information
  90   // that may be needed later in the initialization sequence but before
  91   // full VM_Version initialization is possible. It can not depend on any
  92   // other part of the VM being initialized when called. Platforms that
  93   // need to specialize this define VM_Version::early_initialize().
  94   static void early_initialize() { }
  95 
  96   // Called to initialize VM variables needing initialization
  97   // after command line parsing. Platforms that need to specialize
  98   // this should define VM_Version::init_before_ergo().
  99   static void init_before_ergo() {}
 100 
 101   // Name
 102   static const char* vm_name();
 103   // Vendor
 104   static const char* vm_vendor();
 105   // VM version information string printed by launcher (java -version)
 106   static const char* vm_info_string();
 107   static const char* vm_release();
 108   static const char* vm_platform_string();
 109   static const char* vm_build_user();
 110 
 111   static int vm_major_version()               { return _vm_major_version; }
 112   static int vm_minor_version()               { return _vm_minor_version; }
 113   static int vm_security_version()            { return _vm_security_version; }
 114   static int vm_patch_version()               { return _vm_patch_version; }
 115   static int vm_build_number()                { return _vm_build_number; }
 116 
 117   // Gets the jvm_version_info.jvm_version defined in jvm.h
 118   static unsigned int jvm_version();
 119 
 120   // Internal version providing additional build information
 121   static const char* internal_vm_info_string();
 122   static const char* jre_release_version();
 123   static const char* jdk_debug_level();
 124   static const char* printable_jdk_debug_level();
 125 
 126   static uint64_t features() {
 127     return _features;
 128   }
 129 
 130   static const char* features_string() {
 131     return _features_string;
 132   }
 133 
 134   static VirtualizationType get_detected_virtualization() {
 135     return _detected_virtualization;
 136   }
 137 
 138   // platforms that need to specialize this
 139   // define VM_Version::print_platform_virtualization_info()
 140   static void print_platform_virtualization_info(outputStream*) { }
 141 
 142   // does HW support an 8-byte compare-exchange operation?
 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   // ARCH specific policy for the BiasedLocking
 166   static bool use_biased_locking()  { return true; }
 167 
 168   // Number of page sizes efficiently supported by the hardware.  Most chips now
 169   // support two sizes, thus this default implementation.  Processor-specific
 170   // subclasses should define new versions to hide this one as needed.  Note
 171   // that the O/S may support more sizes, but at most this many are used.
 172   static uint page_size_count() { return 2; }
 173 
 174   // Returns the number of parallel threads to be used for VM
 175   // work.  If that number has not been calculated, do so and
 176   // save it.  Returns ParallelGCThreads if it is set on the
 177   // command line.
 178   static unsigned int parallel_worker_threads();
 179   // Calculates and returns the number of parallel threads.  May
 180   // be VM version specific.
 181   static unsigned int calc_parallel_worker_threads();
 182 
 183   // Does this CPU support spin wait instruction?
 184   static bool supports_on_spin_wait() { return false; }
 185 
 186   static bool print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]);
 187 };
 188 
 189 #include CPU_HEADER(vm_version)
 190 
 191 #endif // SHARE_VM_RUNTIME_VM_VERSION_HPP