hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java
Print this page
rev 611 : Merge
@@ -1,7 +1,7 @@
/*
- * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -29,14 +29,14 @@
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
-// A ConstantPool is an array containing class constants
+// A ConstantPool is an oop containing class constants
// as described in the class file
-public class ConstantPool extends Array implements ClassConstants {
+public class ConstantPool extends Oop implements ClassConstants {
// Used for debugging this code
private static final boolean DEBUG = false;
protected void debugMessage(String message) {
System.out.println(message);
@@ -53,12 +53,13 @@
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
Type type = db.lookupType("constantPoolOopDesc");
tags = new OopField(type.getOopField("_tags"), 0);
cache = new OopField(type.getOopField("_cache"), 0);
poolHolder = new OopField(type.getOopField("_pool_holder"), 0);
+ length = new CIntField(type.getCIntegerField("_length"), 0);
headerSize = type.getSize();
- elementSize = db.getOopSize();
+ elementSize = 0;
}
ConstantPool(OopHandle handle, ObjectHeap heap) {
super(handle, heap);
}
@@ -66,24 +67,34 @@
public boolean isConstantPool() { return true; }
private static OopField tags;
private static OopField cache;
private static OopField poolHolder;
-
+ private static CIntField length; // number of elements in oop
private static long headerSize;
private static long elementSize;
public TypeArray getTags() { return (TypeArray) tags.getValue(this); }
public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); }
public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); }
+ public int getLength() { return (int)length.getValue(this); }
+
+ private long getElementSize() {
+ if (elementSize !=0 ) {
+ return elementSize;
+ } else {
+ elementSize = VM.getVM().getOopSize();
+ }
+ return elementSize;
+ }
private long indexOffset(long index) {
if (Assert.ASSERTS_ENABLED) {
- Assert.that(index > 0 && index < getLength(), "invalid cp index");
+ Assert.that(index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength());
}
- return (index * elementSize) + headerSize;
+ return (index * getElementSize()) + headerSize;
}
public ConstantTag getTagAt(long index) {
return new ConstantTag(getTags().getByteAt((int) index));
}
@@ -462,11 +473,11 @@
public void printValueOn(PrintStream tty) {
tty.print("ConstantPool for " + getPoolHolder().getName().asString());
}
public long getObjectSize() {
- return alignObjectSize(headerSize + (getLength() * elementSize));
+ return alignObjectSize(headerSize + (getLength() * getElementSize()));
}
//----------------------------------------------------------------------
// Internals only below this point
//