< prev index next >

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

Print this page




  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*/
  63 abstract class MethodHandleImpl {


1773                     final String types) {
1774                 return GenerateJLIClassesHelper
1775                         .generateConcreteBMHClassBytes(types);
1776             }
1777 
1778             @Override
1779             public byte[] generateBasicFormsClassBytes(final String className) {
1780                 return GenerateJLIClassesHelper
1781                         .generateBasicFormsClassBytes(className);
1782             }
1783 
1784             @Override
1785             public byte[] generateInvokersHolderClassBytes(final String className,
1786                     MethodType[] invokerMethodTypes,
1787                     MethodType[] callSiteMethodTypes) {
1788                 return GenerateJLIClassesHelper
1789                         .generateInvokersHolderClassBytes(className,
1790                                 invokerMethodTypes, callSiteMethodTypes);
1791             }
1792 






































1793         });
1794     }
1795 
1796     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1797     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1798         if (returnType.isPrimitive()) {
1799             if (returnType == void.class) {
1800                 return ValueConversions.ignore();
1801             } else {
1802                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1803                 return ValueConversions.unboxExact(w);
1804             }
1805         } else {
1806             return MethodHandles.identity(Object.class);
1807         }
1808     }
1809 
1810     /**
1811      * Assembles a loop method handle from the given handles and type information.
1812      *




  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.nio.ByteOrder;
  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*/
  64 abstract class MethodHandleImpl {


1774                     final String types) {
1775                 return GenerateJLIClassesHelper
1776                         .generateConcreteBMHClassBytes(types);
1777             }
1778 
1779             @Override
1780             public byte[] generateBasicFormsClassBytes(final String className) {
1781                 return GenerateJLIClassesHelper
1782                         .generateBasicFormsClassBytes(className);
1783             }
1784 
1785             @Override
1786             public byte[] generateInvokersHolderClassBytes(final String className,
1787                     MethodType[] invokerMethodTypes,
1788                     MethodType[] callSiteMethodTypes) {
1789                 return GenerateJLIClassesHelper
1790                         .generateInvokersHolderClassBytes(className,
1791                                 invokerMethodTypes, callSiteMethodTypes);
1792             }
1793 
1794             @Override
1795             public VarHandle memoryAddressViewVarHandle(Class<?> carrier, long alignmentMask,
1796                                                         ByteOrder order, long offset, long[] strides) {
1797                 return VarHandles.makeMemoryAddressViewHandle(carrier, alignmentMask, order, offset, strides);
1798             }
1799 
1800             @Override
1801             public Class<?> memoryAddressCarrier(VarHandle handle) {
1802                 return checkMemAccessHandle(handle).carrier();
1803             }
1804 
1805             @Override
1806             public long memoryAddressAlignmentMask(VarHandle handle) {
1807                 return checkMemAccessHandle(handle).alignmentMask;
1808             }
1809 
1810             @Override
1811             public ByteOrder memoryAddressByteOrder(VarHandle handle) {
1812                 return checkMemAccessHandle(handle).be ?
1813                         ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
1814             }
1815 
1816             @Override
1817             public long memoryAddressOffset(VarHandle handle) {
1818                 return checkMemAccessHandle(handle).offset;
1819             }
1820 
1821             @Override
1822             public long[] memoryAddressStrides(VarHandle handle) {
1823                 return checkMemAccessHandle(handle).strides();
1824             }
1825 
1826             private VarHandleMemoryAddressBase checkMemAccessHandle(VarHandle handle) {
1827                 if (!(handle instanceof VarHandleMemoryAddressBase)) {
1828                     throw new IllegalArgumentException("Not a memory access varhandle: " + handle);
1829                 }
1830                 return (VarHandleMemoryAddressBase) handle;
1831             }
1832         });
1833     }
1834 
1835     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1836     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1837         if (returnType.isPrimitive()) {
1838             if (returnType == void.class) {
1839                 return ValueConversions.ignore();
1840             } else {
1841                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1842                 return ValueConversions.unboxExact(w);
1843             }
1844         } else {
1845             return MethodHandles.identity(Object.class);
1846         }
1847     }
1848 
1849     /**
1850      * Assembles a loop method handle from the given handles and type information.
1851      *


< prev index next >