Skip to content

Commit 54fef8a

Browse files
committed
Revert "Merge pull request #2816 from rdara/fix/concurrent-hashmap-contention-case-00311074"
This reverts commit 3741c17, reversing changes made to 1e43c50.
1 parent 3741c17 commit 54fef8a

2 files changed

Lines changed: 1 addition & 263 deletions

File tree

newrelic-agent/src/main/java/com/newrelic/agent/instrumentation/weaver/extension/ExtensionHolderFactoryImpl.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,10 @@ public T getAndRemoveExtension(Object instance) {
3939
return instanceCache.remove(instance);
4040
}
4141

42-
/**
43-
* Uses putIfAbsent pattern instead of computeIfAbsent() to avoid
44-
* ConcurrentHashMap bin-level locking during value creation.
45-
* This prevents contention issues where threads get stuck in
46-
* helpTransfer() under high concurrency.
47-
*
48-
* Trade-off: Under race conditions, multiple threads may create
49-
* extension instances, but only one wins (via putIfAbsent).
50-
* This is safe because valueLoader creates empty instances -
51-
* no pre-populated state is lost.
52-
*/
5342
@Override
5443
public T getExtension(Object instance, Supplier<T> valueLoader) {
5544
try {
56-
// Fast path: already exists
57-
T value = instanceCache.get(instance);
58-
if (value != null) {
59-
return value;
60-
}
61-
62-
// Create value OUTSIDE of any lock - avoids computeIfAbsent() bin-level contention
63-
T newValue = valueLoader.get();
64-
65-
// Atomic put - only one thread wins, losers get the winner's value
66-
T existing = instanceCache.putIfAbsent(instance, newValue);
67-
return existing != null ? existing : newValue;
45+
return instanceCache.computeIfAbsent(instance, k -> valueLoader.get());
6846
} catch (RuntimeException e) {
6947
AgentBridge.getAgent().getLogger().log(Level.FINE, e, "Unable to load extension class for {0}",
7048
instance.getClass().getName());

newrelic-agent/src/test/java/com/newrelic/agent/instrumentation/weaver/extension/ExtensionHolderFactoryImplTest.java

Lines changed: 0 additions & 240 deletions
This file was deleted.

0 commit comments

Comments
 (0)