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