Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/PCDesc.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.code;2526import java.io.*;27import java.util.*;28import sun.jvm.hotspot.debugger.*;29import sun.jvm.hotspot.runtime.*;30import sun.jvm.hotspot.types.*;31import sun.jvm.hotspot.utilities.Observable;32import sun.jvm.hotspot.utilities.Observer;3334/** PcDescs map a physical PC (given as offset from start of nmethod)35to the corresponding source scope and byte code index. */3637public class PCDesc extends VMObject {38private static CIntegerField pcOffsetField;39private static CIntegerField scopeDecodeOffsetField;40private static CIntegerField objDecodeOffsetField;41private static CIntegerField pcFlagsField;42private static int reexecuteMask;43private static int isMethodHandleInvokeMask;44private static int returnOopMask;4546static {47VM.registerVMInitializedObserver(new Observer() {48public void update(Observable o, Object data) {49initialize(VM.getVM().getTypeDataBase());50}51});52}5354private static void initialize(TypeDataBase db) {55Type type = db.lookupType("PcDesc");5657pcOffsetField = type.getCIntegerField("_pc_offset");58scopeDecodeOffsetField = type.getCIntegerField("_scope_decode_offset");59objDecodeOffsetField = type.getCIntegerField("_obj_decode_offset");60pcFlagsField = type.getCIntegerField("_flags");6162reexecuteMask = db.lookupIntConstant("PcDesc::PCDESC_reexecute");63isMethodHandleInvokeMask = db.lookupIntConstant("PcDesc::PCDESC_is_method_handle_invoke");64returnOopMask = db.lookupIntConstant("PcDesc::PCDESC_return_oop");65}6667public PCDesc(Address addr) {68super(addr);69}7071// FIXME: add additional constructor probably needed for ScopeDesc::sender()7273public int getPCOffset() {74return (int) pcOffsetField.getValue(addr);75}7677public int getScopeDecodeOffset() {78return ((int) scopeDecodeOffsetField.getValue(addr));79}8081public int getObjDecodeOffset() {82return ((int) objDecodeOffsetField.getValue(addr));83}8485public Address getRealPC(NMethod code) {86return code.codeBegin().addOffsetTo(getPCOffset());87}888990public boolean getReexecute() {91int flags = (int)pcFlagsField.getValue(addr);92return (flags & reexecuteMask) != 0;93}9495public boolean isMethodHandleInvoke() {96int flags = (int)pcFlagsField.getValue(addr);97return (flags & isMethodHandleInvokeMask) != 0;98}99100public void print(NMethod code) {101printOn(System.out, code);102}103104public void printOn(PrintStream tty, NMethod code) {105tty.println("PCDesc(" + getRealPC(code) + "):");106for (ScopeDesc sd = code.getScopeDescAt(getRealPC(code));107sd != null;108sd = sd.sender()) {109tty.print(" ");110sd.getMethod().printValueOn(tty);111tty.print(" @" + sd.getBCI());112tty.print(" reexecute=" + sd.getReexecute());113tty.println();114}115}116}117118119