7
7
import org .jboss .jandex .ClassInfo ;
8
8
import org .jboss .jandex .DotName ;
9
9
10
- import io .quarkus .caffeine .runtime .graal .CacheConstructorsFeature ;
11
10
import io .quarkus .deployment .annotations .BuildProducer ;
12
11
import io .quarkus .deployment .annotations .BuildStep ;
13
12
import io .quarkus .deployment .builditem .CombinedIndexBuildItem ;
14
- import io .quarkus .deployment .builditem .NativeImageFeatureBuildItem ;
15
13
import io .quarkus .deployment .builditem .nativeimage .ReflectiveClassBuildItem ;
14
+ import io .quarkus .deployment .metrics .MetricsCapabilityBuildItem ;
16
15
import io .quarkus .deployment .pkg .steps .NativeOrNativeSourcesBuild ;
16
+ import io .quarkus .runtime .metrics .MetricsFactory ;
17
17
18
18
public class CaffeineProcessor {
19
19
@@ -26,6 +26,45 @@ public class CaffeineProcessor {
26
26
27
27
private static final DotName CACHE_LOADER_NAME = DotName .createSimple (CACHE_LOADER_CLASS_NAME );
28
28
29
+ /**
30
+ * this list is not complete, but a selection of the types we expect being most useful.
31
+ * unfortunately registering all of them has been shown to have a very significant impact
32
+ * on executable sizes. See https://github.com/quarkusio/quarkus/issues/12961
33
+ */
34
+ private static final String [] DEFAULT_CACHE_IMPLEMENTATIONS_TO_REGISTER_FOR_REFLECTION = {
35
+ "com.github.benmanes.caffeine.cache.PDMS" ,
36
+ "com.github.benmanes.caffeine.cache.PSA" ,
37
+ "com.github.benmanes.caffeine.cache.PSMS" ,
38
+ "com.github.benmanes.caffeine.cache.PSW" ,
39
+ "com.github.benmanes.caffeine.cache.PSMW" ,
40
+ "com.github.benmanes.caffeine.cache.PSWMS" ,
41
+ "com.github.benmanes.caffeine.cache.PSWMW" ,
42
+ "com.github.benmanes.caffeine.cache.SILMS" ,
43
+ "com.github.benmanes.caffeine.cache.SSA" ,
44
+ "com.github.benmanes.caffeine.cache.SSLA" ,
45
+ "com.github.benmanes.caffeine.cache.SSLMS" ,
46
+ "com.github.benmanes.caffeine.cache.SSMS" ,
47
+ "com.github.benmanes.caffeine.cache.SSMSA" ,
48
+ "com.github.benmanes.caffeine.cache.SSMSW" ,
49
+ "com.github.benmanes.caffeine.cache.SSW"
50
+ };
51
+
52
+ /**
53
+ * When the Micrometer extension is around, we add the cache classes with metrics.
54
+ * <p>
55
+ * Note that we don't know if they will actually be used given the cache configuration is defined at runtime.
56
+ */
57
+ private static final String [] METRICS_CACHE_IMPLEMENTATIONS_TO_REGISTER_FOR_REFLECTION = {
58
+ "com.github.benmanes.caffeine.cache.SILSMS" ,
59
+ "com.github.benmanes.caffeine.cache.SSSA" ,
60
+ "com.github.benmanes.caffeine.cache.SSLSA" ,
61
+ "com.github.benmanes.caffeine.cache.SSLSMS" ,
62
+ "com.github.benmanes.caffeine.cache.SSSMS" ,
63
+ "com.github.benmanes.caffeine.cache.SSSMSA" ,
64
+ "com.github.benmanes.caffeine.cache.SSSMSW" ,
65
+ "com.github.benmanes.caffeine.cache.SSSW"
66
+ };
67
+
29
68
@ BuildStep
30
69
void cacheLoaders (CombinedIndexBuildItem combinedIndex , BuildProducer <ReflectiveClassBuildItem > reflectiveClasses ) {
31
70
final Collection <ClassInfo > implementors = combinedIndex .getIndex ().getAllKnownImplementors (CACHE_LOADER_NAME );
@@ -46,7 +85,14 @@ void cacheLoaders(CombinedIndexBuildItem combinedIndex, BuildProducer<Reflective
46
85
}
47
86
48
87
@ BuildStep (onlyIf = NativeOrNativeSourcesBuild .class )
49
- NativeImageFeatureBuildItem nativeImageFeature () {
50
- return new NativeImageFeatureBuildItem (CacheConstructorsFeature .class );
88
+ void reflection (MetricsCapabilityBuildItem metricsCapability , BuildProducer <ReflectiveClassBuildItem > reflectiveClasses ) {
89
+ reflectiveClasses
90
+ .produce (new ReflectiveClassBuildItem (false , false , DEFAULT_CACHE_IMPLEMENTATIONS_TO_REGISTER_FOR_REFLECTION ));
91
+
92
+ if (metricsCapability .metricsSupported (MetricsFactory .MICROMETER )) {
93
+ reflectiveClasses
94
+ .produce (new ReflectiveClassBuildItem (false , false ,
95
+ METRICS_CACHE_IMPLEMENTATIONS_TO_REGISTER_FOR_REFLECTION ));
96
+ }
51
97
}
52
98
}
0 commit comments