vmreg.hpp revision 5945:d2907f74462e
1262266Sbapt/* 2289123Sbapt * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 3262266Sbapt * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4262266Sbapt * 5262266Sbapt * This code is free software; you can redistribute it and/or modify it 6289123Sbapt * under the terms of the GNU General Public License version 2 only, as 7262266Sbapt * published by the Free Software Foundation. 8262266Sbapt * 9262266Sbapt * This code is distributed in the hope that it will be useful, but WITHOUT 10262266Sbapt * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11262266Sbapt * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12262266Sbapt * version 2 for more details (a copy is included in the LICENSE file that 13262266Sbapt * accompanied this code). 14262266Sbapt * 15262266Sbapt * You should have received a copy of the GNU General Public License version 16262266Sbapt * 2 along with this work; if not, write to the Free Software Foundation, 17262266Sbapt * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18262266Sbapt * 19262266Sbapt * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20262266Sbapt * or visit www.oracle.com if you need additional information or have any 21262266Sbapt * questions. 22262266Sbapt * 23262266Sbapt */ 24262266Sbapt 25262266Sbapt#ifndef SHARE_VM_CODE_VMREG_HPP 26262266Sbapt#define SHARE_VM_CODE_VMREG_HPP 27262266Sbapt 28262266Sbapt#include "memory/allocation.hpp" 29262266Sbapt#include "utilities/globalDefinitions.hpp" 30262266Sbapt#include "asm/register.hpp" 31262266Sbapt 32262266Sbapt#ifdef COMPILER2 33262266Sbapt#include "opto/adlcVMDeps.hpp" 34262266Sbapt#include "utilities/ostream.hpp" 35262266Sbapt#ifdef TARGET_ARCH_MODEL_x86_32 36262266Sbapt# include "adfiles/adGlobals_x86_32.hpp" 37304587Sbapt#endif 38262266Sbapt#ifdef TARGET_ARCH_MODEL_x86_64 39262266Sbapt# include "adfiles/adGlobals_x86_64.hpp" 40262266Sbapt#endif 41262266Sbapt#ifdef TARGET_ARCH_MODEL_sparc 42262266Sbapt# include "adfiles/adGlobals_sparc.hpp" 43262266Sbapt#endif 44262266Sbapt#ifdef TARGET_ARCH_MODEL_zero 45262266Sbapt# include "adfiles/adGlobals_zero.hpp" 46262266Sbapt#endif 47262266Sbapt#ifdef TARGET_ARCH_MODEL_arm 48262266Sbapt# include "adfiles/adGlobals_arm.hpp" 49262266Sbapt#endif 50262266Sbapt#ifdef TARGET_ARCH_MODEL_ppc_32 51262266Sbapt# include "adfiles/adGlobals_ppc_32.hpp" 52262266Sbapt#endif 53262266Sbapt#ifdef TARGET_ARCH_MODEL_ppc_64 54262266Sbapt# include "adfiles/adGlobals_ppc_64.hpp" 55262266Sbapt#endif 56262266Sbapt#endif 57262266Sbapt 58262266Sbapt//------------------------------VMReg------------------------------------------ 59262266Sbapt// The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots. 60262266Sbapt// Register numbers below VMRegImpl::stack0 are the same for both. Register 61262266Sbapt// numbers above stack0 are either warped (in the compiler) or unwarped 62262266Sbapt// (in the VM). Unwarped numbers represent stack indices, offsets from 63262266Sbapt// the current stack pointer. Warped numbers are required during compilation 64262266Sbapt// when we do not yet know how big the frame will be. 65262266Sbapt 66262266Sbaptclass VMRegImpl; 67262266Sbapttypedef VMRegImpl* VMReg; 68262266Sbapt 69262266Sbaptclass VMRegImpl { 70262266Sbapt// friend class OopMap; 71262266Sbaptfriend class VMStructs; 72262266Sbaptfriend class OptoReg; 73262266Sbapt// friend class Location; 74262266Sbaptprivate: 75262266Sbapt enum { 76262266Sbapt BAD = -1 77262266Sbapt }; 78262266Sbapt 79289123Sbapt 80289123Sbapt 81289123Sbapt static VMReg stack0; 82289123Sbapt // Names for registers 83289123Sbapt static const char *regName[]; 84289123Sbapt static const int register_count; 85289123Sbapt 86289123Sbapt 87289123Sbaptpublic: 88289123Sbapt 89289123Sbapt static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD || bad_ok, "invalid"); return (VMReg) (intptr_t) val; } 90289123Sbapt 91289123Sbapt const char* name() { 92289123Sbapt if (is_reg()) { 93289123Sbapt return regName[value()]; 94289123Sbapt } else if (!is_valid()) { 95289123Sbapt return "BAD"; 96289123Sbapt } else { 97289123Sbapt // shouldn't really be called with stack 98289123Sbapt return "STACKED REG"; 99262266Sbapt } 100262266Sbapt } 101262266Sbapt static VMReg Bad() { return (VMReg) (intptr_t) BAD; } 102262266Sbapt bool is_valid() const { return ((intptr_t) this) != BAD; } 103262266Sbapt bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; } 104262266Sbapt bool is_reg() const { return is_valid() && !is_stack(); } 105262266Sbapt 106262266Sbapt // A concrete register is a value that returns true for is_reg() and is 107262266Sbapt // also a register you could use in the assembler. On machines with 108262266Sbapt // 64bit registers only one half of the VMReg (and OptoReg) is considered 109262266Sbapt // concrete. 110262266Sbapt bool is_concrete(); 111262266Sbapt 112262266Sbapt // VMRegs are 4 bytes wide on all platforms 113262266Sbapt static const int stack_slot_size; 114262266Sbapt static const int slots_per_word; 115262266Sbapt 116262266Sbapt 117262266Sbapt // This really ought to check that the register is "real" in the sense that 118262266Sbapt // we don't try and get the VMReg number of a physical register that doesn't 119262266Sbapt // have an expressible part. That would be pd specific code 120262266Sbapt VMReg next() { 121262266Sbapt assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be"); 122262266Sbapt return (VMReg)(intptr_t)(value() + 1); 123262266Sbapt } 124262266Sbapt VMReg next(int i) { 125262266Sbapt assert((is_reg() && value() < stack0->value() - i) || is_stack(), "must be"); 126262266Sbapt return (VMReg)(intptr_t)(value() + i); 127262266Sbapt } 128262266Sbapt VMReg prev() { 129262266Sbapt assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be"); 130262266Sbapt return (VMReg)(intptr_t)(value() - 1); 131262266Sbapt } 132262266Sbapt 133262266Sbapt 134262266Sbapt intptr_t value() const {return (intptr_t) this; } 135262266Sbapt 136262266Sbapt void print_on(outputStream* st) const; 137262266Sbapt void print() const { print_on(tty); } 138262266Sbapt 139262266Sbapt // bias a stack slot. 140262266Sbapt // Typically used to adjust a virtual frame slots by amounts that are offset by 141262266Sbapt // amounts that are part of the native abi. The VMReg must be a stack slot 142262266Sbapt // and the result must be also. 143262266Sbapt 144262266Sbapt VMReg bias(int offset) { 145262266Sbapt assert(is_stack(), "must be"); 146262266Sbapt // VMReg res = VMRegImpl::as_VMReg(value() + offset); 147262266Sbapt VMReg res = stack2reg(reg2stack() + offset); 148262266Sbapt assert(res->is_stack(), "must be"); 149262266Sbapt return res; 150262266Sbapt } 151262266Sbapt 152262266Sbapt // Convert register numbers to stack slots and vice versa 153262266Sbapt static VMReg stack2reg( int idx ) { 154262266Sbapt return (VMReg) (intptr_t) (stack0->value() + idx); 155262266Sbapt } 156262266Sbapt 157262266Sbapt uintptr_t reg2stack() { 158262266Sbapt assert( is_stack(), "Not a stack-based register" ); 159262266Sbapt return value() - stack0->value(); 160262266Sbapt } 161262266Sbapt 162262266Sbapt static void set_regName(); 163262266Sbapt 164262266Sbapt#ifdef TARGET_ARCH_x86 165262266Sbapt# include "vmreg_x86.hpp" 166262266Sbapt#endif 167262266Sbapt#ifdef TARGET_ARCH_sparc 168262266Sbapt# include "vmreg_sparc.hpp" 169262266Sbapt#endif 170262266Sbapt#ifdef TARGET_ARCH_zero 171262266Sbapt# include "vmreg_zero.hpp" 172262266Sbapt#endif 173262266Sbapt#ifdef TARGET_ARCH_arm 174262266Sbapt# include "vmreg_arm.hpp" 175262266Sbapt#endif 176262266Sbapt#ifdef TARGET_ARCH_ppc 177262266Sbapt# include "vmreg_ppc.hpp" 178262266Sbapt#endif 179262266Sbapt 180262266Sbapt 181262266Sbapt}; 182262266Sbapt 183262266Sbapt//---------------------------VMRegPair------------------------------------------- 184262266Sbapt// Pairs of 32-bit registers for arguments. 185262266Sbapt// SharedRuntime::java_calling_convention will overwrite the structs with 186262266Sbapt// the calling convention's registers. VMRegImpl::Bad is returned for any 187262266Sbapt// unused 32-bit register. This happens for the unused high half of Int 188262266Sbapt// arguments, or for 32-bit pointers or for longs in the 32-bit sparc build 189262266Sbapt// (which are passed to natives in low 32-bits of e.g. O0/O1 and the high 190262266Sbapt// 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles 191262266Sbapt// always return a high and a low register, as do 64-bit pointers. 192262266Sbapt// 193262266Sbaptclass VMRegPair { 194262266Sbaptprivate: 195262266Sbapt VMReg _second; 196262266Sbapt VMReg _first; 197262266Sbaptpublic: 198262266Sbapt void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); } 199262266Sbapt void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; } 200262266Sbapt void set2 ( VMReg v ) { _second=v->next(); _first=v; } 201262266Sbapt void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; } 202262266Sbapt void set_ptr ( VMReg ptr ) { 203262266Sbapt#ifdef _LP64 204262266Sbapt _second = ptr->next(); 205262266Sbapt#else 206262266Sbapt _second = VMRegImpl::Bad(); 207262266Sbapt#endif 208262266Sbapt _first = ptr; 209262266Sbapt } 210262266Sbapt // Return true if single register, even if the pair is really just adjacent stack slots 211262266Sbapt bool is_single_reg() const { 212262266Sbapt return (_first->is_valid()) && (_first->value() + 1 == _second->value()); 213262266Sbapt } 214262266Sbapt 215262266Sbapt // Return true if single stack based "register" where the slot alignment matches input alignment 216262266Sbapt bool is_adjacent_on_stack(int alignment) const { 217262266Sbapt return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); 218262266Sbapt } 219262266Sbapt 220262266Sbapt // Return true if single stack based "register" where the slot alignment matches input alignment 221262266Sbapt bool is_adjacent_aligned_on_stack(int alignment) const { 222262266Sbapt return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0)); 223262266Sbapt } 224262266Sbapt 225262266Sbapt // Return true if single register but adjacent stack slots do not count 226262266Sbapt bool is_single_phys_reg() const { 227262266Sbapt return (_first->is_reg() && (_first->value() + 1 == _second->value())); 228262266Sbapt } 229262266Sbapt 230262266Sbapt VMReg second() const { return _second; } 231262266Sbapt VMReg first() const { return _first; } 232262266Sbapt VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; } 233262266Sbapt VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; } 234262266Sbapt VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); } 235262266Sbapt}; 236262266Sbapt 237262266Sbapt#endif // SHARE_VM_CODE_VMREG_HPP 238262266Sbapt