4141import org .graalvm .nativeimage .Platforms ;
4242import org .graalvm .word .Pointer ;
4343
44+ import com .oracle .svm .configure .config .ConfigurationMemberInfo ;
45+ import com .oracle .svm .configure .config .ConfigurationType ;
4446import com .oracle .svm .core .SubstrateOptions ;
4547import com .oracle .svm .core .Uninterruptible ;
4648import com .oracle .svm .core .heap .Heap ;
5254import com .oracle .svm .core .layeredimagesingleton .MultiLayeredImageSingleton ;
5355import com .oracle .svm .core .layeredimagesingleton .UnsavedSingleton ;
5456import com .oracle .svm .core .log .Log ;
57+ import com .oracle .svm .core .metadata .MetadataTracer ;
5558import com .oracle .svm .core .snippets .KnownIntrinsics ;
5659import com .oracle .svm .core .util .ImageHeapMap ;
5760import com .oracle .svm .core .util .Utf8 .WrappedAsciiCString ;
@@ -185,6 +188,9 @@ public Iterable<JNIAccessibleClass> getClasses() {
185188 public static Class <?> getClassObjectByName (CharSequence name ) {
186189 for (var dictionary : layeredSingletons ()) {
187190 JNIAccessibleClass clazz = dictionary .classesByName .get (name );
191+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && clazz != null && MetadataTracer .singleton ().enabled ()) {
192+ MetadataTracer .singleton ().traceJNIType (convertFindClassNameToBinaryName (name .toString ()));
193+ }
188194 clazz = checkClass (clazz , name );
189195 if (clazz != null ) {
190196 return clazz .getClassObject ();
@@ -194,6 +200,16 @@ public static Class<?> getClassObjectByName(CharSequence name) {
194200 return null ;
195201 }
196202
203+ /**
204+ * FindClass's argument is either an internal class name (e.g., {@code pkg/sub/Class}) or an
205+ * array type signature (e.g., {@code [Lpkg/sub/Class;}). Converts the argument to a regular
206+ * binary name (e.g., {@code pkg.sub.Class}.
207+ */
208+ private static String convertFindClassNameToBinaryName (String name ) {
209+ String internalName = (name .charAt (0 ) != '[' ) ? ('L' + name + ';' ) : name ;
210+ return MetaUtil .internalNameToJava (internalName , true , true );
211+ }
212+
197213 private static JNIAccessibleClass checkClass (JNIAccessibleClass clazz , CharSequence name ) {
198214 if (throwMissingRegistrationErrors () && clazz == null ) {
199215 MissingJNIRegistrationUtils .forClass (name .toString ());
@@ -277,6 +293,10 @@ private static JNIAccessibleMethod getDeclaredMethod(Class<?> classObject, JNIAc
277293 foundClass = true ;
278294 JNIAccessibleMethod method = clazz .getMethod (descriptor );
279295 if (method != null ) {
296+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
297+ ConfigurationType clazzType = MetadataTracer .singleton ().traceJNIType (classObject .getName ());
298+ clazzType .addMethod (descriptor .getNameConvertToString (), descriptor .getSignatureConvertToString (), ConfigurationMemberInfo .ConfigurationMemberDeclaration .DECLARED );
299+ }
280300 return method ;
281301 }
282302 }
@@ -332,6 +352,10 @@ private static JNIAccessibleField getDeclaredField(Class<?> classObject, CharSeq
332352 foundClass = true ;
333353 JNIAccessibleField field = clazz .getField (name );
334354 if (field != null && (field .isStatic () == isStatic || field .isNegative ())) {
355+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
356+ ConfigurationType clazzType = MetadataTracer .singleton ().traceJNIType (classObject .getName ());
357+ clazzType .addField (name .toString (), ConfigurationMemberInfo .ConfigurationMemberDeclaration .DECLARED , false );
358+ }
335359 return field ;
336360 }
337361 }
0 commit comments