1 /*
   2  * Copyright (c) 1998, 2015, 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 #include "runtime/vm_version.hpp"
  30 
  31 const char* Abstract_VM_Version::_s_vm_release = Abstract_VM_Version::vm_release();
  32 const char* Abstract_VM_Version::_s_internal_vm_info_string = Abstract_VM_Version::internal_vm_info_string();
  33 bool Abstract_VM_Version::_supports_cx8 = false;
  34 bool Abstract_VM_Version::_supports_atomic_getset4 = false;
  35 bool Abstract_VM_Version::_supports_atomic_getset8 = false;
  36 bool Abstract_VM_Version::_supports_atomic_getadd4 = false;
  37 bool Abstract_VM_Version::_supports_atomic_getadd8 = false;
  38 unsigned int Abstract_VM_Version::_logical_processors_per_package = 1U;
  39 unsigned int Abstract_VM_Version::_L1_data_cache_line_size = 0;
  40 int Abstract_VM_Version::_reserve_for_allocation_prefetch = 0;
  41 
  42 #ifndef HOTSPOT_VERSION_STRING
  43   #error HOTSPOT_VERSION_STRING must be defined
  44 #endif
  45 
  46 #ifndef VERSION_MAJOR
  47   #error VERSION_MAJOR must be defined
  48 #endif
  49 #ifndef VERSION_MINOR
  50   #error VERSION_MINOR must be defined
  51 #endif
  52 #ifndef VERSION_SECURITY
  53   #error VERSION_SECURITY must be defined
  54 #endif
  55 #ifndef VERSION_BUILD
  56   #error VERSION_BUILD must be defined
  57 #endif
  58 
  59 #ifndef VERSION_STRING
  60   #error VERSION_STRING must be defined
  61 #endif
  62 
  63 // NOTE: Builds within Visual Studio do not define the build target in
  64 //       HOTSPOT_VERSION_STRING, so it must be done here
  65 #if defined(VISUAL_STUDIO_BUILD) && !defined(PRODUCT)
  66   #ifndef HOTSPOT_BUILD_TARGET
  67     #error HOTSPOT_BUILD_TARGET must be defined
  68   #endif
  69   #define VM_RELEASE HOTSPOT_VERSION_STRING "-" HOTSPOT_BUILD_TARGET
  70 #else
  71   #define VM_RELEASE HOTSPOT_VERSION_STRING
  72 #endif
  73 
  74 // HOTSPOT_VERSION_STRING equals the JDK VERSION_STRING (unless overridden
  75 // in a standalone build).
  76 int Abstract_VM_Version::_vm_major_version = VERSION_MAJOR;
  77 int Abstract_VM_Version::_vm_minor_version = VERSION_MINOR;
  78 int Abstract_VM_Version::_vm_security_version = VERSION_SECURITY;
  79 int Abstract_VM_Version::_vm_build_number = VERSION_BUILD;
  80 bool Abstract_VM_Version::_initialized = false;
  81 unsigned 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   // FIXME: Initialization can probably be removed now.
  86   if (_initialized) {
  87     return;
  88   }
  89 
  90   _initialized = true;
  91 }
  92 
  93 #if defined(_LP64)
  94   #define VMLP "64-Bit "
  95 #else
  96   #define VMLP ""
  97 #endif
  98 
  99 #ifndef VMTYPE
 100   #ifdef TIERED
 101     #define VMTYPE "Server"
 102   #else // TIERED
 103   #ifdef ZERO
 104   #ifdef SHARK
 105     #define VMTYPE "Shark"
 106   #else // SHARK
 107     #define VMTYPE "Zero"
 108   #endif // SHARK
 109   #else // ZERO
 110      #define VMTYPE COMPILER1_PRESENT("Client")   \
 111                     COMPILER2_PRESENT("Server")
 112   #endif // ZERO
 113   #endif // TIERED
 114 #endif
 115 
 116 #ifndef HOTSPOT_VM_DISTRO
 117   #error HOTSPOT_VM_DISTRO must be defined
 118 #endif
 119 #define VMNAME HOTSPOT_VM_DISTRO " " VMLP EMBEDDED_ONLY("Embedded ") VMTYPE " VM"
 120 
 121 const char* Abstract_VM_Version::vm_name() {
 122   return VMNAME;
 123 }
 124 
 125 
 126 const char* Abstract_VM_Version::vm_vendor() {
 127 #ifdef VENDOR
 128   return XSTR(VENDOR);
 129 #else
 130   return "Oracle Corporation";
 131 #endif
 132 }
 133 
 134 
 135 const char* Abstract_VM_Version::vm_info_string() {
 136   switch (Arguments::mode()) {
 137     case Arguments::_int:
 138       return UseSharedSpaces ? "interpreted mode, sharing" : "interpreted mode";
 139     case Arguments::_mixed:
 140       return UseSharedSpaces ? "mixed mode, sharing"       :  "mixed mode";
 141     case Arguments::_comp:
 142       return UseSharedSpaces ? "compiled mode, sharing"    : "compiled mode";
 143   };
 144   ShouldNotReachHere();
 145   return "";
 146 }
 147 
 148 // NOTE: do *not* use stringStream. this function is called by
 149 //       fatal error handler. if the crash is in native thread,
 150 //       stringStream cannot get resource allocated and will SEGV.
 151 const char* Abstract_VM_Version::vm_release() {
 152   return VM_RELEASE;
 153 }
 154 
 155 // NOTE: do *not* use stringStream. this function is called by
 156 //       fatal error handlers. if the crash is in native thread,
 157 //       stringStream cannot get resource allocated and will SEGV.
 158 const char* Abstract_VM_Version::jre_release_version() {
 159   return VERSION_STRING;
 160 }
 161 
 162 #define OS       LINUX_ONLY("linux")             \
 163                  WINDOWS_ONLY("windows")         \
 164                  SOLARIS_ONLY("solaris")         \
 165                  AIX_ONLY("aix")                 \
 166                  BSD_ONLY("bsd")
 167 
 168 #ifndef CPU
 169 #ifdef ZERO
 170 #define CPU      ZERO_LIBARCH
 171 #else
 172 #define CPU      IA32_ONLY("x86")                \
 173                  IA64_ONLY("ia64")               \
 174                  AMD64_ONLY("amd64")             \
 175                  PPC64_ONLY("ppc64")             \
 176                  AARCH64_ONLY("aarch64")         \
 177                  SPARC_ONLY("sparc")
 178 #endif // ZERO
 179 #endif
 180 
 181 const char *Abstract_VM_Version::vm_platform_string() {
 182   return OS "-" CPU;
 183 }
 184 
 185 const char* Abstract_VM_Version::internal_vm_info_string() {
 186   #ifndef HOTSPOT_BUILD_USER
 187     #define HOTSPOT_BUILD_USER unknown
 188   #endif
 189 
 190   #ifndef HOTSPOT_BUILD_COMPILER
 191     #ifdef _MSC_VER
 192       #if _MSC_VER == 1600
 193         #define HOTSPOT_BUILD_COMPILER "MS VC++ 10.0 (VS2010)"
 194       #elif _MSC_VER == 1700
 195         #define HOTSPOT_BUILD_COMPILER "MS VC++ 11.0 (VS2012)"
 196       #elif _MSC_VER == 1800
 197         #define HOTSPOT_BUILD_COMPILER "MS VC++ 12.0 (VS2013)"
 198       #else
 199         #define HOTSPOT_BUILD_COMPILER "unknown MS VC++:" XSTR(_MSC_VER)
 200       #endif
 201     #elif defined(__SUNPRO_CC)
 202       #if   __SUNPRO_CC == 0x420
 203         #define HOTSPOT_BUILD_COMPILER "Workshop 4.2"
 204       #elif __SUNPRO_CC == 0x500
 205         #define HOTSPOT_BUILD_COMPILER "Workshop 5.0 compat=" XSTR(__SUNPRO_CC_COMPAT)
 206       #elif __SUNPRO_CC == 0x520
 207         #define HOTSPOT_BUILD_COMPILER "Workshop 5.2 compat=" XSTR(__SUNPRO_CC_COMPAT)
 208       #elif __SUNPRO_CC == 0x580
 209         #define HOTSPOT_BUILD_COMPILER "Workshop 5.8"
 210       #elif __SUNPRO_CC == 0x590
 211         #define HOTSPOT_BUILD_COMPILER "Workshop 5.9"
 212       #elif __SUNPRO_CC == 0x5100
 213         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u1"
 214       #elif __SUNPRO_CC == 0x5120
 215         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u3"
 216       #else
 217         #define HOTSPOT_BUILD_COMPILER "unknown Workshop:" XSTR(__SUNPRO_CC)
 218       #endif
 219     #elif defined(__GNUC__)
 220         #define HOTSPOT_BUILD_COMPILER "gcc " __VERSION__
 221     #elif defined(__IBMCPP__)
 222         #define HOTSPOT_BUILD_COMPILER "xlC " XSTR(__IBMCPP__)
 223 
 224     #else
 225       #define HOTSPOT_BUILD_COMPILER "unknown compiler"
 226     #endif
 227   #endif
 228 
 229   #ifndef FLOAT_ARCH
 230     #if defined(__SOFTFP__)
 231       #define FLOAT_ARCH_STR "-sflt"
 232     #else
 233       #define FLOAT_ARCH_STR ""
 234     #endif
 235   #else
 236     #define FLOAT_ARCH_STR XSTR(FLOAT_ARCH)
 237   #endif
 238 
 239   return VMNAME " (" VM_RELEASE ") for " OS "-" CPU FLOAT_ARCH_STR
 240          " JRE (" VERSION_STRING "), built on " __DATE__ " " __TIME__
 241          " by " XSTR(HOTSPOT_BUILD_USER) " with " HOTSPOT_BUILD_COMPILER;
 242 }
 243 
 244 const char *Abstract_VM_Version::vm_build_user() {
 245   return HOTSPOT_BUILD_USER;
 246 }
 247 
 248 unsigned int Abstract_VM_Version::jvm_version() {
 249   return ((Abstract_VM_Version::vm_major_version() & 0xFF) << 24) |
 250          ((Abstract_VM_Version::vm_minor_version() & 0xFF) << 16) |
 251          ((Abstract_VM_Version::vm_security_version() & 0xFF) << 8) |
 252          (Abstract_VM_Version::vm_build_number() & 0xFF);
 253 }
 254 
 255 
 256 void VM_Version_init() {
 257   VM_Version::initialize();
 258 
 259 #ifndef PRODUCT
 260   if (PrintMiscellaneous && Verbose) {
 261     os::print_cpu_info(tty);
 262   }
 263 #endif
 264 }
 265 
 266 unsigned int Abstract_VM_Version::nof_parallel_worker_threads(
 267                                                       unsigned int num,
 268                                                       unsigned int den,
 269                                                       unsigned int switch_pt) {
 270   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 271     assert(ParallelGCThreads == 0, "Default ParallelGCThreads is not 0");
 272     // For very large machines, there are diminishing returns
 273     // for large numbers of worker threads.  Instead of
 274     // hogging the whole system, use a fraction of the workers for every
 275     // processor after the first 8.  For example, on a 72 cpu machine
 276     // and a chosen fraction of 5/8
 277     // use 8 + (72 - 8) * (5/8) == 48 worker threads.
 278     unsigned int ncpus = (unsigned int) os::active_processor_count();
 279     return (ncpus <= switch_pt) ?
 280            ncpus :
 281           (switch_pt + ((ncpus - switch_pt) * num) / den);
 282   } else {
 283     return ParallelGCThreads;
 284   }
 285 }
 286 
 287 unsigned int Abstract_VM_Version::calc_parallel_worker_threads() {
 288   return nof_parallel_worker_threads(5, 8, 8);
 289 }
 290 
 291 
 292 // Does not set the _initialized flag since it is
 293 // a global flag.
 294 unsigned int Abstract_VM_Version::parallel_worker_threads() {
 295   if (!_parallel_worker_threads_initialized) {
 296     if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 297       _parallel_worker_threads = VM_Version::calc_parallel_worker_threads();
 298     } else {
 299       _parallel_worker_threads = ParallelGCThreads;
 300     }
 301     _parallel_worker_threads_initialized = true;
 302   }
 303   return _parallel_worker_threads;
 304 }