1 /*
   2  * Copyright (c) 1997, 2014, 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.hpp"
  27 #include "asm/macroAssembler.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "runtime/java.hpp"
  30 #include "runtime/stubCodeGenerator.hpp"
  31 #include "vm_version_x86.hpp"
  32 #ifdef TARGET_OS_FAMILY_linux
  33 # include "os_linux.inline.hpp"
  34 #endif
  35 #ifdef TARGET_OS_FAMILY_solaris
  36 # include "os_solaris.inline.hpp"
  37 #endif
  38 #ifdef TARGET_OS_FAMILY_windows
  39 # include "os_windows.inline.hpp"
  40 #endif
  41 #ifdef TARGET_OS_FAMILY_bsd
  42 # include "os_bsd.inline.hpp"
  43 #endif
  44 
  45 
  46 int VM_Version::_cpu;
  47 int VM_Version::_model;
  48 int VM_Version::_stepping;
  49 int VM_Version::_cpuFeatures;
  50 const char*           VM_Version::_features_str = "";
  51 VM_Version::CpuidInfo VM_Version::_cpuid_info   = { 0, };
  52 
  53 // Address of instruction which causes SEGV
  54 address VM_Version::_cpuinfo_segv_addr = 0;
  55 // Address of instruction after the one which causes SEGV
  56 address VM_Version::_cpuinfo_cont_addr = 0;
  57 
  58 static BufferBlob* stub_blob;
  59 static const int stub_size = 600;
  60 
  61 extern "C" {
  62   typedef void (*get_cpu_info_stub_t)(void*);
  63 }
  64 static get_cpu_info_stub_t get_cpu_info_stub = NULL;
  65 
  66 
  67 class VM_Version_StubGenerator: public StubCodeGenerator {
  68  public:
  69 
  70   VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
  71 
  72   address generate_get_cpu_info() {
  73     // Flags to test CPU type.
  74     const uint32_t HS_EFL_AC           = 0x40000;
  75     const uint32_t HS_EFL_ID           = 0x200000;
  76     // Values for when we don't have a CPUID instruction.
  77     const int      CPU_FAMILY_SHIFT = 8;
  78     const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
  79     const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);
  80 
  81     Label detect_486, cpu486, detect_586, std_cpuid1, std_cpuid4;
  82     Label sef_cpuid, ext_cpuid, ext_cpuid1, ext_cpuid5, ext_cpuid7, done;
  83 
  84     StubCodeMark mark(this, "VM_Version", "get_cpu_info_stub");
  85 #   define __ _masm->
  86 
  87     address start = __ pc();
  88 
  89     //
  90     // void get_cpu_info(VM_Version::CpuidInfo* cpuid_info);
  91     //
  92     // LP64: rcx and rdx are first and second argument registers on windows
  93 
  94     __ push(rbp);
  95 #ifdef _LP64
  96     __ mov(rbp, c_rarg0); // cpuid_info address
  97 #else
  98     __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
  99 #endif
 100     __ push(rbx);
 101     __ push(rsi);
 102     __ pushf();          // preserve rbx, and flags
 103     __ pop(rax);
 104     __ push(rax);
 105     __ mov(rcx, rax);
 106     //
 107     // if we are unable to change the AC flag, we have a 386
 108     //
 109     __ xorl(rax, HS_EFL_AC);
 110     __ push(rax);
 111     __ popf();
 112     __ pushf();
 113     __ pop(rax);
 114     __ cmpptr(rax, rcx);
 115     __ jccb(Assembler::notEqual, detect_486);
 116 
 117     __ movl(rax, CPU_FAMILY_386);
 118     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 119     __ jmp(done);
 120 
 121     //
 122     // If we are unable to change the ID flag, we have a 486 which does
 123     // not support the "cpuid" instruction.
 124     //
 125     __ bind(detect_486);
 126     __ mov(rax, rcx);
 127     __ xorl(rax, HS_EFL_ID);
 128     __ push(rax);
 129     __ popf();
 130     __ pushf();
 131     __ pop(rax);
 132     __ cmpptr(rcx, rax);
 133     __ jccb(Assembler::notEqual, detect_586);
 134 
 135     __ bind(cpu486);
 136     __ movl(rax, CPU_FAMILY_486);
 137     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 138     __ jmp(done);
 139 
 140     //
 141     // At this point, we have a chip which supports the "cpuid" instruction
 142     //
 143     __ bind(detect_586);
 144     __ xorl(rax, rax);
 145     __ cpuid();
 146     __ orl(rax, rax);
 147     __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input
 148                                         // value of at least 1, we give up and
 149                                         // assume a 486
 150     __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset())));
 151     __ movl(Address(rsi, 0), rax);
 152     __ movl(Address(rsi, 4), rbx);
 153     __ movl(Address(rsi, 8), rcx);
 154     __ movl(Address(rsi,12), rdx);
 155 
 156     __ cmpl(rax, 0xa);                  // Is cpuid(0xB) supported?
 157     __ jccb(Assembler::belowEqual, std_cpuid4);
 158 
 159     //
 160     // cpuid(0xB) Processor Topology
 161     //
 162     __ movl(rax, 0xb);
 163     __ xorl(rcx, rcx);   // Threads level
 164     __ cpuid();
 165 
 166     __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB0_offset())));
 167     __ movl(Address(rsi, 0), rax);
 168     __ movl(Address(rsi, 4), rbx);
 169     __ movl(Address(rsi, 8), rcx);
 170     __ movl(Address(rsi,12), rdx);
 171 
 172     __ movl(rax, 0xb);
 173     __ movl(rcx, 1);     // Cores level
 174     __ cpuid();
 175     __ push(rax);
 176     __ andl(rax, 0x1f);  // Determine if valid topology level
 177     __ orl(rax, rbx);    // eax[4:0] | ebx[0:15] == 0 indicates invalid level
 178     __ andl(rax, 0xffff);
 179     __ pop(rax);
 180     __ jccb(Assembler::equal, std_cpuid4);
 181 
 182     __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB1_offset())));
 183     __ movl(Address(rsi, 0), rax);
 184     __ movl(Address(rsi, 4), rbx);
 185     __ movl(Address(rsi, 8), rcx);
 186     __ movl(Address(rsi,12), rdx);
 187 
 188     __ movl(rax, 0xb);
 189     __ movl(rcx, 2);     // Packages level
 190     __ cpuid();
 191     __ push(rax);
 192     __ andl(rax, 0x1f);  // Determine if valid topology level
 193     __ orl(rax, rbx);    // eax[4:0] | ebx[0:15] == 0 indicates invalid level
 194     __ andl(rax, 0xffff);
 195     __ pop(rax);
 196     __ jccb(Assembler::equal, std_cpuid4);
 197 
 198     __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB2_offset())));
 199     __ movl(Address(rsi, 0), rax);
 200     __ movl(Address(rsi, 4), rbx);
 201     __ movl(Address(rsi, 8), rcx);
 202     __ movl(Address(rsi,12), rdx);
 203 
 204     //
 205     // cpuid(0x4) Deterministic cache params
 206     //
 207     __ bind(std_cpuid4);
 208     __ movl(rax, 4);
 209     __ cmpl(rax, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset()))); // Is cpuid(0x4) supported?
 210     __ jccb(Assembler::greater, std_cpuid1);
 211 
 212     __ xorl(rcx, rcx);   // L1 cache
 213     __ cpuid();
 214     __ push(rax);
 215     __ andl(rax, 0x1f);  // Determine if valid cache parameters used
 216     __ orl(rax, rax);    // eax[4:0] == 0 indicates invalid cache
 217     __ pop(rax);
 218     __ jccb(Assembler::equal, std_cpuid1);
 219 
 220     __ lea(rsi, Address(rbp, in_bytes(VM_Version::dcp_cpuid4_offset())));
 221     __ movl(Address(rsi, 0), rax);
 222     __ movl(Address(rsi, 4), rbx);
 223     __ movl(Address(rsi, 8), rcx);
 224     __ movl(Address(rsi,12), rdx);
 225 
 226     //
 227     // Standard cpuid(0x1)
 228     //
 229     __ bind(std_cpuid1);
 230     __ movl(rax, 1);
 231     __ cpuid();
 232     __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())));
 233     __ movl(Address(rsi, 0), rax);
 234     __ movl(Address(rsi, 4), rbx);
 235     __ movl(Address(rsi, 8), rcx);
 236     __ movl(Address(rsi,12), rdx);
 237 
 238     //
 239     // Check if OS has enabled XGETBV instruction to access XCR0
 240     // (OSXSAVE feature flag) and CPU supports AVX
 241     //
 242     __ andl(rcx, 0x18000000); // cpuid1 bits osxsave | avx
 243     __ cmpl(rcx, 0x18000000);
 244     __ jccb(Assembler::notEqual, sef_cpuid); // jump if AVX is not supported
 245 
 246     //
 247     // XCR0, XFEATURE_ENABLED_MASK register
 248     //
 249     __ xorl(rcx, rcx);   // zero for XCR0 register
 250     __ xgetbv();
 251     __ lea(rsi, Address(rbp, in_bytes(VM_Version::xem_xcr0_offset())));
 252     __ movl(Address(rsi, 0), rax);
 253     __ movl(Address(rsi, 4), rdx);
 254 
 255     __ andl(rax, 0x6); // xcr0 bits sse | ymm
 256     __ cmpl(rax, 0x6);
 257     __ jccb(Assembler::notEqual, sef_cpuid); // jump if AVX is not supported
 258 
 259     //
 260     // Some OSs have a bug when upper 128bits of YMM
 261     // registers are not restored after a signal processing.
 262     // Generate SEGV here (reference through NULL)
 263     // and check upper YMM bits after it.
 264     //
 265     VM_Version::set_avx_cpuFeatures(); // Enable temporary to pass asserts
 266     intx saved_useavx = UseAVX;
 267     intx saved_usesse = UseSSE;
 268     UseAVX = 1;
 269     UseSSE = 2;
 270 
 271     // load value into all 32 bytes of ymm7 register
 272     __ movl(rcx, VM_Version::ymm_test_value());
 273 
 274     __ movdl(xmm0, rcx);
 275     __ pshufd(xmm0, xmm0, 0x00);
 276     __ vinsertf128h(xmm0, xmm0, xmm0);
 277     __ vmovdqu(xmm7, xmm0);
 278 #ifdef _LP64
 279     __ vmovdqu(xmm8,  xmm0);
 280     __ vmovdqu(xmm15, xmm0);
 281 #endif
 282 
 283     __ xorl(rsi, rsi);
 284     VM_Version::set_cpuinfo_segv_addr( __ pc() );
 285     // Generate SEGV
 286     __ movl(rax, Address(rsi, 0));
 287 
 288     VM_Version::set_cpuinfo_cont_addr( __ pc() );
 289     // Returns here after signal. Save xmm0 to check it later.
 290     __ lea(rsi, Address(rbp, in_bytes(VM_Version::ymm_save_offset())));
 291     __ vmovdqu(Address(rsi,  0), xmm0);
 292     __ vmovdqu(Address(rsi, 32), xmm7);
 293 #ifdef _LP64
 294     __ vmovdqu(Address(rsi, 64), xmm8);
 295     __ vmovdqu(Address(rsi, 96), xmm15);
 296 #endif
 297 
 298     VM_Version::clean_cpuFeatures();
 299     UseAVX = saved_useavx;
 300     UseSSE = saved_usesse;
 301 
 302     //
 303     // cpuid(0x7) Structured Extended Features
 304     //
 305     __ bind(sef_cpuid);
 306     __ movl(rax, 7);
 307     __ cmpl(rax, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset()))); // Is cpuid(0x7) supported?
 308     __ jccb(Assembler::greater, ext_cpuid);
 309 
 310     __ xorl(rcx, rcx);
 311     __ cpuid();
 312     __ lea(rsi, Address(rbp, in_bytes(VM_Version::sef_cpuid7_offset())));
 313     __ movl(Address(rsi, 0), rax);
 314     __ movl(Address(rsi, 4), rbx);
 315 
 316     //
 317     // Extended cpuid(0x80000000)
 318     //
 319     __ bind(ext_cpuid);
 320     __ movl(rax, 0x80000000);
 321     __ cpuid();
 322     __ cmpl(rax, 0x80000000);     // Is cpuid(0x80000001) supported?
 323     __ jcc(Assembler::belowEqual, done);
 324     __ cmpl(rax, 0x80000004);     // Is cpuid(0x80000005) supported?
 325     __ jccb(Assembler::belowEqual, ext_cpuid1);
 326     __ cmpl(rax, 0x80000006);     // Is cpuid(0x80000007) supported?
 327     __ jccb(Assembler::belowEqual, ext_cpuid5);
 328     __ cmpl(rax, 0x80000007);     // Is cpuid(0x80000008) supported?
 329     __ jccb(Assembler::belowEqual, ext_cpuid7);
 330     //
 331     // Extended cpuid(0x80000008)
 332     //
 333     __ movl(rax, 0x80000008);
 334     __ cpuid();
 335     __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid8_offset())));
 336     __ movl(Address(rsi, 0), rax);
 337     __ movl(Address(rsi, 4), rbx);
 338     __ movl(Address(rsi, 8), rcx);
 339     __ movl(Address(rsi,12), rdx);
 340 
 341     //
 342     // Extended cpuid(0x80000007)
 343     //
 344     __ bind(ext_cpuid7);
 345     __ movl(rax, 0x80000007);
 346     __ cpuid();
 347     __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid7_offset())));
 348     __ movl(Address(rsi, 0), rax);
 349     __ movl(Address(rsi, 4), rbx);
 350     __ movl(Address(rsi, 8), rcx);
 351     __ movl(Address(rsi,12), rdx);
 352 
 353     //
 354     // Extended cpuid(0x80000005)
 355     //
 356     __ bind(ext_cpuid5);
 357     __ movl(rax, 0x80000005);
 358     __ cpuid();
 359     __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid5_offset())));
 360     __ movl(Address(rsi, 0), rax);
 361     __ movl(Address(rsi, 4), rbx);
 362     __ movl(Address(rsi, 8), rcx);
 363     __ movl(Address(rsi,12), rdx);
 364 
 365     //
 366     // Extended cpuid(0x80000001)
 367     //
 368     __ bind(ext_cpuid1);
 369     __ movl(rax, 0x80000001);
 370     __ cpuid();
 371     __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid1_offset())));
 372     __ movl(Address(rsi, 0), rax);
 373     __ movl(Address(rsi, 4), rbx);
 374     __ movl(Address(rsi, 8), rcx);
 375     __ movl(Address(rsi,12), rdx);
 376 
 377     //
 378     // return
 379     //
 380     __ bind(done);
 381     __ popf();
 382     __ pop(rsi);
 383     __ pop(rbx);
 384     __ pop(rbp);
 385     __ ret(0);
 386 
 387 #   undef __
 388 
 389     return start;
 390   };
 391 };
 392 
 393 
 394 void VM_Version::get_cpu_info_wrapper() {
 395   get_cpu_info_stub(&_cpuid_info);
 396 }
 397 
 398 #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
 399   #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
 400 #endif
 401 
 402 void VM_Version::get_processor_features() {
 403 
 404   _cpu = 4; // 486 by default
 405   _model = 0;
 406   _stepping = 0;
 407   _cpuFeatures = 0;
 408   _logical_processors_per_package = 1;
 409 
 410   if (!Use486InstrsOnly) {
 411     // Get raw processor info
 412 
 413     // Some platforms (like Win*) need a wrapper around here
 414     // in order to properly handle SEGV for YMM registers test.
 415     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(get_cpu_info_wrapper);
 416 
 417     assert_is_initialized();
 418     _cpu = extended_cpu_family();
 419     _model = extended_cpu_model();
 420     _stepping = cpu_stepping();
 421 
 422     if (cpu_family() > 4) { // it supports CPUID
 423       _cpuFeatures = feature_flags();
 424       // Logical processors are only available on P4s and above,
 425       // and only if hyperthreading is available.
 426       _logical_processors_per_package = logical_processor_count();
 427     }
 428   }
 429 
 430   _supports_cx8 = supports_cmpxchg8();
 431   // xchg and xadd instructions
 432   _supports_atomic_getset4 = true;
 433   _supports_atomic_getadd4 = true;
 434   LP64_ONLY(_supports_atomic_getset8 = true);
 435   LP64_ONLY(_supports_atomic_getadd8 = true);
 436 
 437 #ifdef _LP64
 438   // OS should support SSE for x64 and hardware should support at least SSE2.
 439   if (!VM_Version::supports_sse2()) {
 440     vm_exit_during_initialization("Unknown x64 processor: SSE2 not supported");
 441   }
 442   // in 64 bit the use of SSE2 is the minimum
 443   if (UseSSE < 2) UseSSE = 2;
 444 #endif
 445 
 446 #ifdef AMD64
 447   // flush_icache_stub have to be generated first.
 448   // That is why Icache line size is hard coded in ICache class,
 449   // see icache_x86.hpp. It is also the reason why we can't use
 450   // clflush instruction in 32-bit VM since it could be running
 451   // on CPU which does not support it.
 452   //
 453   // The only thing we can do is to verify that flushed
 454   // ICache::line_size has correct value.
 455   guarantee(_cpuid_info.std_cpuid1_edx.bits.clflush != 0, "clflush is not supported");
 456   // clflush_size is size in quadwords (8 bytes).
 457   guarantee(_cpuid_info.std_cpuid1_ebx.bits.clflush_size == 8, "such clflush size is not supported");
 458 #endif
 459 
 460   // If the OS doesn't support SSE, we can't use this feature even if the HW does
 461   if (!os::supports_sse())
 462     _cpuFeatures &= ~(CPU_SSE|CPU_SSE2|CPU_SSE3|CPU_SSSE3|CPU_SSE4A|CPU_SSE4_1|CPU_SSE4_2);
 463 
 464   if (UseSSE < 4) {
 465     _cpuFeatures &= ~CPU_SSE4_1;
 466     _cpuFeatures &= ~CPU_SSE4_2;
 467   }
 468 
 469   if (UseSSE < 3) {
 470     _cpuFeatures &= ~CPU_SSE3;
 471     _cpuFeatures &= ~CPU_SSSE3;
 472     _cpuFeatures &= ~CPU_SSE4A;
 473   }
 474 
 475   if (UseSSE < 2)
 476     _cpuFeatures &= ~CPU_SSE2;
 477 
 478   if (UseSSE < 1)
 479     _cpuFeatures &= ~CPU_SSE;
 480 
 481   if (UseAVX < 2)
 482     _cpuFeatures &= ~CPU_AVX2;
 483 
 484   if (UseAVX < 1)
 485     _cpuFeatures &= ~CPU_AVX;
 486 
 487   if (!UseAES && !FLAG_IS_DEFAULT(UseAES))
 488     _cpuFeatures &= ~CPU_AES;
 489 
 490   if (logical_processors_per_package() == 1) {
 491     // HT processor could be installed on a system which doesn't support HT.
 492     _cpuFeatures &= ~CPU_HT;
 493   }
 494 
 495   char buf[256];
 496   jio_snprintf(buf, sizeof(buf), "(%u cores per cpu, %u threads per core) family %d model %d stepping %d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
 497                cores_per_cpu(), threads_per_core(),
 498                cpu_family(), _model, _stepping,
 499                (supports_cmov() ? ", cmov" : ""),
 500                (supports_cmpxchg8() ? ", cx8" : ""),
 501                (supports_fxsr() ? ", fxsr" : ""),
 502                (supports_mmx()  ? ", mmx"  : ""),
 503                (supports_sse()  ? ", sse"  : ""),
 504                (supports_sse2() ? ", sse2" : ""),
 505                (supports_sse3() ? ", sse3" : ""),
 506                (supports_ssse3()? ", ssse3": ""),
 507                (supports_sse4_1() ? ", sse4.1" : ""),
 508                (supports_sse4_2() ? ", sse4.2" : ""),
 509                (supports_popcnt() ? ", popcnt" : ""),
 510                (supports_avx()    ? ", avx" : ""),
 511                (supports_avx2()   ? ", avx2" : ""),
 512                (supports_aes()    ? ", aes" : ""),
 513                (supports_clmul()  ? ", clmul" : ""),
 514                (supports_erms()   ? ", erms" : ""),
 515                (supports_rtm()    ? ", rtm" : ""),
 516                (supports_mmx_ext() ? ", mmxext" : ""),
 517                (supports_3dnow_prefetch() ? ", 3dnowpref" : ""),
 518                (supports_lzcnt()   ? ", lzcnt": ""),
 519                (supports_sse4a()   ? ", sse4a": ""),
 520                (supports_ht() ? ", ht": ""),
 521                (supports_tsc() ? ", tsc": ""),
 522                (supports_tscinv_bit() ? ", tscinvbit": ""),
 523                (supports_tscinv() ? ", tscinv": ""),
 524                (supports_bmi1() ? ", bmi1" : ""),
 525                (supports_bmi2() ? ", bmi2" : ""),
 526                (supports_adx() ? ", adx" : ""));
 527   _features_str = strdup(buf);
 528 
 529   // UseSSE is set to the smaller of what hardware supports and what
 530   // the command line requires.  I.e., you cannot set UseSSE to 2 on
 531   // older Pentiums which do not support it.
 532   if (UseSSE > 4) UseSSE=4;
 533   if (UseSSE < 0) UseSSE=0;
 534   if (!supports_sse4_1()) // Drop to 3 if no SSE4 support
 535     UseSSE = MIN2((intx)3,UseSSE);
 536   if (!supports_sse3()) // Drop to 2 if no SSE3 support
 537     UseSSE = MIN2((intx)2,UseSSE);
 538   if (!supports_sse2()) // Drop to 1 if no SSE2 support
 539     UseSSE = MIN2((intx)1,UseSSE);
 540   if (!supports_sse ()) // Drop to 0 if no SSE  support
 541     UseSSE = 0;
 542 
 543   if (UseAVX > 2) UseAVX=2;
 544   if (UseAVX < 0) UseAVX=0;
 545   if (!supports_avx2()) // Drop to 1 if no AVX2 support
 546     UseAVX = MIN2((intx)1,UseAVX);
 547   if (!supports_avx ()) // Drop to 0 if no AVX  support
 548     UseAVX = 0;
 549 
 550   // Use AES instructions if available.
 551   if (supports_aes()) {
 552     if (FLAG_IS_DEFAULT(UseAES)) {
 553       UseAES = true;
 554     }
 555   } else if (UseAES) {
 556     if (!FLAG_IS_DEFAULT(UseAES))
 557       warning("AES instructions are not available on this CPU");
 558     FLAG_SET_DEFAULT(UseAES, false);
 559   }
 560 
 561   // Use CLMUL instructions if available.
 562   if (supports_clmul()) {
 563     if (FLAG_IS_DEFAULT(UseCLMUL)) {
 564       UseCLMUL = true;
 565     }
 566   } else if (UseCLMUL) {
 567     if (!FLAG_IS_DEFAULT(UseCLMUL))
 568       warning("CLMUL instructions not available on this CPU (AVX may also be required)");
 569     FLAG_SET_DEFAULT(UseCLMUL, false);
 570   }
 571 
 572   if (UseCLMUL && (UseSSE > 2)) {
 573     if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
 574       UseCRC32Intrinsics = true;
 575     }
 576   } else if (UseCRC32Intrinsics) {
 577     if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics))
 578       warning("CRC32 Intrinsics requires CLMUL instructions (not available on this CPU)");
 579     FLAG_SET_DEFAULT(UseCRC32Intrinsics, false);
 580   }
 581 
 582   // The AES intrinsic stubs require AES instruction support (of course)
 583   // but also require sse3 mode for instructions it use.
 584   if (UseAES && (UseSSE > 2)) {
 585     if (FLAG_IS_DEFAULT(UseAESIntrinsics)) {
 586       UseAESIntrinsics = true;
 587     }
 588   } else if (UseAESIntrinsics) {
 589     if (!FLAG_IS_DEFAULT(UseAESIntrinsics))
 590       warning("AES intrinsics are not available on this CPU");
 591     FLAG_SET_DEFAULT(UseAESIntrinsics, false);
 592   }
 593 
 594   if (UseSHA) {
 595     warning("SHA instructions are not available on this CPU");
 596     FLAG_SET_DEFAULT(UseSHA, false);
 597   }
 598   if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) {
 599     warning("SHA intrinsics are not available on this CPU");
 600     FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
 601     FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
 602     FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
 603   }
 604 
 605   // Adjust RTM (Restricted Transactional Memory) flags
 606   if (!supports_rtm() && UseRTMLocking) {
 607     // Can't continue because UseRTMLocking affects UseBiasedLocking flag
 608     // setting during arguments processing. See use_biased_locking().
 609     // VM_Version_init() is executed after UseBiasedLocking is used
 610     // in Thread::allocate().
 611     vm_exit_during_initialization("RTM instructions are not available on this CPU");
 612   }
 613 
 614 #if INCLUDE_RTM_OPT
 615   if (UseRTMLocking) {
 616     if (is_intel_family_core()) {
 617       if ((_model == CPU_MODEL_HASWELL_E3) ||
 618           (_model == CPU_MODEL_HASWELL_E7 && _stepping < 3) ||
 619           (_model == CPU_MODEL_BROADWELL  && _stepping < 4)) {
 620         if (!UnlockExperimentalVMOptions) {
 621           vm_exit_during_initialization("UseRTMLocking is only available as experimental option on this platform. It must be enabled via -XX:+UnlockExperimentalVMOptions flag.");
 622         } else {
 623           warning("UseRTMLocking is only available as experimental option on this platform.");
 624         }
 625       }
 626     }
 627     if (!FLAG_IS_CMDLINE(UseRTMLocking)) {
 628       // RTM locking should be used only for applications with
 629       // high lock contention. For now we do not use it by default.
 630       vm_exit_during_initialization("UseRTMLocking flag should be only set on command line");
 631     }
 632     if (!is_power_of_2(RTMTotalCountIncrRate)) {
 633       warning("RTMTotalCountIncrRate must be a power of 2, resetting it to 64");
 634       FLAG_SET_DEFAULT(RTMTotalCountIncrRate, 64);
 635     }
 636     if (RTMAbortRatio < 0 || RTMAbortRatio > 100) {
 637       warning("RTMAbortRatio must be in the range 0 to 100, resetting it to 50");
 638       FLAG_SET_DEFAULT(RTMAbortRatio, 50);
 639     }
 640   } else { // !UseRTMLocking
 641     if (UseRTMForStackLocks) {
 642       if (!FLAG_IS_DEFAULT(UseRTMForStackLocks)) {
 643         warning("UseRTMForStackLocks flag should be off when UseRTMLocking flag is off");
 644       }
 645       FLAG_SET_DEFAULT(UseRTMForStackLocks, false);
 646     }
 647     if (UseRTMDeopt) {
 648       FLAG_SET_DEFAULT(UseRTMDeopt, false);
 649     }
 650     if (PrintPreciseRTMLockingStatistics) {
 651       FLAG_SET_DEFAULT(PrintPreciseRTMLockingStatistics, false);
 652     }
 653   }
 654 #else
 655   if (UseRTMLocking) {
 656     // Only C2 does RTM locking optimization.
 657     // Can't continue because UseRTMLocking affects UseBiasedLocking flag
 658     // setting during arguments processing. See use_biased_locking().
 659     vm_exit_during_initialization("RTM locking optimization is not supported in this VM");
 660   }
 661 #endif
 662 
 663 #ifdef COMPILER2
 664   if (UseFPUForSpilling) {
 665     if (UseSSE < 2) {
 666       // Only supported with SSE2+
 667       FLAG_SET_DEFAULT(UseFPUForSpilling, false);
 668     }
 669   }
 670   if (MaxVectorSize > 0) {
 671     if (!is_power_of_2(MaxVectorSize)) {
 672       warning("MaxVectorSize must be a power of 2");
 673       FLAG_SET_DEFAULT(MaxVectorSize, 32);
 674     }
 675     if (MaxVectorSize > 32) {
 676       FLAG_SET_DEFAULT(MaxVectorSize, 32);
 677     }
 678     if (MaxVectorSize > 16 && (UseAVX == 0 || !os_supports_avx_vectors())) {
 679       // 32 bytes vectors (in YMM) are only supported with AVX+
 680       FLAG_SET_DEFAULT(MaxVectorSize, 16);
 681     }
 682     if (UseSSE < 2) {
 683       // Vectors (in XMM) are only supported with SSE2+
 684       FLAG_SET_DEFAULT(MaxVectorSize, 0);
 685     }
 686 #ifdef ASSERT
 687     if (supports_avx() && PrintMiscellaneous && Verbose && TraceNewVectors) {
 688       tty->print_cr("State of YMM registers after signal handle:");
 689       int nreg = 2 LP64_ONLY(+2);
 690       const char* ymm_name[4] = {"0", "7", "8", "15"};
 691       for (int i = 0; i < nreg; i++) {
 692         tty->print("YMM%s:", ymm_name[i]);
 693         for (int j = 7; j >=0; j--) {
 694           tty->print(" %x", _cpuid_info.ymm_save[i*8 + j]);
 695         }
 696         tty->cr();
 697       }
 698     }
 699 #endif
 700   }
 701 
 702 #ifdef _LP64
 703   if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
 704     UseMultiplyToLenIntrinsic = true;
 705   }
 706   if (FLAG_IS_DEFAULT(UseSquareToLenIntrinsic)) {
 707     UseSquareToLenIntrinsic = true;
 708   }
 709   if (FLAG_IS_DEFAULT(UseMulAddIntrinsic)) {
 710     UseMulAddIntrinsic = true;
 711   }
 712 #else
 713   if (UseMultiplyToLenIntrinsic) {
 714     if (!FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
 715       warning("multiplyToLen intrinsic is not available in 32-bit VM");
 716     }
 717     FLAG_SET_DEFAULT(UseMultiplyToLenIntrinsic, false);
 718   }
 719   if (UseSquareToLenIntrinsic) {
 720     if (!FLAG_IS_DEFAULT(UseSquareToLenIntrinsic)) {
 721       warning("squareToLen intrinsic is not available in 32-bit VM");
 722     }
 723     FLAG_SET_DEFAULT(UseSquareToLenIntrinsic, false);
 724   }
 725   if (UseMulAddIntrinsic) {
 726     if (!FLAG_IS_DEFAULT(UseMulAddIntrinsic)) {
 727       warning("mulAdd intrinsic is not available in 32-bit VM");
 728     }
 729     FLAG_SET_DEFAULT(UseMulAddIntrinsic, false);
 730   }
 731 #endif
 732 #endif // COMPILER2
 733 
 734   // On new cpus instructions which update whole XMM register should be used
 735   // to prevent partial register stall due to dependencies on high half.
 736   //
 737   // UseXmmLoadAndClearUpper == true  --> movsd(xmm, mem)
 738   // UseXmmLoadAndClearUpper == false --> movlpd(xmm, mem)
 739   // UseXmmRegToRegMoveAll == true  --> movaps(xmm, xmm), movapd(xmm, xmm).
 740   // UseXmmRegToRegMoveAll == false --> movss(xmm, xmm),  movsd(xmm, xmm).
 741 
 742   if( is_amd() ) { // AMD cpus specific settings
 743     if( supports_sse2() && FLAG_IS_DEFAULT(UseAddressNop) ) {
 744       // Use it on new AMD cpus starting from Opteron.
 745       UseAddressNop = true;
 746     }
 747     if( supports_sse2() && FLAG_IS_DEFAULT(UseNewLongLShift) ) {
 748       // Use it on new AMD cpus starting from Opteron.
 749       UseNewLongLShift = true;
 750     }
 751     if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
 752       if( supports_sse4a() ) {
 753         UseXmmLoadAndClearUpper = true; // use movsd only on '10h' Opteron
 754       } else {
 755         UseXmmLoadAndClearUpper = false;
 756       }
 757     }
 758     if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
 759       if( supports_sse4a() ) {
 760         UseXmmRegToRegMoveAll = true; // use movaps, movapd only on '10h'
 761       } else {
 762         UseXmmRegToRegMoveAll = false;
 763       }
 764     }
 765     if( FLAG_IS_DEFAULT(UseXmmI2F) ) {
 766       if( supports_sse4a() ) {
 767         UseXmmI2F = true;
 768       } else {
 769         UseXmmI2F = false;
 770       }
 771     }
 772     if( FLAG_IS_DEFAULT(UseXmmI2D) ) {
 773       if( supports_sse4a() ) {
 774         UseXmmI2D = true;
 775       } else {
 776         UseXmmI2D = false;
 777       }
 778     }
 779     if( FLAG_IS_DEFAULT(UseSSE42Intrinsics) ) {
 780       if( supports_sse4_2() && UseSSE >= 4 ) {
 781         UseSSE42Intrinsics = true;
 782       }
 783     }
 784 
 785     // some defaults for AMD family 15h
 786     if ( cpu_family() == 0x15 ) {
 787       // On family 15h processors default is no sw prefetch
 788       if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) {
 789         AllocatePrefetchStyle = 0;
 790       }
 791       // Also, if some other prefetch style is specified, default instruction type is PREFETCHW
 792       if (FLAG_IS_DEFAULT(AllocatePrefetchInstr)) {
 793         AllocatePrefetchInstr = 3;
 794       }
 795       // On family 15h processors use XMM and UnalignedLoadStores for Array Copy
 796       if (supports_sse2() && FLAG_IS_DEFAULT(UseXMMForArrayCopy)) {
 797         UseXMMForArrayCopy = true;
 798       }
 799       if (supports_sse2() && FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
 800         UseUnalignedLoadStores = true;
 801       }
 802     }
 803 
 804 #ifdef COMPILER2
 805     if (MaxVectorSize > 16) {
 806       // Limit vectors size to 16 bytes on current AMD cpus.
 807       FLAG_SET_DEFAULT(MaxVectorSize, 16);
 808     }
 809 #endif // COMPILER2
 810   }
 811 
 812   if( is_intel() ) { // Intel cpus specific settings
 813     if( FLAG_IS_DEFAULT(UseStoreImmI16) ) {
 814       UseStoreImmI16 = false; // don't use it on Intel cpus
 815     }
 816     if( cpu_family() == 6 || cpu_family() == 15 ) {
 817       if( FLAG_IS_DEFAULT(UseAddressNop) ) {
 818         // Use it on all Intel cpus starting from PentiumPro
 819         UseAddressNop = true;
 820       }
 821     }
 822     if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
 823       UseXmmLoadAndClearUpper = true; // use movsd on all Intel cpus
 824     }
 825     if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
 826       if( supports_sse3() ) {
 827         UseXmmRegToRegMoveAll = true; // use movaps, movapd on new Intel cpus
 828       } else {
 829         UseXmmRegToRegMoveAll = false;
 830       }
 831     }
 832     if( cpu_family() == 6 && supports_sse3() ) { // New Intel cpus
 833 #ifdef COMPILER2
 834       if( FLAG_IS_DEFAULT(MaxLoopPad) ) {
 835         // For new Intel cpus do the next optimization:
 836         // don't align the beginning of a loop if there are enough instructions
 837         // left (NumberOfLoopInstrToAlign defined in c2_globals.hpp)
 838         // in current fetch line (OptoLoopAlignment) or the padding
 839         // is big (> MaxLoopPad).
 840         // Set MaxLoopPad to 11 for new Intel cpus to reduce number of
 841         // generated NOP instructions. 11 is the largest size of one
 842         // address NOP instruction '0F 1F' (see Assembler::nop(i)).
 843         MaxLoopPad = 11;
 844       }
 845 #endif // COMPILER2
 846       if (FLAG_IS_DEFAULT(UseXMMForArrayCopy)) {
 847         UseXMMForArrayCopy = true; // use SSE2 movq on new Intel cpus
 848       }
 849       if (supports_sse4_2() && supports_ht()) { // Newest Intel cpus
 850         if (FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
 851           UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
 852         }
 853       }
 854       if (supports_sse4_2() && UseSSE >= 4) {
 855         if (FLAG_IS_DEFAULT(UseSSE42Intrinsics)) {
 856           UseSSE42Intrinsics = true;
 857         }
 858       }
 859     }
 860     if ((cpu_family() == 0x06) &&
 861         ((extended_cpu_model() == 0x36) || // Centerton
 862          (extended_cpu_model() == 0x37) || // Silvermont
 863          (extended_cpu_model() == 0x4D))) {
 864 #ifdef COMPILER2
 865       if (FLAG_IS_DEFAULT(OptoScheduling)) {
 866         OptoScheduling = true;
 867       }
 868 #endif
 869       if (supports_sse4_2()) { // Silvermont
 870         if (FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
 871           UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
 872         }
 873       }
 874     }
 875     if(FLAG_IS_DEFAULT(AllocatePrefetchInstr) && supports_3dnow_prefetch()) {
 876       AllocatePrefetchInstr = 3;
 877     }
 878   }
 879 
 880   // Use count leading zeros count instruction if available.
 881   if (supports_lzcnt()) {
 882     if (FLAG_IS_DEFAULT(UseCountLeadingZerosInstruction)) {
 883       UseCountLeadingZerosInstruction = true;
 884     }
 885    } else if (UseCountLeadingZerosInstruction) {
 886     warning("lzcnt instruction is not available on this CPU");
 887     FLAG_SET_DEFAULT(UseCountLeadingZerosInstruction, false);
 888   }
 889 
 890   // Use count trailing zeros instruction if available
 891   if (supports_bmi1()) {
 892     // tzcnt does not require VEX prefix
 893     if (FLAG_IS_DEFAULT(UseCountTrailingZerosInstruction)) {
 894       if (!UseBMI1Instructions && !FLAG_IS_DEFAULT(UseBMI1Instructions)) {
 895         // Don't use tzcnt if BMI1 is switched off on command line.
 896         UseCountTrailingZerosInstruction = false;
 897       } else {
 898         UseCountTrailingZerosInstruction = true;
 899       }
 900     }
 901   } else if (UseCountTrailingZerosInstruction) {
 902     warning("tzcnt instruction is not available on this CPU");
 903     FLAG_SET_DEFAULT(UseCountTrailingZerosInstruction, false);
 904   }
 905 
 906   // BMI instructions (except tzcnt) use an encoding with VEX prefix.
 907   // VEX prefix is generated only when AVX > 0.
 908   if (supports_bmi1() && supports_avx()) {
 909     if (FLAG_IS_DEFAULT(UseBMI1Instructions)) {
 910       UseBMI1Instructions = true;
 911     }
 912   } else if (UseBMI1Instructions) {
 913     warning("BMI1 instructions are not available on this CPU (AVX is also required)");
 914     FLAG_SET_DEFAULT(UseBMI1Instructions, false);
 915   }
 916 
 917   if (supports_bmi2() && supports_avx()) {
 918     if (FLAG_IS_DEFAULT(UseBMI2Instructions)) {
 919       UseBMI2Instructions = true;
 920     }
 921   } else if (UseBMI2Instructions) {
 922     warning("BMI2 instructions are not available on this CPU (AVX is also required)");
 923     FLAG_SET_DEFAULT(UseBMI2Instructions, false);
 924   }
 925 
 926   // Use population count instruction if available.
 927   if (supports_popcnt()) {
 928     if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
 929       UsePopCountInstruction = true;
 930     }
 931   } else if (UsePopCountInstruction) {
 932     warning("POPCNT instruction is not available on this CPU");
 933     FLAG_SET_DEFAULT(UsePopCountInstruction, false);
 934   }
 935 
 936   // Use fast-string operations if available.
 937   if (supports_erms()) {
 938     if (FLAG_IS_DEFAULT(UseFastStosb)) {
 939       UseFastStosb = true;
 940     }
 941   } else if (UseFastStosb) {
 942     warning("fast-string operations are not available on this CPU");
 943     FLAG_SET_DEFAULT(UseFastStosb, false);
 944   }
 945 
 946 #ifdef COMPILER2
 947   if (FLAG_IS_DEFAULT(AlignVector)) {
 948     // Modern processors allow misaligned memory operations for vectors.
 949     AlignVector = !UseUnalignedLoadStores;
 950   }
 951 #endif // COMPILER2
 952 
 953   assert(0 <= ReadPrefetchInstr && ReadPrefetchInstr <= 3, "invalid value");
 954   assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 3, "invalid value");
 955 
 956   // set valid Prefetch instruction
 957   if( ReadPrefetchInstr < 0 ) ReadPrefetchInstr = 0;
 958   if( ReadPrefetchInstr > 3 ) ReadPrefetchInstr = 3;
 959   if( ReadPrefetchInstr == 3 && !supports_3dnow_prefetch() ) ReadPrefetchInstr = 0;
 960   if( !supports_sse() && supports_3dnow_prefetch() ) ReadPrefetchInstr = 3;
 961 
 962   if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0;
 963   if( AllocatePrefetchInstr > 3 ) AllocatePrefetchInstr = 3;
 964   if( AllocatePrefetchInstr == 3 && !supports_3dnow_prefetch() ) AllocatePrefetchInstr=0;
 965   if( !supports_sse() && supports_3dnow_prefetch() ) AllocatePrefetchInstr = 3;
 966 
 967   // Allocation prefetch settings
 968   intx cache_line_size = prefetch_data_size();
 969   if( cache_line_size > AllocatePrefetchStepSize )
 970     AllocatePrefetchStepSize = cache_line_size;
 971 
 972   assert(AllocatePrefetchLines > 0, "invalid value");
 973   if( AllocatePrefetchLines < 1 )     // set valid value in product VM
 974     AllocatePrefetchLines = 3;
 975   assert(AllocateInstancePrefetchLines > 0, "invalid value");
 976   if( AllocateInstancePrefetchLines < 1 ) // set valid value in product VM
 977     AllocateInstancePrefetchLines = 1;
 978 
 979   AllocatePrefetchDistance = allocate_prefetch_distance();
 980   AllocatePrefetchStyle    = allocate_prefetch_style();
 981 
 982   if (is_intel() && cpu_family() == 6 && supports_sse3()) {
 983     if (AllocatePrefetchStyle == 2) { // watermark prefetching on Core
 984 #ifdef _LP64
 985       AllocatePrefetchDistance = 384;
 986 #else
 987       AllocatePrefetchDistance = 320;
 988 #endif
 989     }
 990     if (supports_sse4_2() && supports_ht()) { // Nehalem based cpus
 991       AllocatePrefetchDistance = 192;
 992       AllocatePrefetchLines = 4;
 993     }
 994 #ifdef COMPILER2
 995     if (supports_sse4_2()) {
 996       if (FLAG_IS_DEFAULT(UseFPUForSpilling)) {
 997         FLAG_SET_DEFAULT(UseFPUForSpilling, true);
 998       }
 999     }
1000 #endif
1001   }
1002   assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value");
1003 
1004 #ifdef _LP64
1005   // Prefetch settings
1006   PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes();
1007   PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes();
1008   PrefetchFieldsAhead         = prefetch_fields_ahead();
1009 #endif
1010 
1011   if (FLAG_IS_DEFAULT(ContendedPaddingWidth) &&
1012      (cache_line_size > ContendedPaddingWidth))
1013      ContendedPaddingWidth = cache_line_size;
1014 
1015 #ifndef PRODUCT
1016   if (PrintMiscellaneous && Verbose) {
1017     tty->print_cr("Logical CPUs per core: %u",
1018                   logical_processors_per_package());
1019     tty->print("UseSSE=%d", (int) UseSSE);
1020     if (UseAVX > 0) {
1021       tty->print("  UseAVX=%d", (int) UseAVX);
1022     }
1023     if (UseAES) {
1024       tty->print("  UseAES=1");
1025     }
1026 #ifdef COMPILER2
1027     if (MaxVectorSize > 0) {
1028       tty->print("  MaxVectorSize=%d", (int) MaxVectorSize);
1029     }
1030 #endif
1031     tty->cr();
1032     tty->print("Allocation");
1033     if (AllocatePrefetchStyle <= 0 || UseSSE == 0 && !supports_3dnow_prefetch()) {
1034       tty->print_cr(": no prefetching");
1035     } else {
1036       tty->print(" prefetching: ");
1037       if (UseSSE == 0 && supports_3dnow_prefetch()) {
1038         tty->print("PREFETCHW");
1039       } else if (UseSSE >= 1) {
1040         if (AllocatePrefetchInstr == 0) {
1041           tty->print("PREFETCHNTA");
1042         } else if (AllocatePrefetchInstr == 1) {
1043           tty->print("PREFETCHT0");
1044         } else if (AllocatePrefetchInstr == 2) {
1045           tty->print("PREFETCHT2");
1046         } else if (AllocatePrefetchInstr == 3) {
1047           tty->print("PREFETCHW");
1048         }
1049       }
1050       if (AllocatePrefetchLines > 1) {
1051         tty->print_cr(" at distance %d, %d lines of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchLines, (int) AllocatePrefetchStepSize);
1052       } else {
1053         tty->print_cr(" at distance %d, one line of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchStepSize);
1054       }
1055     }
1056 
1057     if (PrefetchCopyIntervalInBytes > 0) {
1058       tty->print_cr("PrefetchCopyIntervalInBytes %d", (int) PrefetchCopyIntervalInBytes);
1059     }
1060     if (PrefetchScanIntervalInBytes > 0) {
1061       tty->print_cr("PrefetchScanIntervalInBytes %d", (int) PrefetchScanIntervalInBytes);
1062     }
1063     if (PrefetchFieldsAhead > 0) {
1064       tty->print_cr("PrefetchFieldsAhead %d", (int) PrefetchFieldsAhead);
1065     }
1066     if (ContendedPaddingWidth > 0) {
1067       tty->print_cr("ContendedPaddingWidth %d", (int) ContendedPaddingWidth);
1068     }
1069   }
1070 #endif // !PRODUCT
1071 }
1072 
1073 bool VM_Version::use_biased_locking() {
1074 #if INCLUDE_RTM_OPT
1075   // RTM locking is most useful when there is high lock contention and
1076   // low data contention.  With high lock contention the lock is usually
1077   // inflated and biased locking is not suitable for that case.
1078   // RTM locking code requires that biased locking is off.
1079   // Note: we can't switch off UseBiasedLocking in get_processor_features()
1080   // because it is used by Thread::allocate() which is called before
1081   // VM_Version::initialize().
1082   if (UseRTMLocking && UseBiasedLocking) {
1083     if (FLAG_IS_DEFAULT(UseBiasedLocking)) {
1084       FLAG_SET_DEFAULT(UseBiasedLocking, false);
1085     } else {
1086       warning("Biased locking is not supported with RTM locking; ignoring UseBiasedLocking flag." );
1087       UseBiasedLocking = false;
1088     }
1089   }
1090 #endif
1091   return UseBiasedLocking;
1092 }
1093 
1094 void VM_Version::initialize() {
1095   ResourceMark rm;
1096   // Making this stub must be FIRST use of assembler
1097 
1098   stub_blob = BufferBlob::create("get_cpu_info_stub", stub_size);
1099   if (stub_blob == NULL) {
1100     vm_exit_during_initialization("Unable to allocate get_cpu_info_stub");
1101   }
1102   CodeBuffer c(stub_blob);
1103   VM_Version_StubGenerator g(&c);
1104   get_cpu_info_stub = CAST_TO_FN_PTR(get_cpu_info_stub_t,
1105                                      g.generate_get_cpu_info());
1106 
1107   get_processor_features();
1108 }