vm_version_x86.cpp 38.5 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25
#include "precompiled.hpp"
26 27
#include "asm/macroAssembler.hpp"
#include "asm/macroAssembler.inline.hpp"
28 29 30 31 32 33 34 35 36 37 38 39
#include "memory/resourceArea.hpp"
#include "runtime/java.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "vm_version_x86.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "os_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "os_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "os_windows.inline.hpp"
N
never 已提交
40 41 42
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "os_bsd.inline.hpp"
43
#endif
D
duke 已提交
44 45 46 47 48 49 50 51 52


int VM_Version::_cpu;
int VM_Version::_model;
int VM_Version::_stepping;
int VM_Version::_cpuFeatures;
const char*           VM_Version::_features_str = "";
VM_Version::CpuidInfo VM_Version::_cpuid_info   = { 0, };

53 54 55 56 57
// Address of instruction which causes SEGV
address VM_Version::_cpuinfo_segv_addr = 0;
// Address of instruction after the one which causes SEGV
address VM_Version::_cpuinfo_cont_addr = 0;

D
duke 已提交
58
static BufferBlob* stub_blob;
59
static const int stub_size = 600;
D
duke 已提交
60 61

extern "C" {
62
  typedef void (*get_cpu_info_stub_t)(void*);
D
duke 已提交
63
}
64
static get_cpu_info_stub_t get_cpu_info_stub = NULL;
D
duke 已提交
65 66 67 68 69 70 71


class VM_Version_StubGenerator: public StubCodeGenerator {
 public:

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

72
  address generate_get_cpu_info() {
D
duke 已提交
73
    // Flags to test CPU type.
74 75
    const uint32_t HS_EFL_AC           = 0x40000;
    const uint32_t HS_EFL_ID           = 0x200000;
D
duke 已提交
76 77 78 79 80
    // Values for when we don't have a CPUID instruction.
    const int      CPU_FAMILY_SHIFT = 8;
    const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
    const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);

K
kvn 已提交
81
    Label detect_486, cpu486, detect_586, std_cpuid1, std_cpuid4;
K
Merge  
kvn 已提交
82
    Label sef_cpuid, ext_cpuid, ext_cpuid1, ext_cpuid5, ext_cpuid7, done;
D
duke 已提交
83

84
    StubCodeMark mark(this, "VM_Version", "get_cpu_info_stub");
D
duke 已提交
85 86 87 88 89
#   define __ _masm->

    address start = __ pc();

    //
90
    // void get_cpu_info(VM_Version::CpuidInfo* cpuid_info);
D
duke 已提交
91
    //
92 93
    // LP64: rcx and rdx are first and second argument registers on windows

94
    __ push(rbp);
95 96 97
#ifdef _LP64
    __ mov(rbp, c_rarg0); // cpuid_info address
#else
98
    __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
99
#endif
100 101 102 103 104 105
    __ push(rbx);
    __ push(rsi);
    __ pushf();          // preserve rbx, and flags
    __ pop(rax);
    __ push(rax);
    __ mov(rcx, rax);
D
duke 已提交
106 107 108
    //
    // if we are unable to change the AC flag, we have a 386
    //
109
    __ xorl(rax, HS_EFL_AC);
110 111 112 113 114
    __ push(rax);
    __ popf();
    __ pushf();
    __ pop(rax);
    __ cmpptr(rax, rcx);
D
duke 已提交
115 116 117 118 119 120 121 122 123 124 125
    __ jccb(Assembler::notEqual, detect_486);

    __ movl(rax, CPU_FAMILY_386);
    __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
    __ jmp(done);

    //
    // If we are unable to change the ID flag, we have a 486 which does
    // not support the "cpuid" instruction.
    //
    __ bind(detect_486);
126
    __ mov(rax, rcx);
127
    __ xorl(rax, HS_EFL_ID);
128 129 130 131 132
    __ push(rax);
    __ popf();
    __ pushf();
    __ pop(rax);
    __ cmpptr(rcx, rax);
D
duke 已提交
133 134 135 136 137 138 139 140
    __ jccb(Assembler::notEqual, detect_586);

    __ bind(cpu486);
    __ movl(rax, CPU_FAMILY_486);
    __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
    __ jmp(done);

    //
141
    // At this point, we have a chip which supports the "cpuid" instruction
D
duke 已提交
142 143
    //
    __ bind(detect_586);
144
    __ xorl(rax, rax);
D
duke 已提交
145
    __ cpuid();
146
    __ orl(rax, rax);
D
duke 已提交
147 148 149
    __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input
                                        // value of at least 1, we give up and
                                        // assume a 486
150
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset())));
D
duke 已提交
151 152 153 154 155
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

K
kvn 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    __ cmpl(rax, 0xa);                  // Is cpuid(0xB) supported?
    __ jccb(Assembler::belowEqual, std_cpuid4);

    //
    // cpuid(0xB) Processor Topology
    //
    __ movl(rax, 0xb);
    __ xorl(rcx, rcx);   // Threads level
    __ cpuid();

    __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB0_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

    __ movl(rax, 0xb);
    __ movl(rcx, 1);     // Cores level
    __ cpuid();
    __ push(rax);
    __ andl(rax, 0x1f);  // Determine if valid topology level
    __ orl(rax, rbx);    // eax[4:0] | ebx[0:15] == 0 indicates invalid level
    __ andl(rax, 0xffff);
    __ pop(rax);
    __ jccb(Assembler::equal, std_cpuid4);

    __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB1_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

    __ movl(rax, 0xb);
    __ movl(rcx, 2);     // Packages level
    __ cpuid();
    __ push(rax);
    __ andl(rax, 0x1f);  // Determine if valid topology level
    __ orl(rax, rbx);    // eax[4:0] | ebx[0:15] == 0 indicates invalid level
    __ andl(rax, 0xffff);
    __ pop(rax);
    __ jccb(Assembler::equal, std_cpuid4);

    __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB2_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);
D
duke 已提交
203 204 205 206

    //
    // cpuid(0x4) Deterministic cache params
    //
K
kvn 已提交
207
    __ bind(std_cpuid4);
208
    __ movl(rax, 4);
