1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/ppc/vm/vm_version_ppc.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,488 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2012, 2014 SAP AG. All rights reserved. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "precompiled.hpp" 1.30 +#include "asm/assembler.inline.hpp" 1.31 +#include "asm/macroAssembler.inline.hpp" 1.32 +#include "compiler/disassembler.hpp" 1.33 +#include "memory/resourceArea.hpp" 1.34 +#include "runtime/java.hpp" 1.35 +#include "runtime/stubCodeGenerator.hpp" 1.36 +#include "utilities/defaultStream.hpp" 1.37 +#include "vm_version_ppc.hpp" 1.38 +#ifdef TARGET_OS_FAMILY_aix 1.39 +# include "os_aix.inline.hpp" 1.40 +#endif 1.41 +#ifdef TARGET_OS_FAMILY_linux 1.42 +# include "os_linux.inline.hpp" 1.43 +#endif 1.44 + 1.45 +# include <sys/sysinfo.h> 1.46 + 1.47 +int VM_Version::_features = VM_Version::unknown_m; 1.48 +int VM_Version::_measured_cache_line_size = 128; // default value 1.49 +const char* VM_Version::_features_str = ""; 1.50 +bool VM_Version::_is_determine_features_test_running = false; 1.51 + 1.52 + 1.53 +#define MSG(flag) \ 1.54 + if (flag && !FLAG_IS_DEFAULT(flag)) \ 1.55 + jio_fprintf(defaultStream::error_stream(), \ 1.56 + "warning: -XX:+" #flag " requires -XX:+UseSIGTRAP\n" \ 1.57 + " -XX:+" #flag " will be disabled!\n"); 1.58 + 1.59 +void VM_Version::initialize() { 1.60 + 1.61 + // Test which instructions are supported and measure cache line size. 1.62 + determine_features(); 1.63 + 1.64 + // If PowerArchitecturePPC64 hasn't been specified explicitly determine from features. 1.65 + if (FLAG_IS_DEFAULT(PowerArchitecturePPC64)) { 1.66 + if (VM_Version::has_popcntw()) { 1.67 + FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 7); 1.68 + } else if (VM_Version::has_cmpb()) { 1.69 + FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 6); 1.70 + } else if (VM_Version::has_popcntb()) { 1.71 + FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 5); 1.72 + } else { 1.73 + FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 0); 1.74 + } 1.75 + } 1.76 + guarantee(PowerArchitecturePPC64 == 0 || PowerArchitecturePPC64 == 5 || 1.77 + PowerArchitecturePPC64 == 6 || PowerArchitecturePPC64 == 7, 1.78 + "PowerArchitecturePPC64 should be 0, 5, 6 or 7"); 1.79 + 1.80 + if (!UseSIGTRAP) { 1.81 + MSG(TrapBasedICMissChecks); 1.82 + MSG(TrapBasedNotEntrantChecks); 1.83 + MSG(TrapBasedNullChecks); 1.84 + FLAG_SET_ERGO(bool, TrapBasedNotEntrantChecks, false); 1.85 + FLAG_SET_ERGO(bool, TrapBasedNullChecks, false); 1.86 + FLAG_SET_ERGO(bool, TrapBasedICMissChecks, false); 1.87 + } 1.88 + 1.89 +#ifdef COMPILER2 1.90 + if (!UseSIGTRAP) { 1.91 + MSG(TrapBasedRangeChecks); 1.92 + FLAG_SET_ERGO(bool, TrapBasedRangeChecks, false); 1.93 + } 1.94 + 1.95 + // On Power6 test for section size. 1.96 + if (PowerArchitecturePPC64 == 6) { 1.97 + determine_section_size(); 1.98 + // TODO: PPC port } else { 1.99 + // TODO: PPC port PdScheduling::power6SectorSize = 0x20; 1.100 + } 1.101 + 1.102 + MaxVectorSize = 8; 1.103 +#endif 1.104 + 1.105 + // Create and print feature-string. 1.106 + char buf[(num_features+1) * 16]; // Max 16 chars per feature. 1.107 + jio_snprintf(buf, sizeof(buf), 1.108 + "ppc64%s%s%s%s%s%s%s%s", 1.109 + (has_fsqrt() ? " fsqrt" : ""), 1.110 + (has_isel() ? " isel" : ""), 1.111 + (has_lxarxeh() ? " lxarxeh" : ""), 1.112 + (has_cmpb() ? " cmpb" : ""), 1.113 + //(has_mftgpr()? " mftgpr" : ""), 1.114 + (has_popcntb() ? " popcntb" : ""), 1.115 + (has_popcntw() ? " popcntw" : ""), 1.116 + (has_fcfids() ? " fcfids" : ""), 1.117 + (has_vand() ? " vand" : "") 1.118 + // Make sure number of %s matches num_features! 1.119 + ); 1.120 + _features_str = strdup(buf); 1.121 + NOT_PRODUCT(if (Verbose) print_features();); 1.122 + 1.123 + // PPC64 supports 8-byte compare-exchange operations (see 1.124 + // Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr) 1.125 + // and 'atomic long memory ops' (see Unsafe_GetLongVolatile). 1.126 + _supports_cx8 = true; 1.127 + 1.128 + UseSSE = 0; // Only on x86 and x64 1.129 + 1.130 + intx cache_line_size = _measured_cache_line_size; 1.131 + 1.132 + if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) AllocatePrefetchStyle = 1; 1.133 + 1.134 + if (AllocatePrefetchStyle == 4) { 1.135 + AllocatePrefetchStepSize = cache_line_size; // Need exact value. 1.136 + if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 12; // Use larger blocks by default. 1.137 + if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 2*cache_line_size; // Default is not defined? 1.138 + } else { 1.139 + if (cache_line_size > AllocatePrefetchStepSize) AllocatePrefetchStepSize = cache_line_size; 1.140 + if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 3; // Optimistic value. 1.141 + if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 3*cache_line_size; // Default is not defined? 1.142 + } 1.143 + 1.144 + assert(AllocatePrefetchLines > 0, "invalid value"); 1.145 + if (AllocatePrefetchLines < 1) // Set valid value in product VM. 1.146 + AllocatePrefetchLines = 1; // Conservative value. 1.147 + 1.148 + if (AllocatePrefetchStyle == 3 && AllocatePrefetchDistance < cache_line_size) 1.149 + AllocatePrefetchStyle = 1; // Fall back if inappropriate. 1.150 + 1.151 + assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive"); 1.152 +} 1.153 + 1.154 +void VM_Version::print_features() { 1.155 + tty->print_cr("Version: %s cache_line_size = %d", cpu_features(), (int) get_cache_line_size()); 1.156 +} 1.157 + 1.158 +#ifdef COMPILER2 1.159 +// Determine section size on power6: If section size is 8 instructions, 1.160 +// there should be a difference between the two testloops of ~15 %. If 1.161 +// no difference is detected the section is assumed to be 32 instructions. 1.162 +void VM_Version::determine_section_size() { 1.163 + 1.164 + int unroll = 80; 1.165 + 1.166 + const int code_size = (2* unroll * 32 + 100)*BytesPerInstWord; 1.167 + 1.168 + // Allocate space for the code. 1.169 + ResourceMark rm; 1.170 + CodeBuffer cb("detect_section_size", code_size, 0); 1.171 + MacroAssembler* a = new MacroAssembler(&cb); 1.172 + 1.173 + uint32_t *code = (uint32_t *)a->pc(); 1.174 + // Emit code. 1.175 + void (*test1)() = (void(*)())(void *)a->function_entry(); 1.176 + 1.177 + Label l1; 1.178 + 1.179 + a->li(R4, 1); 1.180 + a->sldi(R4, R4, 28); 1.181 + a->b(l1); 1.182 + a->align(CodeEntryAlignment); 1.183 + 1.184 + a->bind(l1); 1.185 + 1.186 + for (int i = 0; i < unroll; i++) { 1.187 + // Schleife 1 1.188 + // ------- sector 0 ------------ 1.189 + // ;; 0 1.190 + a->nop(); // 1 1.191 + a->fpnop0(); // 2 1.192 + a->fpnop1(); // 3 1.193 + a->addi(R4,R4, -1); // 4 1.194 + 1.195 + // ;; 1 1.196 + a->nop(); // 5 1.197 + a->fmr(F6, F6); // 6 1.198 + a->fmr(F7, F7); // 7 1.199 + a->endgroup(); // 8 1.200 + // ------- sector 8 ------------ 1.201 + 1.202 + // ;; 2 1.203 + a->nop(); // 9 1.204 + a->nop(); // 10 1.205 + a->fmr(F8, F8); // 11 1.206 + a->fmr(F9, F9); // 12 1.207 + 1.208 + // ;; 3 1.209 + a->nop(); // 13 1.210 + a->fmr(F10, F10); // 14 1.211 + a->fmr(F11, F11); // 15 1.212 + a->endgroup(); // 16 1.213 + // -------- sector 16 ------------- 1.214 + 1.215 + // ;; 4 1.216 + a->nop(); // 17 1.217 + a->nop(); // 18 1.218 + a->fmr(F15, F15); // 19 1.219 + a->fmr(F16, F16); // 20 1.220 + 1.221 + // ;; 5 1.222 + a->nop(); // 21 1.223 + a->fmr(F17, F17); // 22 1.224 + a->fmr(F18, F18); // 23 1.225 + a->endgroup(); // 24 1.226 + // ------- sector 24 ------------ 1.227 + 1.228 + // ;; 6 1.229 + a->nop(); // 25 1.230 + a->nop(); // 26 1.231 + a->fmr(F19, F19); // 27 1.232 + a->fmr(F20, F20); // 28 1.233 + 1.234 + // ;; 7 1.235 + a->nop(); // 29 1.236 + a->fmr(F21, F21); // 30 1.237 + a->fmr(F22, F22); // 31 1.238 + a->brnop0(); // 32 1.239 + 1.240 + // ------- sector 32 ------------ 1.241 + } 1.242 + 1.243 + // ;; 8 1.244 + a->cmpdi(CCR0, R4, unroll); // 33 1.245 + a->bge(CCR0, l1); // 34 1.246 + a->blr(); 1.247 + 1.248 + // Emit code. 1.249 + void (*test2)() = (void(*)())(void *)a->function_entry(); 1.250 + // uint32_t *code = (uint32_t *)a->pc(); 1.251 + 1.252 + Label l2; 1.253 + 1.254 + a->li(R4, 1); 1.255 + a->sldi(R4, R4, 28); 1.256 + a->b(l2); 1.257 + a->align(CodeEntryAlignment); 1.258 + 1.259 + a->bind(l2); 1.260 + 1.261 + for (int i = 0; i < unroll; i++) { 1.262 + // Schleife 2 1.263 + // ------- sector 0 ------------ 1.264 + // ;; 0 1.265 + a->brnop0(); // 1 1.266 + a->nop(); // 2 1.267 + //a->cmpdi(CCR0, R4, unroll); 1.268 + a->fpnop0(); // 3 1.269 + a->fpnop1(); // 4 1.270 + a->addi(R4,R4, -1); // 5 1.271 + 1.272 + // ;; 1 1.273 + 1.274 + a->nop(); // 6 1.275 + a->fmr(F6, F6); // 7 1.276 + a->fmr(F7, F7); // 8 1.277 + // ------- sector 8 --------------- 1.278 + 1.279 + // ;; 2 1.280 + a->endgroup(); // 9 1.281 + 1.282 + // ;; 3 1.283 + a->nop(); // 10 1.284 + a->nop(); // 11 1.285 + a->fmr(F8, F8); // 12 1.286 + 1.287 + // ;; 4 1.288 + a->fmr(F9, F9); // 13 1.289 + a->nop(); // 14 1.290 + a->fmr(F10, F10); // 15 1.291 + 1.292 + // ;; 5 1.293 + a->fmr(F11, F11); // 16 1.294 + // -------- sector 16 ------------- 1.295 + 1.296 + // ;; 6 1.297 + a->endgroup(); // 17 1.298 + 1.299 + // ;; 7 1.300 + a->nop(); // 18 1.301 + a->nop(); // 19 1.302 + a->fmr(F15, F15); // 20 1.303 + 1.304 + // ;; 8 1.305 + a->fmr(F16, F16); // 21 1.306 + a->nop(); // 22 1.307 + a->fmr(F17, F17); // 23 1.308 + 1.309 + // ;; 9 1.310 + a->fmr(F18, F18); // 24 1.311 + // -------- sector 24 ------------- 1.312 + 1.313 + // ;; 10 1.314 + a->endgroup(); // 25 1.315 + 1.316 + // ;; 11 1.317 + a->nop(); // 26 1.318 + a->nop(); // 27 1.319 + a->fmr(F19, F19); // 28 1.320 + 1.321 + // ;; 12 1.322 + a->fmr(F20, F20); // 29 1.323 + a->nop(); // 30 1.324 + a->fmr(F21, F21); // 31 1.325 + 1.326 + // ;; 13 1.327 + a->fmr(F22, F22); // 32 1.328 + } 1.329 + 1.330 + // -------- sector 32 ------------- 1.331 + // ;; 14 1.332 + a->cmpdi(CCR0, R4, unroll); // 33 1.333 + a->bge(CCR0, l2); // 34 1.334 + 1.335 + a->blr(); 1.336 + uint32_t *code_end = (uint32_t *)a->pc(); 1.337 + a->flush(); 1.338 + 1.339 + double loop1_seconds,loop2_seconds, rel_diff; 1.340 + uint64_t start1, stop1; 1.341 + 1.342 + start1 = os::current_thread_cpu_time(false); 1.343 + (*test1)(); 1.344 + stop1 = os::current_thread_cpu_time(false); 1.345 + loop1_seconds = (stop1- start1) / (1000 *1000 *1000.0); 1.346 + 1.347 + 1.348 + start1 = os::current_thread_cpu_time(false); 1.349 + (*test2)(); 1.350 + stop1 = os::current_thread_cpu_time(false); 1.351 + 1.352 + loop2_seconds = (stop1 - start1) / (1000 *1000 *1000.0); 1.353 + 1.354 + rel_diff = (loop2_seconds - loop1_seconds) / loop1_seconds *100; 1.355 + 1.356 + if (PrintAssembly) { 1.357 + ttyLocker ttyl; 1.358 + tty->print_cr("Decoding section size detection stub at " INTPTR_FORMAT " before execution:", code); 1.359 + Disassembler::decode((u_char*)code, (u_char*)code_end, tty); 1.360 + tty->print_cr("Time loop1 :%f", loop1_seconds); 1.361 + tty->print_cr("Time loop2 :%f", loop2_seconds); 1.362 + tty->print_cr("(time2 - time1) / time1 = %f %%", rel_diff); 1.363 + 1.364 + if (rel_diff > 12.0) { 1.365 + tty->print_cr("Section Size 8 Instructions"); 1.366 + } else{ 1.367 + tty->print_cr("Section Size 32 Instructions or Power5"); 1.368 + } 1.369 + } 1.370 + 1.371 +#if 0 // TODO: PPC port 1.372 + // Set sector size (if not set explicitly). 1.373 + if (FLAG_IS_DEFAULT(Power6SectorSize128PPC64)) { 1.374 + if (rel_diff > 12.0) { 1.375 + PdScheduling::power6SectorSize = 0x20; 1.376 + } else { 1.377 + PdScheduling::power6SectorSize = 0x80; 1.378 + } 1.379 + } else if (Power6SectorSize128PPC64) { 1.380 + PdScheduling::power6SectorSize = 0x80; 1.381 + } else { 1.382 + PdScheduling::power6SectorSize = 0x20; 1.383 + } 1.384 +#endif 1.385 + if (UsePower6SchedulerPPC64) Unimplemented(); 1.386 +} 1.387 +#endif // COMPILER2 1.388 + 1.389 +void VM_Version::determine_features() { 1.390 +#if defined(ABI_ELFv2) 1.391 + const int code_size = (num_features+1+2*7)*BytesPerInstWord; // TODO(asmundak): calculation is incorrect. 1.392 +#else 1.393 + // 7 InstWords for each call (function descriptor + blr instruction). 1.394 + const int code_size = (num_features+1+2*7)*BytesPerInstWord; 1.395 +#endif 1.396 + int features = 0; 1.397 + 1.398 + // create test area 1.399 + enum { BUFFER_SIZE = 2*4*K }; // Needs to be >=2* max cache line size (cache line size can't exceed min page size). 1.400 + char test_area[BUFFER_SIZE]; 1.401 + char *mid_of_test_area = &test_area[BUFFER_SIZE>>1]; 1.402 + 1.403 + // Allocate space for the code. 1.404 + ResourceMark rm; 1.405 + CodeBuffer cb("detect_cpu_features", code_size, 0); 1.406 + MacroAssembler* a = new MacroAssembler(&cb); 1.407 + 1.408 + // Must be set to true so we can generate the test code. 1.409 + _features = VM_Version::all_features_m; 1.410 + 1.411 + // Emit code. 1.412 + void (*test)(address addr, uint64_t offset)=(void(*)(address addr, uint64_t offset))(void *)a->function_entry(); 1.413 + uint32_t *code = (uint32_t *)a->pc(); 1.414 + // Don't use R0 in ldarx. 1.415 + // Keep R3_ARG1 unmodified, it contains &field (see below). 1.416 + // Keep R4_ARG2 unmodified, it contains offset = 0 (see below). 1.417 + a->fsqrt(F3, F4); // code[0] -> fsqrt_m 1.418 + a->fsqrts(F3, F4); // code[1] -> fsqrts_m 1.419 + a->isel(R7, R5, R6, 0); // code[2] -> isel_m 1.420 + a->ldarx_unchecked(R7, R3_ARG1, R4_ARG2, 1); // code[3] -> lxarx_m 1.421 + a->cmpb(R7, R5, R6); // code[4] -> bcmp 1.422 + //a->mftgpr(R7, F3); // code[5] -> mftgpr 1.423 + a->popcntb(R7, R5); // code[6] -> popcntb 1.424 + a->popcntw(R7, R5); // code[7] -> popcntw 1.425 + a->fcfids(F3, F4); // code[8] -> fcfids 1.426 + a->vand(VR0, VR0, VR0); // code[9] -> vand 1.427 + a->blr(); 1.428 + 1.429 + // Emit function to set one cache line to zero. Emit function descriptor and get pointer to it. 1.430 + void (*zero_cacheline_func_ptr)(char*) = (void(*)(char*))(void *)a->function_entry(); 1.431 + a->dcbz(R3_ARG1); // R3_ARG1 = addr 1.432 + a->blr(); 1.433 + 1.434 + uint32_t *code_end = (uint32_t *)a->pc(); 1.435 + a->flush(); 1.436 + _features = VM_Version::unknown_m; 1.437 + 1.438 + // Print the detection code. 1.439 + if (PrintAssembly) { 1.440 + ttyLocker ttyl; 1.441 + tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " before execution:", code); 1.442 + Disassembler::decode((u_char*)code, (u_char*)code_end, tty); 1.443 + } 1.444 + 1.445 + // Measure cache line size. 1.446 + memset(test_area, 0xFF, BUFFER_SIZE); // Fill test area with 0xFF. 1.447 + (*zero_cacheline_func_ptr)(mid_of_test_area); // Call function which executes dcbz to the middle. 1.448 + int count = 0; // count zeroed bytes 1.449 + for (int i = 0; i < BUFFER_SIZE; i++) if (test_area[i] == 0) count++; 1.450 + guarantee(is_power_of_2(count), "cache line size needs to be a power of 2"); 1.451 + _measured_cache_line_size = count; 1.452 + 1.453 + // Execute code. Illegal instructions will be replaced by 0 in the signal handler. 1.454 + VM_Version::_is_determine_features_test_running = true; 1.455 + (*test)((address)mid_of_test_area, (uint64_t)0); 1.456 + VM_Version::_is_determine_features_test_running = false; 1.457 + 1.458 + // determine which instructions are legal. 1.459 + int feature_cntr = 0; 1.460 + if (code[feature_cntr++]) features |= fsqrt_m; 1.461 + if (code[feature_cntr++]) features |= fsqrts_m; 1.462 + if (code[feature_cntr++]) features |= isel_m; 1.463 + if (code[feature_cntr++]) features |= lxarxeh_m; 1.464 + if (code[feature_cntr++]) features |= cmpb_m; 1.465 + //if(code[feature_cntr++])features |= mftgpr_m; 1.466 + if (code[feature_cntr++]) features |= popcntb_m; 1.467 + if (code[feature_cntr++]) features |= popcntw_m; 1.468 + if (code[feature_cntr++]) features |= fcfids_m; 1.469 + if (code[feature_cntr++]) features |= vand_m; 1.470 + 1.471 + // Print the detection code. 1.472 + if (PrintAssembly) { 1.473 + ttyLocker ttyl; 1.474 + tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " after execution:", code); 1.475 + Disassembler::decode((u_char*)code, (u_char*)code_end, tty); 1.476 + } 1.477 + 1.478 + _features = features; 1.479 +} 1.480 + 1.481 + 1.482 +static int saved_features = 0; 1.483 + 1.484 +void VM_Version::allow_all() { 1.485 + saved_features = _features; 1.486 + _features = all_features_m; 1.487 +} 1.488 + 1.489 +void VM_Version::revert() { 1.490 + _features = saved_features; 1.491 +}