|
113 | 113 | import jdk.graal.compiler.graph.Node;
|
114 | 114 | import jdk.graal.compiler.options.OptionValues;
|
115 | 115 | import jdk.graal.compiler.phases.util.Providers;
|
116 |
| -import jdk.graal.compiler.serviceprovider.JavaVersionUtil; |
117 | 116 | import jdk.vm.ci.meta.ResolvedJavaMethod;
|
118 | 117 |
|
119 | 118 | @AutomaticallyRegisteredFeature
|
@@ -192,45 +191,33 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
|
192 | 191 | * the cost of having to recreate the Locale and BaseLocale objects once when they're
|
193 | 192 | * requested.
|
194 | 193 | *
|
195 |
| - * On JDK21, ReferencedKeySet and ReferencedKeyMap don't exist, so we can't reference them |
196 |
| - * directly and have to go through reflection. |
| 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 |
197 | 196 | */
|
198 |
| - if (JavaVersionUtil.JAVA_SPEC > 21) { |
199 |
| - Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$1InterningCache", "CACHE"); |
200 |
| - Field localeCacheField = accessImpl.findField("java.util.Locale$LocaleCache", "LOCALE_CACHE"); |
201 |
| - |
202 |
| - access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> { |
203 |
| - /* |
204 |
| - * Executes `ReferencedKeySet.create(true, |
205 |
| - * ReferencedKeySet.concurrentHashMapSupplier())` with reflection. |
206 |
| - */ |
207 |
| - Class<?> referencedKeySetClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeySet"); |
208 |
| - Method createMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "create", boolean.class, Supplier.class); |
209 |
| - Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeySetClazz, "concurrentHashMapSupplier"); |
210 |
| - return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); |
211 |
| - }); |
212 |
| - |
213 |
| - access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> { |
214 |
| - /* |
215 |
| - * Executes `ReferencedKeyMap.create(true, |
216 |
| - * ReferencedKeyMap.concurrentHashMapSupplier())` with reflection. |
217 |
| - */ |
218 |
| - Class<?> referencedKeyMapClazz = ReflectionUtil.lookupClass("jdk.internal.util.ReferencedKeyMap"); |
219 |
| - Method createMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "create", boolean.class, Supplier.class); |
220 |
| - Method concurrentHashMapSupplierMethod = ReflectionUtil.lookupMethod(referencedKeyMapClazz, "concurrentHashMapSupplier"); |
221 |
| - return ReflectionUtil.invokeMethod(createMethod, null, true, ReflectionUtil.invokeMethod(concurrentHashMapSupplierMethod, null)); |
222 |
| - }); |
223 |
| - } else { |
| 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) -> { |
224 | 201 | /*
|
225 |
| - * These fields contain an instance of the declaring class (Cache). It has a default |
226 |
| - * constructor that we can invoke to create an empty cache. |
| 202 | + * Executes `ReferencedKeySet.create(true, |
| 203 | + * ReferencedKeySet.concurrentHashMapSupplier())` with reflection. |
227 | 204 | */
|
228 |
| - Field baseLocaleCacheField = accessImpl.findField("sun.util.locale.BaseLocale$Cache", "CACHE"); |
229 |
| - Field localeCacheField = accessImpl.findField("java.util.Locale$Cache", "LOCALECACHE"); |
| 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 | + }); |
230 | 210 |
|
231 |
| - access.registerFieldValueTransformer(baseLocaleCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass())); |
232 |
| - access.registerFieldValueTransformer(localeCacheField, (receiver, originalValue) -> ReflectionUtil.newInstance(originalValue.getClass())); |
233 |
| - } |
| 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 | + }); |
234 | 221 | }
|
235 | 222 |
|
236 | 223 | @Override
|
|
0 commit comments