K
kvn 已提交
209 210 211
    __ cmpl(rax, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset()))); // Is cpuid(0x4) supported?
    __ jccb(Assembler::greater, std_cpuid1);

212
    __ xorl(rcx, rcx);   // L1 cache
D
duke 已提交
213
    __ cpuid();
214
    __ push(rax);
D
duke 已提交
215
    __ andl(rax, 0x1f);  // Determine if valid cache parameters used
216
    __ orl(rax, rax);    // eax[4:0] == 0 indicates invalid cache
217
    __ pop(rax);
D
duke 已提交
218 219
    __ jccb(Assembler::equal, std_cpuid1);

220
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::dcp_cpuid4_offset())));
D
duke 已提交
221 222 223 224 225 226 227 228 229 230 231
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

    //
    // Standard cpuid(0x1)
    //
    __ bind(std_cpuid1);
    __ movl(rax, 1);
    __ cpuid();
232
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())));
D
duke 已提交
233 234 235 236 237
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

K
kvn 已提交
238 239 240 241
    //
    // Check if OS has enabled XGETBV instruction to access XCR0
    // (OSXSAVE feature flag) and CPU supports AVX
    //
242
    __ andl(rcx, 0x18000000); // cpuid1 bits osxsave | avx
K
kvn 已提交
243
    __ cmpl(rcx, 0x18000000);
244
    __ jccb(Assembler::notEqual, sef_cpuid); // jump if AVX is not supported
K
kvn 已提交
245 246 247 248 249 250 251 252 253 254

    //
    // XCR0, XFEATURE_ENABLED_MASK register
    //
    __ xorl(rcx, rcx);   // zero for XCR0 register
    __ xgetbv();
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::xem_xcr0_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rdx);

255 256 257 258 259 260 261 262 263 264 265
    __ andl(rax, 0x6); // xcr0 bits sse | ymm
    __ cmpl(rax, 0x6);
    __ jccb(Assembler::notEqual, sef_cpuid); // jump if AVX is not supported

    //
    // Some OSs have a bug when upper 128bits of YMM
    // registers are not restored after a signal processing.
    // Generate SEGV here (reference through NULL)
    // and check upper YMM bits after it.
    //
    VM_Version::set_avx_cpuFeatures(); // Enable temporary to pass asserts
266 267 268 269
    intx saved_useavx = UseAVX;
    intx saved_usesse = UseSSE;
    UseAVX = 1;
    UseSSE = 2;
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

    // load value into all 32 bytes of ymm7 register
    __ movl(rcx, VM_Version::ymm_test_value());

    __ movdl(xmm0, rcx);
    __ pshufd(xmm0, xmm0, 0x00);
    __ vinsertf128h(xmm0, xmm0, xmm0);
    __ vmovdqu(xmm7, xmm0);
#ifdef _LP64
    __ vmovdqu(xmm8,  xmm0);
    __ vmovdqu(xmm15, xmm0);
#endif

    __ xorl(rsi, rsi);
    VM_Version::set_cpuinfo_segv_addr( __ pc() );
    // Generate SEGV
    __ movl(rax, Address(rsi, 0));

    VM_Version::set_cpuinfo_cont_addr( __ pc() );
    // Returns here after signal. Save xmm0 to check it later.
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ymm_save_offset())));
    __ vmovdqu(Address(rsi,  0), xmm0);
    __ vmovdqu(Address(rsi, 32), xmm7);
#ifdef _LP64
    __ vmovdqu(Address(rsi, 64), xmm8);
    __ vmovdqu(Address(rsi, 96), xmm15);
#endif

    VM_Version::clean_cpuFeatures();
299 300
    UseAVX = saved_useavx;
    UseSSE = saved_usesse;
301

K
kvn 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    //
    // cpuid(0x7) Structured Extended Features
    //
    __ bind(sef_cpuid);
    __ movl(rax, 7);
    __ cmpl(rax, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset()))); // Is cpuid(0x7) supported?
    __ jccb(Assembler::greater, ext_cpuid);

    __ xorl(rcx, rcx);
    __ cpuid();
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::sef_cpuid7_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);

    //
    // Extended cpuid(0x80000000)
    //
    __ bind(ext_cpuid);
D
duke 已提交
320 321 322 323 324 325
    __ movl(rax, 0x80000000);
    __ cpuid();
    __ cmpl(rax, 0x80000000);     // Is cpuid(0x80000001) supported?
    __ jcc(Assembler::belowEqual, done);
    __ cmpl(rax, 0x80000004);     // Is cpuid(0x80000005) supported?
    __ jccb(Assembler::belowEqual, ext_cpuid1);
326
    __ cmpl(rax, 0x80000006);     // Is cpuid(0x80000007) supported?
D
duke 已提交
327
    __ jccb(Assembler::belowEqual, ext_cpuid5);
328 329
    __ cmpl(rax, 0x80000007);     // Is cpuid(0x80000008) supported?
    __ jccb(Assembler::belowEqual, ext_cpuid7);
D
duke 已提交
330 331 332 333 334
    //
    // Extended cpuid(0x80000008)
    //
    __ movl(rax, 0x80000008);
    __ cpuid();
335
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid8_offset())));
D
duke 已提交
336 337 338 339 340
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

341 342 343 344 345 346 347 348 349 350 351 352
    //
    // Extended cpuid(0x80000007)
    //
    __ bind(ext_cpuid7);
    __ movl(rax, 0x80000007);
    __ cpuid();
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid7_offset())));
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

D
duke 已提交
353 354 355 356 357 358
    //
    // Extended cpuid(0x80000005)
    //
    __ bind(ext_cpuid5);
    __ movl(rax, 0x80000005);
    __ cpuid();
359
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid5_offset())));
D
duke 已提交
360 361 362 363 364 365 366 367 368 369 370
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

    //
    // Extended cpuid(0x80000001)
    //
    __ bind(ext_cpuid1);
    __ movl(rax, 0x80000001);
    __ cpuid();
371
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid1_offset())));
D
duke 已提交
372 373 374 375 376 377 378 379 380
    __ movl(Address(rsi, 0), rax);
    __ movl(Address(rsi, 4), rbx);
    __ movl(Address(rsi, 8), rcx);
    __ movl(Address(rsi,12), rdx);

    //
    // return
    //
    __ bind(done);
