comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeUnresolved.java @ 2055:99ad52189524

Refactorings to get towards less CRI overhead.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Thu, 13 Jan 2011 17:45:17 +0100
parents 177398c6147d
children f21664b3dd1c 569d3fe7d65c
comparison
equal deleted inserted replaced
2054:3c0a889a176b 2055:99ad52189524
26 /** 26 /**
27 * Implementation of RiType for unresolved HotSpot classes. 27 * Implementation of RiType for unresolved HotSpot classes.
28 * 28 *
29 * @author Thomas Wuerthinger, Lukas Stadler 29 * @author Thomas Wuerthinger, Lukas Stadler
30 */ 30 */
31 public class HotSpotTypeUnresolved implements HotSpotType { 31 public class HotSpotTypeUnresolved extends HotSpotType {
32 32
33 public final String name; 33 public final String simpleName;
34 public final int dimensions; 34 public final int dimensions;
35 35
36 /** 36 /**
37 * Creates a new unresolved type for a specified type descriptor. 37 * Creates a new unresolved type for a specified type descriptor.
38 */ 38 */
46 while (name.charAt(startIndex) == '[') { 46 while (name.charAt(startIndex) == '[') {
47 startIndex++; 47 startIndex++;
48 dimensions++; 48 dimensions++;
49 } 49 }
50 assert name.charAt(startIndex) == 'L'; 50 assert name.charAt(startIndex) == 'L';
51 name = name.substring(startIndex + 1, name.length() - 1); 51 this.simpleName = name.substring(startIndex + 1, name.length() - 1);
52 this.name = name;
53 } else {
54 this.simpleName = name;
55 this.name = getFullName(name, dimensions);
52 } 56 }
53 57
54 this.name = name;
55 this.dimensions = dimensions; 58 this.dimensions = dimensions;
56 } 59 }
57 60
58 public HotSpotTypeUnresolved(String name, int dimensions) { 61 public HotSpotTypeUnresolved(String name, int dimensions) {
59 assert dimensions >= 0; 62 assert dimensions >= 0;
60 this.name = name; 63 this.simpleName = name;
61 this.dimensions = dimensions; 64 this.dimensions = dimensions;
65 this.name = getFullName(name, dimensions);
62 } 66 }
63 67
64 @Override 68 private String getFullName(String name, int dimensions) {
65 public String name() {
66 StringBuilder str = new StringBuilder(); 69 StringBuilder str = new StringBuilder();
67 for (int i = 0; i < dimensions; i++) { 70 for (int i = 0; i < dimensions; i++) {
68 str.append('['); 71 str.append('[');
69 } 72 }
70 str.append('L').append(name).append(';'); 73 str.append('L').append(simpleName).append(';');
71 return str.toString(); 74 return str.toString();
72 }
73
74 @Override
75 public String simpleName() {
76 return name;
77 } 75 }
78 76
79 @Override 77 @Override
80 public RiType uniqueConcreteSubtype() { 78 public RiType uniqueConcreteSubtype() {
81 throw unresolved("uniqueConcreteSubtype"); 79 throw unresolved("uniqueConcreteSubtype");
142 } 140 }
143 141
144 @Override 142 @Override
145 public RiType componentType() { 143 public RiType componentType() {
146 assert isArrayClass() : "no array class" + name(); 144 assert isArrayClass() : "no array class" + name();
147 return new HotSpotTypeUnresolved(name, dimensions - 1); 145 return new HotSpotTypeUnresolved(simpleName, dimensions - 1);
148 } 146 }
149 147
150 @Override 148 @Override
151 public RiType exactType() { 149 public RiType exactType() {
152 throw unresolved("exactType()"); 150 throw unresolved("exactType()");
153 } 151 }
154 152
155 @Override 153 @Override
156 public RiType arrayOf() { 154 public RiType arrayOf() {
157 return new HotSpotTypeUnresolved(name, dimensions + 1); 155 return new HotSpotTypeUnresolved(simpleName, dimensions + 1);
158 } 156 }
159 157
160 @Override 158 @Override
161 public RiMethod resolveMethodImpl(RiMethod method) { 159 public RiMethod resolveMethodImpl(RiMethod method) {
162 throw unresolved("resolveMethodImpl()"); 160 throw unresolved("resolveMethodImpl()");
166 public CiKind kind() { 164 public CiKind kind() {
167 return CiKind.Object; 165 return CiKind.Object;
168 } 166 }
169 167
170 private CiUnresolvedException unresolved(String operation) { 168 private CiUnresolvedException unresolved(String operation) {
171 throw new CiUnresolvedException(operation + " not defined for unresolved class " + name); 169 throw new CiUnresolvedException(operation + " not defined for unresolved class " + simpleName);
172 } 170 }
173 171
174 @Override 172 @Override
175 public int hashCode() { 173 public int hashCode() {
176 return name.hashCode(); 174 return simpleName.hashCode();
177 } 175 }
178 176
179 @Override 177 @Override
180 public boolean equals(Object o) { 178 public boolean equals(Object o) {
181 return o == this; 179 return o == this;
182 } 180 }
183 181
184 @Override 182 @Override
185 public String toString() { 183 public String toString() {
186 return "HotSpotType<" + name + ", unresolved>"; 184 return "HotSpotType<" + simpleName + ", unresolved>";
187 } 185 }
188 186
189 @Override 187 @Override
190 public CiConstant getEncoding(RiType.Representation r) { 188 public CiConstant getEncoding(RiType.Representation r) {
191 throw unresolved("getEncoding()"); 189 throw unresolved("getEncoding()");