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 jdk.vm.ci.meta;
24
25 import java.lang.annotation.Annotation;
26 import java.lang.reflect.AnnotatedElement;
27 import java.lang.reflect.Array;
28 import java.lang.reflect.Method;
29 import java.lang.reflect.Modifier;
30 import java.lang.reflect.Type;
31
32 /**
33 * Represents a resolved Java method. Methods, like fields and types, are resolved through
34 * {@link ConstantPool constant pools}.
35 */
36 public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider, AnnotatedElement {
37
38 /**
39 * Returns the bytecode of this method, if the method has code. The returned byte array does not
40 * contain breakpoints or non-Java bytecodes. This may return null if the
41 * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}.
42 *
43 * The contained constant pool indices may not be the ones found in the original class file but
44 * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}).
45 *
46 * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the
47 * code is not ready.
48 */
49 byte[] getCode();
55 * @return the size of the bytecode in bytes, or 0 if no bytecode is available
56 */
57 int getCodeSize();
58
59 /**
60 * Returns the {@link ResolvedJavaType} object representing the class or interface that declares
61 * this method.
62 */
63 ResolvedJavaType getDeclaringClass();
64
65 /**
66 * Returns the maximum number of locals used in this method's bytecodes.
67 */
68 int getMaxLocals();
69
70 /**
71 * Returns the maximum number of stack slots used in this method's bytecodes.
72 */
73 int getMaxStackSize();
74
75 /**
76 * {@inheritDoc}
77 * <p>
78 * Only the {@linkplain Modifier#methodModifiers() method flags} specified in the JVM
79 * specification will be included in the returned mask.
80 */
81 int getModifiers();
82
83 default boolean isFinal() {
84 return ModifiersProvider.super.isFinalFlagSet();
85 }
86
87 /**
88 * Determines if this method is a synthetic method as defined by the Java Language
89 * Specification.
90 */
91 default boolean isSynthetic() {
92 return (SYNTHETIC & getModifiers()) == SYNTHETIC;
93 }
94
95 /**
96 * Checks that the method is a
97 * <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6">varargs</a>
98 * method.
99 *
100 * @return whether the method is a varargs method
101 */
102 default boolean isVarArgs() {
103 return (VARARGS & getModifiers()) == VARARGS;
104 }
105
106 /**
107 * Checks that the method is a
108 * <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6">bridge</a>
109 * method.
110 *
111 * @return whether the method is a bridge method
112 */
113 default boolean isBridge() {
114 return (BRIDGE & getModifiers()) == BRIDGE;
115 }
116
117 /**
118 * Returns {@code true} if this method is a default method; returns {@code false} otherwise.
119 *
120 * A default method is a public non-abstract instance method, that is, a non-static method with
121 * a body, declared in an interface type.
122 *
123 * @return true if and only if this method is a default method as defined by the Java Language
124 * Specification.
125 */
126 boolean isDefault();
127
128 /**
129 * Checks whether this method is a class initializer.
130 *
131 * @return {@code true} if the method is a class initializer
132 */
133 boolean isClassInitializer();
134
135 /**
211 boolean canBeInlined();
212
213 /**
214 * Returns {@code true} if the inlining of this method should be forced.
215 */
216 boolean shouldBeInlined();
217
218 /**
219 * Returns the LineNumberTable of this method or null if this method does not have a line
220 * numbers table.
221 */
222 LineNumberTable getLineNumberTable();
223
224 /**
225 * Returns the local variable table of this method or null if this method does not have a local
226 * variable table.
227 */
228 LocalVariableTable getLocalVariableTable();
229
230 /**
231 * Invokes the underlying method represented by this object, on the specified object with the
232 * specified parameters. This method is similar to a reflective method invocation by
233 * {@link Method#invoke}.
234 *
235 * @param receiver The receiver for the invocation, or {@code null} if it is a static method.
236 * @param arguments The arguments for the invocation.
237 * @return The value returned by the method invocation, or {@code null} if the return type is
238 * {@code void}.
239 */
240 JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments);
241
242 /**
243 * Gets the encoding of (that is, a constant representing the value of) this method.
244 *
245 * @return a constant representing a reference to this method
246 */
247 Constant getEncoding();
248
249 /**
250 * Checks if this method is present in the virtual table for subtypes of the specified
251 * {@linkplain ResolvedJavaType type}.
252 *
253 * @return true is this method is present in the virtual table for subtypes of this type.
254 */
255 boolean isInVirtualMethodTable(ResolvedJavaType resolved);
256
257 /**
258 * Gets the annotation of a particular type for a formal parameter of this method.
259 *
260 * @param annotationClass the Class object corresponding to the annotation type
261 * @param parameterIndex the index of a formal parameter of {@code method}
262 * @return the annotation of type {@code annotationClass} for the formal parameter present, else
|
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 jdk.vm.ci.meta;
24
25 import java.lang.annotation.Annotation;
26 import java.lang.reflect.AnnotatedElement;
27 import java.lang.reflect.Array;
28 import java.lang.reflect.Method;
29 import java.lang.reflect.Type;
30
31 /**
32 * Represents a resolved Java method. Methods, like fields and types, are resolved through
33 * {@link ConstantPool constant pools}.
34 */
35 public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider, AnnotatedElement {
36
37 /**
38 * Returns the bytecode of this method, if the method has code. The returned byte array does not
39 * contain breakpoints or non-Java bytecodes. This may return null if the
40 * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}.
41 *
42 * The contained constant pool indices may not be the ones found in the original class file but
43 * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}).
44 *
45 * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the
46 * code is not ready.
47 */
48 byte[] getCode();
54 * @return the size of the bytecode in bytes, or 0 if no bytecode is available
55 */
56 int getCodeSize();
57
58 /**
59 * Returns the {@link ResolvedJavaType} object representing the class or interface that declares
60 * this method.
61 */
62 ResolvedJavaType getDeclaringClass();
63
64 /**
65 * Returns the maximum number of locals used in this method's bytecodes.
66 */
67 int getMaxLocals();
68
69 /**
70 * Returns the maximum number of stack slots used in this method's bytecodes.
71 */
72 int getMaxStackSize();
73
74 default boolean isFinal() {
75 return ModifiersProvider.super.isFinalFlagSet();
76 }
77
78 /**
79 * Determines if this method is a synthetic method as defined by the Java Language
80 * Specification.
81 */
82 boolean isSynthetic();
83
84 /**
85 * Checks that the method is a
86 * <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6">varargs</a>
87 * method.
88 *
89 * @return whether the method is a varargs method
90 */
91 boolean isVarArgs();
92
93 /**
94 * Checks that the method is a
95 * <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6">bridge</a>
96 * method.
97 *
98 * @return whether the method is a bridge method
99 */
100 boolean isBridge();
101
102 /**
103 * Returns {@code true} if this method is a default method; returns {@code false} otherwise.
104 *
105 * A default method is a public non-abstract instance method, that is, a non-static method with
106 * a body, declared in an interface type.
107 *
108 * @return true if and only if this method is a default method as defined by the Java Language
109 * Specification.
110 */
111 boolean isDefault();
112
113 /**
114 * Checks whether this method is a class initializer.
115 *
116 * @return {@code true} if the method is a class initializer
117 */
118 boolean isClassInitializer();
119
120 /**
196 boolean canBeInlined();
197
198 /**
199 * Returns {@code true} if the inlining of this method should be forced.
200 */
201 boolean shouldBeInlined();
202
203 /**
204 * Returns the LineNumberTable of this method or null if this method does not have a line
205 * numbers table.
206 */
207 LineNumberTable getLineNumberTable();
208
209 /**
210 * Returns the local variable table of this method or null if this method does not have a local
211 * variable table.
212 */
213 LocalVariableTable getLocalVariableTable();
214
215 /**
216 * Gets the encoding of (that is, a constant representing the value of) this method.
217 *
218 * @return a constant representing a reference to this method
219 */
220 Constant getEncoding();
221
222 /**
223 * Checks if this method is present in the virtual table for subtypes of the specified
224 * {@linkplain ResolvedJavaType type}.
225 *
226 * @return true is this method is present in the virtual table for subtypes of this type.
227 */
228 boolean isInVirtualMethodTable(ResolvedJavaType resolved);
229
230 /**
231 * Gets the annotation of a particular type for a formal parameter of this method.
232 *
233 * @param annotationClass the Class object corresponding to the annotation type
234 * @param parameterIndex the index of a formal parameter of {@code method}
235 * @return the annotation of type {@code annotationClass} for the formal parameter present, else
|