381 382 383 384
    __ popf();
    __ pop(rsi);
    __ pop(rbx);
    __ pop(rbp);
D
duke 已提交
385 386 387 388 389 390 391 392 393
    __ ret(0);

#   undef __

    return start;
  };
};


394 395 396 397 398 399 400 401
void VM_Version::get_cpu_info_wrapper() {
  get_cpu_info_stub(&_cpuid_info);
}

#ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
  #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
#endif

D
duke 已提交
402 403 404 405 406 407 408
void VM_Version::get_processor_features() {

  _cpu = 4; // 486 by default
  _model = 0;
  _stepping = 0;
  _cpuFeatures = 0;
  _logical_processors_per_package = 1;
409 410
  // i486 internal cache is both I&D and has a 16-byte line size
  _L1_data_cache_line_size = 16;
411

D
duke 已提交
412 413
  if (!Use486InstrsOnly) {
    // Get raw processor info
414 415 416 417 418

    // Some platforms (like Win*) need a wrapper around here
    // in order to properly handle SEGV for YMM registers test.
    CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(get_cpu_info_wrapper);

D
duke 已提交
419 420 421 422
    assert_is_initialized();
    _cpu = extended_cpu_family();
    _model = extended_cpu_model();
    _stepping = cpu_stepping();
423

D
duke 已提交
424 425 426 427 428
    if (cpu_family() > 4) { // it supports CPUID
      _cpuFeatures = feature_flags();
      // Logical processors are only available on P4s and above,
      // and only if hyperthreading is available.
      _logical_processors_per_package = logical_processor_count();
429
      _L1_data_cache_line_size = L1_line_size();
D
duke 已提交
430 431
    }
  }
432

D
duke 已提交
433
  _supports_cx8 = supports_cmpxchg8();
434 435 436 437 438
  // xchg and xadd instructions
  _supports_atomic_getset4 = true;
  _supports_atomic_getadd4 = true;
  LP64_ONLY(_supports_atomic_getset8 = true);
  LP64_ONLY(_supports_atomic_getadd8 = true);
439 440 441 442 443 444

#ifdef _LP64
  // OS should support SSE for x64 and hardware should support at least SSE2.
  if (!VM_Version::supports_sse2()) {
    vm_exit_during_initialization("Unknown x64 processor: SSE2 not supported");
  }
R
roland 已提交
445 446
  // in 64 bit the use of SSE2 is the minimum
  if (UseSSE < 2) UseSSE = 2;
447 448
#endif

449 450 451 452 453 454 455 456 457 458 459 460 461 462
#ifdef AMD64
  // flush_icache_stub have to be generated first.
  // That is why Icache line size is hard coded in ICache class,
  // see icache_x86.hpp. It is also the reason why we can't use
  // clflush instruction in 32-bit VM since it could be running
  // on CPU which does not support it.
  //
  // The only thing we can do is to verify that flushed
  // ICache::line_size has correct value.
  guarantee(_cpuid_info.std_cpuid1_edx.bits.clflush != 0, "clflush is not supported");
  // clflush_size is size in quadwords (8 bytes).
  guarantee(_cpuid_info.std_cpuid1_ebx.bits.clflush_size == 8, "such clflush size is not supported");
#endif

463 464
  // If the OS doesn't support SSE, we can't use this feature even if the HW does
  if (!os::supports_sse())
465
    _cpuFeatures &= ~(CPU_SSE|CPU_SSE2|CPU_SSE3|CPU_SSSE3|CPU_SSE4A|CPU_SSE4_1|CPU_SSE4_2);
466

467 468 469 470
  if (UseSSE < 4) {
    _cpuFeatures &= ~CPU_SSE4_1;
    _cpuFeatures &= ~CPU_SSE4_2;
  }
471

D
duke 已提交
472 473 474 475 476
  if (UseSSE < 3) {
    _cpuFeatures &= ~CPU_SSE3;
    _cpuFeatures &= ~CPU_SSSE3;
    _cpuFeatures &= ~CPU_SSE4A;
  }
477

D
duke 已提交
478 479
  if (UseSSE < 2)
    _cpuFeatures &= ~CPU_SSE2;
480

D
duke 已提交
481 482 483
  if (UseSSE < 1)
    _cpuFeatures &= ~CPU_SSE;

K
kvn 已提交
484 485 486 487 488 489
  if (UseAVX < 2)
    _cpuFeatures &= ~CPU_AVX2;

  if (UseAVX < 1)
    _cpuFeatures &= ~CPU_AVX;

490 491 492
  if (!UseAES && !FLAG_IS_DEFAULT(UseAES))
    _cpuFeatures &= ~CPU_AES;

D
duke 已提交
493 494 495 496 497 498
  if (logical_processors_per_package() == 1) {
    // HT processor could be installed on a system which doesn't support HT.
    _cpuFeatures &= ~CPU_HT;
  }

  char buf[256];
499
  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",
D
duke 已提交
500 501 502 503 504 505 506 507 508 509
               cores_per_cpu(), threads_per_core(),
               cpu_family(), _model, _stepping,
               (supports_cmov() ? ", cmov" : ""),
               (supports_cmpxchg8() ? ", cx8" : ""),
               (supports_fxsr() ? ", fxsr" : ""),
               (supports_mmx()  ? ", mmx"  : ""),
               (supports_sse()  ? ", sse"  : ""),
               (supports_sse2() ? ", sse2" : ""),
               (supports_sse3() ? ", sse3" : ""),
               (supports_ssse3()? ", ssse3": ""),
510 511
               (supports_sse4_1() ? ", sse4.1" : ""),
               (supports_sse4_2() ? ", sse4.2" : ""),
512
               (supports_popcnt() ? ", popcnt" : ""),
K
kvn 已提交
513 514
               (supports_avx()    ? ", avx" : ""),
               (supports_avx2()   ? ", avx2" : ""),
515
               (supports_aes()    ? ", aes" : ""),
516
               (supports_clmul()  ? ", clmul" : ""),
517
               (supports_erms()   ? ", erms" : ""),
518
               (supports_rtm()    ? ", rtm" : ""),
D
duke 已提交
519
               (supports_mmx_ext() ? ", mmxext" : ""),
520
               (supports_3dnow_prefetch() ? ", 3dnowpref" : ""),
521
               (supports_lzcnt()   ? ", lzcnt": ""),
D
duke 已提交
522
               (supports_sse4a()   ? ", sse4a": ""),
523 524 525
               (supports_ht() ? ", ht": ""),
               (supports_tsc() ? ", tsc": ""),
               (supports_tscinv_bit() ? ", tscinvbit": ""),
526 527
               (supports_tscinv() ? ", tscinv": ""),
               (supports_bmi1() ? ", bmi1" : ""),
528 529
               (supports_bmi2() ? ", bmi2" : ""),
               (supports_adx() ? ", adx" : ""));
