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