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