|
35 | 35 | import java.util.List;
|
36 | 36 | import java.util.Map;
|
37 | 37 | import java.util.function.Predicate;
|
38 |
| -import java.util.function.Supplier; |
39 | 38 |
|
40 | 39 | import org.graalvm.nativeimage.AnnotationAccess;
|
41 | 40 | import org.graalvm.nativeimage.ImageSingletons;
|
@@ -189,35 +188,12 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
|
189 | 188 | *
|
190 | 189 | * These caches can contribute ~1MB to the image size, clearing them avoids this overhead at
|
191 | 190 | * the cost of having to recreate the Locale and BaseLocale objects once when they're
|
192 |
| - * requested. |
193 |
| - * |
194 |
| - * On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist. We have to go through |
195 |
| - * reflection to access them because analysis tools like spotbugs still run on JDK21 |
| 191 | + * requested at run-time. |
196 | 192 | */
|
197 |
| - Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE"); |
198 |
| - Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE"); |
199 |
| - |
200 |
| - access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> { |
201 |
| - /* |
202 |
| - * Executes `ReferencedKeySet.create(true, |
203 |
| - * ReferencedKeySet.concurrentHashMapSupplier())` with reflection. |
204 |
| - */ |
205 |
| - Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet"); |
206 |
| - Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class); |
207 |
| - Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier"); |
208 |
| - return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); |
209 |
| - }); |
210 |
| - |
211 |
| - access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> { |
212 |
| - /* |
213 |
| - * Executes `ReferencedKeyMap.create(true, |
214 |
| - * ReferencedKeyMap.concurrentHashMapSupplier())` with reflection. |
215 |
| - */ |
216 |
| - Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap"); |
217 |
| - Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class); |
218 |
| - Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier"); |
219 |
| - return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); |
220 |
| - }); |
| 193 | + Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale", "CACHE"); |
| 194 | + Field localeCacheField = accessImpl.findField("java.util.Locale", "LOCALE_CACHE"); |
| 195 | + access.registerFieldValueTransformer(baseLocaleCacheField, new ResetStableSupplierTransformer()); |
| 196 | + access.registerFieldValueTransformer(localeCacheField, new ResetStableSupplierTransformer()); |
221 | 197 | }
|
222 | 198 |
|
223 | 199 | @Override
|
@@ -341,4 +317,5 @@ private boolean neverInlineTrivial(@SuppressWarnings("unused") AnalysisMethod ca
|
341 | 317 | */
|
342 | 318 | return AnnotationAccess.isAnnotationPresent(callee, JS.class);
|
343 | 319 | }
|
| 320 | + |
344 | 321 | }
|
0 commit comments