Aaws-sdk-java-automationUpdate to next snapshot version: 2.57.11-SNAPSHOT
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
Hold Region.of interned instances weakly so custom ids can be collected (#7416) `RegionCache` is now a weak-value intern map. `VALUES` maps each id to a `RegionReference`, a `WeakReference<Region>` that also records its key and registers with a static `ReferenceQueue`. - `put` first drains the queue and removes each cleared entry with the conditional `remove(key, ref)`, so it never evicts a newer live entry for the same id. - It then returns the existing referent if one is still alive. Otherwise it creates a new `Region` and installs it with `putIfAbsent`, or with `replace(key, staleRef, newRef)` when the old referent was collected. - A thread that loses the race loops and adopts the winner's instance, so concurrent callers still share one object. The public constants such as `US_EAST_1` and `AWS_GLOBAL` stay strongly reachable from `Region`'s static fields, so known ids keep returning them. A custom id stays interned while anything references its `Region`. Once nothing does, the GC clears it and the next `Region.of` call drops the map entry. An entry is only replaced after its referent is gone, so no caller can observe two instances for one id. The hot path is still one map lookup, one `WeakReference.get`, and an O(1) `ReferenceQueue.poll`. A collected custom region is re-created on its next use, which is not observable because no caller can still hold the old instance. I updated the generator and the `regions.java` fixture that `RegionGenerationTest` compares against. I added four tests to `RegionTest`: - An unreferenced custom region is collected and its key is removed from the cache. - 50k distinct ids do not accumulate. - A live custom region keeps its identity across GC. - 8 concurrent callers get a single instance. There is also a bugfix changelog entry. Alternatives I considered: - A size-capped cache, or interning only known regions, breaks `==` identity for ids that are not cached. It would need new public `equals`/`hashCode` semantics. - `WeakHashMap` uses weak keys, but `Region.id` holds the key string, which would pin every entry, and the map is not thread-safe. `EndpointTagGenerator` generates the same unbounded intern pattern for `EndpointTag.of`. I left it alone because no caller in `core/` or `services/s3/src/main` passes remote or user input to it. | 1 个月前 | |
Update to next snapshot version: 2.57.11-SNAPSHOT | 16 小时前 |