jdk

Форк
0
/
vm_version_arm_32.cpp 
369 строк · 11.1 Кб
1
/*
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.
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 "asm/macroAssembler.inline.hpp"
27
#include "jvm.h"
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"
35

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;
40

41
extern "C" {
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);
46
}
47

48
#define __ _masm->
49

50
class VM_Version_StubGenerator: public StubCodeGenerator {
51
 public:
52

53
  VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
54

55
  address generate_get_cpu_info() {
56
    StubCodeMark mark(this, "VM_Version", "get_cpu_info");
57
    address start = __ pc();
58

59
    __ mov(R0, PC);
60
    __ push(PC);
61
    __ pop(R1);
62
    __ sub(R0, R1, R0);
63
    // return the result in R0
64
    __ bx(LR);
65

66
    return start;
67
  };
68

69
  address generate_check_vfp() {
70
    StubCodeMark mark(this, "VM_Version", "check_vfp");
71
    address start = __ pc();
72

73
    __ fstd(D0, Address(R0));
74
    __ mov(R0, 1);
75
    __ bx(LR);
76

77
    return start;
78
  };
79

80
  address generate_check_vfp3_32() {
81
    StubCodeMark mark(this, "VM_Version", "check_vfp3_32");
82
    address start = __ pc();
83

84
    __ fstd(D16, Address(R0));
85
    __ mov(R0, 1);
86
    __ bx(LR);
87

88
    return start;
89
  };
90

91
  address generate_check_simd() {
92
    StubCodeMark mark(this, "VM_Version", "check_simd");
93
    address start = __ pc();
94

95
    __ vcnt(Stemp, Stemp);
96
    __ mov(R0, 1);
97
    __ bx(LR);
98

99
    return start;
100
  };
101

102
  address generate_check_mp_ext() {
103
    StubCodeMark mark(this, "VM_Version", "check_mp_ext");
104
    address start = __ pc();
105

106
    // PLDW is available with Multiprocessing Extensions only
107
    __ pldw(Address(R0));
108
    // Return true if instruction caused no signals
109
    __ mov(R0, 1);
110
    // JVM_handle_linux_signal moves PC here if SIGILL happens
111
    __ bx(LR);
112

113
    return start;
114
  };
115
};
116

117
#undef __
118

119

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;
124

125
void VM_Version::early_initialize() {
126

127
  // Make sure that _arm_arch is initialized so that any calls to OrderAccess will
128
  // use proper dmb instruction
129
  get_os_cpu_info();
130

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());
140
#endif
141
}
142

143
void VM_Version::initialize() {
144
  ResourceMark rm;
145

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");
151
  }
152

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);
157

158
  int pc_adjustment = get_cpu_info();
159

160
  VM_Version::_stored_pc_adjustment = pc_adjustment;
161

162
#ifndef __SOFTFP__
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);
165

166
  check_vfp_fault_instr = (address)check_vfp;
167
  double dummy;
168
  if (check_vfp(&dummy)) {
169
    _features |= vfp_m;
170
  }
171

172
#ifdef COMPILER2
173
  if (has_vfp()) {
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;
177
    double dummy;
178
    if (check_vfp3_32(&dummy)) {
179
      _features |= vfp3_32_m;
180
    }
181

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;
185
    if (check_simd()) {
186
      _features |= simd_m;
187
    }
188
  }
189
#endif
190
#endif
191

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;
198
  }
199

200
  if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) {
201
    warning("AES intrinsics are not available on this CPU");
202
    FLAG_SET_DEFAULT(UseAESIntrinsics, false);
203
  }
204

205
  if (UseAES && !FLAG_IS_DEFAULT(UseAES)) {
206
    warning("AES instructions are not available on this CPU");
207
    FLAG_SET_DEFAULT(UseAES, false);
208
  }
209

210
  if (UseAESCTRIntrinsics) {
211
    warning("AES/CTR intrinsics are not available on this CPU");
212
    FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false);
213
  }
214

215
  if (UseFMA) {
216
    warning("FMA instructions are not available on this CPU");
217
    FLAG_SET_DEFAULT(UseFMA, false);
218
  }
219

220
  if (UseMD5Intrinsics) {
221
    warning("MD5 intrinsics are not available on this CPU");
222
    FLAG_SET_DEFAULT(UseMD5Intrinsics, false);
223
  }
224

225
  if (UseSHA) {
226
    warning("SHA instructions are not available on this CPU");
227
    FLAG_SET_DEFAULT(UseSHA, false);
228
  }
229

230
  if (UseSHA1Intrinsics) {
231
    warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
232
    FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
233
  }
234

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);
238
  }
239

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);
243
  }
244

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);
248
  }
249

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);
254
  }
255

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);
260
  }
261

262
  if (UseAdler32Intrinsics) {
263
    warning("Adler32 intrinsics are not available on this CPU");
264
    FLAG_SET_DEFAULT(UseAdler32Intrinsics, false);
265
  }
266

267
  if (UseVectorizedMismatchIntrinsic) {
268
    warning("vectorizedMismatch intrinsic is not available on this CPU.");
269
    FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false);
270
  }
271

272
#ifdef COMPILER2
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");
276
  }
277
#endif
278

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();
285

286
#ifdef COMPILER2
287
  assert(supports_cx8() && _supports_atomic_getset4 && _supports_atomic_getadd4
288
         && _supports_atomic_getset8 && _supports_atomic_getadd8, "C2: atomic operations must be supported");
289
#endif
290
  char buf[512];
291
  jio_snprintf(buf, sizeof(buf), "(ARMv%d)%s%s%s%s",
292
               _arm_arch,
293
               (has_vfp() ? ", vfp" : ""),
294
               (has_vfp3_32() ? ", vfp3-32" : ""),
295
               (has_simd() ? ", simd" : ""),
296
               (has_multiprocessing_extensions() ? ", mp_ext" : ""));
297

298
  // buf is started with ", " or is empty
299
  _features_string = os::strdup(buf);
300

301
  if (has_simd()) {
302
    if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
303
      FLAG_SET_DEFAULT(UsePopCountInstruction, true);
304
    }
305
  } else {
306
    FLAG_SET_DEFAULT(UsePopCountInstruction, false);
307
  }
308

309
  if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) {
310
    FLAG_SET_DEFAULT(AllocatePrefetchDistance, 128);
311
  }
312

313
#ifdef COMPILER2
314
  FLAG_SET_DEFAULT(UseFPUForSpilling, true);
315

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);
321
  } else {
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);
326
    }
327
  }
328
#endif
329

330
  if (FLAG_IS_DEFAULT(Tier4CompileThreshold)) {
331
    Tier4CompileThreshold = 10000;
332
  }
333
  if (FLAG_IS_DEFAULT(Tier3InvocationThreshold)) {
334
    Tier3InvocationThreshold = 1000;
335
  }
336
  if (FLAG_IS_DEFAULT(Tier3CompileThreshold)) {
337
    Tier3CompileThreshold = 5000;
338
  }
339
  if (FLAG_IS_DEFAULT(Tier3MinInvocationThreshold)) {
340
    Tier3MinInvocationThreshold = 500;
341
  }
342

343
  UNSUPPORTED_OPTION(TypeProfileLevel);
344

345
  FLAG_SET_DEFAULT(TypeProfileLevel, 0); // unsupported
346

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);
352
  }
353

354
  _is_initialized = true;
355
}
356

357
void VM_Version::initialize_cpu_information(void) {
358
  // do nothing if cpu info has been initialized
359
  if (_initialized) {
360
    return;
361
  }
362

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);
368
  _initialized = true;
369
}
370

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.