28
28
import java .nio .file .Files ;
29
29
import java .nio .file .Path ;
30
30
import java .nio .file .Paths ;
31
+ import java .util .Arrays ;
31
32
import java .util .HashMap ;
32
33
import java .util .LinkedHashSet ;
33
34
import java .util .List ;
@@ -173,50 +174,70 @@ private ConfigurationSet getConfigurationSetForTracing() {
173
174
}
174
175
175
176
/**
176
- * Marks the given type as reachable from reflection.
177
+ * Marks the type with the given name as reachable from reflection.
177
178
*/
178
179
public void traceReflectionType (String typeName ) {
179
- traceReflectionTypeImpl (typeName );
180
+ traceReflectionTypeImpl (new NamedConfigurationTypeDescriptor (typeName ));
181
+ }
182
+
183
+ /**
184
+ * Marks the given type as reachable from reflection.
185
+ */
186
+ public void traceReflectionType (Class <?> clazz ) {
187
+ traceReflectionTypeImpl (ConfigurationTypeDescriptor .fromClass (clazz ));
188
+ }
189
+
190
+ public void traceReflectionArrayType (Class <?> componentClazz ) {
191
+ ConfigurationTypeDescriptor typeDescriptor = ConfigurationTypeDescriptor .fromClass (componentClazz );
192
+ if (typeDescriptor instanceof NamedConfigurationTypeDescriptor (String name )) {
193
+ traceReflectionType (name + "[]" );
194
+ } else {
195
+ debug ("array type not registered for reflection (component type is not a named type)" , typeDescriptor );
196
+ }
180
197
}
181
198
182
199
/**
183
200
* Marks the given field as reachable from reflection.
184
201
*/
185
- public void traceField (String typeName , String fieldName , ConfigurationMemberInfo .ConfigurationMemberDeclaration declaration ) {
186
- ConfigurationType type = traceReflectionTypeImpl (typeName );
202
+ public void traceField (Class <?> declaringClass , String fieldName , ConfigurationMemberInfo .ConfigurationMemberDeclaration declaration ) {
203
+ ConfigurationTypeDescriptor typeDescriptor = ConfigurationTypeDescriptor .fromClass (declaringClass );
204
+ ConfigurationType type = traceReflectionTypeImpl (typeDescriptor );
187
205
if (type != null ) {
188
- debugField (typeName , fieldName );
206
+ debugField (typeDescriptor , fieldName );
189
207
type .addField (fieldName , declaration , false );
190
208
}
191
209
}
192
210
193
211
/**
194
212
* Marks the given method as reachable from reflection.
195
213
*/
196
- public void traceMethod (String typeName , String methodName , String internalSignature , ConfigurationMemberInfo .ConfigurationMemberDeclaration declaration ,
214
+ public void traceMethod (Class <?> declaringClass , String methodName , String internalSignature , ConfigurationMemberInfo .ConfigurationMemberDeclaration declaration ,
197
215
ConfigurationMemberInfo .ConfigurationMemberAccessibility accessibility ) {
198
- ConfigurationType type = traceReflectionTypeImpl (typeName );
216
+ ConfigurationTypeDescriptor typeDescriptor = ConfigurationTypeDescriptor .fromClass (declaringClass );
217
+ ConfigurationType type = traceReflectionTypeImpl (typeDescriptor );
199
218
if (type != null ) {
200
- debugMethod (typeName , methodName , internalSignature , accessibility );
219
+ debugMethod (typeDescriptor , methodName , internalSignature , accessibility );
201
220
type .addMethod (methodName , internalSignature , declaration , accessibility );
202
221
}
203
222
}
204
223
205
224
/**
206
225
* Marks the given type as unsafely allocated.
207
226
*/
208
- public void traceUnsafeAllocatedType (String typeName ) {
209
- ConfigurationType type = traceReflectionTypeImpl (typeName );
227
+ public void traceUnsafeAllocatedType (Class <?> clazz ) {
228
+ ConfigurationTypeDescriptor typeDescriptor = ConfigurationTypeDescriptor .fromClass (clazz );
229
+ ConfigurationType type = traceReflectionTypeImpl (typeDescriptor );
210
230
if (type != null ) {
211
- debug ("type marked as unsafely allocated" , typeName );
231
+ debug ("type marked as unsafely allocated" , clazz . getTypeName () );
212
232
type .setUnsafeAllocated ();
213
233
}
214
234
}
215
235
216
236
/**
217
237
* Marks the given proxy type as reachable from reflection.
218
238
*/
219
- public void traceProxyType (List <String > interfaceNames ) {
239
+ public void traceProxyType (Class <?>[] interfaces ) {
240
+ List <String > interfaceNames = Arrays .stream (interfaces ).map (Class ::getTypeName ).toList ();
220
241
ProxyConfigurationTypeDescriptor descriptor = new ProxyConfigurationTypeDescriptor (interfaceNames );
221
242
for (String interfaceName : interfaceNames ) {
222
243
if (isInternal (interfaceName )) {
@@ -233,15 +254,11 @@ public void traceProxyType(List<String> interfaceNames) {
233
254
* not want to expose ConfigurationTypes to the caller, because they could perform further
234
255
* registration (e.g., of methods) which would not be traced by debug logging.
235
256
*/
236
- public ConfigurationType traceReflectionTypeImpl (String typeName ) {
237
- if (isInternal (typeName )) {
257
+ public ConfigurationType traceReflectionTypeImpl (ConfigurationTypeDescriptor typeDescriptor ) {
258
+ assert enabledAtRunTime ();
259
+ if (isInternal (typeDescriptor )) {
238
260
return null ;
239
261
}
240
- return traceReflectionTypeImpl (new NamedConfigurationTypeDescriptor (typeName ));
241
- }
242
-
243
- private ConfigurationType traceReflectionTypeImpl (ConfigurationTypeDescriptor typeDescriptor ) {
244
- assert enabledAtRunTime ();
245
262
ConfigurationSet configurationSet = getConfigurationSetForTracing ();
246
263
if (configurationSet != null ) {
247
264
debugReflectionType (typeDescriptor , configurationSet );
@@ -250,18 +267,36 @@ private ConfigurationType traceReflectionTypeImpl(ConfigurationTypeDescriptor ty
250
267
return null ;
251
268
}
252
269
270
+ private static boolean isInternal (ConfigurationTypeDescriptor typeDescriptor ) {
271
+ if (typeDescriptor instanceof NamedConfigurationTypeDescriptor (String name )) {
272
+ return isInternal (name );
273
+ }
274
+ return false ;
275
+ }
276
+
253
277
private static boolean isInternal (String typeName ) {
254
278
return typeName .startsWith ("com.oracle.svm.core" );
255
279
}
256
280
257
281
/**
258
- * Marks the given type as reachable from JNI.
282
+ * Marks the type with the given name as reachable from JNI.
259
283
*/
260
284
public void traceJNIType (String typeName ) {
285
+ traceJNITypeImpl (new NamedConfigurationTypeDescriptor (typeName ));
286
+ }
287
+
288
+ /**
289
+ * Marks the given type as reachable from JNI.
290
+ */
291
+ public void traceJNIType (Class <?> clazz ) {
292
+ traceJNITypeImpl (ConfigurationTypeDescriptor .fromClass (clazz ));
293
+ }
294
+
295
+ private void traceJNITypeImpl (ConfigurationTypeDescriptor typeDescriptor ) {
261
296
assert enabledAtRunTime ();
262
- ConfigurationType type = traceReflectionTypeImpl (typeName );
297
+ ConfigurationType type = traceReflectionTypeImpl (typeDescriptor );
263
298
if (type != null && !type .isJniAccessible ()) {
264
- debug ("type registered for jni" , typeName );
299
+ debug ("type registered for jni" , typeDescriptor );
265
300
type .setJniAccessible ();
266
301
}
267
302
}
@@ -294,11 +329,12 @@ public void traceResourceBundle(String baseName) {
294
329
/**
295
330
* Marks the given type as serializable.
296
331
*/
297
- public void traceSerializationType (String typeName ) {
332
+ public void traceSerializationType (Class <?> clazz ) {
298
333
assert enabledAtRunTime ();
299
- ConfigurationType result = traceReflectionTypeImpl (typeName );
334
+ ConfigurationTypeDescriptor typeDescriptor = ConfigurationTypeDescriptor .fromClass (clazz );
335
+ ConfigurationType result = traceReflectionTypeImpl (typeDescriptor );
300
336
if (result != null && !result .isSerializable ()) {
301
- debug ("type registered for serialization" , typeName );
337
+ debug ("type registered for serialization" , typeDescriptor );
302
338
result .setSerializable ();
303
339
}
304
340
}
@@ -359,21 +395,21 @@ private void debugReflectionType(ConfigurationTypeDescriptor typeDescriptor, Con
359
395
/**
360
396
* Debug helper for fields. Avoids field name computations if debug logging is disabled.
361
397
*/
362
- private void debugField (String typeName , String fieldName ) {
398
+ private void debugField (ConfigurationTypeDescriptor typeDescriptor , String fieldName ) {
363
399
if (debugWriter == null ) {
364
400
return ;
365
401
}
366
- debug ("field registered for reflection" , typeName + "." + fieldName );
402
+ debug ("field registered for reflection" , typeDescriptor + "." + fieldName );
367
403
}
368
404
369
405
/**
370
406
* Debug helper for methods. Avoids method name computations if debug logging is disabled.
371
407
*/
372
- private void debugMethod (String typeName , String methodName , String internalSignature , ConfigurationMemberInfo .ConfigurationMemberAccessibility accessibility ) {
408
+ private void debugMethod (ConfigurationTypeDescriptor typeDescriptor , String methodName , String internalSignature , ConfigurationMemberInfo .ConfigurationMemberAccessibility accessibility ) {
373
409
if (debugWriter == null ) {
374
410
return ;
375
411
}
376
- debug ("method registered for reflection (" + accessibility .name ().toLowerCase () + ")" , typeName + "." + methodName + internalSignature );
412
+ debug ("method registered for reflection (" + accessibility .name ().toLowerCase () + ")" , typeDescriptor + "." + methodName + internalSignature );
377
413
}
378
414
379
415
/**
0 commit comments