1/* 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25package sun.jvm.hotspot.oops; 26 27import java.util.*; 28import sun.jvm.hotspot.debugger.*; 29import sun.jvm.hotspot.runtime.*; 30import sun.jvm.hotspot.types.*; 31import sun.jvm.hotspot.utilities.*; 32 33public class ConstantPoolCacheEntry { 34 private static long size; 35 private static long baseOffset; 36 private static CIntegerField indices; 37 private static AddressField f1; 38 private static CIntegerField f2; 39 private static CIntegerField flags; 40 41 private ConstantPoolCache cp; 42 private long offset; 43 44 static { 45 VM.registerVMInitializedObserver(new Observer() { 46 public void update(Observable o, Object data) { 47 initialize(VM.getVM().getTypeDataBase()); 48 } 49 }); 50 } 51 52 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 53 Type type = db.lookupType("ConstantPoolCacheEntry"); 54 size = type.getSize(); 55 56 indices = type.getCIntegerField("_indices"); 57 f1 = type.getAddressField ("_f1"); 58 f2 = type.getCIntegerField("_f2"); 59 flags = type.getCIntegerField("_flags"); 60 61 type = db.lookupType("ConstantPoolCache"); 62 baseOffset = type.getSize(); 63 } 64 65 ConstantPoolCacheEntry(ConstantPoolCache cp, int index) { 66 this.cp = cp; 67 offset = baseOffset + index * size; 68 } 69 70 public int getConstantPoolIndex() { 71 if (Assert.ASSERTS_ENABLED) { 72 Assert.that((getIndices() & 0xFFFF) != 0, "must be main entry"); 73 } 74 return (int) (getIndices() & 0xFFFF); 75 } 76 77 private long getIndices() { 78 return cp.getAddress().getCIntegerAt(indices.getOffset() + offset, indices.getSize(), indices.isUnsigned()); 79 } 80 81 public Metadata getF1() { 82 return Metadata.instantiateWrapperFor(cp.getAddress().getAddressAt(f1.getOffset() + offset)); 83 } 84 85 public int getF2() { 86 return cp.getAddress().getJIntAt(f1.getOffset() + offset); 87 } 88 89 public int getFlags() { 90 return cp.getAddress().getJIntAt(flags.getOffset() + offset); 91 } 92 93 static NamedFieldIdentifier f1FieldName = new NamedFieldIdentifier("_f1"); 94 static NamedFieldIdentifier f2FieldName = new NamedFieldIdentifier("_f2"); 95 static NamedFieldIdentifier flagsFieldName = new NamedFieldIdentifier("_flags"); 96 97 public void iterateFields(MetadataVisitor visitor) { 98 visitor.doOop(new OopField(f1FieldName, f1.getOffset() + offset, true), true); 99 visitor.doInt(new IntField(f2FieldName, f2.getOffset() + offset, true), true); 100 visitor.doInt(new IntField(flagsFieldName, flags.getOffset() + offset, true), true); 101 } 102} 103