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.hotspot; 24 25 import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; 26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; 27 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; 29 30 import java.lang.annotation.Annotation; 31 import java.lang.reflect.Executable; 32 import java.lang.reflect.InvocationTargetException; 33 import java.lang.reflect.Method; 34 import java.lang.reflect.Modifier; 35 import java.lang.reflect.Type; 36 import java.util.HashMap; 37 import java.util.Map; 38 39 import jdk.vm.ci.common.JVMCIError; 40 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; 41 import jdk.vm.ci.meta.Constant; 42 import jdk.vm.ci.meta.ConstantPool; 43 import jdk.vm.ci.meta.DefaultProfilingInfo; 44 import jdk.vm.ci.meta.ExceptionHandler; 45 import jdk.vm.ci.meta.JavaConstant; 46 import jdk.vm.ci.meta.JavaMethod; 47 import jdk.vm.ci.meta.JavaType; 48 import jdk.vm.ci.meta.LineNumberTable; 49 import jdk.vm.ci.meta.Local; 50 import jdk.vm.ci.meta.LocalVariableTable; 51 import jdk.vm.ci.meta.ModifiersProvider; 52 import jdk.vm.ci.meta.ProfilingInfo; 53 import jdk.vm.ci.meta.ResolvedJavaMethod; 54 import jdk.vm.ci.meta.ResolvedJavaType; 55 import jdk.vm.ci.meta.Signature; 56 import jdk.vm.ci.meta.SpeculationLog; 57 import jdk.vm.ci.meta.TriState; 58 59 /** 60 * Implementation of {@link JavaMethod} for resolved HotSpot methods. 61 */ 62 final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, MetaspaceWrapperObject { 63 64 /** 65 * Reference to metaspace Method object. 680 Map<Long, SpeculationLog> map = SpeculationLogs.get(holder.mirror()); 681 synchronized (map) { 682 SpeculationLog log = map.get(this.metaspaceMethod); 683 if (log == null) { 684 log = new HotSpotSpeculationLog(); 685 map.put(metaspaceMethod, log); 686 } 687 return log; 688 } 689 } 690 691 public int intrinsicId() { 692 HotSpotVMConfig config = config(); 693 return UNSAFE.getChar(metaspaceMethod + config.methodIntrinsicIdOffset); 694 } 695 696 public boolean isIntrinsicCandidate() { 697 return (getFlags() & config().methodFlagsIntrinsicCandidate) != 0; 698 } 699 700 @Override 701 public JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments) { 702 assert !isConstructor(); 703 Method javaMethod = (Method) toJava(); 704 javaMethod.setAccessible(true); 705 706 Object[] objArguments = new Object[arguments.length]; 707 for (int i = 0; i < arguments.length; i++) { 708 objArguments[i] = HotSpotObjectConstantImpl.asBoxedValue(arguments[i]); 709 } 710 Object objReceiver = receiver != null && !receiver.isNull() ? ((HotSpotObjectConstantImpl) receiver).object() : null; 711 712 try { 713 Object objResult = javaMethod.invoke(objReceiver, objArguments); 714 return javaMethod.getReturnType() == void.class ? null : HotSpotObjectConstantImpl.forBoxedValue(getSignature().getReturnKind(), objResult); 715 716 } catch (IllegalAccessException | InvocationTargetException ex) { 717 throw new IllegalArgumentException(ex); 718 } 719 } 720 721 /** 722 * Allocates a compile id for this method by asking the VM for one. 723 * 724 * @param entryBCI entry bci 725 * @return compile id 726 */ 727 public int allocateCompileId(int entryBCI) { 728 return compilerToVM().allocateCompileId(this, entryBCI); 729 } 730 731 public boolean hasCodeAtLevel(int entryBCI, int level) { 732 if (entryBCI == config().invocationEntryBci) { 733 return hasCompiledCodeAtLevel(level); 734 } 735 return compilerToVM().hasCompiledCodeForOSR(this, entryBCI, level); 736 } 737 } | 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.hotspot; 24 25 import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM; 26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; 27 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; 29 30 import java.lang.annotation.Annotation; 31 import java.lang.reflect.Executable; 32 import java.lang.reflect.Modifier; 33 import java.lang.reflect.Type; 34 import java.util.HashMap; 35 import java.util.Map; 36 37 import jdk.vm.ci.common.JVMCIError; 38 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; 39 import jdk.vm.ci.meta.Constant; 40 import jdk.vm.ci.meta.ConstantPool; 41 import jdk.vm.ci.meta.DefaultProfilingInfo; 42 import jdk.vm.ci.meta.ExceptionHandler; 43 import jdk.vm.ci.meta.JavaMethod; 44 import jdk.vm.ci.meta.JavaType; 45 import jdk.vm.ci.meta.LineNumberTable; 46 import jdk.vm.ci.meta.Local; 47 import jdk.vm.ci.meta.LocalVariableTable; 48 import jdk.vm.ci.meta.ModifiersProvider; 49 import jdk.vm.ci.meta.ProfilingInfo; 50 import jdk.vm.ci.meta.ResolvedJavaMethod; 51 import jdk.vm.ci.meta.ResolvedJavaType; 52 import jdk.vm.ci.meta.Signature; 53 import jdk.vm.ci.meta.SpeculationLog; 54 import jdk.vm.ci.meta.TriState; 55 56 /** 57 * Implementation of {@link JavaMethod} for resolved HotSpot methods. 58 */ 59 final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, MetaspaceWrapperObject { 60 61 /** 62 * Reference to metaspace Method object. 677 Map<Long, SpeculationLog> map = SpeculationLogs.get(holder.mirror()); 678 synchronized (map) { 679 SpeculationLog log = map.get(this.metaspaceMethod); 680 if (log == null) { 681 log = new HotSpotSpeculationLog(); 682 map.put(metaspaceMethod, log); 683 } 684 return log; 685 } 686 } 687 688 public int intrinsicId() { 689 HotSpotVMConfig config = config(); 690 return UNSAFE.getChar(metaspaceMethod + config.methodIntrinsicIdOffset); 691 } 692 693 public boolean isIntrinsicCandidate() { 694 return (getFlags() & config().methodFlagsIntrinsicCandidate) != 0; 695 } 696 697 /** 698 * Allocates a compile id for this method by asking the VM for one. 699 * 700 * @param entryBCI entry bci 701 * @return compile id 702 */ 703 public int allocateCompileId(int entryBCI) { 704 return compilerToVM().allocateCompileId(this, entryBCI); 705 } 706 707 public boolean hasCodeAtLevel(int entryBCI, int level) { 708 if (entryBCI == config().invocationEntryBci) { 709 return hasCompiledCodeAtLevel(level); 710 } 711 return compilerToVM().hasCompiledCodeForOSR(this, entryBCI, level); 712 } 713 } |