D
duke 已提交
530 531 532 533 534
  _features_str = strdup(buf);

  // UseSSE is set to the smaller of what hardware supports and what
  // the command line requires.  I.e., you cannot set UseSSE to 2 on
  // older Pentiums which do not support it.
K
kvn 已提交
535 536 537
  if (UseSSE > 4) UseSSE=4;
  if (UseSSE < 0) UseSSE=0;
  if (!supports_sse4_1()) // Drop to 3 if no SSE4 support
D
duke 已提交
538
    UseSSE = MIN2((intx)3,UseSSE);
K
kvn 已提交
539
  if (!supports_sse3()) // Drop to 2 if no SSE3 support
D
duke 已提交
540
    UseSSE = MIN2((intx)2,UseSSE);
K
kvn 已提交
541
  if (!supports_sse2()) // Drop to 1 if no SSE2 support
D
duke 已提交
542
    UseSSE = MIN2((intx)1,UseSSE);
K
kvn 已提交
543
  if (!supports_sse ()) // Drop to 0 if no SSE  support
D
duke 已提交
544 545
    UseSSE = 0;

K
kvn 已提交
546 547 548 549 550 551 552
  if (UseAVX > 2) UseAVX=2;
  if (UseAVX < 0) UseAVX=0;
  if (!supports_avx2()) // Drop to 1 if no AVX2 support
    UseAVX = MIN2((intx)1,UseAVX);
  if (!supports_avx ()) // Drop to 0 if no AVX  support
    UseAVX = 0;

553 554 555
  // Use AES instructions if available.
  if (supports_aes()) {
    if (FLAG_IS_DEFAULT(UseAES)) {
556
      FLAG_SET_DEFAULT(UseAES, true);
557
    }
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    if (!UseAES) {
      if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) {
        warning("AES intrinsics require UseAES flag to be enabled. Intrinsics will be disabled.");
      }
      FLAG_SET_DEFAULT(UseAESIntrinsics, false);
    } else {
      if (UseSSE > 2) {
        if (FLAG_IS_DEFAULT(UseAESIntrinsics)) {
          FLAG_SET_DEFAULT(UseAESIntrinsics, true);
        }
      } else {
        // The AES intrinsic stubs require AES instruction support (of course)
        // but also require sse3 mode or higher for instructions it use.
        if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) {
          warning("X86 AES intrinsics require SSE3 instructions or higher. Intrinsics will be disabled.");
        }
        FLAG_SET_DEFAULT(UseAESIntrinsics, false);
      }
    }
  } else if (UseAES || UseAESIntrinsics) {
    if (UseAES && !FLAG_IS_DEFAULT(UseAES)) {
579
      warning("AES instructions are not available on this CPU");
580 581 582 583 584 585
      FLAG_SET_DEFAULT(UseAES, false);
    }
    if (UseAESIntrinsics && !FLAG_IS_DEFAULT(UseAESIntrinsics)) {
      warning("AES intrinsics are not available on this CPU");
      FLAG_SET_DEFAULT(UseAESIntrinsics, false);
    }
586 587
  }

588 589 590 591 592 593 594 595 596 597 598
  // Use CLMUL instructions if available.
  if (supports_clmul()) {
    if (FLAG_IS_DEFAULT(UseCLMUL)) {
      UseCLMUL = true;
    }
  } else if (UseCLMUL) {
    if (!FLAG_IS_DEFAULT(UseCLMUL))
      warning("CLMUL instructions not available on this CPU (AVX may also be required)");
    FLAG_SET_DEFAULT(UseCLMUL, false);
  }

599
  if (UseCLMUL && (UseSSE > 2)) {
600 601 602 603 604
    if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
      UseCRC32Intrinsics = true;
    }
  } else if (UseCRC32Intrinsics) {
    if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics))
605
      warning("CRC32 Intrinsics requires CLMUL instructions (not available on this CPU)");
606 607 608
    FLAG_SET_DEFAULT(UseCRC32Intrinsics, false);
  }

609 610 611 612 613 614 615 616 617 618 619
  // GHASH/GCM intrinsics
  if (UseCLMUL && (UseSSE > 2)) {
    if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) {
      UseGHASHIntrinsics = true;
    }
  } else if (UseGHASHIntrinsics) {
    if (!FLAG_IS_DEFAULT(UseGHASHIntrinsics))
      warning("GHASH intrinsic requires CLMUL and SSE2 instructions on this CPU");
    FLAG_SET_DEFAULT(UseGHASHIntrinsics, false);
  }

620 621 622 623 624 625 626 627 628 629 630
  if (UseSHA) {
    warning("SHA instructions are not available on this CPU");
    FLAG_SET_DEFAULT(UseSHA, false);
  }
  if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) {
    warning("SHA intrinsics are not available on this CPU");
    FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
    FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
    FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
  }

631 632 633 634 635 636 637 638 639 640 641
  // Adjust RTM (Restricted Transactional Memory) flags
  if (!supports_rtm() && UseRTMLocking) {
    // Can't continue because UseRTMLocking affects UseBiasedLocking flag
    // setting during arguments processing. See use_biased_locking().
    // VM_Version_init() is executed after UseBiasedLocking is used
    // in Thread::allocate().
    vm_exit_during_initialization("RTM instructions are not available on this CPU");
  }

