Path: blob/master/src/hotspot/share/code/vmreg.hpp
40931 views
/*1* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CODE_VMREG_HPP25#define SHARE_CODE_VMREG_HPP2627#include "asm/register.hpp"28#include "code/vmregTypes.hpp"29#include "runtime/globals.hpp"30#include "utilities/globalDefinitions.hpp"31#include "utilities/macros.hpp"32#include "utilities/ostream.hpp"33#ifdef COMPILER234#include "opto/adlcVMDeps.hpp"35#endif3637//------------------------------VMReg------------------------------------------38// The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots.39// Register numbers below VMRegImpl::stack0 are the same for both. Register40// numbers above stack0 are either warped (in the compiler) or unwarped41// (in the VM). Unwarped numbers represent stack indices, offsets from42// the current stack pointer. Warped numbers are required during compilation43// when we do not yet know how big the frame will be.4445class VMRegImpl;46typedef VMRegImpl* VMReg;4748class VMRegImpl {49// friend class OopMap;50friend class VMStructs;51friend class OptoReg;52// friend class Location;53private:54enum {55BAD_REG = -156};57585960static VMReg stack0;61// Names for registers62static const char *regName[];63static const int register_count;646566public:6768static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD_REG || bad_ok, "invalid"); return (VMReg) (intptr_t) val; }6970const char* name() {71if (is_reg()) {72return regName[value()];73} else if (!is_valid()) {74return "BAD";75} else {76// shouldn't really be called with stack77return "STACKED REG";78}79}80static VMReg Bad() { return (VMReg) (intptr_t) BAD_REG; }81bool is_valid() const { return ((intptr_t) this) != BAD_REG; }82bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; }83bool is_reg() const { return is_valid() && !is_stack(); }8485// A concrete register is a value that returns true for is_reg() and is86// also a register you could use in the assembler. On machines with87// 64bit registers only one half of the VMReg (and OptoReg) is considered88// concrete.89// bool is_concrete();9091// VMRegs are 4 bytes wide on all platforms92static const int stack_slot_size;93static const int slots_per_word;949596// This really ought to check that the register is "real" in the sense that97// we don't try and get the VMReg number of a physical register that doesn't98// have an expressible part. That would be pd specific code99VMReg next() {100assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be");101return (VMReg)(intptr_t)(value() + 1);102}103VMReg next(int i) {104assert((is_reg() && value() < stack0->value() - i) || is_stack(), "must be");105return (VMReg)(intptr_t)(value() + i);106}107VMReg prev() {108assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be");109return (VMReg)(intptr_t)(value() - 1);110}111112113intptr_t value() const {return (intptr_t) this; }114115void print_on(outputStream* st) const;116void print() const;117118// bias a stack slot.119// Typically used to adjust a virtual frame slots by amounts that are offset by120// amounts that are part of the native abi. The VMReg must be a stack slot121// and the result must be also.122123VMReg bias(int offset) {124assert(is_stack(), "must be");125// VMReg res = VMRegImpl::as_VMReg(value() + offset);126VMReg res = stack2reg(reg2stack() + offset);127assert(res->is_stack(), "must be");128return res;129}130131// Convert register numbers to stack slots and vice versa132static VMReg stack2reg( int idx ) {133return (VMReg) (intptr_t) (stack0->value() + idx);134}135136uintptr_t reg2stack() {137assert( is_stack(), "Not a stack-based register" );138return value() - stack0->value();139}140141static void set_regName();142143static VMReg vmStorageToVMReg(int type, int index);144145#include CPU_HEADER(vmreg)146147};148149//---------------------------VMRegPair-------------------------------------------150// Pairs of 32-bit registers for arguments.151// SharedRuntime::java_calling_convention will overwrite the structs with152// the calling convention's registers. VMRegImpl::Bad is returned for any153// unused 32-bit register. This happens for the unused high half of Int154// arguments, or for 32-bit pointers or for longs in the 32-bit sparc build155// (which are passed to natives in low 32-bits of e.g. O0/O1 and the high156// 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles157// always return a high and a low register, as do 64-bit pointers.158//159class VMRegPair {160private:161VMReg _second;162VMReg _first;163public:164void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); }165void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; }166void set2 ( VMReg v ) { _second=v->next(); _first=v; }167void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; }168void set_ptr ( VMReg ptr ) {169#ifdef _LP64170_second = ptr->next();171#else172_second = VMRegImpl::Bad();173#endif174_first = ptr;175}176// Return true if single register, even if the pair is really just adjacent stack slots177bool is_single_reg() const {178return (_first->is_valid()) && (_first->value() + 1 == _second->value());179}180181// Return true if single stack based "register" where the slot alignment matches input alignment182bool is_adjacent_on_stack(int alignment) const {183return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));184}185186// Return true if single stack based "register" where the slot alignment matches input alignment187bool is_adjacent_aligned_on_stack(int alignment) const {188return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));189}190191// Return true if single register but adjacent stack slots do not count192bool is_single_phys_reg() const {193return (_first->is_reg() && (_first->value() + 1 == _second->value()));194}195196VMReg second() const { return _second; }197VMReg first() const { return _first; }198VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; }199VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; }200VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); }201};202203#endif // SHARE_CODE_VMREG_HPP204205206