|
39 | 39 |
|
40 | 40 | import jdk.graal.compiler.core.common.LibGraalSupport; |
41 | 41 | import jdk.graal.compiler.debug.GraalError; |
42 | | -import jdk.graal.compiler.util.EconomicHashMap; |
43 | 42 | import jdk.vm.ci.meta.ResolvedJavaMethod; |
44 | 43 | import jdk.vm.ci.meta.ResolvedJavaType; |
45 | 44 | import jdk.vm.ci.meta.UnresolvedJavaType; |
@@ -153,11 +152,24 @@ public static AnnotationValue getAnnotationValue(Annotated annotated, Class<? ex |
153 | 152 |
|
154 | 153 | /** |
155 | 154 | * Cache for {@link #getAnnotationValue}. Building libgraal-ee shows that this cache grows to |
156 | | - * about 3K entries and there are about 30K accesses so no need to optimize further with an LRU |
157 | | - * cache. |
| 155 | + * about 3K entries so the LRU cache is sized just above that (4096). This cache must not grow |
| 156 | + * too large as there are Native Image tests that build numerous images in the one JVM process. |
158 | 157 | */ |
159 | 158 | @LibGraalSupport.HostedOnly // |
160 | | - private static final Map<Annotated, Map<ResolvedJavaType, AnnotationValue>> declaredAnnotations = LibGraalSupport.INSTANCE == null ? Collections.synchronizedMap(new EconomicHashMap<>()) : null; |
| 159 | + private static final Map<Annotated, Map<ResolvedJavaType, AnnotationValue>> declaredAnnotations; |
| 160 | + static { |
| 161 | + final int cacheMaxSize = 4096; |
| 162 | + if (LibGraalSupport.INSTANCE == null) { |
| 163 | + declaredAnnotations = Collections.synchronizedMap(new java.util.LinkedHashMap<>(cacheMaxSize, 0.75f, true) { |
| 164 | + @Override |
| 165 | + protected boolean removeEldestEntry(Map.Entry<Annotated, Map<ResolvedJavaType, AnnotationValue>> eldest) { |
| 166 | + return size() > cacheMaxSize; |
| 167 | + } |
| 168 | + }); |
| 169 | + } else { |
| 170 | + declaredAnnotations = null; |
| 171 | + } |
| 172 | + } |
161 | 173 |
|
162 | 174 | @LibGraalSupport.HostedOnly |
163 | 175 | private static AnnotationValue getAnnotationValue0(Annotated annotated, Class<? extends Annotation> annotationType, boolean inherited) { |
|
0 commit comments