#if INCLUDE_RTM_OPT
  if (UseRTMLocking) {
642 643 644 645 646 647 648 649 650 651 652
    if (is_intel_family_core()) {
      if ((_model == CPU_MODEL_HASWELL_E3) ||
          (_model == CPU_MODEL_HASWELL_E7 && _stepping < 3) ||
          (_model == CPU_MODEL_BROADWELL  && _stepping < 4)) {
        if (!UnlockExperimentalVMOptions) {
          vm_exit_during_initialization("UseRTMLocking is only available as experimental option on this platform. It must be enabled via -XX:+UnlockExperimentalVMOptions flag.");
        } else {
          warning("UseRTMLocking is only available as experimental option on this platform.");
        }
      }
    }
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
    if (!FLAG_IS_CMDLINE(UseRTMLocking)) {
      // RTM locking should be used only for applications with
      // high lock contention. For now we do not use it by default.
      vm_exit_during_initialization("UseRTMLocking flag should be only set on command line");
    }
    if (!is_power_of_2(RTMTotalCountIncrRate)) {
      warning("RTMTotalCountIncrRate must be a power of 2, resetting it to 64");
      FLAG_SET_DEFAULT(RTMTotalCountIncrRate, 64);
    }
    if (RTMAbortRatio < 0 || RTMAbortRatio > 100) {
      warning("RTMAbortRatio must be in the range 0 to 100, resetting it to 50");
      FLAG_SET_DEFAULT(RTMAbortRatio, 50);
    }
  } else { // !UseRTMLocking
    if (UseRTMForStackLocks) {
      if (!FLAG_IS_DEFAULT(UseRTMForStackLocks)) {
        warning("UseRTMForStackLocks flag should be off when UseRTMLocking flag is off");
      }
      FLAG_SET_DEFAULT(UseRTMForStackLocks, false);
    }
    if (UseRTMDeopt) {
      FLAG_SET_DEFAULT(UseRTMDeopt, false);
    }
    if (PrintPreciseRTMLockingStatistics) {
      FLAG_SET_DEFAULT(PrintPreciseRTMLockingStatistics, false);
    }
  }
#else
  if (UseRTMLocking) {
    // Only C2 does RTM locking optimization.
    // Can't continue because UseRTMLocking affects UseBiasedLocking flag
    // setting during arguments processing. See use_biased_locking().
    vm_exit_during_initialization("RTM locking optimization is not supported in this VM");
  }
#endif

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
#ifdef COMPILER2
  if (UseFPUForSpilling) {
    if (UseSSE < 2) {
      // Only supported with SSE2+
      FLAG_SET_DEFAULT(UseFPUForSpilling, false);
    }
  }
  if (MaxVectorSize > 0) {
    if (!is_power_of_2(MaxVectorSize)) {
      warning("MaxVectorSize must be a power of 2");
      FLAG_SET_DEFAULT(MaxVectorSize, 32);
    }
    if (MaxVectorSize > 32) {
      FLAG_SET_DEFAULT(MaxVectorSize, 32);
    }
704 705
    if (MaxVectorSize > 16 && (UseAVX == 0 || !os_supports_avx_vectors())) {
      // 32 bytes vectors (in YMM) are only supported with AVX+
706 707 708
      FLAG_SET_DEFAULT(MaxVectorSize, 16);
    }
    if (UseSSE < 2) {
709
      // Vectors (in XMM) are only supported with SSE2+
710 711
      FLAG_SET_DEFAULT(MaxVectorSize, 0);
    }
712 713 714 715 716 717 718 719 720 721 722 723 724 725
#ifdef ASSERT
    if (supports_avx() && PrintMiscellaneous && Verbose && TraceNewVectors) {
      tty->print_cr("State of YMM registers after signal handle:");
      int nreg = 2 LP64_ONLY(+2);
      const char* ymm_name[4] = {"0", "7", "8", "15"};
      for (int i = 0; i < nreg; i++) {
        tty->print("YMM%s:", ymm_name[i]);
        for (int j = 7; j >=0; j--) {
          tty->print(" %x", _cpuid_info.ymm_save[i*8 + j]);
        }
        tty->cr();
      }
    }
#endif
726
  }
727 728 729 730 731

#ifdef _LP64
  if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
    UseMultiplyToLenIntrinsic = true;
  }
732
  if (FLAG_IS_DEFAULT(UseSquareToLenIntrinsic)) {
733
    UseSquareToLenIntrinsic = true;
734 735
  }
  if (FLAG_IS_DEFAULT(UseMulAddIntrinsic)) {
736
    UseMulAddIntrinsic = true;
737
  }
738
  if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) {
739
    UseMontgomeryMultiplyIntrinsic = true;
740 741
  }
  if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) {
742
    UseMontgomerySquareIntrinsic = true;
743
  }
744 745 746 747 748 749 750
#else
  if (UseMultiplyToLenIntrinsic) {
    if (!FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) {
      warning("multiplyToLen intrinsic is not available in 32-bit VM");
    }
    FLAG_SET_DEFAULT(UseMultiplyToLenIntrinsic, false);
  }
751 752 753 754 755 756 757 758 759 760 761 762
  if (UseSquareToLenIntrinsic) {
    if (!FLAG_IS_DEFAULT(UseSquareToLenIntrinsic)) {
      warning("squareToLen intrinsic is not available in 32-bit VM");
    }
    FLAG_SET_DEFAULT(UseSquareToLenIntrinsic, false);
  }
  if (UseMulAddIntrinsic) {
    if (!FLAG_IS_DEFAULT(UseMulAddIntrinsic)) {
      warning("mulAdd intrinsic is not available in 32-bit VM");
    }
    FLAG_SET_DEFAULT(UseMulAddIntrinsic, false);
  }
763 764 765 766 767 768 769 770 771 772 773 774
  if (UseMontgomeryMultiplyIntrinsic) {
    if (!FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) {
      warning("montgomeryMultiply intrinsic is not available in 32-bit VM");
    }
    FLAG_SET_DEFAULT(UseMontgomeryMultiplyIntrinsic, false);
  }
  if (UseMontgomerySquareIntrinsic) {
    if (!FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) {
      warning("montgomerySquare intrinsic is not available in 32-bit VM");
    }
    FLAG_SET_DEFAULT(UseMontgomerySquareIntrinsic, false);
  }
