ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject ignite git commit: IGNITE-8587 GridToStringBuilder use ConcurrentHashMap to avoid global locks on classCache
Date Wed, 06 Jun 2018 09:22:44 GMT
Repository: ignite
Updated Branches:
  refs/heads/master c47e30487 -> ecd8261f1


IGNITE-8587 GridToStringBuilder use ConcurrentHashMap to avoid global locks on classCache

IGNITE-8587 GridToStringBuilder use ConcurrentHashMap to avoid global locks on classCache
- Fixes #4059.

Signed-off-by: Alexey Goncharuk <alexey.goncharuk@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ecd8261f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ecd8261f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ecd8261f

Branch: refs/heads/master
Commit: ecd8261f1add62099fde39aa7dca49855a866eda
Parents: c47e304
Author: Sergey Kosarev <skosarev@gridgain.com>
Authored: Wed Jun 6 11:19:26 2018 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Wed Jun 6 12:21:21 2018 +0300

----------------------------------------------------------------------
 .../util/tostring/GridToStringBuilder.java      | 38 +++-----------------
 1 file changed, 5 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ecd8261f/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index d361112..77c333d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -28,15 +28,14 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EventListener;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.internal.util.typedef.F;
@@ -85,10 +84,7 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_
  */
 public class GridToStringBuilder {
     /** */
-    private static final Map<String, GridToStringClassDescriptor> classCache = new
HashMap<>();
-
-    /** */
-    private static final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    private static final Map<String, GridToStringClassDescriptor> classCache = new
ConcurrentHashMap<>();
 
     /** {@link IgniteSystemProperties#IGNITE_TO_STRING_INCLUDE_SENSITIVE} */
     public static final boolean INCLUDE_SENSITIVE =
@@ -1017,16 +1013,10 @@ public class GridToStringBuilder {
         }
         // Specifically catching all exceptions.
         catch (Exception e) {
-            rwLock.writeLock().lock();
 
             // Remove entry from cache to avoid potential memory leak
             // in case new class loader got loaded under the same identity hash.
-            try {
-                classCache.remove(cls.getName() + System.identityHashCode(cls.getClassLoader()));
-            }
-            finally {
-                rwLock.writeLock().unlock();
-            }
+            classCache.remove(cls.getName() + System.identityHashCode(cls.getClassLoader()));
 
             // No other option here.
             throw new IgniteException(e);
@@ -1737,14 +1727,7 @@ public class GridToStringBuilder {
 
         GridToStringClassDescriptor cd;
 
-        rwLock.readLock().lock();
-
-        try {
-            cd = classCache.get(key);
-        }
-        finally {
-            rwLock.readLock().unlock();
-        }
+        cd = classCache.get(key);
 
         if (cd == null) {
             cd = new GridToStringClassDescriptor(cls);
@@ -1806,18 +1789,7 @@ public class GridToStringBuilder {
 
             cd.sortFields();
 
-            /*
-             * Allow multiple puts for the same class - they will simply override.
-             */
-
-            rwLock.writeLock().lock();
-
-            try {
-                classCache.put(key, cd);
-            }
-            finally {
-                rwLock.writeLock().unlock();
-            }
+            classCache.putIfAbsent(key, cd);
         }
 
         return cd;


Mime
View raw message