< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java

Print this page




  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.access.JavaLangInvokeAccess;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  31 import jdk.internal.org.objectweb.asm.ClassWriter;
  32 import jdk.internal.org.objectweb.asm.MethodVisitor;
  33 import jdk.internal.reflect.CallerSensitive;
  34 import jdk.internal.reflect.Reflection;
  35 import jdk.internal.vm.annotation.ForceInline;
  36 import jdk.internal.vm.annotation.Hidden;
  37 import jdk.internal.vm.annotation.Stable;
  38 import sun.invoke.empty.Empty;
  39 import sun.invoke.util.ValueConversions;
  40 import sun.invoke.util.VerifyType;
  41 import sun.invoke.util.Wrapper;
  42 

  43 import java.lang.reflect.Array;
  44 import java.util.Arrays;
  45 import java.util.Collections;
  46 import java.util.HashMap;
  47 import java.util.Iterator;
  48 import java.util.List;
  49 import java.util.Map;
  50 import java.util.function.Function;
  51 import java.util.stream.Stream;
  52 
  53 import static java.lang.invoke.LambdaForm.*;
  54 import static java.lang.invoke.MethodHandleStatics.*;
  55 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  56 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  57 
  58 /**
  59  * Trusted implementation code for MethodHandle.
  60  * @author jrose
  61  */
  62 /*non-public*/ abstract class MethodHandleImpl {


1782                     final String types) {
1783                 return GenerateJLIClassesHelper
1784                         .generateConcreteBMHClassBytes(types);
1785             }
1786 
1787             @Override
1788             public byte[] generateBasicFormsClassBytes(final String className) {
1789                 return GenerateJLIClassesHelper
1790                         .generateBasicFormsClassBytes(className);
1791             }
1792 
1793             @Override
1794             public byte[] generateInvokersHolderClassBytes(final String className,
1795                     MethodType[] invokerMethodTypes,
1796                     MethodType[] callSiteMethodTypes) {
1797                 return GenerateJLIClassesHelper
1798                         .generateInvokersHolderClassBytes(className,
1799                                 invokerMethodTypes, callSiteMethodTypes);
1800             }
1801 




1802         });
1803     }
1804 
1805     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1806     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1807         if (returnType.isPrimitive()) {
1808             if (returnType == void.class) {
1809                 return ValueConversions.ignore();
1810             } else {
1811                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1812                 return ValueConversions.unboxExact(w);
1813             }
1814         } else {
1815             return MethodHandles.identity(Object.class);
1816         }
1817     }
1818 
1819     /**
1820      * Assembles a loop method handle from the given handles and type information.
1821      *




  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.access.JavaLangInvokeAccess;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  31 import jdk.internal.org.objectweb.asm.ClassWriter;
  32 import jdk.internal.org.objectweb.asm.MethodVisitor;
  33 import jdk.internal.reflect.CallerSensitive;
  34 import jdk.internal.reflect.Reflection;
  35 import jdk.internal.vm.annotation.ForceInline;
  36 import jdk.internal.vm.annotation.Hidden;
  37 import jdk.internal.vm.annotation.Stable;
  38 import sun.invoke.empty.Empty;
  39 import sun.invoke.util.ValueConversions;
  40 import sun.invoke.util.VerifyType;
  41 import sun.invoke.util.Wrapper;
  42 
  43 import java.foreign.layout.LayoutPath;
  44 import java.lang.reflect.Array;
  45 import java.util.Arrays;
  46 import java.util.Collections;
  47 import java.util.HashMap;
  48 import java.util.Iterator;
  49 import java.util.List;
  50 import java.util.Map;
  51 import java.util.function.Function;
  52 import java.util.stream.Stream;
  53 
  54 import static java.lang.invoke.LambdaForm.*;
  55 import static java.lang.invoke.MethodHandleStatics.*;
  56 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  57 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  58 
  59 /**
  60  * Trusted implementation code for MethodHandle.
  61  * @author jrose
  62  */
  63 /*non-public*/ abstract class MethodHandleImpl {


1783                     final String types) {
1784                 return GenerateJLIClassesHelper
1785                         .generateConcreteBMHClassBytes(types);
1786             }
1787 
1788             @Override
1789             public byte[] generateBasicFormsClassBytes(final String className) {
1790                 return GenerateJLIClassesHelper
1791                         .generateBasicFormsClassBytes(className);
1792             }
1793 
1794             @Override
1795             public byte[] generateInvokersHolderClassBytes(final String className,
1796                     MethodType[] invokerMethodTypes,
1797                     MethodType[] callSiteMethodTypes) {
1798                 return GenerateJLIClassesHelper
1799                         .generateInvokersHolderClassBytes(className,
1800                                 invokerMethodTypes, callSiteMethodTypes);
1801             }
1802 
1803             @Override
1804             public VarHandle memoryAddressViewVarHandle(Class<?> carrier, LayoutPath path) {
1805                 return VarHandles.makeMemoryAddressViewHandle(carrier, path);
1806             }
1807         });
1808     }
1809 
1810     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1811     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1812         if (returnType.isPrimitive()) {
1813             if (returnType == void.class) {
1814                 return ValueConversions.ignore();
1815             } else {
1816                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1817                 return ValueConversions.unboxExact(w);
1818             }
1819         } else {
1820             return MethodHandles.identity(Object.class);
1821         }
1822     }
1823 
1824     /**
1825      * Assembles a loop method handle from the given handles and type information.
1826      *


< prev index next >