Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2012, 2014 SAP AG. All rights reserved. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | #include "precompiled.hpp" |
aoqi@0 | 27 | #include "asm/assembler.inline.hpp" |
aoqi@0 | 28 | #include "asm/macroAssembler.inline.hpp" |
aoqi@0 | 29 | #include "compiler/disassembler.hpp" |
aoqi@0 | 30 | #include "memory/resourceArea.hpp" |
aoqi@0 | 31 | #include "runtime/java.hpp" |
aoqi@0 | 32 | #include "runtime/stubCodeGenerator.hpp" |
aoqi@0 | 33 | #include "utilities/defaultStream.hpp" |
aoqi@0 | 34 | #include "vm_version_ppc.hpp" |
aoqi@0 | 35 | #ifdef TARGET_OS_FAMILY_aix |
aoqi@0 | 36 | # include "os_aix.inline.hpp" |
aoqi@0 | 37 | #endif |
aoqi@0 | 38 | #ifdef TARGET_OS_FAMILY_linux |
aoqi@0 | 39 | # include "os_linux.inline.hpp" |
aoqi@0 | 40 | #endif |
aoqi@0 | 41 | |
aoqi@0 | 42 | # include <sys/sysinfo.h> |
aoqi@0 | 43 | |
aoqi@0 | 44 | int VM_Version::_features = VM_Version::unknown_m; |
aoqi@0 | 45 | int VM_Version::_measured_cache_line_size = 128; // default value |
aoqi@0 | 46 | const char* VM_Version::_features_str = ""; |
aoqi@0 | 47 | bool VM_Version::_is_determine_features_test_running = false; |
aoqi@0 | 48 | |
aoqi@0 | 49 | |
aoqi@0 | 50 | #define MSG(flag) \ |
aoqi@0 | 51 | if (flag && !FLAG_IS_DEFAULT(flag)) \ |
aoqi@0 | 52 | jio_fprintf(defaultStream::error_stream(), \ |
aoqi@0 | 53 | "warning: -XX:+" #flag " requires -XX:+UseSIGTRAP\n" \ |
aoqi@0 | 54 | " -XX:+" #flag " will be disabled!\n"); |
aoqi@0 | 55 | |
aoqi@0 | 56 | void VM_Version::initialize() { |
aoqi@0 | 57 | |
aoqi@0 | 58 | // Test which instructions are supported and measure cache line size. |
aoqi@0 | 59 | determine_features(); |
aoqi@0 | 60 | |
aoqi@0 | 61 | // If PowerArchitecturePPC64 hasn't been specified explicitly determine from features. |
aoqi@0 | 62 | if (FLAG_IS_DEFAULT(PowerArchitecturePPC64)) { |
aoqi@0 | 63 | if (VM_Version::has_popcntw()) { |
aoqi@0 | 64 | FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 7); |
aoqi@0 | 65 | } else if (VM_Version::has_cmpb()) { |
aoqi@0 | 66 | FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 6); |
aoqi@0 | 67 | } else if (VM_Version::has_popcntb()) { |
aoqi@0 | 68 | FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 5); |
aoqi@0 | 69 | } else { |
aoqi@0 | 70 | FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 0); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | } |
aoqi@0 | 73 | guarantee(PowerArchitecturePPC64 == 0 || PowerArchitecturePPC64 == 5 || |
aoqi@0 | 74 | PowerArchitecturePPC64 == 6 || PowerArchitecturePPC64 == 7, |
aoqi@0 | 75 | "PowerArchitecturePPC64 should be 0, 5, 6 or 7"); |
aoqi@0 | 76 | |
aoqi@0 | 77 | if (!UseSIGTRAP) { |
aoqi@0 | 78 | MSG(TrapBasedICMissChecks); |
aoqi@0 | 79 | MSG(TrapBasedNotEntrantChecks); |
aoqi@0 | 80 | MSG(TrapBasedNullChecks); |
aoqi@0 | 81 | FLAG_SET_ERGO(bool, TrapBasedNotEntrantChecks, false); |
aoqi@0 | 82 | FLAG_SET_ERGO(bool, TrapBasedNullChecks, false); |
aoqi@0 | 83 | FLAG_SET_ERGO(bool, TrapBasedICMissChecks, false); |
aoqi@0 | 84 | } |
aoqi@0 | 85 | |
aoqi@0 | 86 | #ifdef COMPILER2 |
aoqi@0 | 87 | if (!UseSIGTRAP) { |
aoqi@0 | 88 | MSG(TrapBasedRangeChecks); |
aoqi@0 | 89 | FLAG_SET_ERGO(bool, TrapBasedRangeChecks, false); |
aoqi@0 | 90 | } |
aoqi@0 | 91 | |
aoqi@0 | 92 | // On Power6 test for section size. |
aoqi@0 | 93 | if (PowerArchitecturePPC64 == 6) { |
aoqi@0 | 94 | determine_section_size(); |
aoqi@0 | 95 | // TODO: PPC port } else { |
aoqi@0 | 96 | // TODO: PPC port PdScheduling::power6SectorSize = 0x20; |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | MaxVectorSize = 8; |
aoqi@0 | 100 | #endif |
aoqi@0 | 101 | |
aoqi@0 | 102 | // Create and print feature-string. |
aoqi@0 | 103 | char buf[(num_features+1) * 16]; // Max 16 chars per feature. |
aoqi@0 | 104 | jio_snprintf(buf, sizeof(buf), |
aoqi@0 | 105 | "ppc64%s%s%s%s%s%s%s%s", |
aoqi@0 | 106 | (has_fsqrt() ? " fsqrt" : ""), |
aoqi@0 | 107 | (has_isel() ? " isel" : ""), |
aoqi@0 | 108 | (has_lxarxeh() ? " lxarxeh" : ""), |
aoqi@0 | 109 | (has_cmpb() ? " cmpb" : ""), |
aoqi@0 | 110 | //(has_mftgpr()? " mftgpr" : ""), |
aoqi@0 | 111 | (has_popcntb() ? " popcntb" : ""), |
aoqi@0 | 112 | (has_popcntw() ? " popcntw" : ""), |
aoqi@0 | 113 | (has_fcfids() ? " fcfids" : ""), |
aoqi@0 | 114 | (has_vand() ? " vand" : "") |
aoqi@0 | 115 | // Make sure number of %s matches num_features! |
aoqi@0 | 116 | ); |
aoqi@0 | 117 | _features_str = strdup(buf); |
aoqi@0 | 118 | NOT_PRODUCT(if (Verbose) print_features();); |
aoqi@0 | 119 | |
aoqi@0 | 120 | // PPC64 supports 8-byte compare-exchange operations (see |
aoqi@0 | 121 | // Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr) |
aoqi@0 | 122 | // and 'atomic long memory ops' (see Unsafe_GetLongVolatile). |
aoqi@0 | 123 | _supports_cx8 = true; |
aoqi@0 | 124 | |
aoqi@0 | 125 | UseSSE = 0; // Only on x86 and x64 |
aoqi@0 | 126 | |
aoqi@0 | 127 | intx cache_line_size = _measured_cache_line_size; |
aoqi@0 | 128 | |
aoqi@0 | 129 | if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) AllocatePrefetchStyle = 1; |
aoqi@0 | 130 | |
aoqi@0 | 131 | if (AllocatePrefetchStyle == 4) { |
aoqi@0 | 132 | AllocatePrefetchStepSize = cache_line_size; // Need exact value. |
aoqi@0 | 133 | if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 12; // Use larger blocks by default. |
aoqi@0 | 134 | if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 2*cache_line_size; // Default is not defined? |
aoqi@0 | 135 | } else { |
aoqi@0 | 136 | if (cache_line_size > AllocatePrefetchStepSize) AllocatePrefetchStepSize = cache_line_size; |
aoqi@0 | 137 | if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 3; // Optimistic value. |
aoqi@0 | 138 | if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 3*cache_line_size; // Default is not defined? |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | assert(AllocatePrefetchLines > 0, "invalid value"); |
aoqi@0 | 142 | if (AllocatePrefetchLines < 1) // Set valid value in product VM. |
aoqi@0 | 143 | AllocatePrefetchLines = 1; // Conservative value. |
aoqi@0 | 144 | |
aoqi@0 | 145 | if (AllocatePrefetchStyle == 3 && AllocatePrefetchDistance < cache_line_size) |
aoqi@0 | 146 | AllocatePrefetchStyle = 1; // Fall back if inappropriate. |
aoqi@0 | 147 | |
aoqi@0 | 148 | assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive"); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | void VM_Version::print_features() { |
aoqi@0 | 152 | tty->print_cr("Version: %s cache_line_size = %d", cpu_features(), (int) get_cache_line_size()); |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | #ifdef COMPILER2 |
aoqi@0 | 156 | // Determine section size on power6: If section size is 8 instructions, |
aoqi@0 | 157 | // there should be a difference between the two testloops of ~15 %. If |
aoqi@0 | 158 | // no difference is detected the section is assumed to be 32 instructions. |
aoqi@0 | 159 | void VM_Version::determine_section_size() { |
aoqi@0 | 160 | |
aoqi@0 | 161 | int unroll = 80; |
aoqi@0 | 162 | |
aoqi@0 | 163 | const int code_size = (2* unroll * 32 + 100)*BytesPerInstWord; |
aoqi@0 | 164 | |
aoqi@0 | 165 | // Allocate space for the code. |
aoqi@0 | 166 | ResourceMark rm; |
aoqi@0 | 167 | CodeBuffer cb("detect_section_size", code_size, 0); |
aoqi@0 | 168 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 169 | |
aoqi@0 | 170 | uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 171 | // Emit code. |
aoqi@0 | 172 | void (*test1)() = (void(*)())(void *)a->function_entry(); |
aoqi@0 | 173 | |
aoqi@0 | 174 | Label l1; |
aoqi@0 | 175 | |
aoqi@0 | 176 | a->li(R4, 1); |
aoqi@0 | 177 | a->sldi(R4, R4, 28); |
aoqi@0 | 178 | a->b(l1); |
aoqi@0 | 179 | a->align(CodeEntryAlignment); |
aoqi@0 | 180 | |
aoqi@0 | 181 | a->bind(l1); |
aoqi@0 | 182 | |
aoqi@0 | 183 | for (int i = 0; i < unroll; i++) { |
aoqi@0 | 184 | // Schleife 1 |
aoqi@0 | 185 | // ------- sector 0 ------------ |
aoqi@0 | 186 | // ;; 0 |
aoqi@0 | 187 | a->nop(); // 1 |
aoqi@0 | 188 | a->fpnop0(); // 2 |
aoqi@0 | 189 | a->fpnop1(); // 3 |
aoqi@0 | 190 | a->addi(R4,R4, -1); // 4 |
aoqi@0 | 191 | |
aoqi@0 | 192 | // ;; 1 |
aoqi@0 | 193 | a->nop(); // 5 |
aoqi@0 | 194 | a->fmr(F6, F6); // 6 |
aoqi@0 | 195 | a->fmr(F7, F7); // 7 |
aoqi@0 | 196 | a->endgroup(); // 8 |
aoqi@0 | 197 | // ------- sector 8 ------------ |
aoqi@0 | 198 | |
aoqi@0 | 199 | // ;; 2 |
aoqi@0 | 200 | a->nop(); // 9 |
aoqi@0 | 201 | a->nop(); // 10 |
aoqi@0 | 202 | a->fmr(F8, F8); // 11 |
aoqi@0 | 203 | a->fmr(F9, F9); // 12 |
aoqi@0 | 204 | |
aoqi@0 | 205 | // ;; 3 |
aoqi@0 | 206 | a->nop(); // 13 |
aoqi@0 | 207 | a->fmr(F10, F10); // 14 |
aoqi@0 | 208 | a->fmr(F11, F11); // 15 |
aoqi@0 | 209 | a->endgroup(); // 16 |
aoqi@0 | 210 | // -------- sector 16 ------------- |
aoqi@0 | 211 | |
aoqi@0 | 212 | // ;; 4 |
aoqi@0 | 213 | a->nop(); // 17 |
aoqi@0 | 214 | a->nop(); // 18 |
aoqi@0 | 215 | a->fmr(F15, F15); // 19 |
aoqi@0 | 216 | a->fmr(F16, F16); // 20 |
aoqi@0 | 217 | |
aoqi@0 | 218 | // ;; 5 |
aoqi@0 | 219 | a->nop(); // 21 |
aoqi@0 | 220 | a->fmr(F17, F17); // 22 |
aoqi@0 | 221 | a->fmr(F18, F18); // 23 |
aoqi@0 | 222 | a->endgroup(); // 24 |
aoqi@0 | 223 | // ------- sector 24 ------------ |
aoqi@0 | 224 | |
aoqi@0 | 225 | // ;; 6 |
aoqi@0 | 226 | a->nop(); // 25 |
aoqi@0 | 227 | a->nop(); // 26 |
aoqi@0 | 228 | a->fmr(F19, F19); // 27 |
aoqi@0 | 229 | a->fmr(F20, F20); // 28 |
aoqi@0 | 230 | |
aoqi@0 | 231 | // ;; 7 |
aoqi@0 | 232 | a->nop(); // 29 |
aoqi@0 | 233 | a->fmr(F21, F21); // 30 |
aoqi@0 | 234 | a->fmr(F22, F22); // 31 |
aoqi@0 | 235 | a->brnop0(); // 32 |
aoqi@0 | 236 | |
aoqi@0 | 237 | // ------- sector 32 ------------ |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | // ;; 8 |
aoqi@0 | 241 | a->cmpdi(CCR0, R4, unroll); // 33 |
aoqi@0 | 242 | a->bge(CCR0, l1); // 34 |
aoqi@0 | 243 | a->blr(); |
aoqi@0 | 244 | |
aoqi@0 | 245 | // Emit code. |
aoqi@0 | 246 | void (*test2)() = (void(*)())(void *)a->function_entry(); |
aoqi@0 | 247 | // uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 248 | |
aoqi@0 | 249 | Label l2; |
aoqi@0 | 250 | |
aoqi@0 | 251 | a->li(R4, 1); |
aoqi@0 | 252 | a->sldi(R4, R4, 28); |
aoqi@0 | 253 | a->b(l2); |
aoqi@0 | 254 | a->align(CodeEntryAlignment); |
aoqi@0 | 255 | |
aoqi@0 | 256 | a->bind(l2); |
aoqi@0 | 257 | |
aoqi@0 | 258 | for (int i = 0; i < unroll; i++) { |
aoqi@0 | 259 | // Schleife 2 |
aoqi@0 | 260 | // ------- sector 0 ------------ |
aoqi@0 | 261 | // ;; 0 |
aoqi@0 | 262 | a->brnop0(); // 1 |
aoqi@0 | 263 | a->nop(); // 2 |
aoqi@0 | 264 | //a->cmpdi(CCR0, R4, unroll); |
aoqi@0 | 265 | a->fpnop0(); // 3 |
aoqi@0 | 266 | a->fpnop1(); // 4 |
aoqi@0 | 267 | a->addi(R4,R4, -1); // 5 |
aoqi@0 | 268 | |
aoqi@0 | 269 | // ;; 1 |
aoqi@0 | 270 | |
aoqi@0 | 271 | a->nop(); // 6 |
aoqi@0 | 272 | a->fmr(F6, F6); // 7 |
aoqi@0 | 273 | a->fmr(F7, F7); // 8 |
aoqi@0 | 274 | // ------- sector 8 --------------- |
aoqi@0 | 275 | |
aoqi@0 | 276 | // ;; 2 |
aoqi@0 | 277 | a->endgroup(); // 9 |
aoqi@0 | 278 | |
aoqi@0 | 279 | // ;; 3 |
aoqi@0 | 280 | a->nop(); // 10 |
aoqi@0 | 281 | a->nop(); // 11 |
aoqi@0 | 282 | a->fmr(F8, F8); // 12 |
aoqi@0 | 283 | |
aoqi@0 | 284 | // ;; 4 |
aoqi@0 | 285 | a->fmr(F9, F9); // 13 |
aoqi@0 | 286 | a->nop(); // 14 |
aoqi@0 | 287 | a->fmr(F10, F10); // 15 |
aoqi@0 | 288 | |
aoqi@0 | 289 | // ;; 5 |
aoqi@0 | 290 | a->fmr(F11, F11); // 16 |
aoqi@0 | 291 | // -------- sector 16 ------------- |
aoqi@0 | 292 | |
aoqi@0 | 293 | // ;; 6 |
aoqi@0 | 294 | a->endgroup(); // 17 |
aoqi@0 | 295 | |
aoqi@0 | 296 | // ;; 7 |
aoqi@0 | 297 | a->nop(); // 18 |
aoqi@0 | 298 | a->nop(); // 19 |
aoqi@0 | 299 | a->fmr(F15, F15); // 20 |
aoqi@0 | 300 | |
aoqi@0 | 301 | // ;; 8 |
aoqi@0 | 302 | a->fmr(F16, F16); // 21 |
aoqi@0 | 303 | a->nop(); // 22 |
aoqi@0 | 304 | a->fmr(F17, F17); // 23 |
aoqi@0 | 305 | |
aoqi@0 | 306 | // ;; 9 |
aoqi@0 | 307 | a->fmr(F18, F18); // 24 |
aoqi@0 | 308 | // -------- sector 24 ------------- |
aoqi@0 | 309 | |
aoqi@0 | 310 | // ;; 10 |
aoqi@0 | 311 | a->endgroup(); // 25 |
aoqi@0 | 312 | |
aoqi@0 | 313 | // ;; 11 |
aoqi@0 | 314 | a->nop(); // 26 |
aoqi@0 | 315 | a->nop(); // 27 |
aoqi@0 | 316 | a->fmr(F19, F19); // 28 |
aoqi@0 | 317 | |
aoqi@0 | 318 | // ;; 12 |
aoqi@0 | 319 | a->fmr(F20, F20); // 29 |
aoqi@0 | 320 | a->nop(); // 30 |
aoqi@0 | 321 | a->fmr(F21, F21); // 31 |
aoqi@0 | 322 | |
aoqi@0 | 323 | // ;; 13 |
aoqi@0 | 324 | a->fmr(F22, F22); // 32 |
aoqi@0 | 325 | } |
aoqi@0 | 326 | |
aoqi@0 | 327 | // -------- sector 32 ------------- |
aoqi@0 | 328 | // ;; 14 |
aoqi@0 | 329 | a->cmpdi(CCR0, R4, unroll); // 33 |
aoqi@0 | 330 | a->bge(CCR0, l2); // 34 |
aoqi@0 | 331 | |
aoqi@0 | 332 | a->blr(); |
aoqi@0 | 333 | uint32_t *code_end = (uint32_t *)a->pc(); |
aoqi@0 | 334 | a->flush(); |
aoqi@0 | 335 | |
aoqi@0 | 336 | double loop1_seconds,loop2_seconds, rel_diff; |
aoqi@0 | 337 | uint64_t start1, stop1; |
aoqi@0 | 338 | |
aoqi@0 | 339 | start1 = os::current_thread_cpu_time(false); |
aoqi@0 | 340 | (*test1)(); |
aoqi@0 | 341 | stop1 = os::current_thread_cpu_time(false); |
aoqi@0 | 342 | loop1_seconds = (stop1- start1) / (1000 *1000 *1000.0); |
aoqi@0 | 343 | |
aoqi@0 | 344 | |
aoqi@0 | 345 | start1 = os::current_thread_cpu_time(false); |
aoqi@0 | 346 | (*test2)(); |
aoqi@0 | 347 | stop1 = os::current_thread_cpu_time(false); |
aoqi@0 | 348 | |
aoqi@0 | 349 | loop2_seconds = (stop1 - start1) / (1000 *1000 *1000.0); |
aoqi@0 | 350 | |
aoqi@0 | 351 | rel_diff = (loop2_seconds - loop1_seconds) / loop1_seconds *100; |
aoqi@0 | 352 | |
aoqi@0 | 353 | if (PrintAssembly) { |
aoqi@0 | 354 | ttyLocker ttyl; |
aoqi@0 | 355 | tty->print_cr("Decoding section size detection stub at " INTPTR_FORMAT " before execution:", code); |
aoqi@0 | 356 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 357 | tty->print_cr("Time loop1 :%f", loop1_seconds); |
aoqi@0 | 358 | tty->print_cr("Time loop2 :%f", loop2_seconds); |
aoqi@0 | 359 | tty->print_cr("(time2 - time1) / time1 = %f %%", rel_diff); |
aoqi@0 | 360 | |
aoqi@0 | 361 | if (rel_diff > 12.0) { |
aoqi@0 | 362 | tty->print_cr("Section Size 8 Instructions"); |
aoqi@0 | 363 | } else{ |
aoqi@0 | 364 | tty->print_cr("Section Size 32 Instructions or Power5"); |
aoqi@0 | 365 | } |
aoqi@0 | 366 | } |
aoqi@0 | 367 | |
aoqi@0 | 368 | #if 0 // TODO: PPC port |
aoqi@0 | 369 | // Set sector size (if not set explicitly). |
aoqi@0 | 370 | if (FLAG_IS_DEFAULT(Power6SectorSize128PPC64)) { |
aoqi@0 | 371 | if (rel_diff > 12.0) { |
aoqi@0 | 372 | PdScheduling::power6SectorSize = 0x20; |
aoqi@0 | 373 | } else { |
aoqi@0 | 374 | PdScheduling::power6SectorSize = 0x80; |
aoqi@0 | 375 | } |
aoqi@0 | 376 | } else if (Power6SectorSize128PPC64) { |
aoqi@0 | 377 | PdScheduling::power6SectorSize = 0x80; |
aoqi@0 | 378 | } else { |
aoqi@0 | 379 | PdScheduling::power6SectorSize = 0x20; |
aoqi@0 | 380 | } |
aoqi@0 | 381 | #endif |
aoqi@0 | 382 | if (UsePower6SchedulerPPC64) Unimplemented(); |
aoqi@0 | 383 | } |
aoqi@0 | 384 | #endif // COMPILER2 |
aoqi@0 | 385 | |
aoqi@0 | 386 | void VM_Version::determine_features() { |
aoqi@0 | 387 | #if defined(ABI_ELFv2) |
aoqi@0 | 388 | const int code_size = (num_features+1+2*7)*BytesPerInstWord; // TODO(asmundak): calculation is incorrect. |
aoqi@0 | 389 | #else |
aoqi@0 | 390 | // 7 InstWords for each call (function descriptor + blr instruction). |
aoqi@0 | 391 | const int code_size = (num_features+1+2*7)*BytesPerInstWord; |
aoqi@0 | 392 | #endif |
aoqi@0 | 393 | int features = 0; |
aoqi@0 | 394 | |
aoqi@0 | 395 | // create test area |
aoqi@0 | 396 | enum { BUFFER_SIZE = 2*4*K }; // Needs to be >=2* max cache line size (cache line size can't exceed min page size). |
aoqi@0 | 397 | char test_area[BUFFER_SIZE]; |
aoqi@0 | 398 | char *mid_of_test_area = &test_area[BUFFER_SIZE>>1]; |
aoqi@0 | 399 | |
aoqi@0 | 400 | // Allocate space for the code. |
aoqi@0 | 401 | ResourceMark rm; |
aoqi@0 | 402 | CodeBuffer cb("detect_cpu_features", code_size, 0); |
aoqi@0 | 403 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 404 | |
aoqi@0 | 405 | // Must be set to true so we can generate the test code. |
aoqi@0 | 406 | _features = VM_Version::all_features_m; |
aoqi@0 | 407 | |
aoqi@0 | 408 | // Emit code. |
aoqi@0 | 409 | void (*test)(address addr, uint64_t offset)=(void(*)(address addr, uint64_t offset))(void *)a->function_entry(); |
aoqi@0 | 410 | uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 411 | // Don't use R0 in ldarx. |
aoqi@0 | 412 | // Keep R3_ARG1 unmodified, it contains &field (see below). |
aoqi@0 | 413 | // Keep R4_ARG2 unmodified, it contains offset = 0 (see below). |
aoqi@0 | 414 | a->fsqrt(F3, F4); // code[0] -> fsqrt_m |
aoqi@0 | 415 | a->fsqrts(F3, F4); // code[1] -> fsqrts_m |
aoqi@0 | 416 | a->isel(R7, R5, R6, 0); // code[2] -> isel_m |
aoqi@0 | 417 | a->ldarx_unchecked(R7, R3_ARG1, R4_ARG2, 1); // code[3] -> lxarx_m |
aoqi@0 | 418 | a->cmpb(R7, R5, R6); // code[4] -> bcmp |
aoqi@0 | 419 | //a->mftgpr(R7, F3); // code[5] -> mftgpr |
aoqi@0 | 420 | a->popcntb(R7, R5); // code[6] -> popcntb |
aoqi@0 | 421 | a->popcntw(R7, R5); // code[7] -> popcntw |
aoqi@0 | 422 | a->fcfids(F3, F4); // code[8] -> fcfids |
aoqi@0 | 423 | a->vand(VR0, VR0, VR0); // code[9] -> vand |
aoqi@0 | 424 | a->blr(); |
aoqi@0 | 425 | |
aoqi@0 | 426 | // Emit function to set one cache line to zero. Emit function descriptor and get pointer to it. |
aoqi@0 | 427 | void (*zero_cacheline_func_ptr)(char*) = (void(*)(char*))(void *)a->function_entry(); |
aoqi@0 | 428 | a->dcbz(R3_ARG1); // R3_ARG1 = addr |
aoqi@0 | 429 | a->blr(); |
aoqi@0 | 430 | |
aoqi@0 | 431 | uint32_t *code_end = (uint32_t *)a->pc(); |
aoqi@0 | 432 | a->flush(); |
aoqi@0 | 433 | _features = VM_Version::unknown_m; |
aoqi@0 | 434 | |
aoqi@0 | 435 | // Print the detection code. |
aoqi@0 | 436 | if (PrintAssembly) { |
aoqi@0 | 437 | ttyLocker ttyl; |
aoqi@0 | 438 | tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " before execution:", code); |
aoqi@0 | 439 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 440 | } |
aoqi@0 | 441 | |
aoqi@0 | 442 | // Measure cache line size. |
aoqi@0 | 443 | memset(test_area, 0xFF, BUFFER_SIZE); // Fill test area with 0xFF. |
aoqi@0 | 444 | (*zero_cacheline_func_ptr)(mid_of_test_area); // Call function which executes dcbz to the middle. |
aoqi@0 | 445 | int count = 0; // count zeroed bytes |
aoqi@0 | 446 | for (int i = 0; i < BUFFER_SIZE; i++) if (test_area[i] == 0) count++; |
aoqi@0 | 447 | guarantee(is_power_of_2(count), "cache line size needs to be a power of 2"); |
aoqi@0 | 448 | _measured_cache_line_size = count; |
aoqi@0 | 449 | |
aoqi@0 | 450 | // Execute code. Illegal instructions will be replaced by 0 in the signal handler. |
aoqi@0 | 451 | VM_Version::_is_determine_features_test_running = true; |
aoqi@0 | 452 | (*test)((address)mid_of_test_area, (uint64_t)0); |
aoqi@0 | 453 | VM_Version::_is_determine_features_test_running = false; |
aoqi@0 | 454 | |
aoqi@0 | 455 | // determine which instructions are legal. |
aoqi@0 | 456 | int feature_cntr = 0; |
aoqi@0 | 457 | if (code[feature_cntr++]) features |= fsqrt_m; |
aoqi@0 | 458 | if (code[feature_cntr++]) features |= fsqrts_m; |
aoqi@0 | 459 | if (code[feature_cntr++]) features |= isel_m; |
aoqi@0 | 460 | if (code[feature_cntr++]) features |= lxarxeh_m; |
aoqi@0 | 461 | if (code[feature_cntr++]) features |= cmpb_m; |
aoqi@0 | 462 | //if(code[feature_cntr++])features |= mftgpr_m; |
aoqi@0 | 463 | if (code[feature_cntr++]) features |= popcntb_m; |
aoqi@0 | 464 | if (code[feature_cntr++]) features |= popcntw_m; |
aoqi@0 | 465 | if (code[feature_cntr++]) features |= fcfids_m; |
aoqi@0 | 466 | if (code[feature_cntr++]) features |= vand_m; |
aoqi@0 | 467 | |
aoqi@0 | 468 | // Print the detection code. |
aoqi@0 | 469 | if (PrintAssembly) { |
aoqi@0 | 470 | ttyLocker ttyl; |
aoqi@0 | 471 | tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " after execution:", code); |
aoqi@0 | 472 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 473 | } |
aoqi@0 | 474 | |
aoqi@0 | 475 | _features = features; |
aoqi@0 | 476 | } |
aoqi@0 | 477 | |
aoqi@0 | 478 | |
aoqi@0 | 479 | static int saved_features = 0; |
aoqi@0 | 480 | |
aoqi@0 | 481 | void VM_Version::allow_all() { |
aoqi@0 | 482 | saved_features = _features; |
aoqi@0 | 483 | _features = all_features_m; |
aoqi@0 | 484 | } |
aoqi@0 | 485 | |
aoqi@0 | 486 | void VM_Version::revert() { |
aoqi@0 | 487 | _features = saved_features; |
aoqi@0 | 488 | } |