src/cpu/x86/vm/vm_version_x86.cpp

Tue, 28 Jun 2011 15:04:39 -0700

author
kvn
date
Tue, 28 Jun 2011 15:04:39 -0700
changeset 2984
6ae7a1561b53
parent 2808
2a34a4fbc52c
child 3052
1af104d6cf99
child 3058
3be7439273c5
permissions
-rw-r--r--

6990015: Incorrect Icache line size is used for 64 bit x86
Summary: correct Icache::line_size for x64 and add verification code into vm_version_x86.
Reviewed-by: never, phh

twisti@1020 1 /*
trims@2708 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
twisti@1020 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@1020 4 *
twisti@1020 5 * This code is free software; you can redistribute it and/or modify it
twisti@1020 6 * under the terms of the GNU General Public License version 2 only, as
twisti@1020 7 * published by the Free Software Foundation.
twisti@1020 8 *
twisti@1020 9 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@1020 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@1020 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@1020 12 * version 2 for more details (a copy is included in the LICENSE file that
twisti@1020 13 * accompanied this code).
twisti@1020 14 *
twisti@1020 15 * You should have received a copy of the GNU General Public License version
twisti@1020 16 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@1020 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@1020 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
twisti@1020 22 *
twisti@1020 23 */
twisti@1020 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "assembler_x86.inline.hpp"
stefank@2314 27 #include "memory/resourceArea.hpp"
stefank@2314 28 #include "runtime/java.hpp"
stefank@2314 29 #include "runtime/stubCodeGenerator.hpp"
stefank@2314 30 #include "vm_version_x86.hpp"
stefank@2314 31 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 32 # include "os_linux.inline.hpp"
stefank@2314 33 #endif
stefank@2314 34 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 35 # include "os_solaris.inline.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 38 # include "os_windows.inline.hpp"
stefank@2314 39 #endif
twisti@1020 40
twisti@1020 41
twisti@1020 42 int VM_Version::_cpu;
twisti@1020 43 int VM_Version::_model;
twisti@1020 44 int VM_Version::_stepping;
twisti@1020 45 int VM_Version::_cpuFeatures;
twisti@1020 46 const char* VM_Version::_features_str = "";
twisti@1020 47 VM_Version::CpuidInfo VM_Version::_cpuid_info = { 0, };
twisti@1020 48
twisti@1020 49 static BufferBlob* stub_blob;
kvn@1977 50 static const int stub_size = 400;
twisti@1020 51
twisti@1020 52 extern "C" {
twisti@1020 53 typedef void (*getPsrInfo_stub_t)(void*);
twisti@1020 54 }
twisti@1020 55 static getPsrInfo_stub_t getPsrInfo_stub = NULL;
twisti@1020 56
twisti@1020 57
twisti@1020 58 class VM_Version_StubGenerator: public StubCodeGenerator {
twisti@1020 59 public:
twisti@1020 60
twisti@1020 61 VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
twisti@1020 62
twisti@1020 63 address generate_getPsrInfo() {
twisti@1020 64 // Flags to test CPU type.
twisti@1020 65 const uint32_t EFL_AC = 0x40000;
twisti@1020 66 const uint32_t EFL_ID = 0x200000;
twisti@1020 67 // Values for when we don't have a CPUID instruction.
twisti@1020 68 const int CPU_FAMILY_SHIFT = 8;
twisti@1020 69 const uint32_t CPU_FAMILY_386 = (3 << CPU_FAMILY_SHIFT);
twisti@1020 70 const uint32_t CPU_FAMILY_486 = (4 << CPU_FAMILY_SHIFT);
twisti@1020 71
kvn@1977 72 Label detect_486, cpu486, detect_586, std_cpuid1, std_cpuid4;
twisti@1020 73 Label ext_cpuid1, ext_cpuid5, done;
twisti@1020 74
twisti@1020 75 StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
twisti@1020 76 # define __ _masm->
twisti@1020 77
twisti@1020 78 address start = __ pc();
twisti@1020 79
twisti@1020 80 //
twisti@1020 81 // void getPsrInfo(VM_Version::CpuidInfo* cpuid_info);
twisti@1020 82 //
twisti@1020 83 // LP64: rcx and rdx are first and second argument registers on windows
twisti@1020 84
twisti@1020 85 __ push(rbp);
twisti@1020 86 #ifdef _LP64
twisti@1020 87 __ mov(rbp, c_rarg0); // cpuid_info address
twisti@1020 88 #else
twisti@1020 89 __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
twisti@1020 90 #endif
twisti@1020 91 __ push(rbx);
twisti@1020 92 __ push(rsi);
twisti@1020 93 __ pushf(); // preserve rbx, and flags
twisti@1020 94 __ pop(rax);
twisti@1020 95 __ push(rax);
twisti@1020 96 __ mov(rcx, rax);
twisti@1020 97 //
twisti@1020 98 // if we are unable to change the AC flag, we have a 386
twisti@1020 99 //
twisti@1020 100 __ xorl(rax, EFL_AC);
twisti@1020 101 __ push(rax);
twisti@1020 102 __ popf();
twisti@1020 103 __ pushf();
twisti@1020 104 __ pop(rax);
twisti@1020 105 __ cmpptr(rax, rcx);
twisti@1020 106 __ jccb(Assembler::notEqual, detect_486);
twisti@1020 107
twisti@1020 108 __ movl(rax, CPU_FAMILY_386);
twisti@1020 109 __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
twisti@1020 110 __ jmp(done);
twisti@1020 111
twisti@1020 112 //
twisti@1020 113 // If we are unable to change the ID flag, we have a 486 which does
twisti@1020 114 // not support the "cpuid" instruction.
twisti@1020 115 //
twisti@1020 116 __ bind(detect_486);
twisti@1020 117 __ mov(rax, rcx);
twisti@1020 118 __ xorl(rax, EFL_ID);
twisti@1020 119 __ push(rax);
twisti@1020 120 __ popf();
twisti@1020 121 __ pushf();
twisti@1020 122 __ pop(rax);
twisti@1020 123 __ cmpptr(rcx, rax);
twisti@1020 124 __ jccb(Assembler::notEqual, detect_586);
twisti@1020 125
twisti@1020 126 __ bind(cpu486);
twisti@1020 127 __ movl(rax, CPU_FAMILY_486);
twisti@1020 128 __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
twisti@1020 129 __ jmp(done);
twisti@1020 130
twisti@1020 131 //
twisti@1020 132 // At this point, we have a chip which supports the "cpuid" instruction
twisti@1020 133 //
twisti@1020 134 __ bind(detect_586);
twisti@1020 135 __ xorl(rax, rax);
twisti@1020 136 __ cpuid();
twisti@1020 137 __ orl(rax, rax);
twisti@1020 138 __ jcc(Assembler::equal, cpu486); // if cpuid doesn't support an input
twisti@1020 139 // value of at least 1, we give up and
twisti@1020 140 // assume a 486
twisti@1020 141 __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset())));
twisti@1020 142 __ movl(Address(rsi, 0), rax);
twisti@1020 143 __ movl(Address(rsi, 4), rbx);
twisti@1020 144 __ movl(Address(rsi, 8), rcx);
twisti@1020 145 __ movl(Address(rsi,12), rdx);
twisti@1020 146
kvn@1977 147 __ cmpl(rax, 0xa); // Is cpuid(0xB) supported?
kvn@1977 148 __ jccb(Assembler::belowEqual, std_cpuid4);
kvn@1977 149
kvn@1977 150 //
kvn@1977 151 // cpuid(0xB) Processor Topology
kvn@1977 152 //
kvn@1977 153 __ movl(rax, 0xb);
kvn@1977 154 __ xorl(rcx, rcx); // Threads level
kvn@1977 155 __ cpuid();
kvn@1977 156
kvn@1977 157 __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB0_offset())));
kvn@1977 158 __ movl(Address(rsi, 0), rax);
kvn@1977 159 __ movl(Address(rsi, 4), rbx);
kvn@1977 160 __ movl(Address(rsi, 8), rcx);
kvn@1977 161 __ movl(Address(rsi,12), rdx);
kvn@1977 162
kvn@1977 163 __ movl(rax, 0xb);
kvn@1977 164 __ movl(rcx, 1); // Cores level
kvn@1977 165 __ cpuid();
kvn@1977 166 __ push(rax);
kvn@1977 167 __ andl(rax, 0x1f); // Determine if valid topology level
kvn@1977 168 __ orl(rax, rbx); // eax[4:0] | ebx[0:15] == 0 indicates invalid level
kvn@1977 169 __ andl(rax, 0xffff);
kvn@1977 170 __ pop(rax);
kvn@1977 171 __ jccb(Assembler::equal, std_cpuid4);
kvn@1977 172
kvn@1977 173 __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB1_offset())));
kvn@1977 174 __ movl(Address(rsi, 0), rax);
kvn@1977 175 __ movl(Address(rsi, 4), rbx);
kvn@1977 176 __ movl(Address(rsi, 8), rcx);
kvn@1977 177 __ movl(Address(rsi,12), rdx);
kvn@1977 178
kvn@1977 179 __ movl(rax, 0xb);
kvn@1977 180 __ movl(rcx, 2); // Packages level
kvn@1977 181 __ cpuid();
kvn@1977 182 __ push(rax);
kvn@1977 183 __ andl(rax, 0x1f); // Determine if valid topology level
kvn@1977 184 __ orl(rax, rbx); // eax[4:0] | ebx[0:15] == 0 indicates invalid level
kvn@1977 185 __ andl(rax, 0xffff);
kvn@1977 186 __ pop(rax);
kvn@1977 187 __ jccb(Assembler::equal, std_cpuid4);
kvn@1977 188
kvn@1977 189 __ lea(rsi, Address(rbp, in_bytes(VM_Version::tpl_cpuidB2_offset())));
kvn@1977 190 __ movl(Address(rsi, 0), rax);
kvn@1977 191 __ movl(Address(rsi, 4), rbx);
kvn@1977 192 __ movl(Address(rsi, 8), rcx);
kvn@1977 193 __ movl(Address(rsi,12), rdx);
twisti@1020 194
twisti@1020 195 //
twisti@1020 196 // cpuid(0x4) Deterministic cache params
twisti@1020 197 //
kvn@1977 198 __ bind(std_cpuid4);
twisti@1020 199 __ movl(rax, 4);
kvn@1977 200 __ cmpl(rax, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset()))); // Is cpuid(0x4) supported?
kvn@1977 201 __ jccb(Assembler::greater, std_cpuid1);
kvn@1977 202
twisti@1020 203 __ xorl(rcx, rcx); // L1 cache
twisti@1020 204 __ cpuid();
twisti@1020 205 __ push(rax);
twisti@1020 206 __ andl(rax, 0x1f); // Determine if valid cache parameters used
twisti@1020 207 __ orl(rax, rax); // eax[4:0] == 0 indicates invalid cache
twisti@1020 208 __ pop(rax);
twisti@1020 209 __ jccb(Assembler::equal, std_cpuid1);
twisti@1020 210
twisti@1020 211 __ lea(rsi, Address(rbp, in_bytes(VM_Version::dcp_cpuid4_offset())));
twisti@1020 212 __ movl(Address(rsi, 0), rax);
twisti@1020 213 __ movl(Address(rsi, 4), rbx);
twisti@1020 214 __ movl(Address(rsi, 8), rcx);
twisti@1020 215 __ movl(Address(rsi,12), rdx);
twisti@1020 216
twisti@1020 217 //
twisti@1020 218 // Standard cpuid(0x1)
twisti@1020 219 //
twisti@1020 220 __ bind(std_cpuid1);
twisti@1020 221 __ movl(rax, 1);
twisti@1020 222 __ cpuid();
twisti@1020 223 __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())));
twisti@1020 224 __ movl(Address(rsi, 0), rax);
twisti@1020 225 __ movl(Address(rsi, 4), rbx);
twisti@1020 226 __ movl(Address(rsi, 8), rcx);
twisti@1020 227 __ movl(Address(rsi,12), rdx);
twisti@1020 228
twisti@1020 229 __ movl(rax, 0x80000000);
twisti@1020 230 __ cpuid();
twisti@1020 231 __ cmpl(rax, 0x80000000); // Is cpuid(0x80000001) supported?
twisti@1020 232 __ jcc(Assembler::belowEqual, done);
twisti@1020 233 __ cmpl(rax, 0x80000004); // Is cpuid(0x80000005) supported?
twisti@1020 234 __ jccb(Assembler::belowEqual, ext_cpuid1);
twisti@1020 235 __ cmpl(rax, 0x80000007); // Is cpuid(0x80000008) supported?
twisti@1020 236 __ jccb(Assembler::belowEqual, ext_cpuid5);
twisti@1020 237 //
twisti@1020 238 // Extended cpuid(0x80000008)
twisti@1020 239 //
twisti@1020 240 __ movl(rax, 0x80000008);
twisti@1020 241 __ cpuid();
twisti@1020 242 __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid8_offset())));
twisti@1020 243 __ movl(Address(rsi, 0), rax);
twisti@1020 244 __ movl(Address(rsi, 4), rbx);
twisti@1020 245 __ movl(Address(rsi, 8), rcx);
twisti@1020 246 __ movl(Address(rsi,12), rdx);
twisti@1020 247
twisti@1020 248 //
twisti@1020 249 // Extended cpuid(0x80000005)
twisti@1020 250 //
twisti@1020 251 __ bind(ext_cpuid5);
twisti@1020 252 __ movl(rax, 0x80000005);
twisti@1020 253 __ cpuid();
twisti@1020 254 __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid5_offset())));
twisti@1020 255 __ movl(Address(rsi, 0), rax);
twisti@1020 256 __ movl(Address(rsi, 4), rbx);
twisti@1020 257 __ movl(Address(rsi, 8), rcx);
twisti@1020 258 __ movl(Address(rsi,12), rdx);
twisti@1020 259
twisti@1020 260 //
twisti@1020 261 // Extended cpuid(0x80000001)
twisti@1020 262 //
twisti@1020 263 __ bind(ext_cpuid1);
twisti@1020 264 __ movl(rax, 0x80000001);
twisti@1020 265 __ cpuid();
twisti@1020 266 __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid1_offset())));
twisti@1020 267 __ movl(Address(rsi, 0), rax);
twisti@1020 268 __ movl(Address(rsi, 4), rbx);
twisti@1020 269 __ movl(Address(rsi, 8), rcx);
twisti@1020 270 __ movl(Address(rsi,12), rdx);
twisti@1020 271
twisti@1020 272 //
twisti@1020 273 // return
twisti@1020 274 //
twisti@1020 275 __ bind(done);
twisti@1020 276 __ popf();
twisti@1020 277 __ pop(rsi);
twisti@1020 278 __ pop(rbx);
twisti@1020 279 __ pop(rbp);
twisti@1020 280 __ ret(0);
twisti@1020 281
twisti@1020 282 # undef __
twisti@1020 283
twisti@1020 284 return start;
twisti@1020 285 };
twisti@1020 286 };
twisti@1020 287
twisti@1020 288
twisti@1020 289 void VM_Version::get_processor_features() {
twisti@1020 290
twisti@1020 291 _cpu = 4; // 486 by default
twisti@1020 292 _model = 0;
twisti@1020 293 _stepping = 0;
twisti@1020 294 _cpuFeatures = 0;
twisti@1020 295 _logical_processors_per_package = 1;
twisti@1020 296
twisti@1020 297 if (!Use486InstrsOnly) {
twisti@1020 298 // Get raw processor info
twisti@1020 299 getPsrInfo_stub(&_cpuid_info);
twisti@1020 300 assert_is_initialized();
twisti@1020 301 _cpu = extended_cpu_family();
twisti@1020 302 _model = extended_cpu_model();
twisti@1020 303 _stepping = cpu_stepping();
twisti@1020 304
twisti@1020 305 if (cpu_family() > 4) { // it supports CPUID
twisti@1020 306 _cpuFeatures = feature_flags();
twisti@1020 307 // Logical processors are only available on P4s and above,
twisti@1020 308 // and only if hyperthreading is available.
twisti@1020 309 _logical_processors_per_package = logical_processor_count();
twisti@1020 310 }
twisti@1020 311 }
twisti@1020 312
twisti@1020 313 _supports_cx8 = supports_cmpxchg8();
twisti@1020 314
twisti@1020 315 #ifdef _LP64
twisti@1020 316 // OS should support SSE for x64 and hardware should support at least SSE2.
twisti@1020 317 if (!VM_Version::supports_sse2()) {
twisti@1020 318 vm_exit_during_initialization("Unknown x64 processor: SSE2 not supported");
twisti@1020 319 }
roland@1495 320 // in 64 bit the use of SSE2 is the minimum
roland@1495 321 if (UseSSE < 2) UseSSE = 2;
twisti@1020 322 #endif
twisti@1020 323
kvn@2984 324 #ifdef AMD64
kvn@2984 325 // flush_icache_stub have to be generated first.
kvn@2984 326 // That is why Icache line size is hard coded in ICache class,
kvn@2984 327 // see icache_x86.hpp. It is also the reason why we can't use
kvn@2984 328 // clflush instruction in 32-bit VM since it could be running
kvn@2984 329 // on CPU which does not support it.
kvn@2984 330 //
kvn@2984 331 // The only thing we can do is to verify that flushed
kvn@2984 332 // ICache::line_size has correct value.
kvn@2984 333 guarantee(_cpuid_info.std_cpuid1_edx.bits.clflush != 0, "clflush is not supported");
kvn@2984 334 // clflush_size is size in quadwords (8 bytes).
kvn@2984 335 guarantee(_cpuid_info.std_cpuid1_ebx.bits.clflush_size == 8, "such clflush size is not supported");
kvn@2984 336 #endif
kvn@2984 337
twisti@1020 338 // If the OS doesn't support SSE, we can't use this feature even if the HW does
twisti@1020 339 if (!os::supports_sse())
twisti@1020 340 _cpuFeatures &= ~(CPU_SSE|CPU_SSE2|CPU_SSE3|CPU_SSSE3|CPU_SSE4A|CPU_SSE4_1|CPU_SSE4_2);
twisti@1020 341
twisti@1020 342 if (UseSSE < 4) {
twisti@1020 343 _cpuFeatures &= ~CPU_SSE4_1;
twisti@1020 344 _cpuFeatures &= ~CPU_SSE4_2;
twisti@1020 345 }
twisti@1020 346
twisti@1020 347 if (UseSSE < 3) {
twisti@1020 348 _cpuFeatures &= ~CPU_SSE3;
twisti@1020 349 _cpuFeatures &= ~CPU_SSSE3;
twisti@1020 350 _cpuFeatures &= ~CPU_SSE4A;
twisti@1020 351 }
twisti@1020 352
twisti@1020 353 if (UseSSE < 2)
twisti@1020 354 _cpuFeatures &= ~CPU_SSE2;
twisti@1020 355
twisti@1020 356 if (UseSSE < 1)
twisti@1020 357 _cpuFeatures &= ~CPU_SSE;
twisti@1020 358
twisti@1020 359 if (logical_processors_per_package() == 1) {
twisti@1020 360 // HT processor could be installed on a system which doesn't support HT.
twisti@1020 361 _cpuFeatures &= ~CPU_HT;
twisti@1020 362 }
twisti@1020 363
twisti@1020 364 char buf[256];
kvn@2761 365 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",
twisti@1020 366 cores_per_cpu(), threads_per_core(),
twisti@1020 367 cpu_family(), _model, _stepping,
twisti@1020 368 (supports_cmov() ? ", cmov" : ""),
twisti@1020 369 (supports_cmpxchg8() ? ", cx8" : ""),
twisti@1020 370 (supports_fxsr() ? ", fxsr" : ""),
twisti@1020 371 (supports_mmx() ? ", mmx" : ""),
twisti@1020 372 (supports_sse() ? ", sse" : ""),
twisti@1020 373 (supports_sse2() ? ", sse2" : ""),
twisti@1020 374 (supports_sse3() ? ", sse3" : ""),
twisti@1020 375 (supports_ssse3()? ", ssse3": ""),
twisti@1020 376 (supports_sse4_1() ? ", sse4.1" : ""),
twisti@1020 377 (supports_sse4_2() ? ", sse4.2" : ""),
twisti@1078 378 (supports_popcnt() ? ", popcnt" : ""),
twisti@1020 379 (supports_mmx_ext() ? ", mmxext" : ""),
kvn@2761 380 (supports_3dnow_prefetch() ? ", 3dnowpref" : ""),
twisti@1210 381 (supports_lzcnt() ? ", lzcnt": ""),
twisti@1020 382 (supports_sse4a() ? ", sse4a": ""),
twisti@1020 383 (supports_ht() ? ", ht": ""));
twisti@1020 384 _features_str = strdup(buf);
twisti@1020 385
twisti@1020 386 // UseSSE is set to the smaller of what hardware supports and what
twisti@1020 387 // the command line requires. I.e., you cannot set UseSSE to 2 on
twisti@1020 388 // older Pentiums which do not support it.
twisti@1020 389 if( UseSSE > 4 ) UseSSE=4;
twisti@1020 390 if( UseSSE < 0 ) UseSSE=0;
twisti@1020 391 if( !supports_sse4_1() ) // Drop to 3 if no SSE4 support
twisti@1020 392 UseSSE = MIN2((intx)3,UseSSE);
twisti@1020 393 if( !supports_sse3() ) // Drop to 2 if no SSE3 support
twisti@1020 394 UseSSE = MIN2((intx)2,UseSSE);
twisti@1020 395 if( !supports_sse2() ) // Drop to 1 if no SSE2 support
twisti@1020 396 UseSSE = MIN2((intx)1,UseSSE);
twisti@1020 397 if( !supports_sse () ) // Drop to 0 if no SSE support
twisti@1020 398 UseSSE = 0;
twisti@1020 399
twisti@1020 400 // On new cpus instructions which update whole XMM register should be used
twisti@1020 401 // to prevent partial register stall due to dependencies on high half.
twisti@1020 402 //
twisti@1020 403 // UseXmmLoadAndClearUpper == true --> movsd(xmm, mem)
twisti@1020 404 // UseXmmLoadAndClearUpper == false --> movlpd(xmm, mem)
twisti@1020 405 // UseXmmRegToRegMoveAll == true --> movaps(xmm, xmm), movapd(xmm, xmm).
twisti@1020 406 // UseXmmRegToRegMoveAll == false --> movss(xmm, xmm), movsd(xmm, xmm).
twisti@1020 407
twisti@1020 408 if( is_amd() ) { // AMD cpus specific settings
twisti@1020 409 if( supports_sse2() && FLAG_IS_DEFAULT(UseAddressNop) ) {
twisti@1020 410 // Use it on new AMD cpus starting from Opteron.
twisti@1020 411 UseAddressNop = true;
twisti@1020 412 }
twisti@1020 413 if( supports_sse2() && FLAG_IS_DEFAULT(UseNewLongLShift) ) {
twisti@1020 414 // Use it on new AMD cpus starting from Opteron.
twisti@1020 415 UseNewLongLShift = true;
twisti@1020 416 }
twisti@1020 417 if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
twisti@1020 418 if( supports_sse4a() ) {
twisti@1020 419 UseXmmLoadAndClearUpper = true; // use movsd only on '10h' Opteron
twisti@1020 420 } else {
twisti@1020 421 UseXmmLoadAndClearUpper = false;
twisti@1020 422 }
twisti@1020 423 }
twisti@1020 424 if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
twisti@1020 425 if( supports_sse4a() ) {
twisti@1020 426 UseXmmRegToRegMoveAll = true; // use movaps, movapd only on '10h'
twisti@1020 427 } else {
twisti@1020 428 UseXmmRegToRegMoveAll = false;
twisti@1020 429 }
twisti@1020 430 }
twisti@1020 431 if( FLAG_IS_DEFAULT(UseXmmI2F) ) {
twisti@1020 432 if( supports_sse4a() ) {
twisti@1020 433 UseXmmI2F = true;
twisti@1020 434 } else {
twisti@1020 435 UseXmmI2F = false;
twisti@1020 436 }
twisti@1020 437 }
twisti@1020 438 if( FLAG_IS_DEFAULT(UseXmmI2D) ) {
twisti@1020 439 if( supports_sse4a() ) {
twisti@1020 440 UseXmmI2D = true;
twisti@1020 441 } else {
twisti@1020 442 UseXmmI2D = false;
twisti@1020 443 }
twisti@1020 444 }
kvn@2688 445 if( FLAG_IS_DEFAULT(UseSSE42Intrinsics) ) {
kvn@2688 446 if( supports_sse4_2() && UseSSE >= 4 ) {
kvn@2688 447 UseSSE42Intrinsics = true;
kvn@2688 448 }
kvn@2688 449 }
twisti@1210 450
twisti@1210 451 // Use count leading zeros count instruction if available.
twisti@1210 452 if (supports_lzcnt()) {
twisti@1210 453 if (FLAG_IS_DEFAULT(UseCountLeadingZerosInstruction)) {
twisti@1210 454 UseCountLeadingZerosInstruction = true;
twisti@1210 455 }
twisti@1210 456 }
kvn@2640 457
kvn@2808 458 // some defaults for AMD family 15h
kvn@2808 459 if ( cpu_family() == 0x15 ) {
kvn@2808 460 // On family 15h processors default is no sw prefetch
kvn@2640 461 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) {
kvn@2640 462 AllocatePrefetchStyle = 0;
kvn@2640 463 }
kvn@2808 464 // Also, if some other prefetch style is specified, default instruction type is PREFETCHW
kvn@2808 465 if (FLAG_IS_DEFAULT(AllocatePrefetchInstr)) {
kvn@2808 466 AllocatePrefetchInstr = 3;
kvn@2808 467 }
kvn@2808 468 // On family 15h processors use XMM and UnalignedLoadStores for Array Copy
kvn@2808 469 if( FLAG_IS_DEFAULT(UseXMMForArrayCopy) ) {
kvn@2808 470 UseXMMForArrayCopy = true;
kvn@2808 471 }
kvn@2808 472 if( FLAG_IS_DEFAULT(UseUnalignedLoadStores) && UseXMMForArrayCopy ) {
kvn@2808 473 UseUnalignedLoadStores = true;
kvn@2808 474 }
kvn@2640 475 }
kvn@2808 476
twisti@1020 477 }
twisti@1020 478
twisti@1020 479 if( is_intel() ) { // Intel cpus specific settings
twisti@1020 480 if( FLAG_IS_DEFAULT(UseStoreImmI16) ) {
twisti@1020 481 UseStoreImmI16 = false; // don't use it on Intel cpus
twisti@1020 482 }
twisti@1020 483 if( cpu_family() == 6 || cpu_family() == 15 ) {
twisti@1020 484 if( FLAG_IS_DEFAULT(UseAddressNop) ) {
twisti@1020 485 // Use it on all Intel cpus starting from PentiumPro
twisti@1020 486 UseAddressNop = true;
twisti@1020 487 }
twisti@1020 488 }
twisti@1020 489 if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
twisti@1020 490 UseXmmLoadAndClearUpper = true; // use movsd on all Intel cpus
twisti@1020 491 }
twisti@1020 492 if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
twisti@1020 493 if( supports_sse3() ) {
twisti@1020 494 UseXmmRegToRegMoveAll = true; // use movaps, movapd on new Intel cpus
twisti@1020 495 } else {
twisti@1020 496 UseXmmRegToRegMoveAll = false;
twisti@1020 497 }
twisti@1020 498 }
twisti@1020 499 if( cpu_family() == 6 && supports_sse3() ) { // New Intel cpus
twisti@1020 500 #ifdef COMPILER2
twisti@1020 501 if( FLAG_IS_DEFAULT(MaxLoopPad) ) {
twisti@1020 502 // For new Intel cpus do the next optimization:
twisti@1020 503 // don't align the beginning of a loop if there are enough instructions
twisti@1020 504 // left (NumberOfLoopInstrToAlign defined in c2_globals.hpp)
twisti@1020 505 // in current fetch line (OptoLoopAlignment) or the padding
twisti@1020 506 // is big (> MaxLoopPad).
twisti@1020 507 // Set MaxLoopPad to 11 for new Intel cpus to reduce number of
twisti@1020 508 // generated NOP instructions. 11 is the largest size of one
twisti@1020 509 // address NOP instruction '0F 1F' (see Assembler::nop(i)).
twisti@1020 510 MaxLoopPad = 11;
twisti@1020 511 }
twisti@1020 512 #endif // COMPILER2
twisti@1020 513 if( FLAG_IS_DEFAULT(UseXMMForArrayCopy) ) {
twisti@1020 514 UseXMMForArrayCopy = true; // use SSE2 movq on new Intel cpus
twisti@1020 515 }
twisti@1020 516 if( supports_sse4_2() && supports_ht() ) { // Newest Intel cpus
twisti@1020 517 if( FLAG_IS_DEFAULT(UseUnalignedLoadStores) && UseXMMForArrayCopy ) {
twisti@1020 518 UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
twisti@1020 519 }
twisti@1020 520 }
cfang@1116 521 if( supports_sse4_2() && UseSSE >= 4 ) {
cfang@1116 522 if( FLAG_IS_DEFAULT(UseSSE42Intrinsics)) {
cfang@1116 523 UseSSE42Intrinsics = true;
cfang@1116 524 }
cfang@1116 525 }
twisti@1020 526 }
twisti@1020 527 }
twisti@1020 528
twisti@1078 529 // Use population count instruction if available.
twisti@1078 530 if (supports_popcnt()) {
twisti@1078 531 if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
twisti@1078 532 UsePopCountInstruction = true;
twisti@1078 533 }
twisti@1078 534 }
twisti@1078 535
never@2085 536 #ifdef COMPILER2
never@2085 537 if (UseFPUForSpilling) {
never@2085 538 if (UseSSE < 2) {
never@2085 539 // Only supported with SSE2+
never@2085 540 FLAG_SET_DEFAULT(UseFPUForSpilling, false);
never@2085 541 }
never@2085 542 }
never@2085 543 #endif
never@2085 544
twisti@1020 545 assert(0 <= ReadPrefetchInstr && ReadPrefetchInstr <= 3, "invalid value");
twisti@1020 546 assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 3, "invalid value");
twisti@1020 547
twisti@1020 548 // set valid Prefetch instruction
twisti@1020 549 if( ReadPrefetchInstr < 0 ) ReadPrefetchInstr = 0;
twisti@1020 550 if( ReadPrefetchInstr > 3 ) ReadPrefetchInstr = 3;
kvn@2761 551 if( ReadPrefetchInstr == 3 && !supports_3dnow_prefetch() ) ReadPrefetchInstr = 0;
kvn@2761 552 if( !supports_sse() && supports_3dnow_prefetch() ) ReadPrefetchInstr = 3;
twisti@1020 553
twisti@1020 554 if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0;
twisti@1020 555 if( AllocatePrefetchInstr > 3 ) AllocatePrefetchInstr = 3;
kvn@2761 556 if( AllocatePrefetchInstr == 3 && !supports_3dnow_prefetch() ) AllocatePrefetchInstr=0;
kvn@2761 557 if( !supports_sse() && supports_3dnow_prefetch() ) AllocatePrefetchInstr = 3;
twisti@1020 558
twisti@1020 559 // Allocation prefetch settings
twisti@1020 560 intx cache_line_size = L1_data_cache_line_size();
twisti@1020 561 if( cache_line_size > AllocatePrefetchStepSize )
twisti@1020 562 AllocatePrefetchStepSize = cache_line_size;
twisti@1020 563 if( FLAG_IS_DEFAULT(AllocatePrefetchLines) )
twisti@1020 564 AllocatePrefetchLines = 3; // Optimistic value
twisti@1020 565 assert(AllocatePrefetchLines > 0, "invalid value");
twisti@1020 566 if( AllocatePrefetchLines < 1 ) // set valid value in product VM
twisti@1020 567 AllocatePrefetchLines = 1; // Conservative value
twisti@1020 568
twisti@1020 569 AllocatePrefetchDistance = allocate_prefetch_distance();
twisti@1020 570 AllocatePrefetchStyle = allocate_prefetch_style();
twisti@1020 571
kvn@1977 572 if( is_intel() && cpu_family() == 6 && supports_sse3() ) {
kvn@1977 573 if( AllocatePrefetchStyle == 2 ) { // watermark prefetching on Core
twisti@1020 574 #ifdef _LP64
kvn@1977 575 AllocatePrefetchDistance = 384;
twisti@1020 576 #else
kvn@1977 577 AllocatePrefetchDistance = 320;
twisti@1020 578 #endif
kvn@1977 579 }
kvn@1977 580 if( supports_sse4_2() && supports_ht() ) { // Nehalem based cpus
kvn@1977 581 AllocatePrefetchDistance = 192;
kvn@1977 582 AllocatePrefetchLines = 4;
never@2085 583 #ifdef COMPILER2
never@2085 584 if (AggressiveOpts && FLAG_IS_DEFAULT(UseFPUForSpilling)) {
never@2085 585 FLAG_SET_DEFAULT(UseFPUForSpilling, true);
never@2085 586 }
never@2085 587 #endif
kvn@1977 588 }
twisti@1020 589 }
twisti@1020 590 assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value");
twisti@1020 591
twisti@1020 592 #ifdef _LP64
twisti@1020 593 // Prefetch settings
twisti@1020 594 PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes();
twisti@1020 595 PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes();
twisti@1020 596 PrefetchFieldsAhead = prefetch_fields_ahead();
twisti@1020 597 #endif
twisti@1020 598
twisti@1020 599 #ifndef PRODUCT
twisti@1020 600 if (PrintMiscellaneous && Verbose) {
twisti@1020 601 tty->print_cr("Logical CPUs per core: %u",
twisti@1020 602 logical_processors_per_package());
twisti@1020 603 tty->print_cr("UseSSE=%d",UseSSE);
twisti@1020 604 tty->print("Allocation: ");
kvn@2761 605 if (AllocatePrefetchStyle <= 0 || UseSSE == 0 && !supports_3dnow_prefetch()) {
twisti@1020 606 tty->print_cr("no prefetching");
twisti@1020 607 } else {
kvn@2761 608 if (UseSSE == 0 && supports_3dnow_prefetch()) {
twisti@1020 609 tty->print("PREFETCHW");
twisti@1020 610 } else if (UseSSE >= 1) {
twisti@1020 611 if (AllocatePrefetchInstr == 0) {
twisti@1020 612 tty->print("PREFETCHNTA");
twisti@1020 613 } else if (AllocatePrefetchInstr == 1) {
twisti@1020 614 tty->print("PREFETCHT0");
twisti@1020 615 } else if (AllocatePrefetchInstr == 2) {
twisti@1020 616 tty->print("PREFETCHT2");
twisti@1020 617 } else if (AllocatePrefetchInstr == 3) {
twisti@1020 618 tty->print("PREFETCHW");
twisti@1020 619 }
twisti@1020 620 }
twisti@1020 621 if (AllocatePrefetchLines > 1) {
twisti@1020 622 tty->print_cr(" %d, %d lines with step %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize);
twisti@1020 623 } else {
twisti@1020 624 tty->print_cr(" %d, one line", AllocatePrefetchDistance);
twisti@1020 625 }
twisti@1020 626 }
twisti@1020 627
twisti@1020 628 if (PrefetchCopyIntervalInBytes > 0) {
twisti@1020 629 tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes);
twisti@1020 630 }
twisti@1020 631 if (PrefetchScanIntervalInBytes > 0) {
twisti@1020 632 tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes);
twisti@1020 633 }
twisti@1020 634 if (PrefetchFieldsAhead > 0) {
twisti@1020 635 tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead);
twisti@1020 636 }
twisti@1020 637 }
twisti@1020 638 #endif // !PRODUCT
twisti@1020 639 }
twisti@1020 640
twisti@1020 641 void VM_Version::initialize() {
twisti@1020 642 ResourceMark rm;
twisti@1020 643 // Making this stub must be FIRST use of assembler
twisti@1020 644
twisti@1020 645 stub_blob = BufferBlob::create("getPsrInfo_stub", stub_size);
twisti@1020 646 if (stub_blob == NULL) {
twisti@1020 647 vm_exit_during_initialization("Unable to allocate getPsrInfo_stub");
twisti@1020 648 }
twisti@2103 649 CodeBuffer c(stub_blob);
twisti@1020 650 VM_Version_StubGenerator g(&c);
twisti@1020 651 getPsrInfo_stub = CAST_TO_FN_PTR(getPsrInfo_stub_t,
twisti@1020 652 g.generate_getPsrInfo());
twisti@1020 653
twisti@1020 654 get_processor_features();
twisti@1020 655 }

mercurial