2
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
25
#include "precompiled.hpp"
26
#include "asm/macroAssembler.inline.hpp"
28
#include "memory/resourceArea.hpp"
29
#include "runtime/arguments.hpp"
30
#include "runtime/globals_extension.hpp"
31
#include "runtime/java.hpp"
32
#include "runtime/os.inline.hpp"
33
#include "runtime/stubCodeGenerator.hpp"
34
#include "runtime/vm_version.hpp"
36
int VM_Version::_stored_pc_adjustment = 4;
37
int VM_Version::_arm_arch = 5;
38
bool VM_Version::_is_initialized = false;
39
int VM_Version::_kuser_helper_version = 0;
42
typedef int (*get_cpu_info_t)();
43
typedef bool (*check_vfp_t)(double *d);
44
typedef bool (*check_simd_t)();
45
typedef bool (*check_mp_ext_t)(int *addr);
50
class VM_Version_StubGenerator: public StubCodeGenerator {
53
VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
55
address generate_get_cpu_info() {
56
StubCodeMark mark(this, "VM_Version", "get_cpu_info");
57
address start = __ pc();
63
// return the result in R0
69
address generate_check_vfp() {
70
StubCodeMark mark(this, "VM_Version", "check_vfp");
71
address start = __ pc();
73
__ fstd(D0, Address(R0));
80
address generate_check_vfp3_32() {
81
StubCodeMark mark(this, "VM_Version", "check_vfp3_32");
82
address start = __ pc();
84
__ fstd(D16, Address(R0));
91
address generate_check_simd() {
92
StubCodeMark mark(this, "VM_Version", "check_simd");
93
address start = __ pc();
95
__ vcnt(Stemp, Stemp);
102
address generate_check_mp_ext() {
103
StubCodeMark mark(this, "VM_Version", "check_mp_ext");
104
address start = __ pc();
106
// PLDW is available with Multiprocessing Extensions only
107
__ pldw(Address(R0));
108
// Return true if instruction caused no signals
110
// JVM_handle_linux_signal moves PC here if SIGILL happens
120
extern "C" address check_vfp3_32_fault_instr;
121
extern "C" address check_vfp_fault_instr;
122
extern "C" address check_simd_fault_instr;
123
extern "C" address check_mp_ext_fault_instr;
125
void VM_Version::early_initialize() {
127
// Make sure that _arm_arch is initialized so that any calls to OrderAccess will
128
// use proper dmb instruction
131
// Future cleanup: if SUPPORTS_NATIVE_CX8 is defined then we should not need
132
// any alternative solutions. At present this allows for the theoretical
133
// possibility of building for ARMv7 and then running on ARMv5 or 6. If that
134
// is impossible then the ARM port folk should clean this up.
135
_kuser_helper_version = *(int*)KUSER_HELPER_VERSION_ADDR;
136
#ifndef SUPPORTS_NATIVE_CX8
137
// armv7 has the ldrexd instruction that can be used to implement cx8
138
// armv5 with linux >= 3.1 can use kernel helper routine
139
_supports_cx8 = (supports_ldrexd() || supports_kuser_cmpxchg64());
143
void VM_Version::initialize() {
146
// Making this stub must be FIRST use of assembler
147
const int stub_size = 128;
148
BufferBlob* stub_blob = BufferBlob::create("get_cpu_info", stub_size);
149
if (stub_blob == nullptr) {
150
vm_exit_during_initialization("Unable to allocate get_cpu_info stub");
153
CodeBuffer c(stub_blob);
154
VM_Version_StubGenerator g(&c);
155
address get_cpu_info_pc = g.generate_get_cpu_info();
156
get_cpu_info_t get_cpu_info = CAST_TO_FN_PTR(get_cpu_info_t, get_cpu_info_pc);
158
int pc_adjustment = get_cpu_info();
160
VM_Version::_stored_pc_adjustment = pc_adjustment;
163
address check_vfp_pc = g.generate_check_vfp();
164
check_vfp_t check_vfp = CAST_TO_FN_PTR(check_vfp_t, check_vfp_pc);
166
check_vfp_fault_instr = (address)check_vfp;
168
if (check_vfp(&dummy)) {
174
address check_vfp3_32_pc = g.generate_check_vfp3_32();
175
check_vfp_t check_vfp3_32 = CAST_TO_FN_PTR(check_vfp_t, check_vfp3_32_pc);
176
check_vfp3_32_fault_instr = (address)check_vfp3_32;
178
if (check_vfp3_32(&dummy)) {
179
_features |= vfp3_32_m;
182
address check_simd_pc =g.generate_check_simd();
183
check_simd_t check_simd = CAST_TO_FN_PTR(check_simd_t, check_simd_pc);
184
check_simd_fault_instr = (address)check_simd;
192
address check_mp_ext_pc = g.generate_check_mp_ext();
193
check_mp_ext_t check_mp_ext = CAST_TO_FN_PTR(check_mp_ext_t, check_mp_ext_pc);
194
check_mp_ext_fault_instr = (address)check_mp_ext;
195
int dummy_local_variable;
196
if (check_mp_ext(&dummy_local_variable)) {
197
_features |= mp_ext_m;
200
if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) {
201
warning("AES intrinsics are not available on this CPU");
202
FLAG_SET_DEFAULT(UseAESIntrinsics, false);
205
if (UseAES && !FLAG_IS_DEFAULT(UseAES)) {
206
warning("AES instructions are not available on this CPU");
207
FLAG_SET_DEFAULT(UseAES, false);
210
if (UseAESCTRIntrinsics) {
211
warning("AES/CTR intrinsics are not available on this CPU");
212
FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false);
216
warning("FMA instructions are not available on this CPU");
217
FLAG_SET_DEFAULT(UseFMA, false);
220
if (UseMD5Intrinsics) {
221
warning("MD5 intrinsics are not available on this CPU");
222
FLAG_SET_DEFAULT(UseMD5Intrinsics, false);
226
warning("SHA instructions are not available on this CPU");
227
FLAG_SET_DEFAULT(UseSHA, false);
230
if (UseSHA1Intrinsics) {
231
warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
232
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
235
if (UseSHA256Intrinsics) {
236
warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.");
237
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
240
if (UseSHA512Intrinsics) {
241
warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.");
242
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
245
if (UseSHA3Intrinsics) {
246
warning("Intrinsics for SHA3-224, SHA3-256, SHA3-384 and SHA3-512 crypto hash functions not available on this CPU.");
247
FLAG_SET_DEFAULT(UseSHA3Intrinsics, false);
250
if (UseCRC32Intrinsics) {
251
if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics))
252
warning("CRC32 intrinsics are not available on this CPU");
253
FLAG_SET_DEFAULT(UseCRC32Intrinsics, false);
256
if (UseCRC32CIntrinsics) {
257
if (!FLAG_IS_DEFAULT(UseCRC32CIntrinsics))
258
warning("CRC32C intrinsics are not available on this CPU");
259
FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false);
262
if (UseAdler32Intrinsics) {
263
warning("Adler32 intrinsics are not available on this CPU");
264
FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
267
if (UseVectorizedMismatchIntrinsic) {
268
warning("vectorizedMismatch intrinsic is not available on this CPU.");
269
FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false);
273
// C2 is only supported on v7+ VFP at this time
274
if (_arm_arch < 7 || !has_vfp()) {
275
vm_exit_during_initialization("Server VM is only supported on ARMv7+ VFP");
279
// ARM doesn't have special instructions for these but ldrex/ldrexd
280
// enable shorter instruction sequences that the ones based on cas.
281
_supports_atomic_getset4 = supports_ldrex();
282
_supports_atomic_getadd4 = supports_ldrex();
283
_supports_atomic_getset8 = supports_ldrexd();
284
_supports_atomic_getadd8 = supports_ldrexd();
287
assert(supports_cx8() && _supports_atomic_getset4 && _supports_atomic_getadd4
288
&& _supports_atomic_getset8 && _supports_atomic_getadd8, "C2: atomic operations must be supported");
291
jio_snprintf(buf, sizeof(buf), "(ARMv%d)%s%s%s%s",
293
(has_vfp() ? ", vfp" : ""),
294
(has_vfp3_32() ? ", vfp3-32" : ""),
295
(has_simd() ? ", simd" : ""),
296
(has_multiprocessing_extensions() ? ", mp_ext" : ""));
298
// buf is started with ", " or is empty
299
_features_string = os::strdup(buf);
302
if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
303
FLAG_SET_DEFAULT(UsePopCountInstruction, true);
306
FLAG_SET_DEFAULT(UsePopCountInstruction, false);
309
if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) {
310
FLAG_SET_DEFAULT(AllocatePrefetchDistance, 128);
314
FLAG_SET_DEFAULT(UseFPUForSpilling, true);
316
if (FLAG_IS_DEFAULT(MaxVectorSize)) {
317
// FLAG_SET_DEFAULT(MaxVectorSize, has_simd() ? 16 : 8);
318
// SIMD/NEON can use 16, but default is 8 because currently
319
// larger than 8 will disable instruction scheduling
320
FLAG_SET_DEFAULT(MaxVectorSize, 8);
322
int max_vector_size = has_simd() ? 16 : 8;
323
if (MaxVectorSize > max_vector_size) {
324
warning("MaxVectorSize must be at most %i on this platform", max_vector_size);
325
FLAG_SET_DEFAULT(MaxVectorSize, max_vector_size);
330
if (FLAG_IS_DEFAULT(Tier4CompileThreshold)) {
331
Tier4CompileThreshold = 10000;
333
if (FLAG_IS_DEFAULT(Tier3InvocationThreshold)) {
334
Tier3InvocationThreshold = 1000;
336
if (FLAG_IS_DEFAULT(Tier3CompileThreshold)) {
337
Tier3CompileThreshold = 5000;
339
if (FLAG_IS_DEFAULT(Tier3MinInvocationThreshold)) {
340
Tier3MinInvocationThreshold = 500;
343
UNSUPPORTED_OPTION(TypeProfileLevel);
345
FLAG_SET_DEFAULT(TypeProfileLevel, 0); // unsupported
347
// This machine does not allow unaligned memory accesses
348
if (UseUnalignedAccesses) {
349
if (!FLAG_IS_DEFAULT(UseUnalignedAccesses))
350
warning("Unaligned memory access is not available on this CPU");
351
FLAG_SET_DEFAULT(UseUnalignedAccesses, false);
354
_is_initialized = true;
357
void VM_Version::initialize_cpu_information(void) {
358
// do nothing if cpu info has been initialized
363
_no_of_cores = os::processor_count();
364
_no_of_threads = _no_of_cores;
365
_no_of_sockets = _no_of_cores;
366
snprintf(_cpu_name, CPU_TYPE_DESC_BUF_SIZE - 1, "ARM%d", _arm_arch);
367
snprintf(_cpu_desc, CPU_DETAILED_DESC_BUF_SIZE, "%s", _features_string);