Mercurial > hg > truffle
comparison graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaType.java @ 7044:34753b057324
added unit tests for JavaType, JavaMethod and ResolvedJavaMethod
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 27 Nov 2012 16:09:05 +0100 |
parents | dd81042f4eb1 |
children | 7ac6e4c10e37 |
comparison
equal
deleted
inserted
replaced
7043:947de43c68d6 | 7044:34753b057324 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.graal.hotspot.meta; | 23 package com.oracle.graal.hotspot.meta; |
24 | 24 |
25 import static com.oracle.graal.api.meta.MetaUtil.*; | |
25 import static com.oracle.graal.graph.FieldIntrospection.*; | 26 import static com.oracle.graal.graph.FieldIntrospection.*; |
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; | 27 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; |
27 import static java.lang.reflect.Modifier.*; | 28 import static java.lang.reflect.Modifier.*; |
28 | 29 |
29 import java.lang.annotation.*; | 30 import java.lang.annotation.*; |
157 public ResolvedJavaType getComponentType() { | 158 public ResolvedJavaType getComponentType() { |
158 Class javaComponentType = javaMirror.getComponentType(); | 159 Class javaComponentType = javaMirror.getComponentType(); |
159 return javaComponentType == null ? null : fromClass(javaComponentType); | 160 return javaComponentType == null ? null : fromClass(javaComponentType); |
160 } | 161 } |
161 | 162 |
163 public ResolvedJavaType getElementType() { | |
164 ResolvedJavaType type = this; | |
165 while (type.getComponentType() != null) { | |
166 type = type.getComponentType(); | |
167 } | |
168 return type; | |
169 } | |
170 | |
171 private static boolean hasSubtype(ResolvedJavaType type) { | |
172 assert !type.isInterface() && !type.isArrayClass() : type; | |
173 if (isPrimitive(type)) { | |
174 return false; | |
175 } | |
176 HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); | |
177 if (unsafeReadWord(((HotSpotResolvedJavaType) type).metaspaceKlass + config.subklassOffset) != 0) { | |
178 return true; | |
179 } | |
180 return false; | |
181 } | |
182 | |
162 @Override | 183 @Override |
163 public ResolvedJavaType findUniqueConcreteSubtype() { | 184 public ResolvedJavaType findUniqueConcreteSubtype() { |
185 HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); | |
164 if (isArrayClass()) { | 186 if (isArrayClass()) { |
165 return getComponentType().findUniqueConcreteSubtype() == getComponentType() ? this : null; | 187 ResolvedJavaType elementType = getElementType(); |
188 if (hasSubtype(elementType)) { | |
189 return null; | |
190 } | |
191 return this; | |
166 } else { | 192 } else { |
167 HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); | |
168 HotSpotResolvedJavaType type = this; | 193 HotSpotResolvedJavaType type = this; |
169 while (isAbstract(type.getModifiers())) { | 194 while (isAbstract(type.getModifiers())) { |
170 long subklass = unsafeReadWord(type.metaspaceKlass + config.subklassOffset); | 195 long subklass = unsafeReadWord(type.metaspaceKlass + config.subklassOffset); |
171 if (subklass == 0 || unsafeReadWord(subklass + config.nextSiblingOffset) != 0) { | 196 if (subklass == 0 || unsafeReadWord(subklass + config.nextSiblingOffset) != 0) { |
172 return null; | 197 return null; |
174 type = (HotSpotResolvedJavaType) fromMetaspaceKlass(subklass); | 199 type = (HotSpotResolvedJavaType) fromMetaspaceKlass(subklass); |
175 } | 200 } |
176 if (unsafeReadWord(type.metaspaceKlass + config.subklassOffset) != 0) { | 201 if (unsafeReadWord(type.metaspaceKlass + config.subklassOffset) != 0) { |
177 return null; | 202 return null; |
178 } | 203 } |
179 assert !type.isInterface(); | |
180 return type; | 204 return type; |
181 } | 205 } |
182 } | 206 } |
183 | 207 |
184 @Override | 208 @Override |