Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/ResolvedJavaMethod.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/ResolvedJavaMethod.java@9f6733155647 |
children | 36cf15e3219e |
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.lang.reflect.*; | |
27 | |
28 /** | |
29 * Represents a resolved Java method. Methods, like fields and types, are resolved through | |
30 * {@link ConstantPool constant pools}. | |
31 */ | |
32 public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider { | |
33 | |
34 /** | |
35 * Returns the bytecode of this method, if the method has code. The returned byte array does not | |
36 * contain breakpoints or non-Java bytecodes. This may return null if the | |
37 * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}. | |
38 * | |
39 * The contained constant pool indices may not be the ones found in the original class file but | |
40 * they can be used with the Graal API (e.g. methods in {@link ConstantPool}). | |
41 * | |
42 * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the | |
43 * code is not ready. | |
44 */ | |
45 byte[] getCode(); | |
46 | |
47 /** | |
48 * Returns the size of the bytecode of this method, if the method has code. This is equivalent | |
49 * to {@link #getCode()}. {@code length} if the method has code. | |
50 * | |
51 * @return the size of the bytecode in bytes, or 0 if no bytecode is available | |
52 */ | |
53 int getCodeSize(); | |
54 | |
55 /** | |
56 * Returns the {@link ResolvedJavaType} object representing the class or interface that declares | |
57 * this method. | |
58 */ | |
59 ResolvedJavaType getDeclaringClass(); | |
60 | |
61 /** | |
62 * Returns the maximum number of locals used in this method's bytecodes. | |
63 */ | |
64 int getMaxLocals(); | |
65 | |
66 /** | |
67 * Returns the maximum number of stack slots used in this method's bytecodes. | |
68 */ | |
69 int getMaxStackSize(); | |
70 | |
71 /** | |
72 * {@inheritDoc} | |
73 * <p> | |
74 * Only the {@linkplain Modifier#methodModifiers() method flags} specified in the JVM | |
75 * specification will be included in the returned mask. | |
76 */ | |
77 int getModifiers(); | |
78 | |
79 /** | |
80 * Determines if this method is a synthetic method as defined by the Java Language | |
81 * Specification. | |
82 */ | |
83 boolean isSynthetic(); | |
84 | |
85 /** | |
86 * Returns {@code true} if this method is a default method; returns {@code false} otherwise. | |
87 * | |
88 * A default method is a public non-abstract instance method, that is, a non-static method with | |
89 * a body, declared in an interface type. | |
90 * | |
91 * @return true if and only if this method is a default method as defined by the Java Language | |
92 * Specification. | |
93 */ | |
94 boolean isDefault(); | |
95 | |
96 /** | |
97 * Checks whether this method is a class initializer. | |
98 * | |
99 * @return {@code true} if the method is a class initializer | |
100 */ | |
101 boolean isClassInitializer(); | |
102 | |
103 /** | |
104 * Checks whether this method is a constructor. | |
105 * | |
106 * @return {@code true} if the method is a constructor | |
107 */ | |
108 boolean isConstructor(); | |
109 | |
110 /** | |
111 * Checks whether this method can be statically bound (usually, that means it is final or | |
112 * private or static, but not abstract, or the declaring class is final). | |
113 * | |
114 * @return {@code true} if this method can be statically bound | |
115 */ | |
116 boolean canBeStaticallyBound(); | |
117 | |
118 /** | |
119 * Returns the list of exception handlers for this method. | |
120 */ | |
121 ExceptionHandler[] getExceptionHandlers(); | |
122 | |
123 /** | |
124 * Returns a stack trace element for this method and a given bytecode index. | |
125 */ | |
126 StackTraceElement asStackTraceElement(int bci); | |
127 | |
128 /** | |
129 * Returns an object that provides access to the profiling information recorded for this method. | |
130 */ | |
131 ProfilingInfo getProfilingInfo(); | |
132 | |
133 /** | |
134 * Invalidates the profiling information and restarts profiling upon the next invocation. | |
135 */ | |
136 void reprofile(); | |
137 | |
138 /** | |
139 * Returns the constant pool of this method. | |
140 */ | |
141 ConstantPool getConstantPool(); | |
142 | |
143 /** | |
144 * Returns all annotations of this method. If no annotations are present, an array of length 0 | |
145 * is returned. | |
146 */ | |
147 Annotation[] getAnnotations(); | |
148 | |
149 /** | |
150 * Returns the annotation for the specified type of this method, if such an annotation is | |
151 * present. | |
152 * | |
153 * @param annotationClass the Class object corresponding to the annotation type | |
154 * @return this element's annotation for the specified annotation type if present on this | |
155 * method, else {@code null} | |
156 */ | |
157 <T extends Annotation> T getAnnotation(Class<T> annotationClass); | |
158 | |
159 /** | |
160 * Returns an array of arrays that represent the annotations on the formal parameters, in | |
161 * declaration order, of this method. | |
162 * | |
163 * @see Method#getParameterAnnotations() | |
164 */ | |
165 Annotation[][] getParameterAnnotations(); | |
166 | |
167 /** | |
168 * Returns an array of {@link Type} objects that represent the formal parameter types, in | |
169 * declaration order, of this method. | |
170 * | |
171 * @see Method#getGenericParameterTypes() | |
172 */ | |
173 Type[] getGenericParameterTypes(); | |
174 | |
175 /** | |
176 * Returns {@code true} if this method is not excluded from inlining and has associated Java | |
177 * bytecodes (@see {@link ResolvedJavaMethod#hasBytecodes()}). | |
178 */ | |
179 boolean canBeInlined(); | |
180 | |
181 /** | |
182 * Returns {@code true} if the inlining of this method should be forced. | |
183 */ | |
184 boolean shouldBeInlined(); | |
185 | |
186 /** | |
187 * Returns the LineNumberTable of this method or null if this method does not have a line | |
188 * numbers table. | |
189 */ | |
190 LineNumberTable getLineNumberTable(); | |
191 | |
192 /** | |
193 * Returns the local variable table of this method or null if this method does not have a local | |
194 * variable table. | |
195 */ | |
196 LocalVariableTable getLocalVariableTable(); | |
197 | |
198 /** | |
199 * Invokes the underlying method represented by this object, on the specified object with the | |
200 * specified parameters. This method is similar to a reflective method invocation by | |
201 * {@link Method#invoke}. | |
202 * | |
203 * @param receiver The receiver for the invocation, or {@code null} if it is a static method. | |
204 * @param arguments The arguments for the invocation. | |
205 * @return The value returned by the method invocation, or {@code null} if the return type is | |
206 * {@code void}. | |
207 */ | |
208 JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments); | |
209 | |
210 /** | |
211 * Gets the encoding of (that is, a constant representing the value of) this method. | |
212 * | |
213 * @return a constant representing a reference to this method | |
214 */ | |
215 Constant getEncoding(); | |
216 | |
217 /** | |
218 * Checks if this method is present in the virtual table for subtypes of the specified | |
219 * {@linkplain ResolvedJavaType type}. | |
220 * | |
221 * @return true is this method is present in the virtual table for subtypes of this type. | |
222 */ | |
223 boolean isInVirtualMethodTable(ResolvedJavaType resolved); | |
224 | |
225 /** | |
226 * Gets the annotation of a particular type for a formal parameter of this method. | |
227 * | |
228 * @param annotationClass the Class object corresponding to the annotation type | |
229 * @param parameterIndex the index of a formal parameter of {@code method} | |
230 * @return the annotation of type {@code annotationClass} for the formal parameter present, else | |
231 * null | |
232 * @throws IndexOutOfBoundsException if {@code parameterIndex} does not denote a formal | |
233 * parameter | |
234 */ | |
235 default <T extends Annotation> T getParameterAnnotation(Class<T> annotationClass, int parameterIndex) { | |
236 if (parameterIndex >= 0) { | |
237 Annotation[][] parameterAnnotations = getParameterAnnotations(); | |
238 for (Annotation a : parameterAnnotations[parameterIndex]) { | |
239 if (a.annotationType() == annotationClass) { | |
240 return annotationClass.cast(a); | |
241 } | |
242 } | |
243 } | |
244 return null; | |
245 } | |
246 | |
247 default JavaType[] toParameterTypes() { | |
248 JavaType receiver = isStatic() || isConstructor() ? null : getDeclaringClass(); | |
249 return getSignature().toParameterTypes(receiver); | |
250 } | |
251 | |
252 /** | |
253 * Gets the annotations of a particular type for the formal parameters of this method. | |
254 * | |
255 * @param annotationClass the Class object corresponding to the annotation type | |
256 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter | |
257 * present | |
258 */ | |
259 @SuppressWarnings("unchecked") | |
260 default <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass) { | |
261 Annotation[][] parameterAnnotations = getParameterAnnotations(); | |
262 T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); | |
263 for (int i = 0; i < parameterAnnotations.length; i++) { | |
264 for (Annotation a : parameterAnnotations[i]) { | |
265 if (a.annotationType() == annotationClass) { | |
266 result[i] = annotationClass.cast(a); | |
267 } | |
268 } | |
269 } | |
270 return result; | |
271 } | |
272 | |
273 /** | |
274 * Checks whether the method has bytecodes associated with it. Methods without bytecodes are | |
275 * either abstract or native methods. | |
276 * | |
277 * @return whether the definition of this method is Java bytecodes | |
278 */ | |
279 default boolean hasBytecodes() { | |
280 return isConcrete() && !isNative(); | |
281 } | |
282 | |
283 /** | |
284 * Checks whether the method has a receiver parameter - i.e., whether it is not static. | |
285 * | |
286 * @return whether the method has a receiver parameter | |
287 */ | |
288 default boolean hasReceiver() { | |
289 return !isStatic(); | |
290 } | |
291 | |
292 /** | |
293 * Determines if this method is {@link java.lang.Object#Object()}. | |
294 */ | |
295 default boolean isJavaLangObjectInit() { | |
296 return getDeclaringClass().isJavaLangObject() && getName().equals("<init>"); | |
297 } | |
298 } |