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