< prev index next >

src/java.base/share/classes/jdk/internal/reflect/Reflection.java

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com


  34 import jdk.internal.misc.VM;
  35 
  36 /** Common utility routines used by both java.lang and
  37     java.lang.reflect */
  38 
  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




  34 import jdk.internal.misc.VM;
  35 
  36 /** Common utility routines used by both java.lang and
  37     java.lang.reflect */
  38 
  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", "classData"),
  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


< prev index next >