Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ci/ciInstanceKlass.java
41161 views
/*1* Copyright (c) 2011, 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.ci;2526import java.io.*;27import java.util.*;28import sun.jvm.hotspot.debugger.*;29import sun.jvm.hotspot.memory.SystemDictionary;30import sun.jvm.hotspot.runtime.*;31import sun.jvm.hotspot.oops.*;32import sun.jvm.hotspot.types.Type;33import sun.jvm.hotspot.types.TypeDataBase;34import sun.jvm.hotspot.types.WrongTypeException;35import sun.jvm.hotspot.utilities.Observable;36import sun.jvm.hotspot.utilities.Observer;3738public class ciInstanceKlass extends ciKlass {39static {40VM.registerVMInitializedObserver(new Observer() {41public void update(Observable o, Object data) {42initialize(VM.getVM().getTypeDataBase());43}44});45}4647private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {48Type type = db.lookupType("ciInstanceKlass");49initStateField = new CIntField(type.getCIntegerField("_init_state"), 0);50isSharedField = new CIntField(type.getCIntegerField("_is_shared"), 0);51CLASS_STATE_LINKED = db.lookupIntConstant("InstanceKlass::linked").intValue();52CLASS_STATE_FULLY_INITIALIZED = db.lookupIntConstant("InstanceKlass::fully_initialized").intValue();53}5455private static CIntField initStateField;56private static CIntField isSharedField;57private static int CLASS_STATE_LINKED;58private static int CLASS_STATE_FULLY_INITIALIZED;5960public ciInstanceKlass(Address addr) {61super(addr);62}6364public int initState() {65int initState = (int)initStateField.getValue(getAddress());66if (isShared() && initState < CLASS_STATE_LINKED) {67InstanceKlass ik = (InstanceKlass)getMetadata();68initState = ik.getInitStateAsInt();69}70return initState;71}7273public boolean isShared() {74return isSharedField.getValue(getAddress()) != 0;75}7677public boolean isLinked() {78return initState() >= CLASS_STATE_LINKED;79}8081public boolean isInitialized() {82return initState() == CLASS_STATE_FULLY_INITIALIZED;83}8485public void dumpReplayData(PrintStream out) {86InstanceKlass ik = (InstanceKlass)getMetadata();87ConstantPool cp = ik.getConstants();8889// Try to record related loaded classes90Klass sub = ik.getSubklassKlass();91while (sub != null) {92if (sub instanceof InstanceKlass) {93out.println("instanceKlass " + sub.getName().asString());94}95sub = sub.getNextSiblingKlass();96}9798final int length = (int) cp.getLength();99out.print("ciInstanceKlass " + name() + " " + (isLinked() ? 1 : 0) + " " + (isInitialized() ? 1 : 0) + " " + length);100for (int index = 1; index < length; index++) {101out.print(" " + cp.getTags().at(index));102}103out.println();104if (isInitialized()) {105Field[] staticFields = ik.getStaticFields();106for (int i = 0; i < staticFields.length; i++) {107Field f = staticFields[i];108Oop mirror = ik.getJavaMirror();109if (f.isFinal() && !f.hasInitialValue()) {110out.print("staticfield " + name() + " " +111OopUtilities.escapeString(f.getID().getName()) + " " +112f.getFieldType().getSignature().asString() + " ");113if (f instanceof ByteField) {114ByteField bf = (ByteField)f;115out.println(bf.getValue(mirror));116} else if (f instanceof BooleanField) {117BooleanField bf = (BooleanField)f;118out.println(bf.getValue(mirror) ? 1 : 0);119} else if (f instanceof ShortField) {120ShortField bf = (ShortField)f;121out.println(bf.getValue(mirror));122} else if (f instanceof CharField) {123CharField bf = (CharField)f;124out.println(bf.getValue(mirror) & 0xffff);125} else if (f instanceof IntField) {126IntField bf = (IntField)f;127out.println(bf.getValue(mirror));128} else if (f instanceof LongField) {129LongField bf = (LongField)f;130out.println(bf.getValue(mirror));131} else if (f instanceof FloatField) {132FloatField bf = (FloatField)f;133out.println(Float.floatToRawIntBits(bf.getValue(mirror)));134} else if (f instanceof DoubleField) {135DoubleField bf = (DoubleField)f;136out.println(Double.doubleToRawLongBits(bf.getValue(mirror)));137} else if (f instanceof OopField) {138OopField bf = (OopField)f;139Oop value = bf.getValue(mirror);140if (value == null) {141out.println("null");142} else if (value.isInstance()) {143Instance inst = (Instance)value;144if (inst.isA(SystemDictionary.getStringKlass())) {145out.println("\"" + OopUtilities.stringOopToEscapedString(inst) + "\"");146} else {147out.println(inst.getKlass().getName().asString());148}149} else if (value.isObjArray()) {150ObjArray oa = (ObjArray)value;151Klass ek = (ObjArrayKlass)oa.getKlass();152out.println(oa.getLength() + " " + ek.getName().asString());153} else if (value.isTypeArray()) {154TypeArray ta = (TypeArray)value;155out.println(ta.getLength());156} else {157out.println(value);158}159}160}161}162}163}164}165166167