|
25 | 25 | * {@link OpenSslKeyMaterialProvider} that will cache the {@link OpenSslKeyMaterial} to reduce the overhead |
26 | 26 | * of parsing the chain and the key for generation of the material. |
27 | 27 | * <p> |
28 | | - * Cache reads are lock-free ({@link ConcurrentHashMap#get} + {@code retain()}); |
29 | | - * if a concurrent eviction releases the material in between, {@code retain()} |
30 | | - * detects the dead reference count and the read falls back to a cache miss. |
31 | | - * Mutations (insert, evict, destroy) use {@link ConcurrentHashMap#compute} / |
32 | | - * {@link ConcurrentHashMap#computeIfPresent} for atomicity. |
| 28 | + * Cache reads are lock-free ({@link ConcurrentHashMap#get} + {@code retain()}). |
| 29 | + * A concurrent eviction is safe: either {@code retain()} increments the reference count |
| 30 | + * first and the caller keeps a valid reference, or the eviction releases first and |
| 31 | + * {@code retain()} detects the dead count, falling back to a cache miss. |
| 32 | + * Inserts and removals adjust the reference count atomically with the map operation |
| 33 | + * via {@link ConcurrentHashMap#compute} / {@link ConcurrentHashMap#computeIfPresent}. |
33 | 34 | */ |
34 | 35 | final class OpenSslCachingKeyMaterialProvider extends OpenSslKeyMaterialProvider { |
35 | 36 |
|
@@ -60,7 +61,8 @@ private OpenSslKeyMaterial getAndRetain(String alias) { |
60 | 61 | } |
61 | 62 |
|
62 | 63 | /** |
63 | | - * Atomically inserts material if absent, or retains the existing entry. |
| 64 | + * Inserts material if absent, or retains the existing entry if another thread inserted first. |
| 65 | + * The returned material is always retained for the caller. |
64 | 66 | */ |
65 | 67 | private OpenSslKeyMaterial putIfAbsentAndRetain(String alias, OpenSslKeyMaterial material) { |
66 | 68 | return cache.compute(alias, (k, existing) -> { |
@@ -74,7 +76,8 @@ private OpenSslKeyMaterial putIfAbsentAndRetain(String alias, OpenSslKeyMaterial |
74 | 76 | } |
75 | 77 |
|
76 | 78 | /** |
77 | | - * Atomically removes and releases the entry for the given alias. |
| 79 | + * Removes and releases the entry for the given alias under the bucket lock, |
| 80 | + * preventing concurrent {@code retain()} from succeeding on a dead entry. |
78 | 81 | */ |
79 | 82 | private void removeAndRelease(String alias) { |
80 | 83 | cache.computeIfPresent(alias, (k, v) -> { |
|