Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/CodeBlob.java
41171 views
/*1* Copyright (c) 2015, 2021, 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*/22package sun.jvm.hotspot.code;2324import sun.jvm.hotspot.compiler.ImmutableOopMap;25import sun.jvm.hotspot.compiler.ImmutableOopMapSet;26import sun.jvm.hotspot.debugger.Address;27import sun.jvm.hotspot.runtime.VM;28import sun.jvm.hotspot.runtime.VMObject;29import sun.jvm.hotspot.types.AddressField;30import sun.jvm.hotspot.types.CIntegerField;31import sun.jvm.hotspot.types.Type;32import sun.jvm.hotspot.types.TypeDataBase;33import sun.jvm.hotspot.utilities.Assert;34import sun.jvm.hotspot.utilities.CStringUtilities;3536import java.io.PrintStream;37import sun.jvm.hotspot.utilities.Observable;38import sun.jvm.hotspot.utilities.Observer;3940public class CodeBlob extends VMObject {41private static AddressField nameField;42private static CIntegerField sizeField;43private static CIntegerField headerSizeField;44private static AddressField contentBeginField;45private static AddressField codeBeginField;46private static AddressField codeEndField;47private static AddressField dataEndField;48private static CIntegerField frameCompleteOffsetField;49private static CIntegerField dataOffsetField;50private static CIntegerField frameSizeField;51private static AddressField oopMapsField;5253public CodeBlob(Address addr) {54super(addr);55}5657protected static int matcherInterpreterFramePointerReg;5859private static void initialize(TypeDataBase db) {60Type type = db.lookupType("CodeBlob");6162nameField = type.getAddressField("_name");63sizeField = type.getCIntegerField("_size");64headerSizeField = type.getCIntegerField("_header_size");65frameCompleteOffsetField = type.getCIntegerField("_frame_complete_offset");66contentBeginField = type.getAddressField("_content_begin");67codeBeginField = type.getAddressField("_code_begin");68codeEndField = type.getAddressField("_code_end");69dataEndField = type.getAddressField("_data_end");70dataOffsetField = type.getCIntegerField("_data_offset");71frameSizeField = type.getCIntegerField("_frame_size");72oopMapsField = type.getAddressField("_oop_maps");7374if (VM.getVM().isServerCompiler()) {75matcherInterpreterFramePointerReg =76db.lookupIntConstant("Matcher::interpreter_frame_pointer_reg").intValue();77}78}7980static {81VM.registerVMInitializedObserver(new Observer() {82public void update(Observable o, Object data) {83initialize(VM.getVM().getTypeDataBase());84}85});86}8788public Address headerBegin() { return getAddress(); }8990public Address headerEnd() { return getAddress().addOffsetTo(getHeaderSize()); }9192public Address contentBegin() { return contentBeginField.getValue(addr); }9394public Address contentEnd() { return headerBegin().addOffsetTo(getDataOffset()); }9596public Address codeBegin() { return codeBeginField.getValue(addr); }9798public Address codeEnd() { return codeEndField.getValue(addr); }99100public Address dataBegin() { return headerBegin().addOffsetTo(getDataOffset()); }101102public Address dataEnd() { return dataEndField.getValue(addr); }103104public long getFrameCompleteOffset() { return frameCompleteOffsetField.getValue(addr); }105106public int getDataOffset() { return (int) dataOffsetField.getValue(addr); }107108// Sizes109public int getSize() { return (int) sizeField.getValue(addr); }110111public int getHeaderSize() { return (int) headerSizeField.getValue(addr); }112113public long getFrameSizeWords() {114return (int) frameSizeField.getValue(addr);115}116117public String getName() {118return CStringUtilities.getString(nameField.getValue(addr));119}120121/** OopMap for frame; can return null if none available */122123public ImmutableOopMapSet getOopMaps() {124Address value = oopMapsField.getValue(addr);125if (value == null) {126return null;127}128return new ImmutableOopMapSet(value);129}130131132// Typing133public boolean isBufferBlob() { return false; }134135public boolean isCompiled() { return false; }136137public boolean isNMethod() { return false; }138139public boolean isRuntimeStub() { return false; }140141public boolean isDeoptimizationStub() { return false; }142143public boolean isUncommonTrapStub() { return false; }144145public boolean isExceptionStub() { return false; }146147public boolean isSafepointStub() { return false; }148149public boolean isAdapterBlob() { return false; }150151// Fine grain nmethod support: isNmethod() == isJavaMethod() || isNativeMethod() || isOSRMethod()152public boolean isJavaMethod() { return false; }153154public boolean isNativeMethod() { return false; }155156/** On-Stack Replacement method */157public boolean isOSRMethod() { return false; }158159public NMethod asNMethodOrNull() {160if (isNMethod()) return (NMethod)this;161return null;162}163164// FIXME: add getRelocationSize()165public int getContentSize() { return (int) contentEnd().minus(contentBegin()); }166167public int getCodeSize() { return (int) codeEnd() .minus(codeBegin()); }168169public int getDataSize() { return (int) dataEnd() .minus(dataBegin()); }170171// Containment172public boolean blobContains(Address addr) { return headerBegin() .lessThanOrEqual(addr) && dataEnd() .greaterThan(addr); }173174// FIXME: add relocationContains175public boolean contentContains(Address addr) { return contentBegin().lessThanOrEqual(addr) && contentEnd().greaterThan(addr); }176177public boolean codeContains(Address addr) { return codeBegin() .lessThanOrEqual(addr) && codeEnd() .greaterThan(addr); }178179public boolean dataContains(Address addr) { return dataBegin() .lessThanOrEqual(addr) && dataEnd() .greaterThan(addr); }180181public boolean contains(Address addr) { return contentContains(addr); }182183public boolean isFrameCompleteAt(Address a) { return codeContains(a) && a.minus(codeBegin()) >= getFrameCompleteOffset(); }184185// Reclamation support (really only used by the nmethods, but in order to get asserts to work186// in the CodeCache they are defined virtual here)187public boolean isZombie() { return false; }188189public boolean isLockedByVM() { return false; }190191public ImmutableOopMap getOopMapForReturnAddress(Address returnAddress, boolean debugging) {192Address pc = returnAddress;193if (Assert.ASSERTS_ENABLED) {194Assert.that(getOopMaps() != null, "nope");195}196return getOopMaps().findMapAtOffset(pc.minus(codeBegin()), debugging);197}198199/** NOTE: this returns a size in BYTES in this system! */200public long getFrameSize() {201return VM.getVM().getAddressSize() * getFrameSizeWords();202}203204// Returns true, if the next frame is responsible for GC'ing oops passed as arguments205public boolean callerMustGCArguments() { return false; }206207public void print() {208printOn(System.out);209}210211public void printOn(PrintStream tty) {212tty.print(getName());213printComponentsOn(tty);214}215216protected void printComponentsOn(PrintStream tty) {217tty.println(" content: [" + contentBegin() + ", " + contentEnd() + "), " +218" code: [" + codeBegin() + ", " + codeEnd() + "), " +219" data: [" + dataBegin() + ", " + dataEnd() + "), " +220" frame size: " + getFrameSize());221}222}223224225