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