Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstantPoolCache.java
41161 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.oops;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.*;32import sun.jvm.hotspot.utilities.Observable;33import sun.jvm.hotspot.utilities.Observer;3435// ConstantPoolCache : A constant pool cache (ConstantPoolCache).36// See cpCache.hpp for details about this class.37//38public class ConstantPoolCache extends Metadata {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("ConstantPoolCache");49constants = new MetadataField(type.getAddressField("_constant_pool"), 0);50baseOffset = type.getSize();51Type elType = db.lookupType("ConstantPoolCacheEntry");52elementSize = elType.getSize();53length = new CIntField(type.getCIntegerField("_length"), 0);54intSize = VM.getVM().getObjectHeap().getIntSize();55resolvedReferences = type.getAddressField("_resolved_references");56referenceMap = type.getAddressField("_reference_map");57}5859public ConstantPoolCache(Address addr) {60super(addr);61}6263public boolean isConstantPoolCache() { return true; }6465private static MetadataField constants;6667private static long baseOffset;68private static long elementSize;69private static CIntField length;70private static long intSize;71private static AddressField resolvedReferences;72private static AddressField referenceMap;7374public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }7576public long getSize() {77return alignSize(baseOffset + getLength() * elementSize);78}7980public ConstantPoolCacheEntry getEntryAt(int i) {81if (i < 0 || i >= getLength()) throw new IndexOutOfBoundsException(i + " " + getLength());82return new ConstantPoolCacheEntry(this, i);83}8485public int getIntAt(int entry, int fld) {86long offset = baseOffset + entry * elementSize + fld * intSize;87return (int) getAddress().getCIntegerAt(offset, intSize, true );88}899091public void printValueOn(PrintStream tty) {92tty.print("ConstantPoolCache for " + getConstants().getPoolHolder().getName().asString() + " address = " + getAddress() + " offset = " + baseOffset);93}9495public int getLength() {96return (int) length.getValue(getAddress());97}9899public void iterateFields(MetadataVisitor visitor) {100super.iterateFields(visitor);101visitor.doMetadata(constants, true);102for (int i = 0; i < getLength(); i++) {103ConstantPoolCacheEntry entry = getEntryAt(i);104entry.iterateFields(visitor);105}106}107108public Oop getResolvedReferences() {109Address handle = resolvedReferences.getValue(getAddress());110if (handle != null) {111// Load through the handle112OopHandle refs = handle.getOopHandleAt(0);113return VM.getVM().getObjectHeap().newOop(refs);114}115return null;116}117118public U2Array referenceMap() {119return new U2Array(referenceMap.getValue(getAddress()));120}121};122123124