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