Fri, 08 Nov 2013 01:13:11 -0800
8023037: Race between ciEnv::register_method and nmethod::make_not_entrant_or_zombie
Reviewed-by: kvn, iveresov
duke@435 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 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. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_CODE_VMREG_HPP |
stefank@2314 | 26 | #define SHARE_VM_CODE_VMREG_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/allocation.hpp" |
stefank@2314 | 29 | #include "utilities/globalDefinitions.hpp" |
twisti@4323 | 30 | #include "asm/register.hpp" |
twisti@4323 | 31 | |
stefank@2314 | 32 | #ifdef COMPILER2 |
stefank@2314 | 33 | #include "opto/adlcVMDeps.hpp" |
stefank@2314 | 34 | #include "utilities/ostream.hpp" |
stefank@2314 | 35 | #ifdef TARGET_ARCH_MODEL_x86_32 |
stefank@2314 | 36 | # include "adfiles/adGlobals_x86_32.hpp" |
stefank@2314 | 37 | #endif |
stefank@2314 | 38 | #ifdef TARGET_ARCH_MODEL_x86_64 |
stefank@2314 | 39 | # include "adfiles/adGlobals_x86_64.hpp" |
stefank@2314 | 40 | #endif |
stefank@2314 | 41 | #ifdef TARGET_ARCH_MODEL_sparc |
stefank@2314 | 42 | # include "adfiles/adGlobals_sparc.hpp" |
stefank@2314 | 43 | #endif |
stefank@2314 | 44 | #ifdef TARGET_ARCH_MODEL_zero |
stefank@2314 | 45 | # include "adfiles/adGlobals_zero.hpp" |
stefank@2314 | 46 | #endif |
bobv@2508 | 47 | #ifdef TARGET_ARCH_MODEL_arm |
bobv@2508 | 48 | # include "adfiles/adGlobals_arm.hpp" |
bobv@2508 | 49 | #endif |
bobv@2508 | 50 | #ifdef TARGET_ARCH_MODEL_ppc |
bobv@2508 | 51 | # include "adfiles/adGlobals_ppc.hpp" |
bobv@2508 | 52 | #endif |
stefank@2314 | 53 | #endif |
stefank@2314 | 54 | |
duke@435 | 55 | //------------------------------VMReg------------------------------------------ |
duke@435 | 56 | // The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots. |
duke@435 | 57 | // Register numbers below VMRegImpl::stack0 are the same for both. Register |
duke@435 | 58 | // numbers above stack0 are either warped (in the compiler) or unwarped |
duke@435 | 59 | // (in the VM). Unwarped numbers represent stack indices, offsets from |
duke@435 | 60 | // the current stack pointer. Warped numbers are required during compilation |
duke@435 | 61 | // when we do not yet know how big the frame will be. |
duke@435 | 62 | |
duke@435 | 63 | class VMRegImpl; |
duke@435 | 64 | typedef VMRegImpl* VMReg; |
duke@435 | 65 | |
duke@435 | 66 | class VMRegImpl { |
duke@435 | 67 | // friend class OopMap; |
duke@435 | 68 | friend class VMStructs; |
duke@435 | 69 | friend class OptoReg; |
duke@435 | 70 | // friend class Location; |
duke@435 | 71 | private: |
duke@435 | 72 | enum { |
duke@435 | 73 | BAD = -1 |
duke@435 | 74 | }; |
duke@435 | 75 | |
duke@435 | 76 | |
duke@435 | 77 | |
duke@435 | 78 | static VMReg stack0; |
duke@435 | 79 | // Names for registers |
duke@435 | 80 | static const char *regName[]; |
duke@435 | 81 | static const int register_count; |
duke@435 | 82 | |
duke@435 | 83 | |
duke@435 | 84 | public: |
duke@435 | 85 | |
duke@435 | 86 | static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD || bad_ok, "invalid"); return (VMReg) (intptr_t) val; } |
duke@435 | 87 | |
duke@435 | 88 | const char* name() { |
duke@435 | 89 | if (is_reg()) { |
duke@435 | 90 | return regName[value()]; |
duke@435 | 91 | } else if (!is_valid()) { |
duke@435 | 92 | return "BAD"; |
duke@435 | 93 | } else { |
duke@435 | 94 | // shouldn't really be called with stack |
duke@435 | 95 | return "STACKED REG"; |
duke@435 | 96 | } |
duke@435 | 97 | } |
duke@435 | 98 | static VMReg Bad() { return (VMReg) (intptr_t) BAD; } |
kvn@460 | 99 | bool is_valid() const { return ((intptr_t) this) != BAD; } |
kvn@460 | 100 | bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; } |
kvn@460 | 101 | bool is_reg() const { return is_valid() && !is_stack(); } |
duke@435 | 102 | |
duke@435 | 103 | // A concrete register is a value that returns true for is_reg() and is |
duke@435 | 104 | // also a register you could use in the assembler. On machines with |
duke@435 | 105 | // 64bit registers only one half of the VMReg (and OptoReg) is considered |
duke@435 | 106 | // concrete. |
duke@435 | 107 | bool is_concrete(); |
duke@435 | 108 | |
duke@435 | 109 | // VMRegs are 4 bytes wide on all platforms |
duke@435 | 110 | static const int stack_slot_size; |
duke@435 | 111 | static const int slots_per_word; |
duke@435 | 112 | |
duke@435 | 113 | |
duke@435 | 114 | // This really ought to check that the register is "real" in the sense that |
duke@435 | 115 | // we don't try and get the VMReg number of a physical register that doesn't |
duke@435 | 116 | // have an expressible part. That would be pd specific code |
duke@435 | 117 | VMReg next() { |
duke@435 | 118 | assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be"); |
duke@435 | 119 | return (VMReg)(intptr_t)(value() + 1); |
duke@435 | 120 | } |
kvn@3929 | 121 | VMReg next(int i) { |
kvn@3929 | 122 | assert((is_reg() && value() < stack0->value() - i) || is_stack(), "must be"); |
kvn@3929 | 123 | return (VMReg)(intptr_t)(value() + i); |
kvn@3929 | 124 | } |
duke@435 | 125 | VMReg prev() { |
duke@435 | 126 | assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be"); |
duke@435 | 127 | return (VMReg)(intptr_t)(value() - 1); |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | intptr_t value() const {return (intptr_t) this; } |
duke@435 | 132 | |
jrose@535 | 133 | void print_on(outputStream* st) const; |
kvn@460 | 134 | void print() const { print_on(tty); } |
duke@435 | 135 | |
duke@435 | 136 | // bias a stack slot. |
duke@435 | 137 | // Typically used to adjust a virtual frame slots by amounts that are offset by |
duke@435 | 138 | // amounts that are part of the native abi. The VMReg must be a stack slot |
duke@435 | 139 | // and the result must be also. |
duke@435 | 140 | |
duke@435 | 141 | VMReg bias(int offset) { |
duke@435 | 142 | assert(is_stack(), "must be"); |
duke@435 | 143 | // VMReg res = VMRegImpl::as_VMReg(value() + offset); |
duke@435 | 144 | VMReg res = stack2reg(reg2stack() + offset); |
duke@435 | 145 | assert(res->is_stack(), "must be"); |
duke@435 | 146 | return res; |
duke@435 | 147 | } |
duke@435 | 148 | |
duke@435 | 149 | // Convert register numbers to stack slots and vice versa |
duke@435 | 150 | static VMReg stack2reg( int idx ) { |
duke@435 | 151 | return (VMReg) (intptr_t) (stack0->value() + idx); |
duke@435 | 152 | } |
duke@435 | 153 | |
duke@435 | 154 | uintptr_t reg2stack() { |
duke@435 | 155 | assert( is_stack(), "Not a stack-based register" ); |
duke@435 | 156 | return value() - stack0->value(); |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | static void set_regName(); |
duke@435 | 160 | |
stefank@2314 | 161 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 162 | # include "vmreg_x86.hpp" |
stefank@2314 | 163 | #endif |
stefank@2314 | 164 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 165 | # include "vmreg_sparc.hpp" |
stefank@2314 | 166 | #endif |
stefank@2314 | 167 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 168 | # include "vmreg_zero.hpp" |
stefank@2314 | 169 | #endif |
bobv@2508 | 170 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 171 | # include "vmreg_arm.hpp" |
bobv@2508 | 172 | #endif |
bobv@2508 | 173 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 174 | # include "vmreg_ppc.hpp" |
bobv@2508 | 175 | #endif |
stefank@2314 | 176 | |
duke@435 | 177 | |
duke@435 | 178 | }; |
duke@435 | 179 | |
duke@435 | 180 | //---------------------------VMRegPair------------------------------------------- |
duke@435 | 181 | // Pairs of 32-bit registers for arguments. |
duke@435 | 182 | // SharedRuntime::java_calling_convention will overwrite the structs with |
duke@435 | 183 | // the calling convention's registers. VMRegImpl::Bad is returned for any |
duke@435 | 184 | // unused 32-bit register. This happens for the unused high half of Int |
duke@435 | 185 | // arguments, or for 32-bit pointers or for longs in the 32-bit sparc build |
duke@435 | 186 | // (which are passed to natives in low 32-bits of e.g. O0/O1 and the high |
duke@435 | 187 | // 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles |
duke@435 | 188 | // always return a high and a low register, as do 64-bit pointers. |
duke@435 | 189 | // |
duke@435 | 190 | class VMRegPair { |
duke@435 | 191 | private: |
duke@435 | 192 | VMReg _second; |
duke@435 | 193 | VMReg _first; |
duke@435 | 194 | public: |
duke@435 | 195 | void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); } |
duke@435 | 196 | void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; } |
duke@435 | 197 | void set2 ( VMReg v ) { _second=v->next(); _first=v; } |
duke@435 | 198 | void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; } |
duke@435 | 199 | void set_ptr ( VMReg ptr ) { |
duke@435 | 200 | #ifdef _LP64 |
duke@435 | 201 | _second = ptr->next(); |
duke@435 | 202 | #else |
duke@435 | 203 | _second = VMRegImpl::Bad(); |
duke@435 | 204 | #endif |
duke@435 | 205 | _first = ptr; |
duke@435 | 206 | } |
duke@435 | 207 | // Return true if single register, even if the pair is really just adjacent stack slots |
jrose@535 | 208 | bool is_single_reg() const { |
duke@435 | 209 | return (_first->is_valid()) && (_first->value() + 1 == _second->value()); |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | // Return true if single stack based "register" where the slot alignment matches input alignment |
jrose@535 | 213 | bool is_adjacent_on_stack(int alignment) const { |
duke@435 | 214 | return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); |
duke@435 | 215 | } |
duke@435 | 216 | |
duke@435 | 217 | // Return true if single stack based "register" where the slot alignment matches input alignment |
jrose@535 | 218 | bool is_adjacent_aligned_on_stack(int alignment) const { |
duke@435 | 219 | return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); |
duke@435 | 220 | } |
duke@435 | 221 | |
duke@435 | 222 | // Return true if single register but adjacent stack slots do not count |
jrose@535 | 223 | bool is_single_phys_reg() const { |
duke@435 | 224 | return (_first->is_reg() && (_first->value() + 1 == _second->value())); |
duke@435 | 225 | } |
duke@435 | 226 | |
duke@435 | 227 | VMReg second() const { return _second; } |
duke@435 | 228 | VMReg first() const { return _first; } |
duke@435 | 229 | VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; } |
duke@435 | 230 | VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; } |
duke@435 | 231 | VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); } |
duke@435 | 232 | }; |
stefank@2314 | 233 | |
stefank@2314 | 234 | #endif // SHARE_VM_CODE_VMREG_HPP |