775
#endif
776
#endif // COMPILER2
777

D
duke 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790
  // On new cpus instructions which update whole XMM register should be used
  // to prevent partial register stall due to dependencies on high half.
  //
  // UseXmmLoadAndClearUpper == true  --> movsd(xmm, mem)
  // UseXmmLoadAndClearUpper == false --> movlpd(xmm, mem)
  // UseXmmRegToRegMoveAll == true  --> movaps(xmm, xmm), movapd(xmm, xmm).
  // UseXmmRegToRegMoveAll == false --> movss(xmm, xmm),  movsd(xmm, xmm).

  if( is_amd() ) { // AMD cpus specific settings
    if( supports_sse2() && FLAG_IS_DEFAULT(UseAddressNop) ) {
      // Use it on new AMD cpus starting from Opteron.
      UseAddressNop = true;
    }
791 792 793 794
    if( supports_sse2() && FLAG_IS_DEFAULT(UseNewLongLShift) ) {
      // Use it on new AMD cpus starting from Opteron.
      UseNewLongLShift = true;
    }
D
duke 已提交
795 796 797 798 799 800 801 802 803 804 805 806 807 808
    if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
      if( supports_sse4a() ) {
        UseXmmLoadAndClearUpper = true; // use movsd only on '10h' Opteron
      } else {
        UseXmmLoadAndClearUpper = false;
      }
    }
    if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
      if( supports_sse4a() ) {
        UseXmmRegToRegMoveAll = true; // use movaps, movapd only on '10h'
      } else {
        UseXmmRegToRegMoveAll = false;
      }
    }
809 810 811 812 813 814 815 816 817 818 819 820 821 822
    if( FLAG_IS_DEFAULT(UseXmmI2F) ) {
      if( supports_sse4a() ) {
        UseXmmI2F = true;
      } else {
        UseXmmI2F = false;
      }
    }
    if( FLAG_IS_DEFAULT(UseXmmI2D) ) {
      if( supports_sse4a() ) {
        UseXmmI2D = true;
      } else {
        UseXmmI2D = false;
      }
    }
823 824 825 826 827
    if( FLAG_IS_DEFAULT(UseSSE42Intrinsics) ) {
      if( supports_sse4_2() && UseSSE >= 4 ) {
        UseSSE42Intrinsics = true;
      }
    }
828

829 830 831
    // some defaults for AMD family 15h
    if ( cpu_family() == 0x15 ) {
      // On family 15h processors default is no sw prefetch
832 833 834
      if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) {
        AllocatePrefetchStyle = 0;
      }
835 836 837 838 839
      // Also, if some other prefetch style is specified, default instruction type is PREFETCHW
      if (FLAG_IS_DEFAULT(AllocatePrefetchInstr)) {
        AllocatePrefetchInstr = 3;
      }
      // On family 15h processors use XMM and UnalignedLoadStores for Array Copy
K
kvn 已提交
840
      if (supports_sse2() && FLAG_IS_DEFAULT(UseXMMForArrayCopy)) {
841 842
        UseXMMForArrayCopy = true;
      }
K
kvn 已提交
843
      if (supports_sse2() && FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
844 845
        UseUnalignedLoadStores = true;
      }
846
    }
847

848 849 850 851 852 853
#ifdef COMPILER2
    if (MaxVectorSize > 16) {
      // Limit vectors size to 16 bytes on current AMD cpus.
      FLAG_SET_DEFAULT(MaxVectorSize, 16);
    }
#endif // COMPILER2
D
duke 已提交
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
  }

  if( is_intel() ) { // Intel cpus specific settings
    if( FLAG_IS_DEFAULT(UseStoreImmI16) ) {
      UseStoreImmI16 = false; // don't use it on Intel cpus
    }
    if( cpu_family() == 6 || cpu_family() == 15 ) {
      if( FLAG_IS_DEFAULT(UseAddressNop) ) {
        // Use it on all Intel cpus starting from PentiumPro
        UseAddressNop = true;
      }
    }
    if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
      UseXmmLoadAndClearUpper = true; // use movsd on all Intel cpus
    }
    if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
      if( supports_sse3() ) {
        UseXmmRegToRegMoveAll = true; // use movaps, movapd on new Intel cpus
      } else {
        UseXmmRegToRegMoveAll = false;
      }
    }
    if( cpu_family() == 6 && supports_sse3() ) { // New Intel cpus
#ifdef COMPILER2
      if( FLAG_IS_DEFAULT(MaxLoopPad) ) {
        // For new Intel cpus do the next optimization:
        // don't align the beginning of a loop if there are enough instructions
        // left (NumberOfLoopInstrToAlign defined in c2_globals.hpp)
        // in current fetch line (OptoLoopAlignment) or the padding
        // is big (> MaxLoopPad).
        // Set MaxLoopPad to 11 for new Intel cpus to reduce number of
        // generated NOP instructions. 11 is the largest size of one
        // address NOP instruction '0F 1F' (see Assembler::nop(i)).
        MaxLoopPad = 11;
      }
#endif // COMPILER2
K
kvn 已提交
890
      if (FLAG_IS_DEFAULT(UseXMMForArrayCopy)) {
891 892
        UseXMMForArrayCopy = true; // use SSE2 movq on new Intel cpus
      }
K
kvn 已提交
893 894
      if (supports_sse4_2() && supports_ht()) { // Newest Intel cpus
        if (FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
895 896 897
          UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
        }
      }
K
kvn 已提交
898 899
      if (supports_sse4_2() && UseSSE >= 4) {
        if (FLAG_IS_DEFAULT(UseSSE42Intrinsics)) {
C
cfang 已提交
900 901 902
          UseSSE42Intrinsics = true;
        }
      }
D
duke 已提交
903
    }
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
    if ((cpu_family() == 0x06) &&
        ((extended_cpu_model() == 0x36) || // Centerton
         (extended_cpu_model() == 0x37) || // Silvermont
         (extended_cpu_model() == 0x4D))) {
#ifdef COMPILER2
      if (FLAG_IS_DEFAULT(OptoScheduling)) {
        OptoScheduling = true;
      }
#endif
      if (supports_sse4_2()) { // Silvermont
        if (FLAG_IS_DEFAULT(UseUnalignedLoadStores)) {
          UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
        }
      }
    }
