[ https://issues.apache.org/jira/browse/GEODE-6830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16856825#comment-16856825 ]
Darrel Schneider commented on GEODE-6830: ----------------------------------------- Here are changes that remove the synchronization from the OffHeapStoredObjectAddressStack: {noformat} diff --git a/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapStoredObjectAddressStack.java b/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapStoredObjectAddressStack.java index a2174dc68b..72dfc65139 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapStoredObjectAddressStack.java +++ b/geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapStoredObjectAddressStack.java @@ -14,6 +14,8 @@ */ package org.apache.geode.internal.offheap; +import java.util.concurrent.atomic.AtomicLongFieldUpdater; + import org.apache.logging.log4j.Logger; import org.apache.geode.internal.offheap.FreeListManager.LongStack; @@ -24,6 +26,8 @@ import org.apache.geode.internal.offheap.FreeListManager.LongStack; * free-list of the FreeListManager. This class is thread safe. */ public class OffHeapStoredObjectAddressStack implements LongStack { + private static final AtomicLongFieldUpdater<OffHeapStoredObjectAddressStack> topAddrUpdater = + AtomicLongFieldUpdater.newUpdater(OffHeapStoredObjectAddressStack.class, "topAddr"); // Ok to read without sync but must be synced on write private volatile long topAddr; @@ -44,21 +48,22 @@ public class OffHeapStoredObjectAddressStack implements LongStack { public void offer(long e) { assert e != 0; MemoryAllocatorImpl.validateAddress(e); - synchronized (this) { - OffHeapStoredObject.setNext(e, this.topAddr); - this.topAddr = e; - } + long currentTopAddr; + do { + currentTopAddr = this.topAddr; + OffHeapStoredObject.setNext(e, currentTopAddr); + } while (!topAddrUpdater.compareAndSet(this, currentTopAddr, e)); } @Override public long poll() { long result; - synchronized (this) { + do { result = this.topAddr; - if (result != 0L) { - this.topAddr = OffHeapStoredObject.getNext(result); + if (result == 0L) { + break; } - } + } while (!topAddrUpdater.compareAndSet(this, result, OffHeapStoredObject.getNext(result))); return result; } {noformat} > offheap FreeListManager has synchronization that hurts multi-threaded access > ---------------------------------------------------------------------------- > > Key: GEODE-6830 > URL: https://issues.apache.org/jira/browse/GEODE-6830 > Project: Geode > Issue Type: Improvement > Components: offheap > Reporter: Darrel Schneider > Priority: Major > > The FreeListManager has a bunch of free lists implemented by > OffHeapStoredObjectAddressStack. Every time address is added or removed from > this stack it does a synchronization. This shows up as a place that threads > are blocked when 32 of them are doing pr puts. > It also shows that the AtomicReferenceArray is expensive and I believe that > the current implementation could use a normal java array instead. -- This message was sent by Atlassian JIRA (v7.6.3#76005)