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