Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapValue.java
41171 views
/*1* Copyright (c) 2000, 2020, 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*/2324package sun.jvm.hotspot.compiler;2526import java.util.*;2728import sun.jvm.hotspot.code.*;29import sun.jvm.hotspot.runtime.*;30import sun.jvm.hotspot.types.*;31import sun.jvm.hotspot.utilities.*;32import sun.jvm.hotspot.utilities.Observable;33import sun.jvm.hotspot.utilities.Observer;3435public class OopMapValue {36private short value;37private short contentReg;3839/** Read from target VM; located in compiler/oopMap.hpp */40// How bits are organized41static int TYPE_BITS;42static int REGISTER_BITS;43static int TYPE_SHIFT;44static int REGISTER_SHIFT;45static int TYPE_MASK;46static int TYPE_MASK_IN_PLACE;47static int REGISTER_MASK;48static int REGISTER_MASK_IN_PLACE;4950// Types of OopValues51static int OOP_VALUE;52static int NARROWOOP_VALUE;53static int CALLEE_SAVED_VALUE;54static int DERIVED_OOP_VALUE;5556static {57VM.registerVMInitializedObserver(new Observer() {58public void update(Observable o, Object data) {59initialize(VM.getVM().getTypeDataBase());60}61});62}6364private static void initialize(TypeDataBase db) {65TYPE_BITS = db.lookupIntConstant("OopMapValue::type_bits").intValue();66REGISTER_BITS = db.lookupIntConstant("OopMapValue::register_bits").intValue();67TYPE_SHIFT = db.lookupIntConstant("OopMapValue::type_shift").intValue();68REGISTER_SHIFT = db.lookupIntConstant("OopMapValue::register_shift").intValue();69TYPE_MASK = db.lookupIntConstant("OopMapValue::type_mask").intValue();70TYPE_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue();71REGISTER_MASK = db.lookupIntConstant("OopMapValue::register_mask").intValue();72REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue();73OOP_VALUE = db.lookupIntConstant("OopMapValue::oop_value").intValue();74NARROWOOP_VALUE = db.lookupIntConstant("OopMapValue::narrowoop_value").intValue();75CALLEE_SAVED_VALUE = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue();76DERIVED_OOP_VALUE = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue();77}7879public static abstract class OopTypes {80public static final OopTypes OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE; }};81public static final OopTypes NARROWOOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.NARROWOOP_VALUE; }};82public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }};83public static final OopTypes DERIVED_OOP_VALUE = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE; }};8485abstract int getValue();86protected OopTypes() {}87}8889public OopMapValue() { setValue((short) 0); setContentReg(new VMReg(0)); }90public OopMapValue(VMReg reg, OopTypes t) { setReg(reg); setType(t); }91public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); }92public OopMapValue(CompressedReadStream stream) { readFrom(stream); }9394public void readFrom(CompressedReadStream stream) {95setValue((short) stream.readInt());96if (isCalleeSaved() || isDerivedOop()) {97setContentReg(new VMReg(stream.readInt()));98}99}100101// Querying102public boolean isOop() { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE; }103public boolean isNarrowOop() { return (getValue() & TYPE_MASK_IN_PLACE) == NARROWOOP_VALUE; }104public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; }105public boolean isDerivedOop() { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE; }106107public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); }108public void setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); }109110public OopTypes getType() {111int which = (getValue() & TYPE_MASK_IN_PLACE);112if (which == OOP_VALUE) return OopTypes.OOP_VALUE;113else if (which == NARROWOOP_VALUE) return OopTypes.NARROWOOP_VALUE;114else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE;115else if (which == DERIVED_OOP_VALUE) return OopTypes.DERIVED_OOP_VALUE;116else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")");117}118public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); }119120public VMReg getContentReg() { return new VMReg(contentReg); }121public void setContentReg(VMReg r) { contentReg = (short) r.getValue(); }122123/** Physical location queries */124public boolean isRegisterLoc() { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); }125public boolean isStackLoc() { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); }126127/** Returns offset from sp. */128public int getStackOffset() {129if (Assert.ASSERTS_ENABLED) {130Assert.that(isStackLoc(), "must be stack location");131}132return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0());133}134135//--------------------------------------------------------------------------------136// Internals only below this point137//138139private void setValue(short value) {140this.value = value;141}142143private int getValue() {144return value;145}146}147148149