Thu, 12 Oct 2017 21:27:07 +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"); |
goetz@7424 | 142 | if (AllocatePrefetchLines < 1) { // Set valid value in product VM. |
aoqi@0 | 143 | AllocatePrefetchLines = 1; // Conservative value. |
goetz@7424 | 144 | } |
aoqi@0 | 145 | |
goetz@7424 | 146 | if (AllocatePrefetchStyle == 3 && AllocatePrefetchDistance < cache_line_size) { |
aoqi@0 | 147 | AllocatePrefetchStyle = 1; // Fall back if inappropriate. |
goetz@7424 | 148 | } |
aoqi@0 | 149 | |
aoqi@0 | 150 | assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive"); |
goetz@7424 | 151 | |
goetz@7424 | 152 | if (UseCRC32Intrinsics) { |
goetz@7424 | 153 | if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics)) |
goetz@7424 | 154 | warning("CRC32 intrinsics are not available on this CPU"); |
goetz@7424 | 155 | FLAG_SET_DEFAULT(UseCRC32Intrinsics, false); |
goetz@7424 | 156 | } |
goetz@7424 | 157 | |
goetz@7424 | 158 | // The AES intrinsic stubs require AES instruction support. |
goetz@7424 | 159 | if (UseAES) { |
goetz@7424 | 160 | warning("AES instructions are not available on this CPU"); |
goetz@7424 | 161 | FLAG_SET_DEFAULT(UseAES, false); |
goetz@7424 | 162 | } |
goetz@7424 | 163 | if (UseAESIntrinsics) { |
goetz@7424 | 164 | if (!FLAG_IS_DEFAULT(UseAESIntrinsics)) |
goetz@7424 | 165 | warning("AES intrinsics are not available on this CPU"); |
goetz@7424 | 166 | FLAG_SET_DEFAULT(UseAESIntrinsics, false); |
goetz@7424 | 167 | } |
goetz@7424 | 168 | |
goetz@7424 | 169 | if (UseSHA) { |
goetz@7424 | 170 | warning("SHA instructions are not available on this CPU"); |
goetz@7424 | 171 | FLAG_SET_DEFAULT(UseSHA, false); |
goetz@7424 | 172 | } |
goetz@7424 | 173 | if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) { |
goetz@7424 | 174 | warning("SHA intrinsics are not available on this CPU"); |
goetz@7424 | 175 | FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); |
goetz@7424 | 176 | FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); |
goetz@7424 | 177 | FLAG_SET_DEFAULT(UseSHA512Intrinsics, false); |
goetz@7424 | 178 | } |
goetz@7424 | 179 | |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | void VM_Version::print_features() { |
aoqi@0 | 183 | tty->print_cr("Version: %s cache_line_size = %d", cpu_features(), (int) get_cache_line_size()); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | |
aoqi@0 | 186 | #ifdef COMPILER2 |
aoqi@0 | 187 | // Determine section size on power6: If section size is 8 instructions, |
aoqi@0 | 188 | // there should be a difference between the two testloops of ~15 %. If |
aoqi@0 | 189 | // no difference is detected the section is assumed to be 32 instructions. |
aoqi@0 | 190 | void VM_Version::determine_section_size() { |
aoqi@0 | 191 | |
aoqi@0 | 192 | int unroll = 80; |
aoqi@0 | 193 | |
aoqi@0 | 194 | const int code_size = (2* unroll * 32 + 100)*BytesPerInstWord; |
aoqi@0 | 195 | |
aoqi@0 | 196 | // Allocate space for the code. |
aoqi@0 | 197 | ResourceMark rm; |
aoqi@0 | 198 | CodeBuffer cb("detect_section_size", code_size, 0); |
aoqi@0 | 199 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 200 | |
aoqi@0 | 201 | uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 202 | // Emit code. |
aoqi@0 | 203 | void (*test1)() = (void(*)())(void *)a->function_entry(); |
aoqi@0 | 204 | |
aoqi@0 | 205 | Label l1; |
aoqi@0 | 206 | |
aoqi@0 | 207 | a->li(R4, 1); |
aoqi@0 | 208 | a->sldi(R4, R4, 28); |
aoqi@0 | 209 | a->b(l1); |
aoqi@0 | 210 | a->align(CodeEntryAlignment); |
aoqi@0 | 211 | |
aoqi@0 | 212 | a->bind(l1); |
aoqi@0 | 213 | |
aoqi@0 | 214 | for (int i = 0; i < unroll; i++) { |
aoqi@0 | 215 | // Schleife 1 |
aoqi@0 | 216 | // ------- sector 0 ------------ |
aoqi@0 | 217 | // ;; 0 |
aoqi@0 | 218 | a->nop(); // 1 |
aoqi@0 | 219 | a->fpnop0(); // 2 |
aoqi@0 | 220 | a->fpnop1(); // 3 |
aoqi@0 | 221 | a->addi(R4,R4, -1); // 4 |
aoqi@0 | 222 | |
aoqi@0 | 223 | // ;; 1 |
aoqi@0 | 224 | a->nop(); // 5 |
aoqi@0 | 225 | a->fmr(F6, F6); // 6 |
aoqi@0 | 226 | a->fmr(F7, F7); // 7 |
aoqi@0 | 227 | a->endgroup(); // 8 |
aoqi@0 | 228 | // ------- sector 8 ------------ |
aoqi@0 | 229 | |
aoqi@0 | 230 | // ;; 2 |
aoqi@0 | 231 | a->nop(); // 9 |
aoqi@0 | 232 | a->nop(); // 10 |
aoqi@0 | 233 | a->fmr(F8, F8); // 11 |
aoqi@0 | 234 | a->fmr(F9, F9); // 12 |
aoqi@0 | 235 | |
aoqi@0 | 236 | // ;; 3 |
aoqi@0 | 237 | a->nop(); // 13 |
aoqi@0 | 238 | a->fmr(F10, F10); // 14 |
aoqi@0 | 239 | a->fmr(F11, F11); // 15 |
aoqi@0 | 240 | a->endgroup(); // 16 |
aoqi@0 | 241 | // -------- sector 16 ------------- |
aoqi@0 | 242 | |
aoqi@0 | 243 | // ;; 4 |
aoqi@0 | 244 | a->nop(); // 17 |
aoqi@0 | 245 | a->nop(); // 18 |
aoqi@0 | 246 | a->fmr(F15, F15); // 19 |
aoqi@0 | 247 | a->fmr(F16, F16); // 20 |
aoqi@0 | 248 | |
aoqi@0 | 249 | // ;; 5 |
aoqi@0 | 250 | a->nop(); // 21 |
aoqi@0 | 251 | a->fmr(F17, F17); // 22 |
aoqi@0 | 252 | a->fmr(F18, F18); // 23 |
aoqi@0 | 253 | a->endgroup(); // 24 |
aoqi@0 | 254 | // ------- sector 24 ------------ |
aoqi@0 | 255 | |
aoqi@0 | 256 | // ;; 6 |
aoqi@0 | 257 | a->nop(); // 25 |
aoqi@0 | 258 | a->nop(); // 26 |
aoqi@0 | 259 | a->fmr(F19, F19); // 27 |
aoqi@0 | 260 | a->fmr(F20, F20); // 28 |
aoqi@0 | 261 | |
aoqi@0 | 262 | // ;; 7 |
aoqi@0 | 263 | a->nop(); // 29 |
aoqi@0 | 264 | a->fmr(F21, F21); // 30 |
aoqi@0 | 265 | a->fmr(F22, F22); // 31 |
aoqi@0 | 266 | a->brnop0(); // 32 |
aoqi@0 | 267 | |
aoqi@0 | 268 | // ------- sector 32 ------------ |
aoqi@0 | 269 | } |
aoqi@0 | 270 | |
aoqi@0 | 271 | // ;; 8 |
aoqi@0 | 272 | a->cmpdi(CCR0, R4, unroll); // 33 |
aoqi@0 | 273 | a->bge(CCR0, l1); // 34 |
aoqi@0 | 274 | a->blr(); |
aoqi@0 | 275 | |
aoqi@0 | 276 | // Emit code. |
aoqi@0 | 277 | void (*test2)() = (void(*)())(void *)a->function_entry(); |
aoqi@0 | 278 | // uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 279 | |
aoqi@0 | 280 | Label l2; |
aoqi@0 | 281 | |
aoqi@0 | 282 | a->li(R4, 1); |
aoqi@0 | 283 | a->sldi(R4, R4, 28); |
aoqi@0 | 284 | a->b(l2); |
aoqi@0 | 285 | a->align(CodeEntryAlignment); |
aoqi@0 | 286 | |
aoqi@0 | 287 | a->bind(l2); |
aoqi@0 | 288 | |
aoqi@0 | 289 | for (int i = 0; i < unroll; i++) { |
aoqi@0 | 290 | // Schleife 2 |
aoqi@0 | 291 | // ------- sector 0 ------------ |
aoqi@0 | 292 | // ;; 0 |
aoqi@0 | 293 | a->brnop0(); // 1 |
aoqi@0 | 294 | a->nop(); // 2 |
aoqi@0 | 295 | //a->cmpdi(CCR0, R4, unroll); |
aoqi@0 | 296 | a->fpnop0(); // 3 |
aoqi@0 | 297 | a->fpnop1(); // 4 |
aoqi@0 | 298 | a->addi(R4,R4, -1); // 5 |
aoqi@0 | 299 | |
aoqi@0 | 300 | // ;; 1 |
aoqi@0 | 301 | |
aoqi@0 | 302 | a->nop(); // 6 |
aoqi@0 | 303 | a->fmr(F6, F6); // 7 |
aoqi@0 | 304 | a->fmr(F7, F7); // 8 |
aoqi@0 | 305 | // ------- sector 8 --------------- |
aoqi@0 | 306 | |
aoqi@0 | 307 | // ;; 2 |
aoqi@0 | 308 | a->endgroup(); // 9 |
aoqi@0 | 309 | |
aoqi@0 | 310 | // ;; 3 |
aoqi@0 | 311 | a->nop(); // 10 |
aoqi@0 | 312 | a->nop(); // 11 |
aoqi@0 | 313 | a->fmr(F8, F8); // 12 |
aoqi@0 | 314 | |
aoqi@0 | 315 | // ;; 4 |
aoqi@0 | 316 | a->fmr(F9, F9); // 13 |
aoqi@0 | 317 | a->nop(); // 14 |
aoqi@0 | 318 | a->fmr(F10, F10); // 15 |
aoqi@0 | 319 | |
aoqi@0 | 320 | // ;; 5 |
aoqi@0 | 321 | a->fmr(F11, F11); // 16 |
aoqi@0 | 322 | // -------- sector 16 ------------- |
aoqi@0 | 323 | |
aoqi@0 | 324 | // ;; 6 |
aoqi@0 | 325 | a->endgroup(); // 17 |
aoqi@0 | 326 | |
aoqi@0 | 327 | // ;; 7 |
aoqi@0 | 328 | a->nop(); // 18 |
aoqi@0 | 329 | a->nop(); // 19 |
aoqi@0 | 330 | a->fmr(F15, F15); // 20 |
aoqi@0 | 331 | |
aoqi@0 | 332 | // ;; 8 |
aoqi@0 | 333 | a->fmr(F16, F16); // 21 |
aoqi@0 | 334 | a->nop(); // 22 |
aoqi@0 | 335 | a->fmr(F17, F17); // 23 |
aoqi@0 | 336 | |
aoqi@0 | 337 | // ;; 9 |
aoqi@0 | 338 | a->fmr(F18, F18); // 24 |
aoqi@0 | 339 | // -------- sector 24 ------------- |
aoqi@0 | 340 | |
aoqi@0 | 341 | // ;; 10 |
aoqi@0 | 342 | a->endgroup(); // 25 |
aoqi@0 | 343 | |
aoqi@0 | 344 | // ;; 11 |
aoqi@0 | 345 | a->nop(); // 26 |
aoqi@0 | 346 | a->nop(); // 27 |
aoqi@0 | 347 | a->fmr(F19, F19); // 28 |
aoqi@0 | 348 | |
aoqi@0 | 349 | // ;; 12 |
aoqi@0 | 350 | a->fmr(F20, F20); // 29 |
aoqi@0 | 351 | a->nop(); // 30 |
aoqi@0 | 352 | a->fmr(F21, F21); // 31 |
aoqi@0 | 353 | |
aoqi@0 | 354 | // ;; 13 |
aoqi@0 | 355 | a->fmr(F22, F22); // 32 |
aoqi@0 | 356 | } |
aoqi@0 | 357 | |
aoqi@0 | 358 | // -------- sector 32 ------------- |
aoqi@0 | 359 | // ;; 14 |
aoqi@0 | 360 | a->cmpdi(CCR0, R4, unroll); // 33 |
aoqi@0 | 361 | a->bge(CCR0, l2); // 34 |
aoqi@0 | 362 | |
aoqi@0 | 363 | a->blr(); |
aoqi@0 | 364 | uint32_t *code_end = (uint32_t *)a->pc(); |
aoqi@0 | 365 | a->flush(); |
aoqi@0 | 366 | |
aoqi@0 | 367 | double loop1_seconds,loop2_seconds, rel_diff; |
aoqi@0 | 368 | uint64_t start1, stop1; |
aoqi@0 | 369 | |
aoqi@0 | 370 | start1 = os::current_thread_cpu_time(false); |
aoqi@0 | 371 | (*test1)(); |
aoqi@0 | 372 | stop1 = os::current_thread_cpu_time(false); |
aoqi@0 | 373 | loop1_seconds = (stop1- start1) / (1000 *1000 *1000.0); |
aoqi@0 | 374 | |
aoqi@0 | 375 | |
aoqi@0 | 376 | start1 = os::current_thread_cpu_time(false); |
aoqi@0 | 377 | (*test2)(); |
aoqi@0 | 378 | stop1 = os::current_thread_cpu_time(false); |
aoqi@0 | 379 | |
aoqi@0 | 380 | loop2_seconds = (stop1 - start1) / (1000 *1000 *1000.0); |
aoqi@0 | 381 | |
aoqi@0 | 382 | rel_diff = (loop2_seconds - loop1_seconds) / loop1_seconds *100; |
aoqi@0 | 383 | |
aoqi@0 | 384 | if (PrintAssembly) { |
aoqi@0 | 385 | ttyLocker ttyl; |
coleenp@7358 | 386 | tty->print_cr("Decoding section size detection stub at " INTPTR_FORMAT " before execution:", p2i(code)); |
aoqi@0 | 387 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 388 | tty->print_cr("Time loop1 :%f", loop1_seconds); |
aoqi@0 | 389 | tty->print_cr("Time loop2 :%f", loop2_seconds); |
aoqi@0 | 390 | tty->print_cr("(time2 - time1) / time1 = %f %%", rel_diff); |
aoqi@0 | 391 | |
aoqi@0 | 392 | if (rel_diff > 12.0) { |
aoqi@0 | 393 | tty->print_cr("Section Size 8 Instructions"); |
aoqi@0 | 394 | } else{ |
aoqi@0 | 395 | tty->print_cr("Section Size 32 Instructions or Power5"); |
aoqi@0 | 396 | } |
aoqi@0 | 397 | } |
aoqi@0 | 398 | |
aoqi@0 | 399 | #if 0 // TODO: PPC port |
aoqi@0 | 400 | // Set sector size (if not set explicitly). |
aoqi@0 | 401 | if (FLAG_IS_DEFAULT(Power6SectorSize128PPC64)) { |
aoqi@0 | 402 | if (rel_diff > 12.0) { |
aoqi@0 | 403 | PdScheduling::power6SectorSize = 0x20; |
aoqi@0 | 404 | } else { |
aoqi@0 | 405 | PdScheduling::power6SectorSize = 0x80; |
aoqi@0 | 406 | } |
aoqi@0 | 407 | } else if (Power6SectorSize128PPC64) { |
aoqi@0 | 408 | PdScheduling::power6SectorSize = 0x80; |
aoqi@0 | 409 | } else { |
aoqi@0 | 410 | PdScheduling::power6SectorSize = 0x20; |
aoqi@0 | 411 | } |
aoqi@0 | 412 | #endif |
aoqi@0 | 413 | if (UsePower6SchedulerPPC64) Unimplemented(); |
aoqi@0 | 414 | } |
aoqi@0 | 415 | #endif // COMPILER2 |
aoqi@0 | 416 | |
aoqi@0 | 417 | void VM_Version::determine_features() { |
aoqi@0 | 418 | #if defined(ABI_ELFv2) |
aoqi@0 | 419 | const int code_size = (num_features+1+2*7)*BytesPerInstWord; // TODO(asmundak): calculation is incorrect. |
aoqi@0 | 420 | #else |
aoqi@0 | 421 | // 7 InstWords for each call (function descriptor + blr instruction). |
aoqi@0 | 422 | const int code_size = (num_features+1+2*7)*BytesPerInstWord; |
aoqi@0 | 423 | #endif |
aoqi@0 | 424 | int features = 0; |
aoqi@0 | 425 | |
aoqi@0 | 426 | // create test area |
aoqi@0 | 427 | 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 | 428 | char test_area[BUFFER_SIZE]; |
aoqi@0 | 429 | char *mid_of_test_area = &test_area[BUFFER_SIZE>>1]; |
aoqi@0 | 430 | |
aoqi@0 | 431 | // Allocate space for the code. |
aoqi@0 | 432 | ResourceMark rm; |
aoqi@0 | 433 | CodeBuffer cb("detect_cpu_features", code_size, 0); |
aoqi@0 | 434 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 435 | |
aoqi@0 | 436 | // Must be set to true so we can generate the test code. |
aoqi@0 | 437 | _features = VM_Version::all_features_m; |
aoqi@0 | 438 | |
aoqi@0 | 439 | // Emit code. |
aoqi@0 | 440 | void (*test)(address addr, uint64_t offset)=(void(*)(address addr, uint64_t offset))(void *)a->function_entry(); |
aoqi@0 | 441 | uint32_t *code = (uint32_t *)a->pc(); |
aoqi@0 | 442 | // Don't use R0 in ldarx. |
aoqi@0 | 443 | // Keep R3_ARG1 unmodified, it contains &field (see below). |
aoqi@0 | 444 | // Keep R4_ARG2 unmodified, it contains offset = 0 (see below). |
aoqi@0 | 445 | a->fsqrt(F3, F4); // code[0] -> fsqrt_m |
aoqi@0 | 446 | a->fsqrts(F3, F4); // code[1] -> fsqrts_m |
aoqi@0 | 447 | a->isel(R7, R5, R6, 0); // code[2] -> isel_m |
aoqi@0 | 448 | a->ldarx_unchecked(R7, R3_ARG1, R4_ARG2, 1); // code[3] -> lxarx_m |
aoqi@0 | 449 | a->cmpb(R7, R5, R6); // code[4] -> bcmp |
aoqi@0 | 450 | //a->mftgpr(R7, F3); // code[5] -> mftgpr |
aoqi@0 | 451 | a->popcntb(R7, R5); // code[6] -> popcntb |
aoqi@0 | 452 | a->popcntw(R7, R5); // code[7] -> popcntw |
aoqi@0 | 453 | a->fcfids(F3, F4); // code[8] -> fcfids |
aoqi@0 | 454 | a->vand(VR0, VR0, VR0); // code[9] -> vand |
aoqi@0 | 455 | a->blr(); |
aoqi@0 | 456 | |
aoqi@0 | 457 | // Emit function to set one cache line to zero. Emit function descriptor and get pointer to it. |
aoqi@0 | 458 | void (*zero_cacheline_func_ptr)(char*) = (void(*)(char*))(void *)a->function_entry(); |
aoqi@0 | 459 | a->dcbz(R3_ARG1); // R3_ARG1 = addr |
aoqi@0 | 460 | a->blr(); |
aoqi@0 | 461 | |
aoqi@0 | 462 | uint32_t *code_end = (uint32_t *)a->pc(); |
aoqi@0 | 463 | a->flush(); |
aoqi@0 | 464 | _features = VM_Version::unknown_m; |
aoqi@0 | 465 | |
aoqi@0 | 466 | // Print the detection code. |
aoqi@0 | 467 | if (PrintAssembly) { |
aoqi@0 | 468 | ttyLocker ttyl; |
coleenp@7358 | 469 | tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " before execution:", p2i(code)); |
aoqi@0 | 470 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 471 | } |
aoqi@0 | 472 | |
aoqi@0 | 473 | // Measure cache line size. |
aoqi@0 | 474 | memset(test_area, 0xFF, BUFFER_SIZE); // Fill test area with 0xFF. |
aoqi@0 | 475 | (*zero_cacheline_func_ptr)(mid_of_test_area); // Call function which executes dcbz to the middle. |
aoqi@0 | 476 | int count = 0; // count zeroed bytes |
aoqi@0 | 477 | for (int i = 0; i < BUFFER_SIZE; i++) if (test_area[i] == 0) count++; |
aoqi@0 | 478 | guarantee(is_power_of_2(count), "cache line size needs to be a power of 2"); |
aoqi@0 | 479 | _measured_cache_line_size = count; |
aoqi@0 | 480 | |
aoqi@0 | 481 | // Execute code. Illegal instructions will be replaced by 0 in the signal handler. |
aoqi@0 | 482 | VM_Version::_is_determine_features_test_running = true; |
aoqi@0 | 483 | (*test)((address)mid_of_test_area, (uint64_t)0); |
aoqi@0 | 484 | VM_Version::_is_determine_features_test_running = false; |
aoqi@0 | 485 | |
aoqi@0 | 486 | // determine which instructions are legal. |
aoqi@0 | 487 | int feature_cntr = 0; |
aoqi@0 | 488 | if (code[feature_cntr++]) features |= fsqrt_m; |
aoqi@0 | 489 | if (code[feature_cntr++]) features |= fsqrts_m; |
aoqi@0 | 490 | if (code[feature_cntr++]) features |= isel_m; |
aoqi@0 | 491 | if (code[feature_cntr++]) features |= lxarxeh_m; |
aoqi@0 | 492 | if (code[feature_cntr++]) features |= cmpb_m; |
aoqi@0 | 493 | //if(code[feature_cntr++])features |= mftgpr_m; |
aoqi@0 | 494 | if (code[feature_cntr++]) features |= popcntb_m; |
aoqi@0 | 495 | if (code[feature_cntr++]) features |= popcntw_m; |
aoqi@0 | 496 | if (code[feature_cntr++]) features |= fcfids_m; |
aoqi@0 | 497 | if (code[feature_cntr++]) features |= vand_m; |
aoqi@0 | 498 | |
aoqi@0 | 499 | // Print the detection code. |
aoqi@0 | 500 | if (PrintAssembly) { |
aoqi@0 | 501 | ttyLocker ttyl; |
coleenp@7358 | 502 | tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " after execution:", p2i(code)); |
aoqi@0 | 503 | Disassembler::decode((u_char*)code, (u_char*)code_end, tty); |
aoqi@0 | 504 | } |
aoqi@0 | 505 | |
aoqi@0 | 506 | _features = features; |
aoqi@0 | 507 | } |
aoqi@0 | 508 | |
aoqi@0 | 509 | |
aoqi@0 | 510 | static int saved_features = 0; |
aoqi@0 | 511 | |
aoqi@0 | 512 | void VM_Version::allow_all() { |
aoqi@0 | 513 | saved_features = _features; |
aoqi@0 | 514 | _features = all_features_m; |
aoqi@0 | 515 | } |
aoqi@0 | 516 | |
aoqi@0 | 517 | void VM_Version::revert() { |
aoqi@0 | 518 | _features = saved_features; |
aoqi@0 | 519 | } |