4040 */
4141package org .graalvm .nativeimage .dynamicaccess ;
4242
43- import org .graalvm .nativeimage .hosted .Feature ;
44-
4543import java .lang .reflect .Executable ;
4644import java .lang .reflect .Field ;
4745
46+ import org .graalvm .nativeimage .hosted .Feature ;
47+
4848/**
4949 * This interface is used to register classes, methods, and fields for use with the
50- * {@link java.lang.reflect} API at runtime , and for serialization at runtime . An instance of this
50+ * {@link java.lang.reflect} API at run time , and for serialization at run time . An instance of this
5151 * interface is acquired via {@link Feature.AfterRegistrationAccess#getReflectiveAccess()}.
5252 * <p>
5353 * All methods in {@link ReflectiveAccess} require a {@link AccessCondition} as their first
54- * parameter. A class and its members will be registered for dynamic access only if the specified
55- * condition is satisfied.
54+ * parameter. A class and its members will be accessible at run-time only if the specified condition
55+ * is satisfied.
5656 *
5757 * <h3>How to use</h3>
5858 *
59- * {@link ReflectiveAccess} should only be used during {@link Feature#afterRegistration}. Any
60- * attempt to register metadata in any other phase will result in an error.
59+ * {@link ReflectiveAccess} should only be used during {@link Feature#afterRegistration}. Attempts
60+ * to register metadata in any other phase of the {@link Feature} API will result in an error.
6161 * <p>
6262 * <strong>Example:</strong>
6363 *
6464 * <pre>{@code @Override
6565 * public void afterRegistration(AfterRegistrationAccess access) {
6666 * ReflectionAccess reflection = access.getReflectionAccess();
67+ *
6768 * AccessCondition condition = AccessCondition.typeReached(ConditionType.class);
6869 * reflection.register(condition, Foo.class, Bar.class);
70+ *
6971 * reflection.register(AccessCondition.unconditional(), Foo.class.getMethod("method"));
72+ *
7073 * reflection.registerUnsafeAllocation(condition, Foo.class);
74+ *
7175 * Class<?> proxyClass = reflection.registerProxy(condition, Interface1.class, Interface2.class);
7276 * reflection.registerForSerialization(AccessCondition.unconditional(), proxyClass);
7377 * }
7882public interface ReflectiveAccess {
7983
8084 /**
81- * Registers the provided classes for reflection at runtime , if the {@code condition} is
82- * satisfied. This means all reflection methods defined by the {@link java.lang.Class} are
83- * accessible at runtime for those classes.
85+ * Registers the provided classes for reflection at run time , if the {@code condition} is
86+ * satisfied. This means all reflection methods defined by the {@link java.lang.Class} (except
87+ * {@link Class#arrayType()}) are accessible at run time for those classes.
8488 * <p>
85- * If a class is not registered for reflection at runtime, {@link Class#forName} will throw
86- * {@link ClassNotFoundException}.
89+ * If a class is not registered for reflection at run time, the following methods will throw
90+ * {@link ClassNotFoundException}:
91+ * <ul>
92+ * <li>{@link Class#forName(String)}</li>
93+ * <li>{@link Class#forName(Module, String)}</li>
94+ * <li>{@link Class#forName(String, boolean, ClassLoader)}</li>
95+ * <li>{@link ClassLoader#loadClass(String)}</li>
96+ * </ul>
8797 *
8898 * @since 25.0
8999 */
90100 void register (AccessCondition condition , Class <?>... classes );
91101
92102 /**
93- * Registers a class with the provided {@code className} for reflection at runtime , if the
103+ * Registers a class with the provided {@code className} for reflection at run time , if the
94104 * {@code condition} is satisfied. This method should be used when
95105 * {@code --exact-reachability-metadata} is set: it makes calls to
96106 * {@code Class.forName(className)} throw {@link ClassNotFoundException} instead of throwing
@@ -103,29 +113,20 @@ public interface ReflectiveAccess {
103113 void registerClassLookup (AccessCondition condition , String className );
104114
105115 /**
106- * Registers the provided {@code classes} for unsafe allocation at runtime, if the
107- * {@code condition} is satisfied. Unsafe allocation can happen via
108- * {@link sun.misc.Unsafe#allocateInstance(Class)} or from native code via
109- * {@code AllocObject(jClass)}.
110- *
111- * @since 25.0
112- */
113- void registerUnsafeAllocation (AccessCondition condition , Class <?>... classes );
114-
115- /**
116- * Registers the provided {@code methods} for reflective invocation at runtime, if the
117- * {@code condition} is satisfied. This method also registers the declaring classes of the
118- * provided methods for reflection at runtime. The methods will be invocable at runtime via
116+ * Registers the provided {@code executables} (methods and constructors) for reflective
117+ * invocation at run time, if the {@code condition} is satisfied. This method also registers the
118+ * declaring classes of the provided executables for reflection at run time. The executables
119+ * will be invocable at run time via
119120 * {@link java.lang.reflect.Method#invoke(java.lang.Object, java.lang.Object...)}.
120121 *
121122 * @since 25.0
122123 */
123- void register (AccessCondition condition , Executable ... methods );
124+ void register (AccessCondition condition , Executable ... executables );
124125
125126 /**
126- * Registers the provided {@code fields} for reflective access at runtime , if the
127+ * Registers the provided {@code fields} for reflective access at run time , if the
127128 * {@code condition} is satisfied. This method also registers the declaring classes of the
128- * provided fields for reflection at runtime . The fields will be accessible at runtime via
129+ * provided fields for reflection at run time . The fields will be accessible at run time via
129130 * {@link java.lang.reflect.Field#set(java.lang.Object, java.lang.Object)} and
130131 * {@link java.lang.reflect.Field#get(Object)}.
131132 *
@@ -134,8 +135,8 @@ public interface ReflectiveAccess {
134135 void register (AccessCondition condition , Field ... fields );
135136
136137 /**
137- * Registers the provided classes for serialization at runtime , if the {@code condition} is
138- * satisfied. This method also registers the provided classes for reflection at runtime .
138+ * Registers the provided classes for serialization at run time , if the {@code condition} is
139+ * satisfied. This method also registers the provided classes for reflection at run time .
139140 *
140141 * @since 25.0
141142 */
@@ -145,13 +146,14 @@ public interface ReflectiveAccess {
145146 * Registers a {@link java.lang.reflect.Proxy} class in the system classloader that implements
146147 * the specified {@code interfaces}, if the {@code condition} is satisfied. The proxy class is
147148 * fully specified by the interfaces it implements, and proxy instances matching that
148- * specification can be created at runtime. The returned proxy class can be used in registration
149- * for reflection and serialization at runtime. <blockquote> <strong>NOTE</strong>: The order of
150- * the interfaces provided in the {@code interfaces} parameter is significant; different
151- * orderings will produce distinct proxy classes. </blockquote>
149+ * specification can be created at run time. The returned proxy class can be used in
150+ * registration for reflection and serialization at run time. <blockquote>
151+ * <strong>NOTE</strong>: The order of the interfaces provided in the {@code interfaces}
152+ * parameter is significant; different orderings will produce distinct proxy classes.
153+ * </blockquote>
152154 * <p>
153155 * <strong>Example</strong>:
154- *
156+ *
155157 * <pre>{@code
156158 * Class<?> proxyClass = reflection.registerProxy(AccessCondition.unconditional(), Interface1.class, Interface2.class);
157159 * reflection.register(AccessCondition.unconditional(), proxyClass);
@@ -164,4 +166,14 @@ public interface ReflectiveAccess {
164166 * @since 25.0
165167 */
166168 Class <?> registerProxy (AccessCondition condition , Class <?>... interfaces );
169+
170+ /**
171+ * Registers the provided {@code classes} for unsafe allocation at run time, if the
172+ * {@code condition} is satisfied. Unsafe allocation can happen via
173+ * {@link sun.misc.Unsafe#allocateInstance(Class)} or from native code via
174+ * {@code AllocObject(jClass)}.
175+ *
176+ * @since 25.0
177+ */
178+ void registerForUnsafeAllocation (AccessCondition condition , Class <?>... classes );
167179}
0 commit comments