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