comparison graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaType.java @ 21556:48c1ebd24120

renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 00:36:16 +0200
parents graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java@6b11405f0279
children
comparison
equal deleted inserted replaced
21555:d12eaef9af72 21556:48c1ebd24120
1 /*
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.jvmci.meta;
24
25 import java.lang.annotation.*;
26 import java.net.*;
27
28 import com.oracle.jvmci.meta.Assumptions.AssumptionResult;
29
30 /**
31 * Represents a resolved Java type. Types include primitives, objects, {@code void}, and arrays
32 * thereof. Types, like fields and methods, are resolved through {@link ConstantPool constant pools}
33 * .
34 */
35 public interface ResolvedJavaType extends JavaType, ModifiersProvider {
36
37 /**
38 * Gets the runtime representation of the Java class object of this type.
39 */
40 JavaConstant getJavaClass();
41
42 /**
43 * Gets the runtime representation of the "hub" of this type--that is, the closest part of the
44 * type representation which is typically stored in the object header.
45 */
46 Constant getObjectHub();
47
48 /**
49 * Checks whether this type has a finalizer method.
50 *
51 * @return {@code true} if this class has a finalizer
52 */
53 boolean hasFinalizer();
54
55 /**
56 * Checks whether this type has any finalizable subclasses so far. Any decisions based on this
57 * information require the registration of a dependency, since this information may change.
58 *
59 * @return {@code true} if this class has any subclasses with finalizers
60 */
61 AssumptionResult<Boolean> hasFinalizableSubclass();
62
63 /**
64 * Checks whether this type is an interface.
65 *
66 * @return {@code true} if this type is an interface
67 */
68 boolean isInterface();
69
70 /**
71 * Checks whether this type is an instance class.
72 *
73 * @return {@code true} if this type is an instance class
74 */
75 boolean isInstanceClass();
76
77 /**
78 * Checks whether this type is an array class.
79 *
80 * @return {@code true} if this type is an array class
81 */
82 boolean isArray();
83
84 /**
85 * Checks whether this type is primitive.
86 *
87 * @return {@code true} if this type is primitive
88 */
89 boolean isPrimitive();
90
91 /**
92 * {@inheritDoc}
93 * <p>
94 * Only the flags specified in the JVM specification will be included in the returned mask. This
95 * method is identical to {@link Class#getModifiers()} in terms of the value return for this
96 * type.
97 */
98 int getModifiers();
99
100 /**
101 * Checks whether this type is initialized. If a type is initialized it implies that it was
102 * {@link #isLinked() linked} and that the static initializer has run.
103 *
104 * @return {@code true} if this type is initialized
105 */
106 boolean isInitialized();
107
108 /**
109 * Initializes this type.
110 */
111 void initialize();
112
113 /**
114 * Checks whether this type is linked and verified. When a type is linked the static initializer
115 * has not necessarily run. An {@link #isInitialized() initialized} type is always linked.
116 *
117 * @return {@code true} if this type is linked
118 */
119 boolean isLinked();
120
121 /**
122 * Determines if this type is either the same as, or is a superclass or superinterface of, the
123 * type represented by the specified parameter. This method is identical to
124 * {@link Class#isAssignableFrom(Class)} in terms of the value return for this type.
125 */
126 boolean isAssignableFrom(ResolvedJavaType other);
127
128 /**
129 * Returns true if this type is exactly the type {@link java.lang.Object}.
130 */
131 default boolean isJavaLangObject() {
132 // Removed assertion due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=434442
133 return getSuperclass() == null && !isInterface() && getKind() == Kind.Object;
134 }
135
136 /**
137 * Checks whether the specified object is an instance of this type.
138 *
139 * @param obj the object to test
140 * @return {@code true} if the object is an instance of this type
141 */
142 boolean isInstance(JavaConstant obj);
143
144 /**
145 * Returns this type if it is an exact type otherwise returns null. This type is exact if it is
146 * void, primitive, final, or an array of a final or primitive type.
147 *
148 * @return this type if it is exact; {@code null} otherwise
149 */
150 ResolvedJavaType asExactType();
151
152 /**
153 * Gets the super class of this type. If this type represents either the {@code Object} class,
154 * an interface, a primitive type, or void, then null is returned. If this object represents an
155 * array class then the type object representing the {@code Object} class is returned.
156 */
157 ResolvedJavaType getSuperclass();
158
159 /**
160 * Gets the interfaces implemented or extended by this type. This method is analogous to
161 * {@link Class#getInterfaces()} and as such, only returns the interfaces directly implemented
162 * or extended by this type.
163 */
164 ResolvedJavaType[] getInterfaces();
165
166 /**
167 * Gets the single implementor of this type. Calling this method on a non-interface type causes
168 * an exception.
169 * <p>
170 * If the compiler uses the result of this method for its compilation, the usage must be guarded
171 * because the verifier can not guarantee that the assigned type really implements this
172 * interface. Additionally, class loading can invalidate the result of this method.
173 *
174 * @return {@code null} if there is no implementor, the implementor if there is only one, or
175 * {@code this} if there are more than one.
176 */
177 ResolvedJavaType getSingleImplementor();
178
179 /**
180 * Walks the class hierarchy upwards and returns the least common class that is a superclass of
181 * both the current and the given type.
182 *
183 * @return the least common type that is a super type of both the current and the given type, or
184 * {@code null} if primitive types are involved.
185 */
186 ResolvedJavaType findLeastCommonAncestor(ResolvedJavaType otherType);
187
188 /**
189 * Attempts to get a leaf concrete subclass of this type.
190 * <p>
191 * For an {@linkplain #isArray() array} type A, the leaf concrete subclass is A if the
192 * {@linkplain #getElementalType() elemental} type of A is final (which includes primitive
193 * types). Otherwise {@code null} is returned for A.
194 * <p>
195 * For a non-array type T, the result is the leaf concrete type in the current hierarchy of T.
196 * <p>
197 * A runtime may decide not to manage or walk a large hierarchy and so the result is
198 * conservative. That is, a non-null result is guaranteed to be the leaf concrete class in T's
199 * hierarchy <b>at the current point in time</b> but a null result does not necessarily imply
200 * that there is no leaf concrete class in T's hierarchy.
201 * <p>
202 * If the compiler uses the result of this method for its compilation, it must register the
203 * {@link AssumptionResult} in its {@link Assumptions} because dynamic class loading can
204 * invalidate the result of this method.
205 *
206 * @return an {@link AssumptionResult} containing the leaf concrete subclass for this type as
207 * described above
208 */
209 AssumptionResult<ResolvedJavaType> findLeafConcreteSubtype();
210
211 ResolvedJavaType getComponentType();
212
213 default ResolvedJavaType getElementalType() {
214 ResolvedJavaType t = this;
215 while (t.isArray()) {
216 t = t.getComponentType();
217 }
218 return t;
219 }
220
221 ResolvedJavaType getArrayClass();
222
223 /**
224 * Resolves the method implementation for virtual dispatches on objects of this dynamic type.
225 * This resolution process only searches "up" the class hierarchy of this type.
226 *
227 * @param method the method to select the implementation of
228 * @param callerType the caller or context type used to perform access checks
229 * @param includeAbstract whether abstract methods should be returned. If it is {@code false}
230 * this method behaves like {@link #resolveConcreteMethod}. This is just a temporary
231 * parameter to highlight the changed semantics of this method. TODO (je) remove this
232 * flag.
233 * @return the link-time resolved method (might be abstract) or {@code null} if it can not be
234 * linked
235 */
236 ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method, ResolvedJavaType callerType, boolean includeAbstract);
237
238 /**
239 * Resolves the method implementation for virtual dispatches on objects of this dynamic type.
240 * This resolution process only searches "up" the class hierarchy of this type. A broader search
241 * that also walks "down" the hierarchy is implemented by
242 * {@link #findUniqueConcreteMethod(ResolvedJavaMethod)}.
243 *
244 * @param method the method to select the implementation of
245 * @param callerType the caller or context type used to perform access checks
246 * @return the concrete method that would be selected at runtime, or {@code null} if there is no
247 * concrete implementation of {@code method} in this type or any of its superclasses
248 */
249 ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJavaType callerType);
250
251 /**
252 * Given a {@link ResolvedJavaMethod} A, returns a concrete {@link ResolvedJavaMethod} B that is
253 * the only possible unique target for a virtual call on A(). Returns {@code null} if either no
254 * such concrete method or more than one such method exists. Returns the method A if A is a
255 * concrete method that is not overridden.
256 * <p>
257 * If the compiler uses the result of this method for its compilation, it must register an
258 * assumption because dynamic class loading can invalidate the result of this method.
259 *
260 * @param method the method A for which a unique concrete target is searched
261 * @return the unique concrete target or {@code null} if no such target exists or assumptions
262 * are not supported by this runtime
263 */
264 AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method);
265
266 /**
267 * Returns the instance fields of this class, including
268 * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned
269 * for array and primitive types. The order of fields returned by this method is stable. That
270 * is, for a single JVM execution the same order is returned each time this method is called. It
271 * is also the "natural" order, which means that the JVM would expect the fields in this order
272 * if no specific order is given.
273 *
274 * @param includeSuperclasses if true, then instance fields for the complete hierarchy of this
275 * type are included in the result
276 * @return an array of instance fields
277 */
278 ResolvedJavaField[] getInstanceFields(boolean includeSuperclasses);
279
280 /**
281 * Returns the static fields of this class, including
282 * {@linkplain ResolvedJavaField#isInternal() internal} fields. A zero-length array is returned
283 * for array and primitive types. The order of fields returned by this method is stable. That
284 * is, for a single JVM execution the same order is returned each time this method is called.
285 */
286 ResolvedJavaField[] getStaticFields();
287
288 /**
289 * Returns the annotation for the specified type of this class, if such an annotation is
290 * present.
291 *
292 * @param annotationClass the Class object corresponding to the annotation type
293 * @return this element's annotation for the specified annotation type if present on this class,
294 * else {@code null}
295 */
296 <T extends Annotation> T getAnnotation(Class<T> annotationClass);
297
298 /**
299 * Returns the instance field of this class (or one of its super classes) at the given offset,
300 * or {@code null} if there is no such field.
301 *
302 * @param offset the offset of the field to look for
303 * @return the field with the given offset, or {@code null} if there is no such field.
304 */
305 ResolvedJavaField findInstanceFieldWithOffset(long offset, Kind expectedKind);
306
307 /**
308 * Returns name of source file of this type.
309 */
310 String getSourceFileName();
311
312 /**
313 * Returns the class file path - if available - of this type, or {@code null}.
314 */
315 URL getClassFilePath();
316
317 /**
318 * Returns {@code true} if the type is a local type.
319 */
320 boolean isLocal();
321
322 /**
323 * Returns {@code true} if the type is a member type.
324 */
325 boolean isMember();
326
327 /**
328 * Returns the enclosing type of this type, if it exists, or {@code null}.
329 */
330 ResolvedJavaType getEnclosingType();
331
332 /**
333 * Returns an array reflecting all the constructors declared by this type. This method is
334 * similar to {@link Class#getDeclaredConstructors()} in terms of returned constructors.
335 */
336 ResolvedJavaMethod[] getDeclaredConstructors();
337
338 /**
339 * Returns an array reflecting all the methods declared by this type. This method is similar to
340 * {@link Class#getDeclaredMethods()} in terms of returned methods.
341 */
342 ResolvedJavaMethod[] getDeclaredMethods();
343
344 /**
345 * Returns the {@code <clinit>} method for this class if there is one.
346 */
347 ResolvedJavaMethod getClassInitializer();
348
349 /**
350 * Returns true if this type represents an interface and it should be trusted even in places
351 * where the JVM verifier would not give any guarantees other than {@link Object}.
352 */
353 boolean isTrustedInterfaceType();
354 }