ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject [1/8] ignite git commit: IGNITE-3200: Resolved classloader leak.
Date Thu, 02 Jun 2016 13:26:06 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 3c3ed0563 -> 4cc10982e


IGNITE-3200: Resolved classloader leak.


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

Branch: refs/heads/master
Commit: 56c605622dbecf71f3ee87cc41a16d2ee87e92d3
Parents: a28e16e
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Thu May 26 11:15:48 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Tue May 31 11:28:18 2016 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/util/ClassCache.java | 32 ++++++++++++++++++++
 .../ignite/internal/util/IgniteUtils.java       |  6 +++-
 .../processors/hadoop/HadoopClassLoader.java    | 23 +++++++++++++-
 3 files changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/56c60562/modules/core/src/main/java/org/apache/ignite/internal/util/ClassCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ClassCache.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ClassCache.java
new file mode 100644
index 0000000..7d6edbe
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ClassCache.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+/**
+ * Class cache.
+ */
+public interface ClassCache {
+    /**
+     * Get class for the given name.
+     *
+     * @param clsName Class name.
+     * @return Class.
+     * @throws ClassNotFoundException If not found.
+     */
+    public Class<?> getFromCache(String clsName) throws ClassNotFoundException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/56c60562/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index ed8e100..cbefd7d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -8232,7 +8232,11 @@ public abstract class IgniteUtils {
         if (cls != null)
             return cls;
 
-        if (ldr == null)
+        if (ldr != null) {
+            if (ldr instanceof ClassCache)
+                return ((ClassCache)ldr).getFromCache(clsName);
+        }
+        else
             ldr = gridClassLoader;
 
         ConcurrentMap<String, Class> ldrMap = classCache.get(ldr);

http://git-wip-us.apache.org/repos/asf/ignite/blob/56c60562/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClassLoader.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClassLoader.java
b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClassLoader.java
index 270b31d..4448b2d 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClassLoader.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/HadoopClassLoader.java
@@ -31,10 +31,14 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
 import org.apache.hadoop.util.NativeCodeLoader;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.hadoop.v2.HadoopDaemon;
 import org.apache.ignite.internal.processors.hadoop.v2.HadoopShutdownHookManager;
+import org.apache.ignite.internal.util.ClassCache;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -59,7 +63,7 @@ import org.objectweb.asm.commons.RemappingClassAdapter;
  * Also supports class parsing for finding dependencies which contain transitive dependencies
  * unavailable for parent.
  */
-public class HadoopClassLoader extends URLClassLoader {
+public class HadoopClassLoader extends URLClassLoader implements ClassCache {
     /**
      * We are very parallel capable.
      */
@@ -88,6 +92,9 @@ public class HadoopClassLoader extends URLClassLoader {
     /** */
     private static final Map<String, byte[]> bytesCache = new ConcurrentHashMap8<>();
 
+    /** Class cache. */
+    private final ConcurrentMap<String, Class> cacheMap = new ConcurrentHashMap<>();
+
     /** Diagnostic name of this class loader. */
     @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
     private final String name;
@@ -282,6 +289,20 @@ public class HadoopClassLoader extends URLClassLoader {
         }
     }
 
+    /** {@inheritDoc} */
+    @Override public Class<?> getFromCache(String clsName) throws ClassNotFoundException
{
+        Class<?> cls = cacheMap.get(clsName);
+
+        if (cls == null) {
+            Class old = cacheMap.putIfAbsent(clsName, cls = Class.forName(clsName, true,
this));
+
+            if (old != null)
+                cls = old;
+        }
+
+        return cls;
+    }
+
     /**
      * @param name Class name.
      * @param resolve Resolve class.


Mime
View raw message