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