919 920 921
    if(FLAG_IS_DEFAULT(AllocatePrefetchInstr) && supports_3dnow_prefetch()) {
      AllocatePrefetchInstr = 3;
    }
D
duke 已提交
922 923
  }

924 925 926 927 928 929 930 931 932 933
  // Use count leading zeros count instruction if available.
  if (supports_lzcnt()) {
    if (FLAG_IS_DEFAULT(UseCountLeadingZerosInstruction)) {
      UseCountLeadingZerosInstruction = true;
    }
   } else if (UseCountLeadingZerosInstruction) {
    warning("lzcnt instruction is not available on this CPU");
    FLAG_SET_DEFAULT(UseCountLeadingZerosInstruction, false);
  }

934
  // Use count trailing zeros instruction if available
935
  if (supports_bmi1()) {
936 937
    // tzcnt does not require VEX prefix
    if (FLAG_IS_DEFAULT(UseCountTrailingZerosInstruction)) {
938 939 940 941 942 943
      if (!UseBMI1Instructions && !FLAG_IS_DEFAULT(UseBMI1Instructions)) {
        // Don't use tzcnt if BMI1 is switched off on command line.
        UseCountTrailingZerosInstruction = false;
      } else {
        UseCountTrailingZerosInstruction = true;
      }
944 945 946 947 948 949
    }
  } else if (UseCountTrailingZerosInstruction) {
    warning("tzcnt instruction is not available on this CPU");
    FLAG_SET_DEFAULT(UseCountTrailingZerosInstruction, false);
  }

950
  // BMI instructions (except tzcnt) use an encoding with VEX prefix.
951 952
  // VEX prefix is generated only when AVX > 0.
  if (supports_bmi1() && supports_avx()) {
953 954 955 956
    if (FLAG_IS_DEFAULT(UseBMI1Instructions)) {
      UseBMI1Instructions = true;
    }
  } else if (UseBMI1Instructions) {
957
    warning("BMI1 instructions are not available on this CPU (AVX is also required)");
958 959 960
    FLAG_SET_DEFAULT(UseBMI1Instructions, false);
  }

961 962 963
  if (supports_bmi2() && supports_avx()) {
    if (FLAG_IS_DEFAULT(UseBMI2Instructions)) {
      UseBMI2Instructions = true;
964
    }
965 966 967
  } else if (UseBMI2Instructions) {
    warning("BMI2 instructions are not available on this CPU (AVX is also required)");
    FLAG_SET_DEFAULT(UseBMI2Instructions, false);
968 969
  }

970 971 972 973 974
  // Use population count instruction if available.
  if (supports_popcnt()) {
    if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
      UsePopCountInstruction = true;
    }
K
kvn 已提交
975 976 977
  } else if (UsePopCountInstruction) {
    warning("POPCNT instruction is not available on this CPU");
    FLAG_SET_DEFAULT(UsePopCountInstruction, false);
978 979
  }

980 981 982 983 984 985 986 987 988 989
  // Use fast-string operations if available.
  if (supports_erms()) {
    if (FLAG_IS_DEFAULT(UseFastStosb)) {
      UseFastStosb = true;
    }
  } else if (UseFastStosb) {
    warning("fast-string operations are not available on this CPU");
    FLAG_SET_DEFAULT(UseFastStosb, false);
  }

K
kvn 已提交
990 991 992 993 994 995 996
#ifdef COMPILER2
  if (FLAG_IS_DEFAULT(AlignVector)) {
    // Modern processors allow misaligned memory operations for vectors.
    AlignVector = !UseUnalignedLoadStores;
  }
#endif // COMPILER2

D
duke 已提交
997 998 999 1000 1001 1002
  assert(0 <= ReadPrefetchInstr && ReadPrefetchInstr <= 3, "invalid value");
  assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 3, "invalid value");

  // set valid Prefetch instruction
  if( ReadPrefetchInstr < 0 ) ReadPrefetchInstr = 0;
  if( ReadPrefetchInstr > 3 ) ReadPrefetchInstr = 3;
1003 1004
  if( ReadPrefetchInstr == 3 && !supports_3dnow_prefetch() ) ReadPrefetchInstr = 0;
  if( !supports_sse() && supports_3dnow_prefetch() ) ReadPrefetchInstr = 3;
D
duke 已提交
1005 1006 1007

  if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0;
  if( AllocatePrefetchInstr > 3 ) AllocatePrefetchInstr = 3;
1008 1009
  if( AllocatePrefetchInstr == 3 && !supports_3dnow_prefetch() ) AllocatePrefetchInstr=0;
  if( !supports_sse() && supports_3dnow_prefetch() ) AllocatePrefetchInstr = 3;
D
duke 已提交
1010 1011

  // Allocation prefetch settings
1012
  intx cache_line_size = prefetch_data_size();
D
duke 已提交
1013 1014
  if( cache_line_size > AllocatePrefetchStepSize )
    AllocatePrefetchStepSize = cache_line_size;
1015

D
duke 已提交
1016
  assert(AllocatePrefetchLines > 0, "invalid value");
1017 1018 1019 1020 1021
  if( AllocatePrefetchLines < 1 )     // set valid value in product VM
    AllocatePrefetchLines = 3;
  assert(AllocateInstancePrefetchLines > 0, "invalid value");
  if( AllocateInstancePrefetchLines < 1 ) // set valid value in product VM
    AllocateInstancePrefetchLines = 1;
D
duke 已提交
1022 1023 1024 1025

  AllocatePrefetchDistance = allocate_prefetch_distance();
  AllocatePrefetchStyle    = allocate_prefetch_style();

