duke@435: /* duke@435: * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: //------------------------------VMReg------------------------------------------ duke@435: // The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots. duke@435: // Register numbers below VMRegImpl::stack0 are the same for both. Register duke@435: // numbers above stack0 are either warped (in the compiler) or unwarped duke@435: // (in the VM). Unwarped numbers represent stack indices, offsets from duke@435: // the current stack pointer. Warped numbers are required during compilation duke@435: // when we do not yet know how big the frame will be. duke@435: duke@435: class VMRegImpl; duke@435: typedef VMRegImpl* VMReg; duke@435: duke@435: class VMRegImpl { duke@435: // friend class OopMap; duke@435: friend class VMStructs; duke@435: friend class OptoReg; duke@435: // friend class Location; duke@435: private: duke@435: enum { duke@435: BAD = -1 duke@435: }; duke@435: duke@435: duke@435: duke@435: static VMReg stack0; duke@435: // Names for registers duke@435: static const char *regName[]; duke@435: static const int register_count; duke@435: duke@435: duke@435: public: duke@435: duke@435: static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD || bad_ok, "invalid"); return (VMReg) (intptr_t) val; } duke@435: duke@435: const char* name() { duke@435: if (is_reg()) { duke@435: return regName[value()]; duke@435: } else if (!is_valid()) { duke@435: return "BAD"; duke@435: } else { duke@435: // shouldn't really be called with stack duke@435: return "STACKED REG"; duke@435: } duke@435: } duke@435: static VMReg Bad() { return (VMReg) (intptr_t) BAD; } duke@435: bool is_valid() { return ((intptr_t) this) != BAD; } duke@435: bool is_stack() { return (intptr_t) this >= (intptr_t) stack0; } duke@435: bool is_reg() { return is_valid() && !is_stack(); } duke@435: duke@435: // A concrete register is a value that returns true for is_reg() and is duke@435: // also a register you could use in the assembler. On machines with duke@435: // 64bit registers only one half of the VMReg (and OptoReg) is considered duke@435: // concrete. duke@435: bool is_concrete(); duke@435: duke@435: // VMRegs are 4 bytes wide on all platforms duke@435: static const int stack_slot_size; duke@435: static const int slots_per_word; duke@435: duke@435: duke@435: // This really ought to check that the register is "real" in the sense that duke@435: // we don't try and get the VMReg number of a physical register that doesn't duke@435: // have an expressible part. That would be pd specific code duke@435: VMReg next() { duke@435: assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be"); duke@435: return (VMReg)(intptr_t)(value() + 1); duke@435: } duke@435: VMReg prev() { duke@435: assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be"); duke@435: return (VMReg)(intptr_t)(value() - 1); duke@435: } duke@435: duke@435: duke@435: intptr_t value() const {return (intptr_t) this; } duke@435: duke@435: void print(); duke@435: duke@435: // bias a stack slot. duke@435: // Typically used to adjust a virtual frame slots by amounts that are offset by duke@435: // amounts that are part of the native abi. The VMReg must be a stack slot duke@435: // and the result must be also. duke@435: duke@435: VMReg bias(int offset) { duke@435: assert(is_stack(), "must be"); duke@435: // VMReg res = VMRegImpl::as_VMReg(value() + offset); duke@435: VMReg res = stack2reg(reg2stack() + offset); duke@435: assert(res->is_stack(), "must be"); duke@435: return res; duke@435: } duke@435: duke@435: // Convert register numbers to stack slots and vice versa duke@435: static VMReg stack2reg( int idx ) { duke@435: return (VMReg) (intptr_t) (stack0->value() + idx); duke@435: } duke@435: duke@435: uintptr_t reg2stack() { duke@435: assert( is_stack(), "Not a stack-based register" ); duke@435: return value() - stack0->value(); duke@435: } duke@435: duke@435: static void set_regName(); duke@435: duke@435: #include "incls/_vmreg_pd.hpp.incl" duke@435: duke@435: }; duke@435: duke@435: //---------------------------VMRegPair------------------------------------------- duke@435: // Pairs of 32-bit registers for arguments. duke@435: // SharedRuntime::java_calling_convention will overwrite the structs with duke@435: // the calling convention's registers. VMRegImpl::Bad is returned for any duke@435: // unused 32-bit register. This happens for the unused high half of Int duke@435: // arguments, or for 32-bit pointers or for longs in the 32-bit sparc build duke@435: // (which are passed to natives in low 32-bits of e.g. O0/O1 and the high duke@435: // 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles duke@435: // always return a high and a low register, as do 64-bit pointers. duke@435: // duke@435: class VMRegPair { duke@435: private: duke@435: VMReg _second; duke@435: VMReg _first; duke@435: public: duke@435: void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); } duke@435: void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; } duke@435: void set2 ( VMReg v ) { _second=v->next(); _first=v; } duke@435: void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; } duke@435: void set_ptr ( VMReg ptr ) { duke@435: #ifdef _LP64 duke@435: _second = ptr->next(); duke@435: #else duke@435: _second = VMRegImpl::Bad(); duke@435: #endif duke@435: _first = ptr; duke@435: } duke@435: // Return true if single register, even if the pair is really just adjacent stack slots duke@435: bool is_single_reg() { duke@435: return (_first->is_valid()) && (_first->value() + 1 == _second->value()); duke@435: } duke@435: duke@435: // Return true if single stack based "register" where the slot alignment matches input alignment duke@435: bool is_adjacent_on_stack(int alignment) { duke@435: return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); duke@435: } duke@435: duke@435: // Return true if single stack based "register" where the slot alignment matches input alignment duke@435: bool is_adjacent_aligned_on_stack(int alignment) { duke@435: return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); duke@435: } duke@435: duke@435: // Return true if single register but adjacent stack slots do not count duke@435: bool is_single_phys_reg() { duke@435: return (_first->is_reg() && (_first->value() + 1 == _second->value())); duke@435: } duke@435: duke@435: VMReg second() const { return _second; } duke@435: VMReg first() const { return _first; } duke@435: VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; } duke@435: VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; } duke@435: VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); } duke@435: };