< prev index next >

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

Print this page

  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.access.JavaLangInvokeAccess;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.invoke.NativeEntryPoint;
  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.invoke.MethodHandles.Lookup;
  44 import java.lang.reflect.Array;

  45 import java.nio.ByteOrder;
  46 import java.util.Arrays;
  47 import java.util.Collections;
  48 import java.util.HashMap;
  49 import java.util.Iterator;
  50 import java.util.List;
  51 import java.util.Map;
  52 import java.util.Objects;
  53 import java.util.concurrent.ConcurrentHashMap;
  54 import java.util.function.Function;
  55 import java.util.stream.Stream;
  56 
  57 import static java.lang.invoke.LambdaForm.*;
  58 import static java.lang.invoke.MethodHandleStatics.*;
  59 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  60 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  61 
  62 /**
  63  * Trusted implementation code for MethodHandle.
  64  * @author jrose

1486 
1487             @Override
1488             public VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes) {
1489                 return VarHandles.dropCoordinates(target, pos, valueTypes);
1490             }
1491 
1492             @Override
1493             public VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder) {
1494                 return VarHandles.permuteCoordinates(target, newCoordinates, reorder);
1495             }
1496 
1497             @Override
1498             public VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter) {
1499                 return VarHandles.collectCoordinates(target, pos, filter);
1500             }
1501 
1502             @Override
1503             public VarHandle insertCoordinates(VarHandle target, int pos, Object... values) {
1504                 return VarHandles.insertCoordinates(target, pos, values);
1505             }










1506         });
1507     }
1508 
1509     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1510     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1511         if (returnType.isPrimitive()) {
1512             if (returnType == void.class) {
1513                 return ValueConversions.ignore();
1514             } else {
1515                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1516                 return ValueConversions.unboxExact(w);
1517             }
1518         } else {
1519             return MethodHandles.identity(Object.class);
1520         }
1521     }
1522 
1523     /**
1524      * Assembles a loop method handle from the given handles and type information.
1525      *

  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.access.JavaLangInvokeAccess;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.invoke.NativeEntryPoint;
  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.invoke.MethodHandles.Lookup;
  44 import java.lang.reflect.Array;
  45 import java.lang.reflect.Field;
  46 import java.nio.ByteOrder;
  47 import java.util.Arrays;
  48 import java.util.Collections;
  49 import java.util.HashMap;
  50 import java.util.Iterator;
  51 import java.util.List;
  52 import java.util.Map;
  53 import java.util.Objects;
  54 import java.util.concurrent.ConcurrentHashMap;
  55 import java.util.function.Function;
  56 import java.util.stream.Stream;
  57 
  58 import static java.lang.invoke.LambdaForm.*;
  59 import static java.lang.invoke.MethodHandleStatics.*;
  60 import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
  61 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  62 
  63 /**
  64  * Trusted implementation code for MethodHandle.
  65  * @author jrose

1487 
1488             @Override
1489             public VarHandle dropCoordinates(VarHandle target, int pos, Class<?>... valueTypes) {
1490                 return VarHandles.dropCoordinates(target, pos, valueTypes);
1491             }
1492 
1493             @Override
1494             public VarHandle permuteCoordinates(VarHandle target, List<Class<?>> newCoordinates, int... reorder) {
1495                 return VarHandles.permuteCoordinates(target, newCoordinates, reorder);
1496             }
1497 
1498             @Override
1499             public VarHandle collectCoordinates(VarHandle target, int pos, MethodHandle filter) {
1500                 return VarHandles.collectCoordinates(target, pos, filter);
1501             }
1502 
1503             @Override
1504             public VarHandle insertCoordinates(VarHandle target, int pos, Object... values) {
1505                 return VarHandles.insertCoordinates(target, pos, values);
1506             }
1507 
1508             @Override
1509             public MethodHandle findStatic(Class<?> cls, String name, MethodType methodType) throws NoSuchMethodException, IllegalAccessException {
1510                 return IMPL_LOOKUP.findStatic(cls, name, methodType);
1511             }
1512 
1513             @Override
1514             public MethodHandle unreflectGetter(Field field) throws IllegalAccessException {
1515                 return IMPL_LOOKUP.unreflectGetter(field);
1516             }
1517         });
1518     }
1519 
1520     /** Result unboxing: ValueConversions.unbox() OR ValueConversions.identity() OR ValueConversions.ignore(). */
1521     private static MethodHandle unboxResultHandle(Class<?> returnType) {
1522         if (returnType.isPrimitive()) {
1523             if (returnType == void.class) {
1524                 return ValueConversions.ignore();
1525             } else {
1526                 Wrapper w = Wrapper.forPrimitiveType(returnType);
1527                 return ValueConversions.unboxExact(w);
1528             }
1529         } else {
1530             return MethodHandles.identity(Object.class);
1531         }
1532     }
1533 
1534     /**
1535      * Assembles a loop method handle from the given handles and type information.
1536      *
< prev index next >