Mercurial > hg > truffle
comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/HotSpotTypeResolved.java @ 1941:79d04223b8a5
Added caching for resolved types and resolved fields.
This is crucial, because the local load elimination will lead to wrong results, if field equality (of two RiField objects with the same object and the same RiType) is not given. The caching makes sure that the default equals implementation is sufficient.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Tue, 28 Dec 2010 18:33:26 +0100 |
parents | 71cd4b9610eb |
children | 177398c6147d |
comparison
equal
deleted
inserted
replaced
1940:e92a9a73324e | 1941:79d04223b8a5 |
---|---|
19 * Company, Ltd. | 19 * Company, Ltd. |
20 */ | 20 */ |
21 package com.sun.hotspot.c1x; | 21 package com.sun.hotspot.c1x; |
22 | 22 |
23 import java.lang.reflect.*; | 23 import java.lang.reflect.*; |
24 import java.util.*; | |
24 | 25 |
25 import com.sun.cri.ci.*; | 26 import com.sun.cri.ci.*; |
26 import com.sun.cri.ri.*; | 27 import com.sun.cri.ri.*; |
27 import com.sun.hotspot.c1x.logging.*; | 28 import com.sun.hotspot.c1x.logging.*; |
28 | 29 |
31 * | 32 * |
32 * @author Thomas Wuerthinger, Lukas Stadler | 33 * @author Thomas Wuerthinger, Lukas Stadler |
33 */ | 34 */ |
34 public class HotSpotTypeResolved implements HotSpotType { | 35 public class HotSpotTypeResolved implements HotSpotType { |
35 | 36 |
36 private long vmId; | |
37 private Class javaMirror; | 37 private Class javaMirror; |
38 private String name; | 38 private String name; |
39 private int accessFlags; | 39 private int accessFlags; |
40 private boolean hasFinalizer; | 40 private boolean hasFinalizer; |
41 private boolean hasSubclass; | 41 private boolean hasSubclass; |
44 private boolean isArrayClass; | 44 private boolean isArrayClass; |
45 private boolean isInstanceClass; | 45 private boolean isInstanceClass; |
46 private boolean isInterface; | 46 private boolean isInterface; |
47 private int instanceSize; | 47 private int instanceSize; |
48 private RiType componentType; | 48 private RiType componentType; |
49 private HashMap<Integer, RiField> fieldCache; | |
49 | 50 |
50 @Override | 51 @Override |
51 public int accessFlags() { | 52 public int accessFlags() { |
52 return accessFlags; | 53 return accessFlags; |
53 } | 54 } |
59 //return Compiler.getVMEntries().RiType_arrayOf(vmId); | 60 //return Compiler.getVMEntries().RiType_arrayOf(vmId); |
60 } | 61 } |
61 | 62 |
62 @Override | 63 @Override |
63 public RiType componentType() { | 64 public RiType componentType() { |
64 return Compiler.getVMEntries().RiType_componentType(vmId); | 65 return Compiler.getVMEntries().RiType_componentType(this); |
65 } | 66 } |
66 | 67 |
67 @Override | 68 @Override |
68 public RiType exactType() { | 69 public RiType exactType() { |
69 if (Modifier.isFinal(accessFlags)) { | 70 if (Modifier.isFinal(accessFlags)) { |
139 } | 140 } |
140 | 141 |
141 @Override | 142 @Override |
142 public boolean isSubtypeOf(RiType other) { | 143 public boolean isSubtypeOf(RiType other) { |
143 if (other instanceof HotSpotTypeResolved) { | 144 if (other instanceof HotSpotTypeResolved) { |
144 return Compiler.getVMEntries().RiType_isSubtypeOf(vmId, other); | 145 return Compiler.getVMEntries().RiType_isSubtypeOf(this, other); |
145 } | 146 } |
146 // No resolved type is a subtype of an unresolved type. | 147 // No resolved type is a subtype of an unresolved type. |
147 return false; | 148 return false; |
148 } | 149 } |
149 | 150 |
168 } | 169 } |
169 | 170 |
170 @Override | 171 @Override |
171 public RiMethod resolveMethodImpl(RiMethod method) { | 172 public RiMethod resolveMethodImpl(RiMethod method) { |
172 assert method instanceof HotSpotMethod; | 173 assert method instanceof HotSpotMethod; |
173 return Compiler.getVMEntries().RiType_resolveMethodImpl(vmId, method.name(), method.signature().asString()); | 174 return Compiler.getVMEntries().RiType_resolveMethodImpl(this, method.name(), method.signature().asString()); |
174 } | 175 } |
175 | 176 |
176 @Override | 177 @Override |
177 public String toString() { | 178 public String toString() { |
178 return "HotSpotType<" + name + ", resolved>"; | 179 return "HotSpotType<" + name + ", resolved>"; |
179 } | 180 } |
180 | 181 |
181 public RiConstantPool constantPool() { | 182 public RiConstantPool constantPool() { |
182 return Compiler.getVMEntries().RiType_constantPool(vmId); | 183 return Compiler.getVMEntries().RiType_constantPool(this); |
183 } | |
184 | |
185 public long getVmId() { | |
186 return vmId; | |
187 } | 184 } |
188 | 185 |
189 public int instanceSize() { | 186 public int instanceSize() { |
190 return instanceSize; | 187 return instanceSize; |
191 } | 188 } |
192 | 189 |
190 public RiField createRiField(String name, RiType type, int offset) { | |
191 RiField result = null; | |
192 | |
193 // (tw) Must cache the fields, because the local load elimination only works if the objects from two field lookups are equal. | |
194 if (fieldCache == null) { | |
195 fieldCache = new HashMap<Integer, RiField>(8); | |
196 } else { | |
197 result = fieldCache.get(offset); | |
198 } | |
199 | |
200 if (result == null) { | |
201 result = new HotSpotField(this, name, type, offset); | |
202 fieldCache.put(offset, result); | |
203 } | |
204 | |
205 return result; | |
206 } | |
207 | |
193 } | 208 } |