src/share/vm/code/vmreg.hpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6461
bdd155477289
child 6876
710a3c8b516e
child 7598
ddce0b7cee93
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

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
goetz@6441 50 #ifdef TARGET_ARCH_MODEL_ppc_32
goetz@6441 51 # include "adfiles/adGlobals_ppc_32.hpp"
goetz@6441 52 #endif
goetz@6441 53 #ifdef TARGET_ARCH_MODEL_ppc_64
goetz@6441 54 # include "adfiles/adGlobals_ppc_64.hpp"
bobv@2508 55 #endif
stefank@2314 56 #endif
stefank@2314 57
duke@435 58 //------------------------------VMReg------------------------------------------
duke@435 59 // The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots.
duke@435 60 // Register numbers below VMRegImpl::stack0 are the same for both. Register
duke@435 61 // numbers above stack0 are either warped (in the compiler) or unwarped
duke@435 62 // (in the VM). Unwarped numbers represent stack indices, offsets from
duke@435 63 // the current stack pointer. Warped numbers are required during compilation
duke@435 64 // when we do not yet know how big the frame will be.
duke@435 65
duke@435 66 class VMRegImpl;
duke@435 67 typedef VMRegImpl* VMReg;
duke@435 68
duke@435 69 class VMRegImpl {
duke@435 70 // friend class OopMap;
duke@435 71 friend class VMStructs;
duke@435 72 friend class OptoReg;
duke@435 73 // friend class Location;
duke@435 74 private:
duke@435 75 enum {
goetz@6461 76 BAD_REG = -1
duke@435 77 };
duke@435 78
duke@435 79
duke@435 80
duke@435 81 static VMReg stack0;
duke@435 82 // Names for registers
duke@435 83 static const char *regName[];
duke@435 84 static const int register_count;
duke@435 85
duke@435 86
duke@435 87 public:
duke@435 88
goetz@6461 89 static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD_REG || bad_ok, "invalid"); return (VMReg) (intptr_t) val; }
duke@435 90
duke@435 91 const char* name() {
duke@435 92 if (is_reg()) {
duke@435 93 return regName[value()];
duke@435 94 } else if (!is_valid()) {
duke@435 95 return "BAD";
duke@435 96 } else {
duke@435 97 // shouldn't really be called with stack
duke@435 98 return "STACKED REG";
duke@435 99 }
duke@435 100 }
goetz@6461 101 static VMReg Bad() { return (VMReg) (intptr_t) BAD_REG; }
goetz@6461 102 bool is_valid() const { return ((intptr_t) this) != BAD_REG; }
kvn@460 103 bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; }
kvn@460 104 bool is_reg() const { return is_valid() && !is_stack(); }
duke@435 105
duke@435 106 // A concrete register is a value that returns true for is_reg() and is
duke@435 107 // also a register you could use in the assembler. On machines with
duke@435 108 // 64bit registers only one half of the VMReg (and OptoReg) is considered
duke@435 109 // concrete.
duke@435 110 bool is_concrete();
duke@435 111
duke@435 112 // VMRegs are 4 bytes wide on all platforms
duke@435 113 static const int stack_slot_size;
duke@435 114 static const int slots_per_word;
duke@435 115
duke@435 116
duke@435 117 // This really ought to check that the register is "real" in the sense that
duke@435 118 // we don't try and get the VMReg number of a physical register that doesn't
duke@435 119 // have an expressible part. That would be pd specific code
duke@435 120 VMReg next() {
duke@435 121 assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be");
duke@435 122 return (VMReg)(intptr_t)(value() + 1);
duke@435 123 }
kvn@3929 124 VMReg next(int i) {
kvn@3929 125 assert((is_reg() && value() < stack0->value() - i) || is_stack(), "must be");
kvn@3929 126 return (VMReg)(intptr_t)(value() + i);
kvn@3929 127 }
duke@435 128 VMReg prev() {
duke@435 129 assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be");
duke@435 130 return (VMReg)(intptr_t)(value() - 1);
duke@435 131 }
duke@435 132
duke@435 133
duke@435 134 intptr_t value() const {return (intptr_t) this; }
duke@435 135
jrose@535 136 void print_on(outputStream* st) const;
kvn@460 137 void print() const { print_on(tty); }
duke@435 138
duke@435 139 // bias a stack slot.
duke@435 140 // Typically used to adjust a virtual frame slots by amounts that are offset by
duke@435 141 // amounts that are part of the native abi. The VMReg must be a stack slot
duke@435 142 // and the result must be also.
duke@435 143
duke@435 144 VMReg bias(int offset) {
duke@435 145 assert(is_stack(), "must be");
duke@435 146 // VMReg res = VMRegImpl::as_VMReg(value() + offset);
duke@435 147 VMReg res = stack2reg(reg2stack() + offset);
duke@435 148 assert(res->is_stack(), "must be");
duke@435 149 return res;
duke@435 150 }
duke@435 151
duke@435 152 // Convert register numbers to stack slots and vice versa
duke@435 153 static VMReg stack2reg( int idx ) {
duke@435 154 return (VMReg) (intptr_t) (stack0->value() + idx);
duke@435 155 }
duke@435 156
duke@435 157 uintptr_t reg2stack() {
duke@435 158 assert( is_stack(), "Not a stack-based register" );
duke@435 159 return value() - stack0->value();
duke@435 160 }
duke@435 161
duke@435 162 static void set_regName();
duke@435 163
stefank@2314 164 #ifdef TARGET_ARCH_x86
stefank@2314 165 # include "vmreg_x86.hpp"
stefank@2314 166 #endif
stefank@2314 167 #ifdef TARGET_ARCH_sparc
stefank@2314 168 # include "vmreg_sparc.hpp"
stefank@2314 169 #endif
stefank@2314 170 #ifdef TARGET_ARCH_zero
stefank@2314 171 # include "vmreg_zero.hpp"
stefank@2314 172 #endif
bobv@2508 173 #ifdef TARGET_ARCH_arm
bobv@2508 174 # include "vmreg_arm.hpp"
bobv@2508 175 #endif
bobv@2508 176 #ifdef TARGET_ARCH_ppc
bobv@2508 177 # include "vmreg_ppc.hpp"
bobv@2508 178 #endif
stefank@2314 179
duke@435 180
duke@435 181 };
duke@435 182
duke@435 183 //---------------------------VMRegPair-------------------------------------------
duke@435 184 // Pairs of 32-bit registers for arguments.
duke@435 185 // SharedRuntime::java_calling_convention will overwrite the structs with
duke@435 186 // the calling convention's registers. VMRegImpl::Bad is returned for any
duke@435 187 // unused 32-bit register. This happens for the unused high half of Int
duke@435 188 // arguments, or for 32-bit pointers or for longs in the 32-bit sparc build
duke@435 189 // (which are passed to natives in low 32-bits of e.g. O0/O1 and the high
duke@435 190 // 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles
duke@435 191 // always return a high and a low register, as do 64-bit pointers.
duke@435 192 //
duke@435 193 class VMRegPair {
duke@435 194 private:
duke@435 195 VMReg _second;
duke@435 196 VMReg _first;
duke@435 197 public:
duke@435 198 void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); }
duke@435 199 void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; }
duke@435 200 void set2 ( VMReg v ) { _second=v->next(); _first=v; }
duke@435 201 void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; }
duke@435 202 void set_ptr ( VMReg ptr ) {
duke@435 203 #ifdef _LP64
duke@435 204 _second = ptr->next();
duke@435 205 #else
duke@435 206 _second = VMRegImpl::Bad();
duke@435 207 #endif
duke@435 208 _first = ptr;
duke@435 209 }
duke@435 210 // Return true if single register, even if the pair is really just adjacent stack slots
jrose@535 211 bool is_single_reg() const {
duke@435 212 return (_first->is_valid()) && (_first->value() + 1 == _second->value());
duke@435 213 }
duke@435 214
duke@435 215 // Return true if single stack based "register" where the slot alignment matches input alignment
jrose@535 216 bool is_adjacent_on_stack(int alignment) const {
duke@435 217 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
duke@435 218 }
duke@435 219
duke@435 220 // Return true if single stack based "register" where the slot alignment matches input alignment
jrose@535 221 bool is_adjacent_aligned_on_stack(int alignment) const {
duke@435 222 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
duke@435 223 }
duke@435 224
duke@435 225 // Return true if single register but adjacent stack slots do not count
jrose@535 226 bool is_single_phys_reg() const {
duke@435 227 return (_first->is_reg() && (_first->value() + 1 == _second->value()));
duke@435 228 }
duke@435 229
duke@435 230 VMReg second() const { return _second; }
duke@435 231 VMReg first() const { return _first; }
duke@435 232 VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; }
duke@435 233 VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; }
duke@435 234 VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); }
duke@435 235 };
stefank@2314 236
stefank@2314 237 #endif // SHARE_VM_CODE_VMREG_HPP

mercurial