1 /*
   2  * Copyright (c) 1998, 2019, 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 "logging/logStream.hpp"
  28 #include "memory/universe.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/vm_version.hpp"
  32 
  33 const char* Abstract_VM_Version::_s_vm_release = Abstract_VM_Version::vm_release();
  34 const char* Abstract_VM_Version::_s_internal_vm_info_string = Abstract_VM_Version::internal_vm_info_string();
  35 
  36 uint64_t Abstract_VM_Version::_features = 0;
  37 const char* Abstract_VM_Version::_features_string = "";
  38 
  39 bool Abstract_VM_Version::_supports_cx8 = false;
  40 bool Abstract_VM_Version::_supports_atomic_getset4 = false;
  41 bool Abstract_VM_Version::_supports_atomic_getset8 = false;
  42 bool Abstract_VM_Version::_supports_atomic_getadd4 = false;
  43 bool Abstract_VM_Version::_supports_atomic_getadd8 = false;
  44 unsigned int Abstract_VM_Version::_logical_processors_per_package = 1U;
  45 unsigned int Abstract_VM_Version::_L1_data_cache_line_size = 0;
  46 
  47 VirtualizationType Abstract_VM_Version::_detected_virtualization = NoDetectedVirtualization;
  48 
  49 #ifndef HOTSPOT_VERSION_STRING
  50   #error HOTSPOT_VERSION_STRING must be defined
  51 #endif
  52 
  53 #ifndef VERSION_FEATURE
  54   #error VERSION_FEATURE must be defined
  55 #endif
  56 #ifndef VERSION_INTERIM
  57   #error VERSION_INTERIM must be defined
  58 #endif
  59 #ifndef VERSION_UPDATE
  60   #error VERSION_UPDATE must be defined
  61 #endif
  62 #ifndef VERSION_PATCH
  63   #error VERSION_PATCH must be defined
  64 #endif
  65 #ifndef VERSION_BUILD
  66   #error VERSION_BUILD must be defined
  67 #endif
  68 
  69 #ifndef VERSION_STRING
  70   #error VERSION_STRING must be defined
  71 #endif
  72 
  73 #ifndef DEBUG_LEVEL
  74   #error DEBUG_LEVEL must be defined
  75 #endif
  76 
  77 #define VM_RELEASE HOTSPOT_VERSION_STRING
  78 
  79 // HOTSPOT_VERSION_STRING equals the JDK VERSION_STRING (unless overridden
  80 // in a standalone build).
  81 int Abstract_VM_Version::_vm_major_version = VERSION_FEATURE;
  82 int Abstract_VM_Version::_vm_minor_version = VERSION_INTERIM;
  83 int Abstract_VM_Version::_vm_security_version = VERSION_UPDATE;
  84 int Abstract_VM_Version::_vm_patch_version = VERSION_PATCH;
  85 int Abstract_VM_Version::_vm_build_number = VERSION_BUILD;
  86 
  87 #if defined(_LP64)
  88   #define VMLP "64-Bit "
  89 #else
  90   #define VMLP ""
  91 #endif
  92 
  93 #ifndef VMTYPE
  94   #ifdef TIERED
  95     #define VMTYPE "Server"
  96   #else // TIERED
  97   #ifdef ZERO
  98     #define VMTYPE "Zero"
  99   #else // ZERO
 100      #define VMTYPE COMPILER1_PRESENT("Client")   \
 101                     COMPILER2_PRESENT("Server")
 102   #endif // ZERO
 103   #endif // TIERED
 104 #endif
 105 
 106 #ifndef HOTSPOT_VM_DISTRO
 107   #error HOTSPOT_VM_DISTRO must be defined
 108 #endif
 109 #define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
 110 
 111 const char* Abstract_VM_Version::vm_name() {
 112   return VMNAME;
 113 }
 114 
 115 
 116 const char* Abstract_VM_Version::vm_vendor() {
 117 #ifdef VENDOR
 118   return VENDOR;
 119 #else
 120   return "Oracle Corporation";
 121 #endif
 122 }
 123 
 124 
 125 const char* Abstract_VM_Version::vm_info_string() {
 126   switch (Arguments::mode()) {
 127     case Arguments::_int:
 128       return UseSharedSpaces ? "interpreted mode, sharing" : "interpreted mode";
 129     case Arguments::_mixed:
 130       if (UseSharedSpaces) {
 131         if (UseAOT) {
 132           return "mixed mode, aot, sharing";
 133 #ifdef TIERED
 134         } else if(is_client_compilation_mode_vm()) {
 135           return "mixed mode, emulated-client, sharing";
 136 #endif
 137         } else {
 138           return "mixed mode, sharing";
 139          }
 140       } else {
 141         if (UseAOT) {
 142           return "mixed mode, aot";
 143 #ifdef TIERED
 144         } else if(is_client_compilation_mode_vm()) {
 145           return "mixed mode, emulated-client";
 146 #endif
 147         } else {
 148           return "mixed mode";
 149         }
 150       }
 151     case Arguments::_comp:
 152 #ifdef TIERED
 153       if (is_client_compilation_mode_vm()) {
 154          return UseSharedSpaces ? "compiled mode, emulated-client, sharing" : "compiled mode, emulated-client";
 155       }
 156 #endif
 157       return UseSharedSpaces ? "compiled mode, sharing"    : "compiled mode";
 158   };
 159   ShouldNotReachHere();
 160   return "";
 161 }
 162 
 163 // NOTE: do *not* use stringStream. this function is called by
 164 //       fatal error handler. if the crash is in native thread,
 165 //       stringStream cannot get resource allocated and will SEGV.
 166 const char* Abstract_VM_Version::vm_release() {
 167   return VM_RELEASE;
 168 }
 169 
 170 // NOTE: do *not* use stringStream. this function is called by
 171 //       fatal error handlers. if the crash is in native thread,
 172 //       stringStream cannot get resource allocated and will SEGV.
 173 const char* Abstract_VM_Version::jre_release_version() {
 174   return VERSION_STRING;
 175 }
 176 
 177 #define OS       LINUX_ONLY("linux")             \
 178                  WINDOWS_ONLY("windows")         \
 179                  SOLARIS_ONLY("solaris")         \
 180                  AIX_ONLY("aix")                 \
 181                  BSD_ONLY("bsd")
 182 
 183 #ifndef CPU
 184 #ifdef ZERO
 185 #define CPU      ZERO_LIBARCH
 186 #elif defined(PPC64)
 187 #if defined(VM_LITTLE_ENDIAN)
 188 #define CPU      "ppc64le"
 189 #else
 190 #define CPU      "ppc64"
 191 #endif // PPC64
 192 #else
 193 #define CPU      AARCH64_ONLY("aarch64")         \
 194                  AMD64_ONLY("amd64")             \
 195                  IA32_ONLY("x86")                \
 196                  IA64_ONLY("ia64")               \
 197                  S390_ONLY("s390")               \
 198                  SPARC_ONLY("sparc")
 199 #endif // !ZERO
 200 #endif // !CPU
 201 
 202 const char *Abstract_VM_Version::vm_platform_string() {
 203   return OS "-" CPU;
 204 }
 205 
 206 const char* Abstract_VM_Version::internal_vm_info_string() {
 207   #ifndef HOTSPOT_BUILD_USER
 208     #define HOTSPOT_BUILD_USER unknown
 209   #endif
 210 
 211   #ifndef HOTSPOT_BUILD_COMPILER
 212     #ifdef _MSC_VER
 213       #if _MSC_VER == 1600
 214         #define HOTSPOT_BUILD_COMPILER "MS VC++ 10.0 (VS2010)"
 215       #elif _MSC_VER == 1700
 216         #define HOTSPOT_BUILD_COMPILER "MS VC++ 11.0 (VS2012)"
 217       #elif _MSC_VER == 1800
 218         #define HOTSPOT_BUILD_COMPILER "MS VC++ 12.0 (VS2013)"
 219       #elif _MSC_VER == 1900
 220         #define HOTSPOT_BUILD_COMPILER "MS VC++ 14.0 (VS2015)"
 221       #elif _MSC_VER == 1911
 222         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.3 (VS2017)"
 223       #elif _MSC_VER == 1912
 224         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.5 (VS2017)"
 225       #elif _MSC_VER == 1913
 226         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.6 (VS2017)"
 227       #elif _MSC_VER == 1914
 228         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.7 (VS2017)"
 229       #elif _MSC_VER == 1915
 230         #define HOTSPOT_BUILD_COMPILER "MS VC++ 15.8 (VS2017)"
 231       #else
 232         #define HOTSPOT_BUILD_COMPILER "unknown MS VC++:" XSTR(_MSC_VER)
 233       #endif
 234     #elif defined(__SUNPRO_CC)
 235       #if __SUNPRO_CC == 0x580
 236         #define HOTSPOT_BUILD_COMPILER "Workshop 5.8"
 237       #elif __SUNPRO_CC == 0x590
 238         #define HOTSPOT_BUILD_COMPILER "Workshop 5.9"
 239       #elif __SUNPRO_CC == 0x5100
 240         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u1"
 241       #elif __SUNPRO_CC == 0x5120
 242         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u3"
 243       #elif __SUNPRO_CC == 0x5130
 244         #define HOTSPOT_BUILD_COMPILER "Sun Studio 12u4"
 245       #else
 246         #define HOTSPOT_BUILD_COMPILER "unknown Workshop:" XSTR(__SUNPRO_CC)
 247       #endif
 248     #elif defined(__clang_version__)
 249         #define HOTSPOT_BUILD_COMPILER "clang " __VERSION__
 250     #elif defined(__GNUC__)
 251         #define HOTSPOT_BUILD_COMPILER "gcc " __VERSION__
 252     #elif defined(__IBMCPP__)
 253         #define HOTSPOT_BUILD_COMPILER "xlC " XSTR(__IBMCPP__)
 254 
 255     #else
 256       #define HOTSPOT_BUILD_COMPILER "unknown compiler"
 257     #endif
 258   #endif
 259 
 260   #ifndef FLOAT_ARCH
 261     #if defined(__SOFTFP__)
 262       #define FLOAT_ARCH_STR "-sflt"
 263     #else
 264       #define FLOAT_ARCH_STR ""
 265     #endif
 266   #else
 267     #define FLOAT_ARCH_STR XSTR(FLOAT_ARCH)
 268   #endif
 269 
 270   #define INTERNAL_VERSION_SUFFIX VM_RELEASE ")" \
 271          " for " OS "-" CPU FLOAT_ARCH_STR \
 272          " JRE (" VERSION_STRING "), built on " __DATE__ " " __TIME__ \
 273          " by " XSTR(HOTSPOT_BUILD_USER) " with " HOTSPOT_BUILD_COMPILER
 274 
 275   return strcmp(DEBUG_LEVEL, "release") == 0
 276       ? VMNAME " (" INTERNAL_VERSION_SUFFIX
 277       : VMNAME " (" DEBUG_LEVEL " " INTERNAL_VERSION_SUFFIX;
 278 }
 279 
 280 const char *Abstract_VM_Version::vm_build_user() {
 281   return HOTSPOT_BUILD_USER;
 282 }
 283 
 284 const char *Abstract_VM_Version::jdk_debug_level() {
 285   return DEBUG_LEVEL;
 286 }
 287 
 288 const char *Abstract_VM_Version::printable_jdk_debug_level() {
 289   // Debug level is not printed for "release" builds
 290   return strcmp(DEBUG_LEVEL, "release") == 0 ? "" : DEBUG_LEVEL " ";
 291 }
 292 
 293 unsigned int Abstract_VM_Version::jvm_version() {
 294   return ((Abstract_VM_Version::vm_major_version() & 0xFF) << 24) |
 295          ((Abstract_VM_Version::vm_minor_version() & 0xFF) << 16) |
 296          ((Abstract_VM_Version::vm_security_version() & 0xFF) << 8) |
 297          (Abstract_VM_Version::vm_build_number() & 0xFF);
 298 }
 299 
 300 void VM_Version_init() {
 301   VM_Version::initialize();
 302 
 303   if (log_is_enabled(Info, os, cpu)) {
 304     char buf[1024];
 305     ResourceMark rm;
 306     LogStream ls(Log(os, cpu)::info());
 307     os::print_cpu_info(&ls, buf, sizeof(buf));
 308   }
 309 }
 310 
 311 bool Abstract_VM_Version::print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]) {
 312   char line[500];
 313   FILE* fp = fopen(filename, "r");
 314   if (fp == NULL) {
 315     return false;
 316   }
 317 
 318   st->print_cr("Virtualization information:");
 319   while (fgets(line, sizeof(line), fp) != NULL) {
 320     int i = 0;
 321     while (keywords_to_match[i] != NULL) {
 322       if (strncmp(line, keywords_to_match[i], strlen(keywords_to_match[i])) == 0) {
 323         st->print("%s", line);
 324         break;
 325       }
 326       i++;
 327     }
 328   }
 329   fclose(fp);
 330   return true;
 331 }
 332 
 333