Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/VMRegImpl.java
41161 views
/*1* Copyright (c) 2006, 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.util.*;2728import sun.jvm.hotspot.debugger.*;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 VMRegImpl {3637private static VMReg stack0;38private static int stack0Val;39private static Address stack0Addr;40private static AddressField regNameField;41private static int stackSlotSize;4243static {44VM.registerVMInitializedObserver(new Observer() {45public void update(Observable o, Object data) {46initialize(VM.getVM().getTypeDataBase());47}48});49}5051private static void initialize(TypeDataBase db) {52Type type = db.lookupType("VMRegImpl");53AddressField stack0Field = type.getAddressField("stack0");54stack0Addr = stack0Field.getValue();55stack0Val = (int) stack0Addr.hashCode();56stack0 = new VMReg(stack0Val);57regNameField = type.getAddressField("regName[0]");58stackSlotSize = db.lookupIntConstant("VMRegImpl::stack_slot_size");59}6061public static VMReg getStack0() {62return stack0;63}6465public static String getRegisterName(int index) {66if (Assert.ASSERTS_ENABLED) {67Assert.that(index >= 0 && index < stack0Val, "invalid index : " + index);68}69Address regName = regNameField.getStaticFieldAddress();70long addrSize = VM.getVM().getAddressSize();71return CStringUtilities.getString(regName.getAddressAt(index * addrSize));72}7374public static int getStackSlotSize() {75return stackSlotSize;76}77}787980