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       if (UseSharedSpaces) {
 134           if (UseAOT) {
 135             return "mixed mode, aot, sharing";
 136           } else {
 137             return "mixed mode, sharing";
 138           }
 139       } else {
 140         if (UseAOT) {
 141           return "mixed mode, aot";
 142         } else {
 143           return "mixed mode";
 144         }
 145       }
 146     case Arguments::_comp:
 147       return UseSharedSpaces ? "compiled mode, sharing"    : "compiled mode";
 148   };
 149   ShouldNotReachHere();
 150   return "";
 151 }
 152 
 153 // NOTE: do *not* use stringStream. this function is called by
 154 //       fatal error handler. if the crash is in native thread,
 155 //       stringStream cannot get resource allocated and will SEGV.
 156 const char* Abstract_VM_Version::vm_release() {
 157   return VM_RELEASE;
 158 }
 159 
 160 // NOTE: do *not* use stringStream. this function is called by
 161 //       fatal error handlers. if the crash is in native thread,
 162 //       stringStream cannot get resource allocated and will SEGV.
 163 const char* Abstract_VM_Version::jre_release_version() {
 164   return VERSION_STRING;
 165 }
 166 
 167 #define OS       LINUX_ONLY("linux")             \
 168                  WINDOWS_ONLY("windows")         \
 169                  SOLARIS_ONLY("solaris")         \
 170                  AIX_ONLY("aix")                 \
 171                  BSD_ONLY("bsd")
 172 
 173 #ifndef CPU
 174 #ifdef ZERO
 175 #define CPU      ZERO_LIBARCH
 176 #elif defined(PPC64)
 177 #if defined(VM_LITTLE_ENDIAN)
 178 #define CPU      "ppc64le"
 179 #else
 180 #define CPU      "ppc64"
 181 #endif // PPC64
 182 #else
 183 #define CPU      AARCH64_ONLY("aarch64")         \
 184                  AMD64_ONLY("amd64")             \
 185                  IA32_ONLY("x86")                \
 186                  IA64_ONLY("ia64")               \
 187                  S390_ONLY("s390")               \
 188                  SPARC_ONLY("sparc")
 189 #endif // !ZERO
 190 #endif // !CPU
 191 
 192 const char *Abstract_VM_Version::vm_platform_string() {
 193   return OS "-" CPU;
 194 }
 195 
 196 const char* Abstract_VM_Version::internal_vm_info_string() {
 197   #ifndef HOTSPOT_BUILD_USER
 198     #define HOTSPOT_BUILD_USER unknown
 199   #endif
 200 
 201   #ifndef HOTSPOT_BUILD_COMPILER
 202     #ifdef _MSC_VER
 203       #if _MSC_VER == 1600
 204         #define HOTSPOT_BUILD_COMPILER "MS VC++ 10.0 (VS2010)"
 205       #elif _MSC_VER == 1700
 206         #define HOTSPOT_BUILD_COMPILER "MS VC++ 11.0 (VS2012)"
 207       #elif _MSC_VER == 1800
 208         #define HOTSPOT_BUILD_COMPILER "MS VC++ 12.0 (VS2013)"
 209       #else
 210         #define HOTSPOT_BUILD_COMPILER "unknown MS VC++:" XSTR(_MSC_VER)
 211       #endif
 212     #elif defined(__SUNPRO_CC)
 213       #if   __SUNPRO_CC == 0x420
 214         #define HOTSPOT_BUILD_COMPILER "Workshop 4.2"
 215       #elif __SUNPRO_CC == 0x500
 216         #define HOTSPOT_BUILD_COMPILER "Workshop 5.0 compat=" XSTR(__SUNPRO_CC_COMPAT)
 217       #elif __SUNPRO_CC == 0x520
 218         #define HOTSPOT_BUILD_COMPILER "Workshop 5.2 compat=" XSTR(__SUNPRO_CC_COMPAT)
 219       #elif __SUNPRO_CC == 0x580
 220         #define HOTSPOT_BUILD_COMPILER "Workshop 5.8"
 221       #elif __SUNPRO_CC == 0x590
 222         #define HOTSPOT_BUILD_COMPILER "Workshop 5.9"
 223       #elif __SUNPRO_CC == 0x5100
 224         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u1"
 225       #elif __SUNPRO_CC == 0x5120
 226         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u3"
 227       #elif __SUNPRO_CC == 0x5130
 228         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u4"
 229       #else
 230         #define HOTSPOT_BUILD_COMPILER "unknown Workshop:" XSTR(__SUNPRO_CC)
 231       #endif
 232     #elif defined(__GNUC__)
 233         #define HOTSPOT_BUILD_COMPILER "gcc " __VERSION__
 234     #elif defined(__IBMCPP__)
 235         #define HOTSPOT_BUILD_COMPILER "xlC " XSTR(__IBMCPP__)
 236 
 237     #else
 238       #define HOTSPOT_BUILD_COMPILER "unknown compiler"
 239     #endif
 240   #endif
 241 
 242   #ifndef FLOAT_ARCH
 243     #if defined(__SOFTFP__)
 244       #define FLOAT_ARCH_STR "-sflt"
 245     #else
 246       #define FLOAT_ARCH_STR ""
 247     #endif
 248   #else
 249     #define FLOAT_ARCH_STR XSTR(FLOAT_ARCH)
 250   #endif
 251 
 252   #define INTERNAL_VERSION_SUFFIX VM_RELEASE ")" \
 253          " for " OS "-" CPU FLOAT_ARCH_STR \
 254          " JRE (" VERSION_STRING "), built on " __DATE__ " " __TIME__ \
 255          " by " XSTR(HOTSPOT_BUILD_USER) " with " HOTSPOT_BUILD_COMPILER
 256 
 257   return strcmp(DEBUG_LEVEL, "release") == 0
 258       ? VMNAME " (" INTERNAL_VERSION_SUFFIX
 259       : VMNAME " (" DEBUG_LEVEL " " INTERNAL_VERSION_SUFFIX;
 260 }
 261 
 262 const char *Abstract_VM_Version::vm_build_user() {
 263   return HOTSPOT_BUILD_USER;
 264 }
 265 
 266 const char *Abstract_VM_Version::jdk_debug_level() {
 267   return DEBUG_LEVEL;
 268 }
 269 
 270 const char *Abstract_VM_Version::printable_jdk_debug_level() {
 271   // Debug level is not printed for "release" builds
 272   return strcmp(DEBUG_LEVEL, "release") == 0 ? "" : DEBUG_LEVEL " ";
 273 }
 274 
 275 unsigned int Abstract_VM_Version::jvm_version() {
 276   return ((Abstract_VM_Version::vm_major_version() & 0xFF) << 24) |
 277          ((Abstract_VM_Version::vm_minor_version() & 0xFF) << 16) |
 278          ((Abstract_VM_Version::vm_security_version() & 0xFF) << 8) |
 279          (Abstract_VM_Version::vm_build_number() & 0xFF);
 280 }
 281 
 282 
 283 void VM_Version_init() {
 284   VM_Version::initialize();
 285 
 286   if (log_is_enabled(Info, os, cpu)) {
 287     char buf[1024];
 288     ResourceMark rm;
 289     outputStream* log = Log(os, cpu)::info_stream();
 290     os::print_cpu_info(log, buf, sizeof(buf));
 291   }
 292 }
 293 
 294 unsigned int Abstract_VM_Version::nof_parallel_worker_threads(
 295                                                       unsigned int num,
 296                                                       unsigned int den,
 297                                                       unsigned int switch_pt) {
 298   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 299     assert(ParallelGCThreads == 0, "Default ParallelGCThreads is not 0");
 300     unsigned int threads;
 301     // For very large machines, there are diminishing returns
 302     // for large numbers of worker threads.  Instead of
 303     // hogging the whole system, use a fraction of the workers for every
 304     // processor after the first 8.  For example, on a 72 cpu machine
 305     // and a chosen fraction of 5/8
 306     // use 8 + (72 - 8) * (5/8) == 48 worker threads.
 307     unsigned int ncpus = (unsigned int) os::initial_active_processor_count();
 308     threads = (ncpus <= switch_pt) ?
 309              ncpus :
 310              (switch_pt + ((ncpus - switch_pt) * num) / den);
 311 #ifndef _LP64
 312     // On 32-bit binaries the virtual address space available to the JVM
 313     // is usually limited to 2-3 GB (depends on the platform).
 314     // Do not use up address space with too many threads (stacks and per-thread
 315     // data). Note that x86 apps running on Win64 have 2 stacks per thread.
 316     // GC may more generally scale down threads by max heap size (etc), but the
 317     // consequences of over-provisioning threads are higher on 32-bit JVMS,
 318     // so add hard limit here:
 319     threads = MIN2(threads, (2*switch_pt));
 320 #endif
 321     return threads;
 322   } else {
 323     return ParallelGCThreads;
 324   }
 325 }
 326 
 327 unsigned int Abstract_VM_Version::calc_parallel_worker_threads() {
 328   return nof_parallel_worker_threads(5, 8, 8);
 329 }
 330 
 331 
 332 // Does not set the _initialized flag since it is
 333 // a global flag.
 334 unsigned int Abstract_VM_Version::parallel_worker_threads() {
 335   if (!_parallel_worker_threads_initialized) {
 336     if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 337       _parallel_worker_threads = VM_Version::calc_parallel_worker_threads();
 338     } else {
 339       _parallel_worker_threads = ParallelGCThreads;
 340     }
 341     _parallel_worker_threads_initialized = true;
 342   }
 343   return _parallel_worker_threads;
 344 }