Path: blob/master/src/hotspot/share/code/location.hpp
40931 views
/*1* Copyright (c) 1997, 2019, 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_LOCATION_HPP25#define SHARE_CODE_LOCATION_HPP2627#include "asm/assembler.hpp"28#include "code/vmreg.hpp"2930class DebugInfoReadStream;31class DebugInfoWriteStream;3233// A Location describes a concrete machine variable location34// (such as integer or floating point register or a stack-held35// variable). Used when generating debug-information for nmethods.36//37// Encoding:38//39// bits (use low bits for best compression):40// Type: [3..0]41// Where: [4]42// Offset: [31..5]4344class Location {45friend class VMStructs;46public:47enum Where {48on_stack,49in_register50};5152enum Type {53invalid, // Invalid location54normal, // Ints, floats, double halves55oop, // Oop (please GC me!)56int_in_long, // Integer held in long register57lng, // Long held in one register58float_in_dbl, // Float held in double register59dbl, // Double held in one register60vector, // Vector in one register61addr, // JSR return address62narrowoop // Narrow Oop (please GC me!)63};646566private:67enum {68TYPE_MASK = (juint) 0x0F,69TYPE_SHIFT = 0,70WHERE_MASK = (juint) 0x10,71WHERE_SHIFT = 4,72OFFSET_MASK = (juint) 0xFFFFFFE0,73OFFSET_SHIFT = 574};7576juint _value;7778// Create a bit-packed Location79Location(Where where_, Type type_, unsigned offset_) {80set(where_, type_, offset_);81assert( where () == where_ , "" );82assert( type () == type_ , "" );83assert( offset() == offset_, "" );84}8586inline void set(Where where_, Type type_, unsigned offset_) {87_value = (juint) ((where_ << WHERE_SHIFT) |88(type_ << TYPE_SHIFT) |89((offset_ << OFFSET_SHIFT) & OFFSET_MASK));90}9192public:9394// Stack location Factory. Offset is 4-byte aligned; remove low bits95static Location new_stk_loc( Type t, int offset ) { return Location(on_stack,t,offset>>LogBytesPerInt); }96// Register location Factory97static Location new_reg_loc( Type t, VMReg reg ) { return Location(in_register, t, reg->value()); }98// Default constructor99Location() { set(on_stack,invalid,0); }100101// Bit field accessors102Where where() const { return (Where) ((_value & WHERE_MASK) >> WHERE_SHIFT);}103Type type() const { return (Type) ((_value & TYPE_MASK) >> TYPE_SHIFT); }104unsigned offset() const { return (unsigned) ((_value & OFFSET_MASK) >> OFFSET_SHIFT); }105106// Accessors107bool is_register() const { return where() == in_register; }108bool is_stack() const { return where() == on_stack; }109110int stack_offset() const { assert(where() == on_stack, "wrong Where"); return offset()<<LogBytesPerInt; }111int register_number() const { assert(where() == in_register, "wrong Where"); return offset() ; }112113VMReg reg() const { assert(where() == in_register, "wrong Where"); return VMRegImpl::as_VMReg(offset()) ; }114115// Printing116void print_on(outputStream* st) const;117118// Serialization of debugging information119Location(DebugInfoReadStream* stream);120void write_on(DebugInfoWriteStream* stream);121122// check123static bool legal_offset_in_bytes(int offset_in_bytes);124};125126#endif // SHARE_CODE_LOCATION_HPP127128129