1 /*
   2  * Copyright (c) 1998, 2018, 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 "logging/log.hpp"
  27 #include "logging/logStream.hpp"
  28 #include "memory/universe.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/vm_version.hpp"
  32 
  33 const char* Abstract_VM_Version::_s_vm_release = Abstract_VM_Version::vm_release();
  34 const char* Abstract_VM_Version::_s_internal_vm_info_string = Abstract_VM_Version::internal_vm_info_string();
  35 
  36 uint64_t Abstract_VM_Version::_features = 0;
  37 const char* Abstract_VM_Version::_features_string = "";
  38 
  39 bool Abstract_VM_Version::_supports_cx8 = false;
  40 bool Abstract_VM_Version::_supports_atomic_getset4 = false;
  41 bool Abstract_VM_Version::_supports_atomic_getset8 = false;
  42 bool Abstract_VM_Version::_supports_atomic_getadd4 = false;
  43 bool Abstract_VM_Version::_supports_atomic_getadd8 = false;
  44 unsigned int Abstract_VM_Version::_logical_processors_per_package = 1U;
  45 unsigned int Abstract_VM_Version::_L1_data_cache_line_size = 0;
  46 unsigned int Abstract_VM_Version::_data_cache_line_flush_size = 0;
  47 
  48 #ifndef HOTSPOT_VERSION_STRING
  49   #error HOTSPOT_VERSION_STRING must be defined
  50 #endif
  51 
  52 #ifndef VERSION_FEATURE
  53   #error VERSION_FEATURE must be defined
  54 #endif
  55 #ifndef VERSION_INTERIM
  56   #error VERSION_INTERIM must be defined
  57 #endif
  58 #ifndef VERSION_UPDATE
  59   #error VERSION_UPDATE must be defined
  60 #endif
  61 #ifndef VERSION_PATCH
  62   #error VERSION_PATCH must be defined
  63 #endif
  64 #ifndef VERSION_BUILD
  65   #error VERSION_BUILD must be defined
  66 #endif
  67 
  68 #ifndef VERSION_STRING
  69   #error VERSION_STRING must be defined
  70 #endif
  71 
  72 #ifndef DEBUG_LEVEL
  73   #error DEBUG_LEVEL must be defined
  74 #endif
  75 
  76 #define VM_RELEASE HOTSPOT_VERSION_STRING
  77 
  78 // HOTSPOT_VERSION_STRING equals the JDK VERSION_STRING (unless overridden
  79 // in a standalone build).
  80 int Abstract_VM_Version::_vm_major_version = VERSION_FEATURE;
  81 int Abstract_VM_Version::_vm_minor_version = VERSION_INTERIM;
  82 int Abstract_VM_Version::_vm_security_version = VERSION_UPDATE;
  83 int Abstract_VM_Version::_vm_patch_version = VERSION_PATCH;
  84 int Abstract_VM_Version::_vm_build_number = VERSION_BUILD;
  85 unsigned int Abstract_VM_Version::_parallel_worker_threads = 0;
  86 bool Abstract_VM_Version::_parallel_worker_threads_initialized = false;
  87 
  88 #if defined(_LP64)
  89   #define VMLP "64-Bit "
  90 #else
  91   #define VMLP ""
  92 #endif
  93 
  94 #ifndef VMTYPE
  95   #ifdef TIERED
  96     #define VMTYPE "Server"
  97   #else // TIERED
  98   #ifdef ZERO
  99     #define VMTYPE "Zero"
 100   #else // ZERO
 101      #define VMTYPE COMPILER1_PRESENT("Client")   \
 102                     COMPILER2_PRESENT("Server")
 103   #endif // ZERO
 104   #endif // TIERED
 105 #endif
 106 
 107 #ifndef HOTSPOT_VM_DISTRO
 108   #error HOTSPOT_VM_DISTRO must be defined
 109 #endif
 110 #define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
 111 
 112 const char* Abstract_VM_Version::vm_name() {
 113   return VMNAME;
 114 }
 115 
 116 
 117 const char* Abstract_VM_Version::vm_vendor() {
 118 #ifdef VENDOR
 119   return VENDOR;
 120 #else
 121   return "Oracle Corporation";
 122 #endif
 123 }
 124 
 125 
 126 const char* Abstract_VM_Version::vm_info_string() {
 127   switch (Arguments::mode()) {
 128     case Arguments::_int:
 129       return UseSharedSpaces ? "interpreted mode, sharing" : "interpreted mode";
 130     case Arguments::_mixed:
 131       if (UseSharedSpaces) {
 132         if (UseAOT) {
 133           return "mixed mode, aot, sharing";
 134 #ifdef TIERED
 135         } else if(is_client_compilation_mode_vm()) {
 136           return "mixed mode, emulated-client, sharing";
 137 #endif
 138         } else {
 139           return "mixed mode, sharing";
 140          }
 141       } else {
 142         if (UseAOT) {
 143           return "mixed mode, aot";
 144 #ifdef TIERED
 145         } else if(is_client_compilation_mode_vm()) {
 146           return "mixed mode, emulated-client";
 147 #endif
 148         } else {
 149           return "mixed mode";
 150         }
 151       }
 152     case Arguments::_comp:
 153 #ifdef TIERED
 154       if (is_client_compilation_mode_vm()) {
 155          return UseSharedSpaces ? "compiled mode, emulated-client, sharing" : "compiled mode, emulated-client";
 156       }
 157 #endif
 158       return UseSharedSpaces ? "compiled mode, sharing"    : "compiled mode";
 159   };
 160   ShouldNotReachHere();
 161   return "";
 162 }
 163 
 164 // NOTE: do *not* use stringStream. this function is called by
 165 //       fatal error handler. if the crash is in native thread,
 166 //       stringStream cannot get resource allocated and will SEGV.
 167 const char* Abstract_VM_Version::vm_release() {
 168   return VM_RELEASE;
 169 }
 170 
 171 // NOTE: do *not* use stringStream. this function is called by
 172 //       fatal error handlers. if the crash is in native thread,
 173 //       stringStream cannot get resource allocated and will SEGV.
 174 const char* Abstract_VM_Version::jre_release_version() {
 175   return VERSION_STRING;
 176 }
 177 
 178 #define OS       LINUX_ONLY("linux")             \
 179                  WINDOWS_ONLY("windows")         \
 180                  SOLARIS_ONLY("solaris")         \
 181                  AIX_ONLY("aix")                 \
 182                  BSD_ONLY("bsd")
 183 
 184 #ifndef CPU
 185 #ifdef ZERO
 186 #define CPU      ZERO_LIBARCH
 187 #elif defined(PPC64)
 188 #if defined(VM_LITTLE_ENDIAN)
 189 #define CPU      "ppc64le"
 190 #else
 191 #define CPU      "ppc64"
 192 #endif // PPC64
 193 #else
 194 #define CPU      AARCH64_ONLY("aarch64")         \
 195                  AMD64_ONLY("amd64")             \
 196                  IA32_ONLY("x86")                \
 197                  IA64_ONLY("ia64")               \
 198                  S390_ONLY("s390")               \
 199                  SPARC_ONLY("sparc")
 200 #endif // !ZERO
 201 #endif // !CPU
 202 
 203 const char *Abstract_VM_Version::vm_platform_string() {
 204   return OS "-" CPU;
 205 }
 206 
 207 const char* Abstract_VM_Version::internal_vm_info_string() {
 208   #ifndef HOTSPOT_BUILD_USER
 209     #define HOTSPOT_BUILD_USER unknown
 210   #endif
 211 
 212   #ifndef HOTSPOT_BUILD_COMPILER
 213     #ifdef _MSC_VER
 214       #if _MSC_VER == 1600
 215         #define HOTSPOT_BUILD_COMPILER "MS VC++ 10.0 (VS2010)"
 216       #elif _MSC_VER == 1700
 217         #define HOTSPOT_BUILD_COMPILER "MS VC++ 11.0 (VS2012)"
 218       #elif _MSC_VER == 1800
 219         #define HOTSPOT_BUILD_COMPILER "MS VC++ 12.0 (VS2013)"
 220       #elif _MSC_VER == 1900
 221         #define HOTSPOT_BUILD_COMPILER "MS VC++ 14.0 (VS2015)"
 222       #elif _MSC_VER == 1912
 223         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.5 (VS2017)"
 224       #else
 225         #define HOTSPOT_BUILD_COMPILER "unknown MS VC++:" XSTR(_MSC_VER)
 226       #endif
 227     #elif defined(__SUNPRO_CC)
 228       #if   __SUNPRO_CC == 0x420
 229         #define HOTSPOT_BUILD_COMPILER "Workshop 4.2"
 230       #elif __SUNPRO_CC == 0x500
 231         #define HOTSPOT_BUILD_COMPILER "Workshop 5.0 compat=" XSTR(__SUNPRO_CC_COMPAT)
 232       #elif __SUNPRO_CC == 0x520
 233         #define HOTSPOT_BUILD_COMPILER "Workshop 5.2 compat=" XSTR(__SUNPRO_CC_COMPAT)
 234       #elif __SUNPRO_CC == 0x580
 235         #define HOTSPOT_BUILD_COMPILER "Workshop 5.8"
 236       #elif __SUNPRO_CC == 0x590
 237         #define HOTSPOT_BUILD_COMPILER "Workshop 5.9"
 238       #elif __SUNPRO_CC == 0x5100
 239         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u1"
 240       #elif __SUNPRO_CC == 0x5120
 241         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u3"
 242       #elif __SUNPRO_CC == 0x5130
 243         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u4"
 244       #else
 245         #define HOTSPOT_BUILD_COMPILER "unknown Workshop:" XSTR(__SUNPRO_CC)
 246       #endif
 247     #elif defined(__GNUC__)
 248         #define HOTSPOT_BUILD_COMPILER "gcc " __VERSION__
 249     #elif defined(__IBMCPP__)
 250         #define HOTSPOT_BUILD_COMPILER "xlC " XSTR(__IBMCPP__)
 251 
 252     #else
 253       #define HOTSPOT_BUILD_COMPILER "unknown compiler"
 254     #endif
 255   #endif
 256 
 257   #ifndef FLOAT_ARCH
 258     #if defined(__SOFTFP__)
 259       #define FLOAT_ARCH_STR "-sflt"
 260     #else
 261       #define FLOAT_ARCH_STR ""
 262     #endif
 263   #else
 264     #define FLOAT_ARCH_STR XSTR(FLOAT_ARCH)
 265   #endif
 266 
 267   #define INTERNAL_VERSION_SUFFIX VM_RELEASE ")" \
 268          " for " OS "-" CPU FLOAT_ARCH_STR \
 269          " JRE (" VERSION_STRING "), built on " __DATE__ " " __TIME__ \
 270          " by " XSTR(HOTSPOT_BUILD_USER) " with " HOTSPOT_BUILD_COMPILER
 271 
 272   return strcmp(DEBUG_LEVEL, "release") == 0
 273       ? VMNAME " (" INTERNAL_VERSION_SUFFIX
 274       : VMNAME " (" DEBUG_LEVEL " " INTERNAL_VERSION_SUFFIX;
 275 }
 276 
 277 const char *Abstract_VM_Version::vm_build_user() {
 278   return HOTSPOT_BUILD_USER;
 279 }
 280 
 281 const char *Abstract_VM_Version::jdk_debug_level() {
 282   return DEBUG_LEVEL;
 283 }
 284 
 285 const char *Abstract_VM_Version::printable_jdk_debug_level() {
 286   // Debug level is not printed for "release" builds
 287   return strcmp(DEBUG_LEVEL, "release") == 0 ? "" : DEBUG_LEVEL " ";
 288 }
 289 
 290 unsigned int Abstract_VM_Version::jvm_version() {
 291   return ((Abstract_VM_Version::vm_major_version() & 0xFF) << 24) |
 292          ((Abstract_VM_Version::vm_minor_version() & 0xFF) << 16) |
 293          ((Abstract_VM_Version::vm_security_version() & 0xFF) << 8) |
 294          (Abstract_VM_Version::vm_build_number() & 0xFF);
 295 }
 296 
 297 
 298 void VM_Version_init() {
 299   VM_Version::initialize();
 300 
 301   if (log_is_enabled(Info, os, cpu)) {
 302     char buf[1024];
 303     ResourceMark rm;
 304     LogStream ls(Log(os, cpu)::info());
 305     os::print_cpu_info(&ls, buf, sizeof(buf));
 306   }
 307 }
 308 
 309 unsigned int Abstract_VM_Version::nof_parallel_worker_threads(
 310                                                       unsigned int num,
 311                                                       unsigned int den,
 312                                                       unsigned int switch_pt) {
 313   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 314     assert(ParallelGCThreads == 0, "Default ParallelGCThreads is not 0");
 315     unsigned int threads;
 316     // For very large machines, there are diminishing returns
 317     // for large numbers of worker threads.  Instead of
 318     // hogging the whole system, use a fraction of the workers for every
 319     // processor after the first 8.  For example, on a 72 cpu machine
 320     // and a chosen fraction of 5/8
 321     // use 8 + (72 - 8) * (5/8) == 48 worker threads.
 322     unsigned int ncpus = (unsigned int) os::initial_active_processor_count();
 323     threads = (ncpus <= switch_pt) ?
 324              ncpus :
 325              (switch_pt + ((ncpus - switch_pt) * num) / den);
 326 #ifndef _LP64
 327     // On 32-bit binaries the virtual address space available to the JVM
 328     // is usually limited to 2-3 GB (depends on the platform).
 329     // Do not use up address space with too many threads (stacks and per-thread
 330     // data). Note that x86 apps running on Win64 have 2 stacks per thread.
 331     // GC may more generally scale down threads by max heap size (etc), but the
 332     // consequences of over-provisioning threads are higher on 32-bit JVMS,
 333     // so add hard limit here:
 334     threads = MIN2(threads, (2*switch_pt));
 335 #endif
 336     return threads;
 337   } else {
 338     return ParallelGCThreads;
 339   }
 340 }
 341 
 342 unsigned int Abstract_VM_Version::calc_parallel_worker_threads() {
 343   return nof_parallel_worker_threads(5, 8, 8);
 344 }
 345 
 346 
 347 // Does not set the _initialized flag since it is
 348 // a global flag.
 349 unsigned int Abstract_VM_Version::parallel_worker_threads() {
 350   if (!_parallel_worker_threads_initialized) {
 351     if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 352       _parallel_worker_threads = VM_Version::calc_parallel_worker_threads();
 353     } else {
 354       _parallel_worker_threads = ParallelGCThreads;
 355     }
 356     _parallel_worker_threads_initialized = true;
 357   }
 358   return _parallel_worker_threads;
 359 }