39 public class Reflection {
40
41 /** Used to filter out fields and methods from certain classes from public
42 view, where they are sensitive or they may contain VM-internal objects.
43 These Maps are updated very rarely. Rather than synchronize on
44 each access, we use copy-on-write */
45 private static volatile Map<Class<?>, Set<String>> fieldFilterMap;
46 private static volatile Map<Class<?>, Set<String>> methodFilterMap;
47 private static final String WILDCARD = "*";
48 public static final Set<String> ALL_MEMBERS = Set.of(WILDCARD);
49
50 static {
51 fieldFilterMap = Map.of(
52 Reflection.class, ALL_MEMBERS,
53 AccessibleObject.class, ALL_MEMBERS,
54 Class.class, Set.of("classLoader"),
55 ClassLoader.class, ALL_MEMBERS,
56 Constructor.class, ALL_MEMBERS,
57 Field.class, ALL_MEMBERS,
58 Method.class, ALL_MEMBERS,
59 System.class, Set.of("security")
60 );
61 methodFilterMap = Map.of();
62 }
63
64 /** Returns the class of the caller of the method calling this method,
65 ignoring frames associated with java.lang.reflect.Method.invoke()
66 and its implementation. */
67 @CallerSensitive
68 @HotSpotIntrinsicCandidate
69 public static native Class<?> getCallerClass();
70
71 /** Retrieves the access flags written to the class file. For
72 inner classes these flags may differ from those returned by
73 Class.getModifiers(), which searches the InnerClasses
74 attribute to find the source-level access flags. This is used
75 instead of Class.getModifiers() for run-time access checks due
76 to compatibility reasons; see 4471811. Only the values of the
77 low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
78 valid. */
|
39 public class Reflection {
40
41 /** Used to filter out fields and methods from certain classes from public
42 view, where they are sensitive or they may contain VM-internal objects.
43 These Maps are updated very rarely. Rather than synchronize on
44 each access, we use copy-on-write */
45 private static volatile Map<Class<?>, Set<String>> fieldFilterMap;
46 private static volatile Map<Class<?>, Set<String>> methodFilterMap;
47 private static final String WILDCARD = "*";
48 public static final Set<String> ALL_MEMBERS = Set.of(WILDCARD);
49
50 static {
51 fieldFilterMap = Map.of(
52 Reflection.class, ALL_MEMBERS,
53 AccessibleObject.class, ALL_MEMBERS,
54 Class.class, Set.of("classLoader"),
55 ClassLoader.class, ALL_MEMBERS,
56 Constructor.class, ALL_MEMBERS,
57 Field.class, ALL_MEMBERS,
58 Method.class, ALL_MEMBERS,
59 Module.class, ALL_MEMBERS,
60 System.class, Set.of("security")
61 );
62 methodFilterMap = Map.of();
63 }
64
65 /** Returns the class of the caller of the method calling this method,
66 ignoring frames associated with java.lang.reflect.Method.invoke()
67 and its implementation. */
68 @CallerSensitive
69 @HotSpotIntrinsicCandidate
70 public static native Class<?> getCallerClass();
71
72 /** Retrieves the access flags written to the class file. For
73 inner classes these flags may differ from those returned by
74 Class.getModifiers(), which searches the InnerClasses
75 attribute to find the source-level access flags. This is used
76 instead of Class.getModifiers() for run-time access checks due
77 to compatibility reasons; see 4471811. Only the values of the
78 low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
79 valid. */
|