comparison agent/src/share/classes/sun/jvm/hotspot/oops/Symbol.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 c18cbe5936b8
children 1d1603768966
comparison
equal deleted inserted replaced
2176:27e4ea99855d 2177:3582bf76420e
32 import sun.jvm.hotspot.utilities.*; 32 import sun.jvm.hotspot.utilities.*;
33 33
34 // A Symbol is a canonicalized string. 34 // A Symbol is a canonicalized string.
35 // All Symbols reside in global symbolTable. 35 // All Symbols reside in global symbolTable.
36 36
37 public class Symbol extends Oop { 37 public class Symbol extends VMObject {
38 static { 38 static {
39 VM.registerVMInitializedObserver(new Observer() { 39 VM.registerVMInitializedObserver(new Observer() {
40 public void update(Observable o, Object data) { 40 public void update(Observable o, Object data) {
41 initialize(VM.getVM().getTypeDataBase()); 41 initialize(VM.getVM().getTypeDataBase());
42 } 42 }
43 }); 43 });
44 } 44 }
45 45
46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
47 Type type = db.lookupType("symbolOopDesc"); 47 Type type = db.lookupType("Symbol");
48 length = new CIntField(type.getCIntegerField("_length"), 0); 48 length = type.getCIntegerField("_length");
49 baseOffset = type.getField("_body").getOffset(); 49 baseOffset = type.getField("_body").getOffset();
50 idHash = type.getCIntegerField("_identity_hash");
50 } 51 }
51 52
52 // Format: 53 // Format:
53 // [header] 54 // [header]
54 // [klass ] 55 // [klass ]
55 // [length] byte size of uft8 string 56 // [length] byte size of uft8 string
56 // ..body.. 57 // ..body..
57 58
58 Symbol(OopHandle handle, ObjectHeap heap) { 59 public static Symbol create(Address addr) {
59 super(handle, heap); 60 if (addr == null) {
61 return null;
62 }
63 return new Symbol(addr);
64 }
65
66 Symbol(Address addr) {
67 super(addr);
60 } 68 }
61 69
62 public boolean isSymbol() { return true; } 70 public boolean isSymbol() { return true; }
63 71
64 private static long baseOffset; // tells where the array part starts 72 private static long baseOffset; // tells where the array part starts
65 73
66 // Fields 74 // Fields
67 private static CIntField length; 75 private static CIntegerField length;
68 76
69 // Accessors for declared fields 77 // Accessors for declared fields
70 public long getLength() { return length.getValue(this); } 78 public long getLength() { return length.getValue(this.addr); }
71 79
72 public byte getByteAt(long index) { 80 public byte getByteAt(long index) {
73 return getHandle().getJByteAt(baseOffset + index); 81 return addr.getJByteAt(baseOffset + index);
74 } 82 }
83
84 private static CIntegerField idHash;
85
86 public int identityHash() { return (int)idHash.getValue(this.addr); }
75 87
76 public boolean equals(byte[] modUTF8Chars) { 88 public boolean equals(byte[] modUTF8Chars) {
77 int l = (int) getLength(); 89 int l = (int) getLength();
78 if (l != modUTF8Chars.length) return false; 90 if (l != modUTF8Chars.length) return false;
79 while (l-- > 0) { 91 while (l-- > 0) {
96 108
97 public String asString() { 109 public String asString() {
98 // Decode the byte array and return the string. 110 // Decode the byte array and return the string.
99 try { 111 try {
100 return readModifiedUTF8(asByteArray()); 112 return readModifiedUTF8(asByteArray());
101 } catch(IOException e) { 113 } catch(Exception e) {
114 System.err.println(addr);
115 e.printStackTrace();
102 return null; 116 return null;
103 } 117 }
104 } 118 }
105 119
106 public boolean startsWith(String str) { 120 public boolean startsWith(String str) {
109 123
110 public void printValueOn(PrintStream tty) { 124 public void printValueOn(PrintStream tty) {
111 tty.print("#" + asString()); 125 tty.print("#" + asString());
112 } 126 }
113 127
114 public long getObjectSize() {
115 return alignObjectSize(baseOffset + getLength());
116 }
117
118 void iterateFields(OopVisitor visitor, boolean doVMFields) {
119 super.iterateFields(visitor, doVMFields);
120 if (doVMFields) {
121 visitor.doCInt(length, true);
122 int length = (int) getLength();
123 for (int index = 0; index < length; index++) {
124 visitor.doByte(new ByteField(new IndexableFieldIdentifier(index), baseOffset + index, false), true);
125 }
126 }
127 }
128
129 /** Note: this comparison is used for vtable sorting only; it 128 /** Note: this comparison is used for vtable sorting only; it
130 doesn't matter what order it defines, as long as it is a total, 129 doesn't matter what order it defines, as long as it is a total,
131 time-invariant order Since symbolOops are in permSpace, their 130 time-invariant order Since Symbol* are in C_HEAP, their
132 relative order in memory never changes, so use address 131 relative order in memory never changes, so use address
133 comparison for speed. */ 132 comparison for speed. */
134 public int fastCompare(Symbol other) { 133 public int fastCompare(Symbol other) {
135 return (int) getHandle().minus(other.getHandle()); 134 return (int) addr.minus(other.addr);
136 } 135 }
137 136
138 private static String readModifiedUTF8(byte[] buf) throws IOException { 137 private static String readModifiedUTF8(byte[] buf) throws IOException {
139 final int len = buf.length; 138 final int len = buf.length;
140 byte[] tmp = new byte[len + 2]; 139 byte[] tmp = new byte[len + 2];