1 /*
   2  * Copyright (c) 1998, 2016, 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 #include "precompiled.hpp"
  26 #include "memory/universe.hpp"
  27 #include "oops/oop.inline.hpp"
  28 #include "runtime/arguments.hpp"
  29 #ifdef TARGET_ARCH_x86
  30 # include "vm_version_x86.hpp"
  31 #endif
  32 #ifdef TARGET_ARCH_aarch64
  33 # include "vm_version_aarch64.hpp"
  34 #endif
  35 #ifdef TARGET_ARCH_sparc
  36 # include "vm_version_sparc.hpp"
  37 #endif
  38 #ifdef TARGET_ARCH_zero
  39 # include "vm_version_zero.hpp"
  40 #endif
  41 #ifdef TARGET_ARCH_arm
  42 # include "vm_version_arm.hpp"
  43 #endif
  44 #ifdef TARGET_ARCH_ppc
  45 # include "vm_version_ppc.hpp"
  46 #endif
  47 
  48 const char* Abstract_VM_Version::_s_vm_release = Abstract_VM_Version::vm_release();
  49 const char* Abstract_VM_Version::_s_internal_vm_info_string = Abstract_VM_Version::internal_vm_info_string();
  50 bool Abstract_VM_Version::_supports_cx8 = false;
  51 bool Abstract_VM_Version::_supports_atomic_getset4 = false;
  52 bool Abstract_VM_Version::_supports_atomic_getset8 = false;
  53 bool Abstract_VM_Version::_supports_atomic_getadd4 = false;
  54 bool Abstract_VM_Version::_supports_atomic_getadd8 = false;
  55 unsigned int Abstract_VM_Version::_logical_processors_per_package = 1U;
  56 unsigned int Abstract_VM_Version::_L1_data_cache_line_size = 0;
  57 int Abstract_VM_Version::_reserve_for_allocation_prefetch = 0;
  58 
  59 #ifndef HOTSPOT_RELEASE_VERSION
  60   #error HOTSPOT_RELEASE_VERSION must be defined
  61 #endif
  62 #ifndef JRE_RELEASE_VERSION
  63   #error JRE_RELEASE_VERSION must be defined
  64 #endif
  65 #ifndef HOTSPOT_BUILD_TARGET
  66   #error HOTSPOT_BUILD_TARGET must be defined
  67 #endif
  68 
  69 #ifdef PRODUCT
  70   #define VM_RELEASE HOTSPOT_RELEASE_VERSION
  71 #else
  72   #define VM_RELEASE HOTSPOT_RELEASE_VERSION "-" HOTSPOT_BUILD_TARGET
  73 #endif
  74 
  75 // HOTSPOT_RELEASE_VERSION must follow the release version naming convention
  76 // <major_ver>.<minor_ver>-b<nn>[-<identifier>][-<debug_target>]
  77 int Abstract_VM_Version::_vm_major_version = 0;
  78 int Abstract_VM_Version::_vm_minor_version = 0;
  79 int Abstract_VM_Version::_vm_build_number = 0;
  80 bool Abstract_VM_Version::_initialized = false;
  81 int Abstract_VM_Version::_parallel_worker_threads = 0;
  82 bool Abstract_VM_Version::_parallel_worker_threads_initialized = false;
  83 
  84 void Abstract_VM_Version::initialize() {
  85   if (_initialized) {
  86     return;
  87   }
  88   char* vm_version = os::strdup(HOTSPOT_RELEASE_VERSION);
  89 
  90   // Expecting the next vm_version format:
  91   // <major_ver>.<minor_ver>-b<nn>[-<identifier>]
  92   char* vm_major_ver = vm_version;
  93   assert(isdigit(vm_major_ver[0]),"wrong vm major version number");
  94   char* vm_minor_ver = strchr(vm_major_ver, '.');
  95   assert(vm_minor_ver != NULL && isdigit(vm_minor_ver[1]),"wrong vm minor version number");
  96   vm_minor_ver[0] = '\0'; // terminate vm_major_ver
  97   vm_minor_ver += 1;
  98   char* vm_build_num = strchr(vm_minor_ver, '-');
  99   assert(vm_build_num != NULL && vm_build_num[1] == 'b' && isdigit(vm_build_num[2]),"wrong vm build number");
 100   vm_build_num[0] = '\0'; // terminate vm_minor_ver
 101   vm_build_num += 2;
 102 
 103   _vm_major_version = atoi(vm_major_ver);
 104   _vm_minor_version = atoi(vm_minor_ver);
 105   _vm_build_number  = atoi(vm_build_num);
 106 
 107   os::free(vm_version);
 108   _initialized = true;
 109 }
 110 
 111 #if defined(_LP64)
 112   #define VMLP "64-Bit "
 113 #else
 114   #define VMLP ""
 115 #endif
 116 
 117 #ifndef VMTYPE
 118   #ifdef TIERED
 119     #define VMTYPE "Server"
 120   #else // TIERED
 121   #ifdef ZERO
 122   #ifdef SHARK
 123     #define VMTYPE "Shark"
 124   #else // SHARK
 125     #define VMTYPE "Zero"
 126   #endif // SHARK
 127   #else // ZERO
 128      #define VMTYPE COMPILER1_PRESENT("Client")   \
 129                     COMPILER2_PRESENT("Server")
 130   #endif // ZERO
 131   #endif // TIERED
 132 #endif
 133 
 134 #ifndef HOTSPOT_VM_DISTRO
 135   #error HOTSPOT_VM_DISTRO must be defined
 136 #endif
 137 #define VMNAME HOTSPOT_VM_DISTRO " " VMLP EMBEDDED_ONLY("Embedded ") VMTYPE " VM"
 138 
 139 const char* Abstract_VM_Version::vm_name() {
 140   return VMNAME;
 141 }
 142 
 143 
 144 const char* Abstract_VM_Version::vm_vendor() {
 145 #ifdef VENDOR
 146   return VENDOR;
 147 #else
 148   return JDK_Version::is_gte_jdk17x_version() ?
 149     "Oracle Corporation" : "Sun Microsystems Inc.";
 150 #endif
 151 }
 152 
 153 
 154 const char* Abstract_VM_Version::vm_info_string() {
 155   switch (Arguments::mode()) {
 156     case Arguments::_int:
 157       return UseSharedSpaces ? "interpreted mode, sharing" : "interpreted mode";
 158     case Arguments::_mixed:
 159       return UseSharedSpaces ? "mixed mode, sharing"       :  "mixed mode";
 160     case Arguments::_comp:
 161       return UseSharedSpaces ? "compiled mode, sharing"    : "compiled mode";
 162   };
 163   ShouldNotReachHere();
 164   return "";
 165 }
 166 
 167 // NOTE: do *not* use stringStream. this function is called by
 168 //       fatal error handler. if the crash is in native thread,
 169 //       stringStream cannot get resource allocated and will SEGV.
 170 const char* Abstract_VM_Version::vm_release() {
 171   return VM_RELEASE;
 172 }
 173 
 174 // NOTE: do *not* use stringStream. this function is called by
 175 //       fatal error handlers. if the crash is in native thread,
 176 //       stringStream cannot get resource allocated and will SEGV.
 177 const char* Abstract_VM_Version::jre_release_version() {
 178   return JRE_RELEASE_VERSION;
 179 }
 180 
 181 #define OS       LINUX_ONLY("linux")             \
 182                  WINDOWS_ONLY("windows")         \
 183                  SOLARIS_ONLY("solaris")         \
 184                  AIX_ONLY("aix")                 \
 185                  BSD_ONLY("bsd")
 186 
 187 #ifndef CPU
 188 #ifdef ZERO
 189 #define CPU      ZERO_LIBARCH
 190 #elif defined(PPC64)
 191 #if defined(VM_LITTLE_ENDIAN)
 192 #define CPU      "ppc64le"
 193 #else
 194 #define CPU      "ppc64"
 195 #endif
 196 #else
 197 #define CPU      IA32_ONLY("x86")                \
 198                  IA64_ONLY("ia64")               \
 199                  AMD64_ONLY("amd64")             \
 200                  AARCH64_ONLY("aarch64")         \
 201                  SPARC_ONLY("sparc")
 202 #endif // ZERO
 203 #endif
 204 
 205 const char *Abstract_VM_Version::vm_platform_string() {
 206   return OS "-" CPU;
 207 }
 208 
 209 const char* Abstract_VM_Version::internal_vm_info_string() {
 210   #ifndef HOTSPOT_BUILD_USER
 211     #define HOTSPOT_BUILD_USER unknown
 212   #endif
 213 
 214   #ifndef HOTSPOT_BUILD_COMPILER
 215     #ifdef _MSC_VER
 216       #if   _MSC_VER == 1100
 217         #define HOTSPOT_BUILD_COMPILER "MS VC++ 5.0"
 218       #elif _MSC_VER == 1200
 219         #define HOTSPOT_BUILD_COMPILER "MS VC++ 6.0"
 220       #elif _MSC_VER == 1310
 221         #define HOTSPOT_BUILD_COMPILER "MS VC++ 7.1 (VS2003)"
 222       #elif _MSC_VER == 1400
 223         #define HOTSPOT_BUILD_COMPILER "MS VC++ 8.0 (VS2005)"
 224       #elif _MSC_VER == 1500
 225         #define HOTSPOT_BUILD_COMPILER "MS VC++ 9.0 (VS2008)"
 226       #elif _MSC_VER == 1600
 227         #define HOTSPOT_BUILD_COMPILER "MS VC++ 10.0 (VS2010)"
 228       #elif _MSC_VER == 1700
 229         #define HOTSPOT_BUILD_COMPILER "MS VC++ 11.0 (VS2012)"
 230       #elif _MSC_VER == 1800
 231         #define HOTSPOT_BUILD_COMPILER "MS VC++ 12.0 (VS2013)"
 232       #elif _MSC_VER == 1900
 233         #define HOTSPOT_BUILD_COMPILER "MS VC++ 14.0 (VS2015)"
 234       #elif _MSC_VER == 1912
 235         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.5 (VS2017)"
 236       #elif _MSC_VER == 1913
 237         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.6 (VS2017)"
 238       #else
 239         #define HOTSPOT_BUILD_COMPILER "unknown MS VC++:" XSTR(_MSC_VER)
 240       #endif
 241     #elif defined(__SUNPRO_CC)
 242       #if   __SUNPRO_CC == 0x420
 243         #define HOTSPOT_BUILD_COMPILER "Workshop 4.2"
 244       #elif __SUNPRO_CC == 0x500
 245         #define HOTSPOT_BUILD_COMPILER "Workshop 5.0 compat=" XSTR(__SUNPRO_CC_COMPAT)
 246       #elif __SUNPRO_CC == 0x520
 247         #define HOTSPOT_BUILD_COMPILER "Workshop 5.2 compat=" XSTR(__SUNPRO_CC_COMPAT)
 248       #elif __SUNPRO_CC == 0x580
 249         #define HOTSPOT_BUILD_COMPILER "Workshop 5.8"
 250       #elif __SUNPRO_CC == 0x590
 251         #define HOTSPOT_BUILD_COMPILER "Workshop 5.9"
 252       #elif __SUNPRO_CC == 0x5100
 253         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u1"
 254       #elif __SUNPRO_CC == 0x5120
 255         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u3"
 256       #else
 257         #define HOTSPOT_BUILD_COMPILER "unknown Workshop:" XSTR(__SUNPRO_CC)
 258       #endif
 259     #elif defined(__GNUC__)
 260         #define HOTSPOT_BUILD_COMPILER "gcc " __VERSION__
 261     #elif defined(__IBMCPP__)
 262         #define HOTSPOT_BUILD_COMPILER "xlC " XSTR(__IBMCPP__)
 263 
 264     #else
 265       #define HOTSPOT_BUILD_COMPILER "unknown compiler"
 266     #endif
 267   #endif
 268 
 269   #ifndef FLOAT_ARCH
 270     #if defined(__SOFTFP__)
 271       #define FLOAT_ARCH_STR "-sflt"
 272     #else
 273       #define FLOAT_ARCH_STR ""
 274     #endif
 275   #else
 276     #define FLOAT_ARCH_STR XSTR(FLOAT_ARCH)
 277   #endif
 278 
 279   return VMNAME " (" VM_RELEASE ") for " OS "-" CPU FLOAT_ARCH_STR
 280          " JRE (" JRE_RELEASE_VERSION "), built on " __DATE__ " " __TIME__
 281          " by " XSTR(HOTSPOT_BUILD_USER) " with " HOTSPOT_BUILD_COMPILER;
 282 }
 283 
 284 const char *Abstract_VM_Version::vm_build_user() {
 285   return HOTSPOT_BUILD_USER;
 286 }
 287 
 288 unsigned int Abstract_VM_Version::jvm_version() {
 289   return ((Abstract_VM_Version::vm_major_version() & 0xFF) << 24) |
 290          ((Abstract_VM_Version::vm_minor_version() & 0xFF) << 16) |
 291          (Abstract_VM_Version::vm_build_number() & 0xFF);
 292 }
 293 
 294 
 295 void VM_Version_init() {
 296   VM_Version::initialize();
 297 
 298 #ifndef PRODUCT
 299   if (PrintMiscellaneous && Verbose) {
 300     os::print_cpu_info(tty);
 301   }
 302 #endif
 303 }
 304 
 305 unsigned int Abstract_VM_Version::nof_parallel_worker_threads(
 306                                                       unsigned int num,
 307                                                       unsigned int den,
 308                                                       unsigned int switch_pt) {
 309   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 310     assert(ParallelGCThreads == 0, "Default ParallelGCThreads is not 0");
 311     // For very large machines, there are diminishing returns
 312     // for large numbers of worker threads.  Instead of
 313     // hogging the whole system, use a fraction of the workers for every
 314     // processor after the first 8.  For example, on a 72 cpu machine
 315     // and a chosen fraction of 5/8
 316     // use 8 + (72 - 8) * (5/8) == 48 worker threads.
 317     unsigned int ncpus = (unsigned int) os::initial_active_processor_count();
 318     return (ncpus <= switch_pt) ?
 319            ncpus :
 320           (switch_pt + ((ncpus - switch_pt) * num) / den);
 321   } else {
 322     return ParallelGCThreads;
 323   }
 324 }
 325 
 326 unsigned int Abstract_VM_Version::calc_parallel_worker_threads() {
 327   return nof_parallel_worker_threads(5, 8, 8);
 328 }
 329 
 330 
 331 // Does not set the _initialized flag since it is
 332 // a global flag.
 333 unsigned int Abstract_VM_Version::parallel_worker_threads() {
 334   if (!_parallel_worker_threads_initialized) {
 335     if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 336       _parallel_worker_threads = VM_Version::calc_parallel_worker_threads();
 337     } else {
 338       _parallel_worker_threads = ParallelGCThreads;
 339     }
 340     _parallel_worker_threads_initialized = true;
 341   }
 342   return _parallel_worker_threads;
 343 }