54
54
import org .graalvm .nativeimage .Platforms ;
55
55
import org .graalvm .nativeimage .impl .ConfigurationCondition ;
56
56
57
+ import com .oracle .svm .core .AlwaysInline ;
57
58
import com .oracle .svm .core .BuildPhaseProvider ;
58
59
import com .oracle .svm .core .ClassLoaderSupport .ConditionWithOrigin ;
59
60
import com .oracle .svm .core .MissingRegistrationUtils ;
@@ -437,6 +438,10 @@ public static ResourceStorageEntryBase getAtRuntime(String name) {
437
438
* The {@code probe} parameter indicates whether the caller is probing for the existence of a
438
439
* resource. If {@code probe} is true, failed resource lookups return will not throw missing
439
440
* registration errors and may instead return {@link #MISSING_METADATA_MARKER}.
441
+ * <p>
442
+ * Tracing note: When this method is used for probing, only successful metadata matches will be
443
+ * traced. If a probing result is {@link #MISSING_METADATA_MARKER}, the caller must explicitly
444
+ * trace the missing metadata.
440
445
*/
441
446
public static ResourceStorageEntryBase getAtRuntime (Module module , String resourceName , boolean probe ) {
442
447
VMError .guarantee (ImageInfo .inImageRuntimeCode (), "This function should be used only at runtime." );
@@ -448,16 +453,20 @@ public static ResourceStorageEntryBase getAtRuntime(Module module, String resour
448
453
if (missingResourceMatchesIncludePattern (resourceName , moduleName ) || missingResourceMatchesIncludePattern (canonicalResourceName , moduleName )) {
449
454
// This resource name matches a pattern/glob from the provided metadata, but no
450
455
// resource with the name actually exists. Do not report missing metadata.
456
+ traceResource (resourceName , moduleName );
451
457
return null ;
452
458
}
459
+ traceResourceMissingMetadata (resourceName , moduleName , probe );
453
460
return missingMetadata (module , resourceName , probe );
454
461
} else {
462
+ // NB: Without exact reachability metadata, resource include patterns are not
463
+ // stored in the image heap, so we cannot reliably identify if the resource was
464
+ // included at build time. Assume it is missing.
465
+ traceResourceMissingMetadata (resourceName , moduleName , probe );
455
466
return null ;
456
467
}
457
468
}
458
- if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
459
- MetadataTracer .singleton ().traceResource (resourceName , moduleName );
460
- }
469
+ traceResource (resourceName , moduleName );
461
470
if (!entry .getConditions ().satisfied ()) {
462
471
return missingMetadata (module , resourceName , probe );
463
472
}
@@ -487,6 +496,28 @@ public static ResourceStorageEntryBase getAtRuntime(Module module, String resour
487
496
return unconditionalEntry ;
488
497
}
489
498
499
+ @ AlwaysInline ("tracing should fold away when disabled" )
500
+ private static void traceResource (String resourceName , String moduleName ) {
501
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
502
+ MetadataTracer .singleton ().traceResource (resourceName , moduleName );
503
+ }
504
+ }
505
+
506
+ @ AlwaysInline ("tracing should fold away when disabled" )
507
+ private static void traceResourceMissingMetadata (String resourceName , String moduleName ) {
508
+ traceResourceMissingMetadata (resourceName , moduleName , false );
509
+ }
510
+
511
+ @ AlwaysInline ("tracing should fold away when disabled" )
512
+ private static void traceResourceMissingMetadata (String resourceName , String moduleName , boolean probe ) {
513
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled () && !probe ) {
514
+ // Do not trace missing metadata for probing queries, otherwise we'll trace an entry for
515
+ // every module. The caller is responsible for tracing missing entries if it uses
516
+ // probing.
517
+ MetadataTracer .singleton ().traceResource (resourceName , moduleName );
518
+ }
519
+ }
520
+
490
521
/**
491
522
* Checks whether the given missing resource is matched by a pattern/glob registered at build
492
523
* time. In such a case, we should not report missing metadata.
@@ -558,6 +589,7 @@ public static InputStream createInputStream(Module module, String resourceName)
558
589
}
559
590
ResourceStorageEntryBase entry = findResourceForInputStream (module , resourceName );
560
591
if (entry == MISSING_METADATA_MARKER ) {
592
+ traceResourceMissingMetadata (resourceName , moduleName (module ));
561
593
MissingResourceRegistrationUtils .reportResourceAccess (module , resourceName );
562
594
return null ;
563
595
} else if (entry == null ) {
0 commit comments