29 import sun.jvm.hotspot.debugger.*; |
29 import sun.jvm.hotspot.debugger.*; |
30 import sun.jvm.hotspot.runtime.*; |
30 import sun.jvm.hotspot.runtime.*; |
31 import sun.jvm.hotspot.types.*; |
31 import sun.jvm.hotspot.types.*; |
32 import sun.jvm.hotspot.utilities.*; |
32 import sun.jvm.hotspot.utilities.*; |
33 |
33 |
34 // A ConstantPool is an array containing class constants |
34 // A ConstantPool is an oop containing class constants |
35 // as described in the class file |
35 // as described in the class file |
36 |
36 |
37 public class ConstantPool extends Array implements ClassConstants { |
37 public class ConstantPool extends Oop implements ClassConstants { |
38 // Used for debugging this code |
38 // Used for debugging this code |
39 private static final boolean DEBUG = false; |
39 private static final boolean DEBUG = false; |
40 |
40 |
41 protected void debugMessage(String message) { |
41 protected void debugMessage(String message) { |
42 System.out.println(message); |
42 System.out.println(message); |
53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
53 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
54 Type type = db.lookupType("constantPoolOopDesc"); |
54 Type type = db.lookupType("constantPoolOopDesc"); |
55 tags = new OopField(type.getOopField("_tags"), 0); |
55 tags = new OopField(type.getOopField("_tags"), 0); |
56 cache = new OopField(type.getOopField("_cache"), 0); |
56 cache = new OopField(type.getOopField("_cache"), 0); |
57 poolHolder = new OopField(type.getOopField("_pool_holder"), 0); |
57 poolHolder = new OopField(type.getOopField("_pool_holder"), 0); |
|
58 length = new CIntField(type.getCIntegerField("_length"), 0); |
58 headerSize = type.getSize(); |
59 headerSize = type.getSize(); |
59 elementSize = db.getOopSize(); |
60 elementSize = 0; |
60 } |
61 } |
61 |
62 |
62 ConstantPool(OopHandle handle, ObjectHeap heap) { |
63 ConstantPool(OopHandle handle, ObjectHeap heap) { |
63 super(handle, heap); |
64 super(handle, heap); |
64 } |
65 } |
66 public boolean isConstantPool() { return true; } |
67 public boolean isConstantPool() { return true; } |
67 |
68 |
68 private static OopField tags; |
69 private static OopField tags; |
69 private static OopField cache; |
70 private static OopField cache; |
70 private static OopField poolHolder; |
71 private static OopField poolHolder; |
71 |
72 private static CIntField length; // number of elements in oop |
72 |
73 |
73 private static long headerSize; |
74 private static long headerSize; |
74 private static long elementSize; |
75 private static long elementSize; |
75 |
76 |
76 public TypeArray getTags() { return (TypeArray) tags.getValue(this); } |
77 public TypeArray getTags() { return (TypeArray) tags.getValue(this); } |
77 public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); } |
78 public ConstantPoolCache getCache() { return (ConstantPoolCache) cache.getValue(this); } |
78 public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); } |
79 public Klass getPoolHolder() { return (Klass) poolHolder.getValue(this); } |
|
80 public int getLength() { return (int)length.getValue(this); } |
|
81 |
|
82 private long getElementSize() { |
|
83 if (elementSize !=0 ) { |
|
84 return elementSize; |
|
85 } else { |
|
86 elementSize = VM.getVM().getOopSize(); |
|
87 } |
|
88 return elementSize; |
|
89 } |
79 |
90 |
80 private long indexOffset(long index) { |
91 private long indexOffset(long index) { |
81 if (Assert.ASSERTS_ENABLED) { |
92 if (Assert.ASSERTS_ENABLED) { |
82 Assert.that(index > 0 && index < getLength(), "invalid cp index"); |
93 Assert.that(index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength()); |
83 } |
94 } |
84 return (index * elementSize) + headerSize; |
95 return (index * getElementSize()) + headerSize; |
85 } |
96 } |
86 |
97 |
87 public ConstantTag getTagAt(long index) { |
98 public ConstantTag getTagAt(long index) { |
88 return new ConstantTag(getTags().getByteAt((int) index)); |
99 return new ConstantTag(getTags().getByteAt((int) index)); |
89 } |
100 } |
462 public void printValueOn(PrintStream tty) { |
473 public void printValueOn(PrintStream tty) { |
463 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); |
474 tty.print("ConstantPool for " + getPoolHolder().getName().asString()); |
464 } |
475 } |
465 |
476 |
466 public long getObjectSize() { |
477 public long getObjectSize() { |
467 return alignObjectSize(headerSize + (getLength() * elementSize)); |
478 return alignObjectSize(headerSize + (getLength() * getElementSize())); |
468 } |
479 } |
469 |
480 |
470 //---------------------------------------------------------------------- |
481 //---------------------------------------------------------------------- |
471 // Internals only below this point |
482 // Internals only below this point |
472 // |
483 // |