diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-30 14:38:18 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-30 14:54:50 +0100 |
commit | 3cc97ab837ce8bd66627b5f186db8d307c98d902 (patch) | |
tree | e8c949b688e097da2a1dbca0eccb700c25d1eea4 | |
parent | 9d4a1d80b09d58a6a91257e45afdf6bb3315a7d3 (diff) |
- Storing references instead of just counting them has been default for a while now, so making it default in code too.
- Remove option to do just do refcounting.
3 files changed, 3 insertions, 89 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/AbstractResource.java b/jdisc_core/src/main/java/com/yahoo/jdisc/AbstractResource.java index a131fc557c4..cabadafa8a0 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/AbstractResource.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/AbstractResource.java @@ -5,7 +5,6 @@ import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.refcount.DebugReferencesByContextMap; import com.yahoo.jdisc.refcount.DebugReferencesWithStack; import com.yahoo.jdisc.refcount.DestructableResource; -import com.yahoo.jdisc.refcount.ReferencesByCount; import com.yahoo.jdisc.service.ClientProvider; import com.yahoo.jdisc.service.ServerProvider; import com.yahoo.jdisc.refcount.References; @@ -25,12 +24,10 @@ public abstract class AbstractResource implements SharedResource { protected AbstractResource() { DestructableResource destructable = new WrappedResource(this); - if (debug == Debug.SIMPLE) { - references = new DebugReferencesByContextMap(destructable, this); - } else if (debug == Debug.STACK) { + if (debug == Debug.STACK) { references = new DebugReferencesWithStack(destructable); } else { - references = new ReferencesByCount(destructable); + references = new DebugReferencesByContextMap(destructable, this); } } diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java b/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java index 051cebee465..654402d181c 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java @@ -39,7 +39,7 @@ public interface SharedResource { return Debug.valueOf(val); } catch (IllegalArgumentException e) { } } - return Debug.NO; + return Debug.SIMPLE; } /** diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java b/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java deleted file mode 100644 index 0f417c81a8b..00000000000 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/refcount/ReferencesByCount.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.jdisc.refcount; - -import com.yahoo.jdisc.ResourceReference; -import com.yahoo.jdisc.SharedResource; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Does reference counting by using atomic counting of references - * Default in production - * - * @author baldersheim - */ -public class ReferencesByCount implements References { - private final AtomicInteger refCount; - private final DestructableResource resource; - private final NoDebugResourceReference initialReference; - - public ReferencesByCount(DestructableResource resource) { - refCount = new AtomicInteger(1); - this.resource = resource; - initialReference = new NoDebugResourceReference(this); - } - - @Override - public void release() { - initialReference.close(); - } - - @Override - public int referenceCount() { - return refCount.get(); - } - - @Override - public ResourceReference refer(Object context) { - addRef(1); - return new NoDebugResourceReference(this); - } - - @Override - public String currentState() { - return "Active references: " + refCount.get() + "." - + " Resource reference debugging is turned off. Consider toggling the " - + SharedResource.SYSTEM_PROPERTY_NAME_DEBUG - + " system property to get debugging assistance with reference tracking."; - } - - private void removeRef() { - int refCount = addRef(-1); - if (refCount == 0) { - resource.close(); - } - } - - private int addRef(int value) { - while (true) { - int prev = refCount.get(); - if (prev == 0) { - throw new IllegalStateException(getClass().getName() + ".addRef(" + value + "):" - + " Object is already destroyed." - + " Consider toggling the " + SharedResource.SYSTEM_PROPERTY_NAME_DEBUG - + " system property to get debugging assistance with reference tracking."); - } - int next = prev + value; - if (refCount.compareAndSet(prev, next)) { - return next; - } - } - } - - private static class NoDebugResourceReference extends CloseableOnce { - private final ReferencesByCount resource; - - NoDebugResourceReference(final ReferencesByCount resource) { - this.resource = resource; - } - - @Override final void onClose() { resource.removeRef(); } - @Override References getReferences() { return resource; } - } -} |