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();
99 if (l != modUTF8Chars.length) return false;
100 while (l-- > 0) {
101 if (modUTF8Chars[l] != getByteAt(l)) return false;
102 }
103 if (Assert.ASSERTS_ENABLED) {
104 Assert.that(l == -1, "we should be at the beginning");
105 }
106 return true;
107 }
108
109 public byte[] asByteArray() {
110 int length = (int) getLength();
111 byte [] result = new byte [length];
112 for (int index = 0; index < length; index++) {
113 result[index] = getByteAt(index);
114 }
|
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 long identityHash() {
87 long addr_value = getAddress().asLongValue();
88 long addr_bits =
89 (addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3)) & 0xffffffffL;
90 int length = (int)getLength();
91 int byte0 = getByteAt(0);
92 int byte1 = getByteAt(1);
93 long id_hash = 0xffffL & (long)idHash.getValue(this.addr);
94 return (id_hash |
95 ((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16)) & 0xffffffffL;
96 }
97
98 public boolean equals(byte[] modUTF8Chars) {
99 int l = (int) getLength();
100 if (l != modUTF8Chars.length) return false;
101 while (l-- > 0) {
102 if (modUTF8Chars[l] != getByteAt(l)) return false;
103 }
104 if (Assert.ASSERTS_ENABLED) {
105 Assert.that(l == -1, "we should be at the beginning");
106 }
107 return true;
108 }
109
110 public byte[] asByteArray() {
111 int length = (int) getLength();
112 byte [] result = new byte [length];
113 for (int index = 0; index < length; index++) {
114 result[index] = getByteAt(index);
115 }
|