1026 1027
  if (is_intel() && cpu_family() == 6 && supports_sse3()) {
    if (AllocatePrefetchStyle == 2) { // watermark prefetching on Core
1028
#ifdef _LP64
K
kvn 已提交
1029
      AllocatePrefetchDistance = 384;
1030
#else
K
kvn 已提交
1031
      AllocatePrefetchDistance = 320;
1032
#endif
K
kvn 已提交
1033
    }
1034
    if (supports_sse4_2() && supports_ht()) { // Nehalem based cpus
K
kvn 已提交
1035 1036
      AllocatePrefetchDistance = 192;
      AllocatePrefetchLines = 4;
1037
    }
1038
#ifdef COMPILER2
1039 1040
    if (supports_sse4_2()) {
      if (FLAG_IS_DEFAULT(UseFPUForSpilling)) {
1041 1042
        FLAG_SET_DEFAULT(UseFPUForSpilling, true);
      }
K
kvn 已提交
1043
    }
1044
#endif
D
duke 已提交
1045 1046 1047
  }
  assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value");

1048 1049 1050 1051 1052 1053 1054
#ifdef _LP64
  // Prefetch settings
  PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes();
  PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes();
  PrefetchFieldsAhead         = prefetch_fields_ahead();
#endif

1055 1056 1057 1058
  if (FLAG_IS_DEFAULT(ContendedPaddingWidth) &&
     (cache_line_size > ContendedPaddingWidth))
     ContendedPaddingWidth = cache_line_size;

D
duke 已提交
1059 1060
#ifndef PRODUCT
  if (PrintMiscellaneous && Verbose) {
1061
    tty->print_cr("Logical CPUs per core: %u",
D
duke 已提交
1062
                  logical_processors_per_package());
1063
    tty->print_cr("L1 data cache line size: %u", L1_data_cache_line_size());
1064
    tty->print("UseSSE=%d", (int) UseSSE);
K
kvn 已提交
1065
    if (UseAVX > 0) {
1066
      tty->print("  UseAVX=%d", (int) UseAVX);
K
kvn 已提交
1067
    }
1068 1069 1070
    if (UseAES) {
      tty->print("  UseAES=1");
    }
1071 1072
#ifdef COMPILER2
    if (MaxVectorSize > 0) {
1073
      tty->print("  MaxVectorSize=%d", (int) MaxVectorSize);
1074 1075
    }
#endif
K
kvn 已提交
1076
    tty->cr();
1077
    tty->print("Allocation");
1078
    if (AllocatePrefetchStyle <= 0 || UseSSE == 0 && !supports_3dnow_prefetch()) {
1079
      tty->print_cr(": no prefetching");
D
duke 已提交
1080
    } else {
1081
      tty->print(" prefetching: ");
1082
      if (UseSSE == 0 && supports_3dnow_prefetch()) {
D
duke 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
        tty->print("PREFETCHW");
      } else if (UseSSE >= 1) {
        if (AllocatePrefetchInstr == 0) {
          tty->print("PREFETCHNTA");
        } else if (AllocatePrefetchInstr == 1) {
          tty->print("PREFETCHT0");
        } else if (AllocatePrefetchInstr == 2) {
          tty->print("PREFETCHT2");
        } else if (AllocatePrefetchInstr == 3) {
          tty->print("PREFETCHW");
        }
      }
      if (AllocatePrefetchLines > 1) {
1096
        tty->print_cr(" at distance %d, %d lines of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchLines, (int) AllocatePrefetchStepSize);
D
duke 已提交
1097
      } else {
1098
        tty->print_cr(" at distance %d, one line of %d bytes", (int) AllocatePrefetchDistance, (int) AllocatePrefetchStepSize);
D
duke 已提交
1099 1100
      }
    }
1101 1102

    if (PrefetchCopyIntervalInBytes > 0) {
1103
      tty->print_cr("PrefetchCopyIntervalInBytes %d", (int) PrefetchCopyIntervalInBytes);
1104 1105
    }
    if (PrefetchScanIntervalInBytes > 0) {
1106
      tty->print_cr("PrefetchScanIntervalInBytes %d", (int) PrefetchScanIntervalInBytes);
1107 1108
    }
    if (PrefetchFieldsAhead > 0) {
1109
      tty->print_cr("PrefetchFieldsAhead %d", (int) PrefetchFieldsAhead);
1110
    }
1111
    if (ContendedPaddingWidth > 0) {
1112
      tty->print_cr("ContendedPaddingWidth %d", (int) ContendedPaddingWidth);
1113
    }
D
duke 已提交
1114 1115 1116 1117
  }
#endif // !PRODUCT
}

1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
bool VM_Version::use_biased_locking() {
#if INCLUDE_RTM_OPT
  // RTM locking is most useful when there is high lock contention and
  // low data contention.  With high lock contention the lock is usually
  // inflated and biased locking is not suitable for that case.
  // RTM locking code requires that biased locking is off.
  // Note: we can't switch off UseBiasedLocking in get_processor_features()
  // because it is used by Thread::allocate() which is called before
  // VM_Version::initialize().
  if (UseRTMLocking && UseBiasedLocking) {
    if (FLAG_IS_DEFAULT(UseBiasedLocking)) {
      FLAG_SET_DEFAULT(UseBiasedLocking, false);
    } else {
      warning("Biased locking is not supported with RTM locking; ignoring UseBiasedLocking flag." );
      UseBiasedLocking = false;
    }
  }
#endif
  return UseBiasedLocking;
}

D
duke 已提交
1139 1140 1141 1142
void VM_Version::initialize() {
  ResourceMark rm;
  // Making this stub must be FIRST use of assembler

1143
  stub_blob = BufferBlob::create("get_cpu_info_stub", stub_size);
D
duke 已提交
1144
  if (stub_blob == NULL) {
1145
    vm_exit_during_initialization("Unable to allocate get_cpu_info_stub");
D
duke 已提交
1146
  }
T
twisti 已提交
1147
  CodeBuffer c(stub_blob);
D
duke 已提交
1148
  VM_Version_StubGenerator g(&c);
1149 1150
  get_cpu_info_stub = CAST_TO_FN_PTR(get_cpu_info_stub_t,
                                     g.generate_get_cpu_info());
D
duke 已提交
1151 1152 1153

  get_processor_features();
}