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 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.InvocationTargetException; 29 import java.lang.reflect.Method; 30 import java.lang.reflect.Modifier; 31 import java.lang.reflect.Type; 32 33 /** 34 * Represents a resolved Java method. Methods, like fields and types, are resolved through 35 * {@link ConstantPool constant pools}. 36 */ 37 public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider, AnnotatedElement { 38 39 /** 40 * Returns the bytecode of this method, if the method has code. The returned byte array does not 41 * contain breakpoints or non-Java bytecodes. This may return null if the 42 * {@link #getDeclaringClass() holder} is not {@link ResolvedJavaType#isLinked() linked}. 43 * 44 * The contained constant pool indices may not be the ones found in the original class file but 45 * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}). 46 * 47 * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the 48 * code is not ready. 49 */ 50 byte[] getCode(); 51 52 /** 53 * Returns the size of the bytecode of this method, if the method has code. This is equivalent 54 * to {@link #getCode()}. {@code length} if the method has code. 55 * 56 * @return the size of the bytecode in bytes, or 0 if no bytecode is available 57 */ 58 int getCodeSize(); 59 60 /** 61 * Returns the {@link ResolvedJavaType} object representing the class or interface that declares 62 * this method. 422 * 423 * @param annotationClass the Class object corresponding to the annotation type 424 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter 425 * present 426 */ 427 @SuppressWarnings("unchecked") 428 default <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass) { 429 Annotation[][] parameterAnnotations = getParameterAnnotations(); 430 T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); 431 for (int i = 0; i < parameterAnnotations.length; i++) { 432 for (Annotation a : parameterAnnotations[i]) { 433 if (a.annotationType() == annotationClass) { 434 result[i] = annotationClass.cast(a); 435 } 436 } 437 } 438 return result; 439 } 440 441 /** 442 * Checks whether the method has bytecodes associated with it. Methods without bytecodes are 443 * either abstract or native methods. 444 * 445 * @return whether the definition of this method is Java bytecodes 446 */ 447 default boolean hasBytecodes() { 448 return isConcrete() && !isNative(); 449 } 450 451 /** 452 * Checks whether the method has a receiver parameter - i.e., whether it is not static. 453 * 454 * @return whether the method has a receiver parameter 455 */ 456 default boolean hasReceiver() { 457 return !isStatic(); 458 } 459 460 /** 461 * Determines if this method is {@link java.lang.Object#Object()}. 462 */ 463 default boolean isJavaLangObjectInit() { 464 return getDeclaringClass().isJavaLangObject() && getName().equals("<init>"); 465 } 466 467 SpeculationLog getSpeculationLog(); 468 469 /** 470 * 471 * @param object 472 * @param args 473 * @throws InvocationTargetException 474 * @throws IllegalAccessException 475 */ 476 default JavaConstant invoke(JavaConstant object, JavaConstant... args) throws InvocationTargetException, IllegalAccessException { 477 throw new InternalError("unimplemented"); 478 } 479 } | 1 /* 2 * Copyright (c) 2009, 2019, 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 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 * {@linkplain #getDeclaringClass() declaring class} is not 42 * {@linkplain ResolvedJavaType#isLinked() linked}. 43 * 44 * The contained constant pool indices may not be the ones found in the original class file but 45 * they can be used with the JVMCI API (e.g. methods in {@link ConstantPool}). 46 * 47 * @return the bytecode of the method, or {@code null} if {@code getCodeSize() == 0} or if the 48 * code is not ready. 49 */ 50 byte[] getCode(); 51 52 /** 53 * Returns the size of the bytecode of this method, if the method has code. This is equivalent 54 * to {@link #getCode()}. {@code length} if the method has code. 55 * 56 * @return the size of the bytecode in bytes, or 0 if no bytecode is available 57 */ 58 int getCodeSize(); 59 60 /** 61 * Returns the {@link ResolvedJavaType} object representing the class or interface that declares 62 * this method. 422 * 423 * @param annotationClass the Class object corresponding to the annotation type 424 * @return the annotation of type {@code annotationClass} (if any) for each formal parameter 425 * present 426 */ 427 @SuppressWarnings("unchecked") 428 default <T extends Annotation> T[] getParameterAnnotations(Class<T> annotationClass) { 429 Annotation[][] parameterAnnotations = getParameterAnnotations(); 430 T[] result = (T[]) Array.newInstance(annotationClass, parameterAnnotations.length); 431 for (int i = 0; i < parameterAnnotations.length; i++) { 432 for (Annotation a : parameterAnnotations[i]) { 433 if (a.annotationType() == annotationClass) { 434 result[i] = annotationClass.cast(a); 435 } 436 } 437 } 438 return result; 439 } 440 441 /** 442 * Checks whether the method has bytecodes associated with it. Note that even if this method 443 * returns {@code true}, {@link #getCode} can return {@code null} if 444 * {@linkplain #getDeclaringClass() declaring class} is not 445 * {@linkplain ResolvedJavaType#isLinked() linked}. 446 * 447 * @return {@code this.getCodeSize() != 0} 448 */ 449 default boolean hasBytecodes() { 450 return getCodeSize() != 0; 451 } 452 453 /** 454 * Checks whether the method has a receiver parameter - i.e., whether it is not static. 455 * 456 * @return whether the method has a receiver parameter 457 */ 458 default boolean hasReceiver() { 459 return !isStatic(); 460 } 461 462 /** 463 * Determines if this method is {@link java.lang.Object#Object()}. 464 */ 465 default boolean isJavaLangObjectInit() { 466 return getDeclaringClass().isJavaLangObject() && getName().equals("<init>"); 467 } 468 469 /** 470 * Gets a speculation log that can be used when compiling this method to make new speculations 471 * and query previously failed speculations. The implementation may return a new 472 * {@link SpeculationLog} object each time this method is called so its the caller's 473 * responsibility to ensure the same speculation log is used throughout a compilation. 474 */ 475 SpeculationLog getSpeculationLog(); 476 } |