37 import sun.reflect.misc.ReflectUtil;
38 import sun.security.util.SecurityConstants;
39
40 import java.lang.invoke.LambdaForm.BasicType;
41 import java.lang.reflect.Constructor;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.Member;
44 import java.lang.reflect.Method;
45 import java.lang.reflect.Modifier;
46 import java.lang.reflect.ReflectPermission;
47 import java.nio.ByteOrder;
48 import java.security.AccessController;
49 import java.security.PrivilegedAction;
50 import java.security.ProtectionDomain;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.BitSet;
54 import java.util.Iterator;
55 import java.util.List;
56 import java.util.Objects;
57 import java.util.concurrent.ConcurrentHashMap;
58 import java.util.stream.Collectors;
59 import java.util.stream.Stream;
60
61 import static java.lang.invoke.MethodHandleImpl.Intrinsic;
62 import static java.lang.invoke.MethodHandleNatives.Constants.*;
63 import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
64 import static java.lang.invoke.MethodType.methodType;
65
66 /**
67 * This class consists exclusively of static methods that operate on or return
68 * method handles. They fall into several categories:
69 * <ul>
70 * <li>Lookup methods which help create method handles for methods and fields.
71 * <li>Combinator methods, which combine or transform pre-existing method handles into new ones.
72 * <li>Other factory methods to create method handles that emulate other common JVM operations or control flow patterns.
73 * </ul>
74 * A lookup, combinator, or factory method will fail and throw an
75 * {@code IllegalArgumentException} if the created method handle's type
76 * would have <a href="MethodHandle.html#maxarity">too many parameters</a>.
626 * and the application must take appropriate action in that case.
627 * It may be that a later lookup, perhaps during the invocation of a
628 * bootstrap method, can incorporate the specific identity
629 * of the caller, making the method accessible.
630 * <p style="font-size:smaller;">
631 * The function {@code MethodHandles.lookup} is caller sensitive
632 * so that there can be a secure foundation for lookups.
633 * Nearly all other methods in the JSR 292 API rely on lookup
634 * objects to check access requests.
635 *
636 * @revised 9
637 */
638 public static final
639 class Lookup {
640 /** The class on behalf of whom the lookup is being performed. */
641 private final Class<?> lookupClass;
642
643 /** The allowed sorts of members which may be looked up (PUBLIC, etc.). */
644 private final int allowedModes;
645
646 /** A single-bit mask representing {@code public} access,
647 * which may contribute to the result of {@link #lookupModes lookupModes}.
648 * The value, {@code 0x01}, happens to be the same as the value of the
649 * {@code public} {@linkplain java.lang.reflect.Modifier#PUBLIC modifier bit}.
650 */
651 public static final int PUBLIC = Modifier.PUBLIC;
652
653 /** A single-bit mask representing {@code private} access,
654 * which may contribute to the result of {@link #lookupModes lookupModes}.
655 * The value, {@code 0x02}, happens to be the same as the value of the
656 * {@code private} {@linkplain java.lang.reflect.Modifier#PRIVATE modifier bit}.
657 */
658 public static final int PRIVATE = Modifier.PRIVATE;
659
660 /** A single-bit mask representing {@code protected} access,
661 * which may contribute to the result of {@link #lookupModes lookupModes}.
662 * The value, {@code 0x04}, happens to be the same as the value of the
663 * {@code protected} {@linkplain java.lang.reflect.Modifier#PROTECTED modifier bit}.
664 */
665 public static final int PROTECTED = Modifier.PROTECTED;
|
37 import sun.reflect.misc.ReflectUtil;
38 import sun.security.util.SecurityConstants;
39
40 import java.lang.invoke.LambdaForm.BasicType;
41 import java.lang.reflect.Constructor;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.Member;
44 import java.lang.reflect.Method;
45 import java.lang.reflect.Modifier;
46 import java.lang.reflect.ReflectPermission;
47 import java.nio.ByteOrder;
48 import java.security.AccessController;
49 import java.security.PrivilegedAction;
50 import java.security.ProtectionDomain;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.BitSet;
54 import java.util.Iterator;
55 import java.util.List;
56 import java.util.Objects;
57 import java.util.Set;
58 import java.util.concurrent.ConcurrentHashMap;
59 import java.util.stream.Collectors;
60 import java.util.stream.Stream;
61
62 import static java.lang.invoke.MethodHandleImpl.Intrinsic;
63 import static java.lang.invoke.MethodHandleNatives.Constants.*;
64 import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
65 import static java.lang.invoke.MethodType.methodType;
66
67 /**
68 * This class consists exclusively of static methods that operate on or return
69 * method handles. They fall into several categories:
70 * <ul>
71 * <li>Lookup methods which help create method handles for methods and fields.
72 * <li>Combinator methods, which combine or transform pre-existing method handles into new ones.
73 * <li>Other factory methods to create method handles that emulate other common JVM operations or control flow patterns.
74 * </ul>
75 * A lookup, combinator, or factory method will fail and throw an
76 * {@code IllegalArgumentException} if the created method handle's type
77 * would have <a href="MethodHandle.html#maxarity">too many parameters</a>.
627 * and the application must take appropriate action in that case.
628 * It may be that a later lookup, perhaps during the invocation of a
629 * bootstrap method, can incorporate the specific identity
630 * of the caller, making the method accessible.
631 * <p style="font-size:smaller;">
632 * The function {@code MethodHandles.lookup} is caller sensitive
633 * so that there can be a secure foundation for lookups.
634 * Nearly all other methods in the JSR 292 API rely on lookup
635 * objects to check access requests.
636 *
637 * @revised 9
638 */
639 public static final
640 class Lookup {
641 /** The class on behalf of whom the lookup is being performed. */
642 private final Class<?> lookupClass;
643
644 /** The allowed sorts of members which may be looked up (PUBLIC, etc.). */
645 private final int allowedModes;
646
647 static {
648 Reflection.registerFieldsToFilter(Lookup.class, Set.of("lookupClass", "allowedModes"));
649 }
650
651 /** A single-bit mask representing {@code public} access,
652 * which may contribute to the result of {@link #lookupModes lookupModes}.
653 * The value, {@code 0x01}, happens to be the same as the value of the
654 * {@code public} {@linkplain java.lang.reflect.Modifier#PUBLIC modifier bit}.
655 */
656 public static final int PUBLIC = Modifier.PUBLIC;
657
658 /** A single-bit mask representing {@code private} access,
659 * which may contribute to the result of {@link #lookupModes lookupModes}.
660 * The value, {@code 0x02}, happens to be the same as the value of the
661 * {@code private} {@linkplain java.lang.reflect.Modifier#PRIVATE modifier bit}.
662 */
663 public static final int PRIVATE = Modifier.PRIVATE;
664
665 /** A single-bit mask representing {@code protected} access,
666 * which may contribute to the result of {@link #lookupModes lookupModes}.
667 * The value, {@code 0x04}, happens to be the same as the value of the
668 * {@code protected} {@linkplain java.lang.reflect.Modifier#PROTECTED modifier bit}.
669 */
670 public static final int PROTECTED = Modifier.PROTECTED;
|