Mercurial > hg > truffle
comparison agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java @ 2177:3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank
author | coleenp |
---|---|
date | Thu, 27 Jan 2011 16:11:27 -0800 |
parents | dad31fc330cd |
children | 1d1603768966 ed69575596ac |
comparison
equal
deleted
inserted
replaced
2176:27e4ea99855d | 2177:3582bf76420e |
---|---|
33 | 33 |
34 // A ConstantPool is an oop 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 Oop implements ClassConstants { | 37 public class ConstantPool extends Oop implements ClassConstants { |
38 | |
39 public class CPSlot { | |
40 private Address ptr; | |
41 | |
42 CPSlot(Address ptr) { | |
43 this.ptr = ptr; | |
44 } | |
45 CPSlot(Symbol sym) { | |
46 this.ptr = sym.getAddress().orWithMask(1); | |
47 } | |
48 | |
49 public boolean isOop() { | |
50 return (ptr.minus(null) & 1) == 0; | |
51 } | |
52 public boolean isMetaData() { | |
53 return (ptr.minus(null) & 1) == 1; | |
54 } | |
55 | |
56 public Symbol getSymbol() { | |
57 if (isMetaData()) { | |
58 return Symbol.create(ptr.xorWithMask(1)); | |
59 } | |
60 throw new InternalError("not a symbol"); | |
61 } | |
62 public Oop getOop() { | |
63 if (isOop()) { | |
64 return VM.getVM().getObjectHeap().newOop(ptr.addOffsetToAsOopHandle(0)); | |
65 } | |
66 throw new InternalError("not an oop"); | |
67 } | |
68 } | |
69 | |
38 // Used for debugging this code | 70 // Used for debugging this code |
39 private static final boolean DEBUG = false; | 71 private static final boolean DEBUG = false; |
40 | 72 |
41 protected void debugMessage(String message) { | 73 protected void debugMessage(String message) { |
42 System.out.println(message); | 74 System.out.println(message); |
108 | 140 |
109 public ConstantTag getTagAt(long index) { | 141 public ConstantTag getTagAt(long index) { |
110 return new ConstantTag(getTags().getByteAt((int) index)); | 142 return new ConstantTag(getTags().getByteAt((int) index)); |
111 } | 143 } |
112 | 144 |
113 public Oop getObjAt(long index){ | 145 public CPSlot getSlotAt(long index) { |
146 return new CPSlot(getHandle().getAddressAt(indexOffset(index))); | |
147 } | |
148 | |
149 public Oop getObjAtRaw(long index){ | |
114 return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index))); | 150 return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index))); |
115 } | 151 } |
116 | 152 |
117 public Symbol getSymbolAt(long index) { | 153 public Symbol getSymbolAt(long index) { |
118 return (Symbol) getObjAt(index); | 154 CPSlot slot = getSlotAt(index); |
155 return slot.getSymbol(); | |
119 } | 156 } |
120 | 157 |
121 public int getIntAt(long index){ | 158 public int getIntAt(long index){ |
122 return getHandle().getJIntAt(indexOffset(index)); | 159 return getHandle().getJIntAt(indexOffset(index)); |
123 } | 160 } |
185 } | 222 } |
186 | 223 |
187 // returns null, if not resolved. | 224 // returns null, if not resolved. |
188 public Klass getKlassRefAt(int which) { | 225 public Klass getKlassRefAt(int which) { |
189 if( ! getTagAt(which).isKlass()) return null; | 226 if( ! getTagAt(which).isKlass()) return null; |
190 return (Klass) getObjAt(which); | 227 return (Klass) getObjAtRaw(which); |
191 } | 228 } |
192 | 229 |
193 // returns null, if not resolved. | 230 // returns null, if not resolved. |
194 public InstanceKlass getFieldOrMethodKlassRefAt(int which) { | 231 public InstanceKlass getFieldOrMethodKlassRefAt(int which) { |
195 int refIndex = getFieldOrMethodAt(which); | 232 int refIndex = getFieldOrMethodAt(which); |
475 break; | 512 break; |
476 | 513 |
477 case JVM_CONSTANT_Class: { | 514 case JVM_CONSTANT_Class: { |
478 dos.writeByte(cpConstType); | 515 dos.writeByte(cpConstType); |
479 // Klass already resolved. ConstantPool constains klassOop. | 516 // Klass already resolved. ConstantPool constains klassOop. |
480 Klass refKls = (Klass) getObjAt(ci); | 517 Klass refKls = (Klass) getObjAtRaw(ci); |
481 String klassName = refKls.getName().asString(); | 518 String klassName = refKls.getName().asString(); |
482 Short s = (Short) utf8ToIndex.get(klassName); | 519 Short s = (Short) utf8ToIndex.get(klassName); |
483 dos.writeShort(s.shortValue()); | 520 dos.writeShort(s.shortValue()); |
484 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); | 521 if (DEBUG) debugMessage("CP[" + ci + "] = class " + s); |
485 break; | 522 break; |
496 break; | 533 break; |
497 } | 534 } |
498 | 535 |
499 case JVM_CONSTANT_String: { | 536 case JVM_CONSTANT_String: { |
500 dos.writeByte(cpConstType); | 537 dos.writeByte(cpConstType); |
501 String str = OopUtilities.stringOopToString(getObjAt(ci)); | 538 String str = OopUtilities.stringOopToString(getObjAtRaw(ci)); |
502 Short s = (Short) utf8ToIndex.get(str); | 539 Short s = (Short) utf8ToIndex.get(str); |
503 dos.writeShort(s.shortValue()); | 540 dos.writeShort(s.shortValue()); |
504 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); | 541 if (DEBUG) debugMessage("CP[" + ci + "] = string " + s); |
505 break; | 542 break; |
506 } | 543 } |