28 import java.util.*; 29 import sun.jvm.hotspot.debugger.*; 30 import sun.jvm.hotspot.runtime.*; 31 import sun.jvm.hotspot.types.*; 32 import sun.jvm.hotspot.utilities.*; 33 34 // A Symbol is a canonicalized string. 35 // All Symbols reside in global symbolTable. 36 37 public class Symbol extends VMObject { 38 static { 39 VM.registerVMInitializedObserver(new Observer() { 40 public void update(Observable o, Object data) { 41 initialize(VM.getVM().getTypeDataBase()); 42 } 43 }); 44 } 45 46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 47 Type type = db.lookupType("Symbol"); 48 length = type.getCIntegerField("_length"); 49 baseOffset = type.getField("_body").getOffset(); 50 idHash = type.getCIntegerField("_identity_hash"); 51 } 52 53 // Format: 54 // [header] 55 // [klass ] 56 // [length] byte size of uft8 string 57 // ..body.. 58 59 public static Symbol create(Address addr) { 60 if (addr == null) { 61 return null; 62 } 63 return new Symbol(addr); 64 } 65 66 Symbol(Address addr) { 67 super(addr); 68 } 69 70 public boolean isSymbol() { return true; } 71 72 private static long baseOffset; // tells where the array part starts 73 74 // Fields 75 private static CIntegerField length; 76 77 // Accessors for declared fields 78 public long getLength() { return length.getValue(this.addr); } 79 80 public byte getByteAt(long index) { 81 return addr.getJByteAt(baseOffset + index); 82 } 83 // _identity_hash is a short 84 private static CIntegerField idHash; 85 86 public int identityHash() { 87 long addr_value = getAddress().asLongValue(); 88 int addr_bits = (int)(addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3)); 89 int length = (int)getLength(); 90 int byte0 = getByteAt(0); 91 int byte1 = getByteAt(1); 92 int id_hash = (int)(0xffff & idHash.getValue(this.addr)); 93 return id_hash | 94 ((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16); 95 } 96 97 public boolean equals(byte[] modUTF8Chars) { 98 int l = (int) getLength(); | 28 import java.util.*; 29 import sun.jvm.hotspot.debugger.*; 30 import sun.jvm.hotspot.runtime.*; 31 import sun.jvm.hotspot.types.*; 32 import sun.jvm.hotspot.utilities.*; 33 34 // A Symbol is a canonicalized string. 35 // All Symbols reside in global symbolTable. 36 37 public class Symbol extends VMObject { 38 static { 39 VM.registerVMInitializedObserver(new Observer() { 40 public void update(Observable o, Object data) { 41 initialize(VM.getVM().getTypeDataBase()); 42 } 43 }); 44 } 45 46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 47 Type type = db.lookupType("Symbol"); 48 length = type.getCIntegerField("_length_and_refcount"); 49 baseOffset = type.getField("_body").getOffset(); 50 idHash = type.getCIntegerField("_identity_hash"); 51 } 52 53 // Format: 54 // [header] 55 // [klass ] 56 // [length] byte size of uft8 string 57 // ..body.. 58 59 public static Symbol create(Address addr) { 60 if (addr == null) { 61 return null; 62 } 63 return new Symbol(addr); 64 } 65 66 Symbol(Address addr) { 67 super(addr); 68 } 69 70 public boolean isSymbol() { return true; } 71 72 private static long baseOffset; // tells where the array part starts 73 74 // Fields 75 private static CIntegerField length; 76 77 // Accessors for declared fields 78 public long getLength() { 79 long i = length.getValue(this.addr); 80 return (i >> 16) & 0xffff; 81 } 82 83 public byte getByteAt(long index) { 84 return addr.getJByteAt(baseOffset + index); 85 } 86 // _identity_hash is a short 87 private static CIntegerField idHash; 88 89 public int identityHash() { 90 long addr_value = getAddress().asLongValue(); 91 int addr_bits = (int)(addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3)); 92 int length = (int)getLength(); 93 int byte0 = getByteAt(0); 94 int byte1 = getByteAt(1); 95 int id_hash = (int)(0xffff & idHash.getValue(this.addr)); 96 return id_hash | 97 ((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16); 98 } 99 100 public boolean equals(byte[] modUTF8Chars) { 101 int l = (int) getLength(); |