< 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

1402                                                    MethodHandle.class, Object[].class));
1403                 case NF_tryFinally          -> new NamedFunction(MethodHandleImpl.class
1404                                                 .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class));
1405                 case NF_loop                -> new NamedFunction(MethodHandleImpl.class
1406                                                 .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class));
1407                 case NF_throwException      -> new NamedFunction(MethodHandleImpl.class
1408                                                 .getDeclaredMethod("throwException", Throwable.class));
1409                 case NF_profileBoolean      -> new NamedFunction(MethodHandleImpl.class
1410                                                 .getDeclaredMethod("profileBoolean", boolean.class, int[].class));
1411                 case NF_tableSwitch         -> new NamedFunction(MethodHandleImpl.class
1412                                                 .getDeclaredMethod("tableSwitch", int.class, MethodHandle.class, CasesHolder.class, Object[].class));
1413                 default -> throw new InternalError("Undefined function: " + func);
1414             };
1415         } catch (ReflectiveOperationException ex) {
1416             throw newInternalError(ex);
1417         }
1418     }
1419 
1420     static {
1421         SharedSecrets.setJavaLangInvokeAccess(new JavaLangInvokeAccess() {





























1422             @Override
1423             public Object newMemberName() {
1424                 return new MemberName();
1425             }
1426 





1427             @Override
1428             public String getName(Object mname) {
1429                 MemberName memberName = (MemberName)mname;
1430                 return memberName.getName();
1431             }
1432             @Override
1433             public Class<?> getDeclaringClass(Object mname) {
1434                 MemberName memberName = (MemberName)mname;
1435                 return memberName.getDeclaringClass();
1436             }
1437 
1438             @Override
1439             public MethodType getMethodType(Object mname) {
1440                 MemberName memberName = (MemberName)mname;
1441                 return memberName.getMethodType();
1442             }
1443 
1444             @Override
1445             public String getMethodDescriptor(Object mname) {
1446                 MemberName memberName = (MemberName)mname;

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

1404                                                    MethodHandle.class, Object[].class));
1405                 case NF_tryFinally          -> new NamedFunction(MethodHandleImpl.class
1406                                                 .getDeclaredMethod("tryFinally", MethodHandle.class, MethodHandle.class, Object[].class));
1407                 case NF_loop                -> new NamedFunction(MethodHandleImpl.class
1408                                                 .getDeclaredMethod("loop", BasicType[].class, LoopClauses.class, Object[].class));
1409                 case NF_throwException      -> new NamedFunction(MethodHandleImpl.class
1410                                                 .getDeclaredMethod("throwException", Throwable.class));
1411                 case NF_profileBoolean      -> new NamedFunction(MethodHandleImpl.class
1412                                                 .getDeclaredMethod("profileBoolean", boolean.class, int[].class));
1413                 case NF_tableSwitch         -> new NamedFunction(MethodHandleImpl.class
1414                                                 .getDeclaredMethod("tableSwitch", int.class, MethodHandle.class, CasesHolder.class, Object[].class));
1415                 default -> throw new InternalError("Undefined function: " + func);
1416             };
1417         } catch (ReflectiveOperationException ex) {
1418             throw newInternalError(ex);
1419         }
1420     }
1421 
1422     static {
1423         SharedSecrets.setJavaLangInvokeAccess(new JavaLangInvokeAccess() {
1424 
1425             @Override
1426             public MethodHandle privilegedUnreflect(Method method) {
1427                 try {
1428                     return IMPL_LOOKUP.unreflect(method);
1429                 } catch (IllegalAccessException e) {
1430                     throw new InternalError(e);
1431                 }
1432             }
1433 
1434             @Override
1435             public MethodHandle privilegedUnreflect(Constructor<?> ctor) {
1436                 try {
1437                     return IMPL_LOOKUP.unreflectConstructor(ctor);
1438                 } catch (IllegalAccessException e) {
1439                     throw new InternalError(e);
1440                 }
1441             }
1442 
1443             @Override
1444             public MethodHandle privilegedFindStatic(Class<?> refc, String name, MethodType type)
1445                     throws NoSuchMethodException {
1446                 try {
1447                     return IMPL_LOOKUP.findStatic(refc, name, type);
1448                 } catch (IllegalAccessException e) {
1449                     throw new InternalError(e);
1450                 }
1451             }
1452 
1453             @Override
1454             public Object newMemberName() {
1455                 return new MemberName();
1456             }
1457 
1458             @Override
1459             public Object newMemberName(Method method) {
1460                 return new MemberName(method);
1461             }
1462 
1463             @Override
1464             public String getName(Object mname) {
1465                 MemberName memberName = (MemberName)mname;
1466                 return memberName.getName();
1467             }
1468             @Override
1469             public Class<?> getDeclaringClass(Object mname) {
1470                 MemberName memberName = (MemberName)mname;
1471                 return memberName.getDeclaringClass();
1472             }
1473 
1474             @Override
1475             public MethodType getMethodType(Object mname) {
1476                 MemberName memberName = (MemberName)mname;
1477                 return memberName.getMethodType();
1478             }
1479 
1480             @Override
1481             public String getMethodDescriptor(Object mname) {
1482                 MemberName memberName = (MemberName)mname;
< prev index next >