1 /* 2 * Copyright (c) 1997, 2017, 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 "logging/log.hpp" 28 #include "memory/resourceArea.hpp" 29 #include "prims/jvm.h" 30 #include "runtime/java.hpp" 31 #include "runtime/os.hpp" 32 #include "runtime/stubCodeGenerator.hpp" 33 #include "vm_version_sparc.hpp" 34 35 #include <sys/mman.h> 36 37 uint VM_Version::_L2_data_cache_line_size = 0; 38 39 void VM_Version::initialize() { 40 assert(_features != 0, "System pre-initialization is not complete."); 41 guarantee(VM_Version::has_v9(), "only SPARC v9 is supported"); 42 43 PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes(); 44 PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes(); 45 PrefetchFieldsAhead = prefetch_fields_ahead(); 46 47 // Allocation prefetch settings 48 49 AllocatePrefetchDistance = allocate_prefetch_distance(); 50 AllocatePrefetchStyle = allocate_prefetch_style(); 51 52 intx cache_line_size = prefetch_data_size(); 53 54 if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize)) { 55 AllocatePrefetchStepSize = MAX2(AllocatePrefetchStepSize, cache_line_size); 56 } 57 58 if (AllocatePrefetchInstr == 1) { 59 if (!has_blk_init()) { 60 warning("BIS instructions required for AllocatePrefetchInstr 1 unavailable"); 61 FLAG_SET_DEFAULT(AllocatePrefetchInstr, 0); 62 } 63 if (cache_line_size <= 0) { 64 warning("Cache-line size must be known for AllocatePrefetchInstr 1 to work"); 65 FLAG_SET_DEFAULT(AllocatePrefetchInstr, 0); 66 } 67 } 68 69 UseSSE = false; // Only used on x86 and x64. 70 71 _supports_cx8 = true; // All SPARC V9 implementations. 72 _supports_atomic_getset4 = true; // Using the 'swap' instruction. 73 74 if (has_fast_ind_br() && FLAG_IS_DEFAULT(UseInlineCaches)) { 75 // Indirect and direct branches are cost equivalent. 76 FLAG_SET_DEFAULT(UseInlineCaches, false); 77 } 78 // Align loops on the proper instruction boundary to fill the instruction 79 // fetch buffer. 80 if (FLAG_IS_DEFAULT(OptoLoopAlignment)) { 81 FLAG_SET_DEFAULT(OptoLoopAlignment, VM_Version::insn_fetch_alignment); 82 } 83 84 // 32-bit oops don't make sense for the 64-bit VM on SPARC since the 32-bit 85 // VM has the same registers and smaller objects. 86 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); 87 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes); 88 89 #ifdef COMPILER2 90 if (has_fast_ind_br() && FLAG_IS_DEFAULT(UseJumpTables)) { 91 // Indirect and direct branches are cost equivalent. 92 FLAG_SET_DEFAULT(UseJumpTables, true); 93 } 94 // Entry and loop tops are aligned to fill the instruction fetch buffer. 95 if (FLAG_IS_DEFAULT(InteriorEntryAlignment)) { 96 FLAG_SET_DEFAULT(InteriorEntryAlignment, VM_Version::insn_fetch_alignment); 97 } 98 if (UseTLAB && cache_line_size > 0 && 99 FLAG_IS_DEFAULT(AllocatePrefetchInstr)) { 100 if (has_fast_bis()) { 101 // Use BIS instruction for TLAB allocation prefetch. 102 FLAG_SET_DEFAULT(AllocatePrefetchInstr, 1); 103 } 104 else if (has_sparc5()) { 105 // Use prefetch instruction to avoid partial RAW issue on Core S4 processors, 106 // also use prefetch style 3. 107 FLAG_SET_DEFAULT(AllocatePrefetchInstr, 0); 108 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { 109 FLAG_SET_DEFAULT(AllocatePrefetchStyle, 3); 110 } 111 } 112 } 113 if (AllocatePrefetchInstr == 1) { 114 // Use allocation prefetch style 3 because BIS instructions require 115 // aligned memory addresses. 116 FLAG_SET_DEFAULT(AllocatePrefetchStyle, 3); 117 } 118 if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { 119 if (AllocatePrefetchInstr == 0) { 120 // Use different prefetch distance without BIS 121 FLAG_SET_DEFAULT(AllocatePrefetchDistance, 256); 122 } else { 123 // Use smaller prefetch distance with BIS 124 FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64); 125 } 126 } 127 128 // We increase the number of prefetched cache lines, to use just a bit more 129 // aggressive approach, when the L2-cache line size is small (32 bytes), or 130 // when running on newer processor implementations, such as the Core S4. 131 bool inc_prefetch = cache_line_size > 0 && (cache_line_size < 64 || has_sparc5()); 132 133 if (inc_prefetch) { 134 // We use a factor two for small cache line sizes (as before) but a slightly 135 // more conservative increase when running on more recent hardware that will 136 // benefit from just a bit more aggressive prefetching. 137 if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) { 138 const int ap_lns = AllocatePrefetchLines; 139 const int ap_inc = cache_line_size < 64 ? ap_lns : (ap_lns + 1) / 2; 140 FLAG_SET_ERGO(intx, AllocatePrefetchLines, ap_lns + ap_inc); 141 } 142 if (FLAG_IS_DEFAULT(AllocateInstancePrefetchLines)) { 143 const int ip_lns = AllocateInstancePrefetchLines; 144 const int ip_inc = cache_line_size < 64 ? ip_lns : (ip_lns + 1) / 2; 145 FLAG_SET_ERGO(intx, AllocateInstancePrefetchLines, ip_lns + ip_inc); 146 } 147 } 148 #endif /* COMPILER2 */ 149 150 // Use hardware population count instruction if available. 151 if (has_popc()) { 152 if (FLAG_IS_DEFAULT(UsePopCountInstruction)) { 153 FLAG_SET_DEFAULT(UsePopCountInstruction, true); 154 } 155 } else if (UsePopCountInstruction) { 156 warning("POPC instruction is not available on this CPU"); 157 FLAG_SET_DEFAULT(UsePopCountInstruction, false); 158 } 159 160 // Use compare and branch instructions if available. 161 if (has_cbcond()) { 162 if (FLAG_IS_DEFAULT(UseCBCond)) { 163 FLAG_SET_DEFAULT(UseCBCond, true); 164 } 165 } else if (UseCBCond) { 166 warning("CBCOND instruction is not available on this CPU"); 167 FLAG_SET_DEFAULT(UseCBCond, false); 168 } 169 170 assert(BlockZeroingLowLimit > 0, "invalid value"); 171 172 if (has_blk_zeroing() && cache_line_size > 0) { 173 if (FLAG_IS_DEFAULT(UseBlockZeroing)) { 174 FLAG_SET_DEFAULT(UseBlockZeroing, true); 175 } 176 } else if (UseBlockZeroing) { 177 warning("BIS zeroing instructions are not available on this CPU"); 178 FLAG_SET_DEFAULT(UseBlockZeroing, false); 179 } 180 181 assert(BlockCopyLowLimit > 0, "invalid value"); 182 183 if (has_blk_zeroing() && cache_line_size > 0) { 184 if (FLAG_IS_DEFAULT(UseBlockCopy)) { 185 FLAG_SET_DEFAULT(UseBlockCopy, true); 186 } 187 } else if (UseBlockCopy) { 188 warning("BIS instructions are not available or expensive on this CPU"); 189 FLAG_SET_DEFAULT(UseBlockCopy, false); 190 } 191 192 #ifdef COMPILER2 193 if (has_fast_rdpc() && FLAG_IS_DEFAULT(UseRDPCForConstantTableBase)) { 194 FLAG_SET_DEFAULT(UseRDPCForConstantTableBase, true); 195 } 196 197 // Currently not supported anywhere. 198 FLAG_SET_DEFAULT(UseFPUForSpilling, false); 199 200 MaxVectorSize = 8; 201 202 assert((InteriorEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); 203 #endif 204 205 assert((CodeEntryAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); 206 assert((OptoLoopAlignment % relocInfo::addr_unit()) == 0, "alignment is not a multiple of NOP size"); 207 208 char buf[512]; 209 jio_snprintf(buf, sizeof(buf), 210 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" 211 "%s%s%s%s%s%s%s%s%s" "%s%s%s%s%s%s%s%s%s" 212 "%s%s%s%s%s%s%s", 213 (has_v9() ? "v9" : ""), 214 (has_popc() ? ", popc" : ""), 215 (has_vis1() ? ", vis1" : ""), 216 (has_vis2() ? ", vis2" : ""), 217 (has_blk_init() ? ", blk_init" : ""), 218 (has_fmaf() ? ", fmaf" : ""), 219 (has_hpc() ? ", hpc" : ""), 220 (has_ima() ? ", ima" : ""), 221 (has_aes() ? ", aes" : ""), 222 (has_des() ? ", des" : ""), 223 (has_kasumi() ? ", kas" : ""), 224 (has_camellia() ? ", cam" : ""), 225 (has_md5() ? ", md5" : ""), 226 (has_sha1() ? ", sha1" : ""), 227 (has_sha256() ? ", sha256" : ""), 228 (has_sha512() ? ", sha512" : ""), 229 (has_mpmul() ? ", mpmul" : ""), 230 (has_mont() ? ", mont" : ""), 231 (has_pause() ? ", pause" : ""), 232 (has_cbcond() ? ", cbcond" : ""), 233 (has_crc32c() ? ", crc32c" : ""), 234 235 (has_athena_plus() ? ", athena_plus" : ""), 236 (has_vis3b() ? ", vis3b" : ""), 237 (has_adi() ? ", adi" : ""), 238 (has_sparc5() ? ", sparc5" : ""), 239 (has_mwait() ? ", mwait" : ""), 240 (has_xmpmul() ? ", xmpmul" : ""), 241 (has_xmont() ? ", xmont" : ""), 242 (has_pause_nsec() ? ", pause_nsec" : ""), 243 (has_vamask() ? ", vamask" : ""), 244 245 (has_sparc6() ? ", sparc6" : ""), 246 (has_dictunp() ? ", dictunp" : ""), 247 (has_fpcmpshl() ? ", fpcmpshl" : ""), 248 (has_rle() ? ", rle" : ""), 249 (has_sha3() ? ", sha3" : ""), 250 (has_athena_plus2()? ", athena_plus2" : ""), 251 (has_vis3c() ? ", vis3c" : ""), 252 (has_sparc5b() ? ", sparc5b" : ""), 253 (has_mme() ? ", mme" : ""), 254 255 (has_fast_idiv() ? ", *idiv" : ""), 256 (has_fast_rdpc() ? ", *rdpc" : ""), 257 (has_fast_bis() ? ", *bis" : ""), 258 (has_fast_ld() ? ", *ld" : ""), 259 (has_fast_cmove() ? ", *cmove" : ""), 260 (has_fast_ind_br() ? ", *ind_br" : ""), 261 (has_blk_zeroing() ? ", *blk_zeroing" : "")); 262 263 assert(strlen(buf) >= 2, "must be"); 264 265 _features_string = os::strdup(buf); 266 267 log_info(os, cpu)("SPARC features detected: %s", _features_string); 268 269 // UseVIS is set to the smallest of what hardware supports and what the command 270 // line requires, i.e. you cannot set UseVIS to 3 on older UltraSparc which do 271 // not support it. 272 273 if (UseVIS > 3) UseVIS = 3; 274 if (UseVIS < 0) UseVIS = 0; 275 if (!has_vis3()) // Drop to 2 if no VIS3 support 276 UseVIS = MIN2((intx)2, UseVIS); 277 if (!has_vis2()) // Drop to 1 if no VIS2 support 278 UseVIS = MIN2((intx)1, UseVIS); 279 if (!has_vis1()) // Drop to 0 if no VIS1 support 280 UseVIS = 0; 281 282 if (has_aes()) { 283 if (FLAG_IS_DEFAULT(UseAES)) { 284 FLAG_SET_DEFAULT(UseAES, true); 285 } 286 if (!UseAES) { 287 if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { 288 warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled."); 289 } 290 FLAG_SET_DEFAULT(UseAESIntrinsics, false); 291 } else { 292 // The AES intrinsic stubs require AES instruction support (of course) 293 // but also require VIS3 mode or higher for instructions it use. 294 if (UseVIS > 2) { 295 if (FLAG_IS_DEFAULT(UseAESIntrinsics)) { 296 FLAG_SET_DEFAULT(UseAESIntrinsics, true); 297 } 298 } else { 299 if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { 300 warning("SPARC AES intrinsics require VIS3 instructions. Intrinsics will be disabled."); 301 } 302 FLAG_SET_DEFAULT(UseAESIntrinsics, false); 303 } 304 } 305 } else if (UseAES || UseAESIntrinsics) { 306 if (UseAES && !FLAG_IS_DEFAULT(UseAES)) { 307 warning("AES instructions are not available on this CPU"); 308 FLAG_SET_DEFAULT(UseAES, false); 309 } 310 if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) { 311 warning("AES intrinsics are not available on this CPU"); 312 FLAG_SET_DEFAULT(UseAESIntrinsics, false); 313 } 314 } 315 316 if (UseAESCTRIntrinsics) { 317 warning("AES/CTR intrinsics are not available on this CPU"); 318 FLAG_SET_DEFAULT(UseAESCTRIntrinsics, false); 319 } 320 321 // GHASH/GCM intrinsics 322 if (has_vis3() && (UseVIS > 2)) { 323 if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) { 324 UseGHASHIntrinsics = true; 325 } 326 } else if (UseGHASHIntrinsics) { 327 if (!FLAG_IS_DEFAULT(UseGHASHIntrinsics)) 328 warning("GHASH intrinsics require VIS3 instruction support. Intrinsics will be disabled"); 329 FLAG_SET_DEFAULT(UseGHASHIntrinsics, false); 330 } 331 332 if (has_fmaf()) { 333 if (FLAG_IS_DEFAULT(UseFMA)) { 334 UseFMA = true; 335 } 336 } else if (UseFMA) { 337 warning("FMA instructions are not available on this CPU"); 338 FLAG_SET_DEFAULT(UseFMA, false); 339 } 340 341 // SHA1, SHA256, and SHA512 instructions were added to SPARC at different times 342 if (has_sha1() || has_sha256() || has_sha512()) { 343 if (UseVIS > 0) { // SHA intrinsics use VIS1 instructions 344 if (FLAG_IS_DEFAULT(UseSHA)) { 345 FLAG_SET_DEFAULT(UseSHA, true); 346 } 347 } else { 348 if (UseSHA) { 349 warning("SPARC SHA intrinsics require VIS1 instruction support. Intrinsics will be disabled."); 350 FLAG_SET_DEFAULT(UseSHA, false); 351 } 352 } 353 } else if (UseSHA) { 354 warning("SHA instructions are not available on this CPU"); 355 FLAG_SET_DEFAULT(UseSHA, false); 356 } 357 358 if (UseSHA && has_sha1()) { 359 if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) { 360 FLAG_SET_DEFAULT(UseSHA1Intrinsics, true); 361 } 362 } else if (UseSHA1Intrinsics) { 363 warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU."); 364 FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); 365 } 366 367 if (UseSHA && has_sha256()) { 368 if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) { 369 FLAG_SET_DEFAULT(UseSHA256Intrinsics, true); 370 } 371 } else if (UseSHA256Intrinsics) { 372 warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU."); 373 FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); 374 } 375 376 if (UseSHA && has_sha512()) { 377 if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) { 378 FLAG_SET_DEFAULT(UseSHA512Intrinsics, true); 379 } 380 } else if (UseSHA512Intrinsics) { 381 warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU."); 382 FLAG_SET_DEFAULT(UseSHA512Intrinsics, false); 383 } 384 385 if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) { 386 FLAG_SET_DEFAULT(UseSHA, false); 387 } 388 389 if (has_crc32c()) { 390 if (UseVIS > 2) { // CRC32C intrinsics use VIS3 instructions 391 if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) { 392 FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true); 393 } 394 } else { 395 if (UseCRC32CIntrinsics) { 396 warning("SPARC CRC32C intrinsics require VIS3 instruction support. Intrinsics will be disabled."); 397 FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false); 398 } 399 } 400 } else if (UseCRC32CIntrinsics) { 401 warning("CRC32C instruction is not available on this CPU"); 402 FLAG_SET_DEFAULT(UseCRC32CIntrinsics, false); 403 } 404 405 if (UseVIS > 2) { 406 if (FLAG_IS_DEFAULT(UseAdler32Intrinsics)) { 407 FLAG_SET_DEFAULT(UseAdler32Intrinsics, true); 408 } 409 } else if (UseAdler32Intrinsics) { 410 warning("SPARC Adler32 intrinsics require VIS3 instruction support. Intrinsics will be disabled."); 411 FLAG_SET_DEFAULT(UseAdler32Intrinsics, false); 412 } 413 414 if (UseVIS > 2) { 415 if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) { 416 FLAG_SET_DEFAULT(UseCRC32Intrinsics, true); 417 } 418 } else if (UseCRC32Intrinsics) { 419 warning("SPARC CRC32 intrinsics require VIS3 instructions support. Intrinsics will be disabled"); 420 FLAG_SET_DEFAULT(UseCRC32Intrinsics, false); 421 } 422 423 if (UseVectorizedMismatchIntrinsic) { 424 warning("UseVectorizedMismatchIntrinsic specified, but not available on this CPU."); 425 FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false); 426 } 427 428 if (FLAG_IS_DEFAULT(ContendedPaddingWidth) && 429 (cache_line_size > ContendedPaddingWidth)) 430 ContendedPaddingWidth = cache_line_size; 431 432 // This machine does not allow unaligned memory accesses 433 if (UseUnalignedAccesses) { 434 if (!FLAG_IS_DEFAULT(UseUnalignedAccesses)) 435 warning("Unaligned memory access is not available on this CPU"); 436 FLAG_SET_DEFAULT(UseUnalignedAccesses, false); 437 } 438 439 if (log_is_enabled(Info, os, cpu)) { 440 ResourceMark rm; 441 outputStream* log = Log(os, cpu)::info_stream(); 442 log->print_cr("L1 data cache line size: %u", L1_data_cache_line_size()); 443 log->print_cr("L2 data cache line size: %u", L2_data_cache_line_size()); 444 log->print("Allocation"); 445 if (AllocatePrefetchStyle <= 0) { 446 log->print(": no prefetching"); 447 } else { 448 log->print(" prefetching: "); 449 if (AllocatePrefetchInstr == 0) { 450 log->print("PREFETCH"); 451 } else if (AllocatePrefetchInstr == 1) { 452 log->print("BIS"); 453 } 454 if (AllocatePrefetchLines > 1) { 455 log->print_cr(" at distance %d, %d lines of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchLines, (int) AllocatePrefetchStepSize); 456 } else { 457 log->print_cr(" at distance %d, one line of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchStepSize); 458 } 459 } 460 if (PrefetchCopyIntervalInBytes > 0) { 461 log->print_cr("PrefetchCopyIntervalInBytes %d", (int) PrefetchCopyIntervalInBytes); 462 } 463 if (PrefetchScanIntervalInBytes > 0) { 464 log->print_cr("PrefetchScanIntervalInBytes %d", (int) PrefetchScanIntervalInBytes); 465 } 466 if (PrefetchFieldsAhead > 0) { 467 log->print_cr("PrefetchFieldsAhead %d", (int) PrefetchFieldsAhead); 468 } 469 if (ContendedPaddingWidth > 0) { 470 log->print_cr("ContendedPaddingWidth %d", (int) ContendedPaddingWidth); 471 } 472 } 473 } 474 475 void VM_Version::print_features() { 476 tty->print("ISA features [0x%0" PRIx64 "]:", _features); 477 if (_features_string != NULL) { 478 tty->print(" %s", _features_string); 479 } 480 tty->cr(); 481 } 482 483 void VM_Version::determine_features() { 484 platform_features(); // platform_features() is os_arch specific. 485 486 assert(has_v9(), "must be"); 487 488 if (UseNiagaraInstrs) { // Limit code generation to Niagara. 489 _features &= niagara1_msk; 490 } 491 } 492 493 static uint64_t saved_features = 0; 494 495 void VM_Version::allow_all() { 496 saved_features = _features; 497 _features = full_feature_msk; 498 } 499 500 void VM_Version::revert() { 501 _features = saved_features; 502 } 503 504 /* Determine a suitable number of threads on this particular machine. 505 * 506 * FIXME: Simply checking the processor family is insufficient. 507 */ 508 unsigned int VM_Version::calc_parallel_worker_threads() { 509 const int num = 5; 510 const int den = is_post_niagara() ? 16 : 8; 511 const int threshold = 8; 512 513 return nof_parallel_worker_threads(num, den, threshold); 514 }