src/share/vm/code/vmreg.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 535
c7c777385a15
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

duke@435 1 /*
xdono@631 2 * Copyright 1998-2008 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 //------------------------------VMReg------------------------------------------
duke@435 26 // The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots.
duke@435 27 // Register numbers below VMRegImpl::stack0 are the same for both. Register
duke@435 28 // numbers above stack0 are either warped (in the compiler) or unwarped
duke@435 29 // (in the VM). Unwarped numbers represent stack indices, offsets from
duke@435 30 // the current stack pointer. Warped numbers are required during compilation
duke@435 31 // when we do not yet know how big the frame will be.
duke@435 32
duke@435 33 class VMRegImpl;
duke@435 34 typedef VMRegImpl* VMReg;
duke@435 35
duke@435 36 class VMRegImpl {
duke@435 37 // friend class OopMap;
duke@435 38 friend class VMStructs;
duke@435 39 friend class OptoReg;
duke@435 40 // friend class Location;
duke@435 41 private:
duke@435 42 enum {
duke@435 43 BAD = -1
duke@435 44 };
duke@435 45
duke@435 46
duke@435 47
duke@435 48 static VMReg stack0;
duke@435 49 // Names for registers
duke@435 50 static const char *regName[];
duke@435 51 static const int register_count;
duke@435 52
duke@435 53
duke@435 54 public:
duke@435 55
duke@435 56 static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD || bad_ok, "invalid"); return (VMReg) (intptr_t) val; }
duke@435 57
duke@435 58 const char* name() {
duke@435 59 if (is_reg()) {
duke@435 60 return regName[value()];
duke@435 61 } else if (!is_valid()) {
duke@435 62 return "BAD";
duke@435 63 } else {
duke@435 64 // shouldn't really be called with stack
duke@435 65 return "STACKED REG";
duke@435 66 }
duke@435 67 }
duke@435 68 static VMReg Bad() { return (VMReg) (intptr_t) BAD; }
kvn@460 69 bool is_valid() const { return ((intptr_t) this) != BAD; }
kvn@460 70 bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; }
kvn@460 71 bool is_reg() const { return is_valid() && !is_stack(); }
duke@435 72
duke@435 73 // A concrete register is a value that returns true for is_reg() and is
duke@435 74 // also a register you could use in the assembler. On machines with
duke@435 75 // 64bit registers only one half of the VMReg (and OptoReg) is considered
duke@435 76 // concrete.
duke@435 77 bool is_concrete();
duke@435 78
duke@435 79 // VMRegs are 4 bytes wide on all platforms
duke@435 80 static const int stack_slot_size;
duke@435 81 static const int slots_per_word;
duke@435 82
duke@435 83
duke@435 84 // This really ought to check that the register is "real" in the sense that
duke@435 85 // we don't try and get the VMReg number of a physical register that doesn't
duke@435 86 // have an expressible part. That would be pd specific code
duke@435 87 VMReg next() {
duke@435 88 assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be");
duke@435 89 return (VMReg)(intptr_t)(value() + 1);
duke@435 90 }
duke@435 91 VMReg prev() {
duke@435 92 assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be");
duke@435 93 return (VMReg)(intptr_t)(value() - 1);
duke@435 94 }
duke@435 95
duke@435 96
duke@435 97 intptr_t value() const {return (intptr_t) this; }
duke@435 98
jrose@535 99 void print_on(outputStream* st) const;
kvn@460 100 void print() const { print_on(tty); }
duke@435 101
duke@435 102 // bias a stack slot.
duke@435 103 // Typically used to adjust a virtual frame slots by amounts that are offset by
duke@435 104 // amounts that are part of the native abi. The VMReg must be a stack slot
duke@435 105 // and the result must be also.
duke@435 106
duke@435 107 VMReg bias(int offset) {
duke@435 108 assert(is_stack(), "must be");
duke@435 109 // VMReg res = VMRegImpl::as_VMReg(value() + offset);
duke@435 110 VMReg res = stack2reg(reg2stack() + offset);
duke@435 111 assert(res->is_stack(), "must be");
duke@435 112 return res;
duke@435 113 }
duke@435 114
duke@435 115 // Convert register numbers to stack slots and vice versa
duke@435 116 static VMReg stack2reg( int idx ) {
duke@435 117 return (VMReg) (intptr_t) (stack0->value() + idx);
duke@435 118 }
duke@435 119
duke@435 120 uintptr_t reg2stack() {
duke@435 121 assert( is_stack(), "Not a stack-based register" );
duke@435 122 return value() - stack0->value();
duke@435 123 }
duke@435 124
duke@435 125 static void set_regName();
duke@435 126
duke@435 127 #include "incls/_vmreg_pd.hpp.incl"
duke@435 128
duke@435 129 };
duke@435 130
duke@435 131 //---------------------------VMRegPair-------------------------------------------
duke@435 132 // Pairs of 32-bit registers for arguments.
duke@435 133 // SharedRuntime::java_calling_convention will overwrite the structs with
duke@435 134 // the calling convention's registers. VMRegImpl::Bad is returned for any
duke@435 135 // unused 32-bit register. This happens for the unused high half of Int
duke@435 136 // arguments, or for 32-bit pointers or for longs in the 32-bit sparc build
duke@435 137 // (which are passed to natives in low 32-bits of e.g. O0/O1 and the high
duke@435 138 // 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles
duke@435 139 // always return a high and a low register, as do 64-bit pointers.
duke@435 140 //
duke@435 141 class VMRegPair {
duke@435 142 private:
duke@435 143 VMReg _second;
duke@435 144 VMReg _first;
duke@435 145 public:
duke@435 146 void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); }
duke@435 147 void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; }
duke@435 148 void set2 ( VMReg v ) { _second=v->next(); _first=v; }
duke@435 149 void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; }
duke@435 150 void set_ptr ( VMReg ptr ) {
duke@435 151 #ifdef _LP64
duke@435 152 _second = ptr->next();
duke@435 153 #else
duke@435 154 _second = VMRegImpl::Bad();
duke@435 155 #endif
duke@435 156 _first = ptr;
duke@435 157 }
duke@435 158 // Return true if single register, even if the pair is really just adjacent stack slots
jrose@535 159 bool is_single_reg() const {
duke@435 160 return (_first->is_valid()) && (_first->value() + 1 == _second->value());
duke@435 161 }
duke@435 162
duke@435 163 // Return true if single stack based "register" where the slot alignment matches input alignment
jrose@535 164 bool is_adjacent_on_stack(int alignment) const {
duke@435 165 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
duke@435 166 }
duke@435 167
duke@435 168 // Return true if single stack based "register" where the slot alignment matches input alignment
jrose@535 169 bool is_adjacent_aligned_on_stack(int alignment) const {
duke@435 170 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
duke@435 171 }
duke@435 172
duke@435 173 // Return true if single register but adjacent stack slots do not count
jrose@535 174 bool is_single_phys_reg() const {
duke@435 175 return (_first->is_reg() && (_first->value() + 1 == _second->value()));
duke@435 176 }
duke@435 177
duke@435 178 VMReg second() const { return _second; }
duke@435 179 VMReg first() const { return _first; }
duke@435 180 VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; }
duke@435 181 VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; }
duke@435 182 VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); }
duke@435 183 };

mercurial