Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/vmreg.hpp
32285 views
/*1* Copyright (c) 1998, 2015, 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_VM_CODE_VMREG_HPP25#define SHARE_VM_CODE_VMREG_HPP2627#include "memory/allocation.hpp"28#include "utilities/globalDefinitions.hpp"29#include "asm/register.hpp"3031#ifdef COMPILER232#include "opto/adlcVMDeps.hpp"33#include "utilities/ostream.hpp"34#if defined ADGLOBALS_MD_HPP35# include ADGLOBALS_MD_HPP36#elif defined TARGET_ARCH_MODEL_x86_3237# include "adfiles/adGlobals_x86_32.hpp"38#elif defined TARGET_ARCH_MODEL_x86_6439# include "adfiles/adGlobals_x86_64.hpp"40#elif defined TARGET_ARCH_MODEL_aarch3241# include "adfiles/adGlobals_aarch32.hpp"42#elif defined TARGET_ARCH_MODEL_aarch6443# include "adfiles/adGlobals_aarch64.hpp"44#elif defined TARGET_ARCH_MODEL_sparc45# include "adfiles/adGlobals_sparc.hpp"46#elif defined TARGET_ARCH_MODEL_zero47# include "adfiles/adGlobals_zero.hpp"48#elif defined TARGET_ARCH_MODEL_ppc_6449# include "adfiles/adGlobals_ppc_64.hpp"50#endif51#endif5253//------------------------------VMReg------------------------------------------54// The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots.55// Register numbers below VMRegImpl::stack0 are the same for both. Register56// numbers above stack0 are either warped (in the compiler) or unwarped57// (in the VM). Unwarped numbers represent stack indices, offsets from58// the current stack pointer. Warped numbers are required during compilation59// when we do not yet know how big the frame will be.6061class VMRegImpl;62typedef VMRegImpl* VMReg;6364class VMRegImpl {65// friend class OopMap;66friend class VMStructs;67friend class OptoReg;68// friend class Location;69private:70enum {71BAD_REG = -172};73747576static VMReg stack0;77// Names for registers78static const char *regName[];79static const int register_count;808182public:8384static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD_REG || bad_ok, "invalid"); return (VMReg) (intptr_t) val; }8586const char* name() {87if (is_reg()) {88return regName[value()];89} else if (!is_valid()) {90return "BAD";91} else {92// shouldn't really be called with stack93return "STACKED REG";94}95}96static VMReg Bad() { return (VMReg) (intptr_t) BAD_REG; }97bool is_valid() const { return ((intptr_t) this) != BAD_REG; }98bool is_stack() const { return (intptr_t) this >= (intptr_t) stack0; }99bool is_reg() const { return is_valid() && !is_stack(); }100101// A concrete register is a value that returns true for is_reg() and is102// also a register you could use in the assembler. On machines with103// 64bit registers only one half of the VMReg (and OptoReg) is considered104// concrete.105bool is_concrete();106107// VMRegs are 4 bytes wide on all platforms108static const int stack_slot_size;109static const int slots_per_word;110111112// This really ought to check that the register is "real" in the sense that113// we don't try and get the VMReg number of a physical register that doesn't114// have an expressible part. That would be pd specific code115VMReg next() {116assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be");117return (VMReg)(intptr_t)(value() + 1);118}119VMReg next(int i) {120assert((is_reg() && value() < stack0->value() - i) || is_stack(), "must be");121return (VMReg)(intptr_t)(value() + i);122}123VMReg prev() {124assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be");125return (VMReg)(intptr_t)(value() - 1);126}127128129intptr_t value() const {return (intptr_t) this; }130131void print_on(outputStream* st) const;132void print() const { print_on(tty); }133134// bias a stack slot.135// Typically used to adjust a virtual frame slots by amounts that are offset by136// amounts that are part of the native abi. The VMReg must be a stack slot137// and the result must be also.138139VMReg bias(int offset) {140assert(is_stack(), "must be");141// VMReg res = VMRegImpl::as_VMReg(value() + offset);142VMReg res = stack2reg(reg2stack() + offset);143assert(res->is_stack(), "must be");144return res;145}146147// Convert register numbers to stack slots and vice versa148static VMReg stack2reg( int idx ) {149return (VMReg) (intptr_t) (stack0->value() + idx);150}151152uintptr_t reg2stack() {153assert( is_stack(), "Not a stack-based register" );154return value() - stack0->value();155}156157static void set_regName();158159#ifdef TARGET_ARCH_x86160# include "vmreg_x86.hpp"161#endif162#ifdef TARGET_ARCH_aarch32163# include "vmreg_aarch32.hpp"164#endif165#ifdef TARGET_ARCH_aarch64166# include "vmreg_aarch64.hpp"167#endif168#ifdef TARGET_ARCH_sparc169# include "vmreg_sparc.hpp"170#endif171#ifdef TARGET_ARCH_zero172# include "vmreg_zero.hpp"173#endif174#ifdef TARGET_ARCH_arm175# include "vmreg_arm.hpp"176#endif177#ifdef TARGET_ARCH_ppc178# include "vmreg_ppc.hpp"179#endif180181182};183184//---------------------------VMRegPair-------------------------------------------185// Pairs of 32-bit registers for arguments.186// SharedRuntime::java_calling_convention will overwrite the structs with187// the calling convention's registers. VMRegImpl::Bad is returned for any188// unused 32-bit register. This happens for the unused high half of Int189// arguments, or for 32-bit pointers or for longs in the 32-bit sparc build190// (which are passed to natives in low 32-bits of e.g. O0/O1 and the high191// 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles192// always return a high and a low register, as do 64-bit pointers.193//194class VMRegPair {195private:196VMReg _second;197VMReg _first;198public:199void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); }200void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; }201void set2 ( VMReg v ) { _second=v->next(); _first=v; }202void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; }203void set_ptr ( VMReg ptr ) {204#ifdef _LP64205_second = ptr->next();206#else207_second = VMRegImpl::Bad();208#endif209_first = ptr;210}211// Return true if single register, even if the pair is really just adjacent stack slots212bool is_single_reg() const {213return (_first->is_valid()) && (_first->value() + 1 == _second->value());214}215216// Return true if single stack based "register" where the slot alignment matches input alignment217bool is_adjacent_on_stack(int alignment) const {218return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));219}220221// Return true if single stack based "register" where the slot alignment matches input alignment222bool is_adjacent_aligned_on_stack(int alignment) const {223return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));224}225226// Return true if single register but adjacent stack slots do not count227bool is_single_phys_reg() const {228return (_first->is_reg() && (_first->value() + 1 == _second->value()));229}230231VMReg second() const { return _second; }232VMReg first() const { return _first; }233VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; }234VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; }235VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); }236};237238#endif // SHARE_VM_CODE_VMREG_HPP239240241