ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-3200: Resolving classlaoder leak issue.
Date Wed, 25 May 2016 19:08:44 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-7.5.22-huawei [created] 2a4792092


IGNITE-3200: Resolving classlaoder leak issue.


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

Branch: refs/heads/ignite-7.5.22-huawei
Commit: 2a479209255e74bada845ebd71fccf92c2458304
Parents: 27564aa
Author: thatcoach <ppozerov@list.ru>
Authored: Wed May 25 22:04:50 2016 +0300
Committer: thatcoach <ppozerov@list.ru>
Committed: Wed May 25 22:07:35 2016 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/util/ClassCache.java | 32 +++++++++
 .../ignite/internal/util/IgniteUtils.java       |  6 +-
 .../junits/multijvm/IgniteNodeRunner.java       | 71 +++++++++-----------
 .../processors/hadoop/HadoopClassLoader.java    | 51 +++++++++-----
 4 files changed, 106 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2a479209/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/2a479209/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 ab2ba9d..c5c6398 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
@@ -8199,7 +8199,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/2a479209/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
index 7d1a37d..bc0d963 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
@@ -17,17 +17,6 @@
 
 package org.apache.ignite.testframework.junits.multijvm;
 
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
 import com.thoughtworks.xstream.XStream;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
@@ -41,11 +30,17 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.testframework.junits.IgniteTestResources;
-import sun.jvmstat.monitor.HostIdentifier;
-import sun.jvmstat.monitor.MonitoredHost;
-import sun.jvmstat.monitor.MonitoredVm;
-import sun.jvmstat.monitor.MonitoredVmUtil;
-import sun.jvmstat.monitor.VmIdentifier;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * Run ignite node.
@@ -150,31 +145,31 @@ public class IgniteNodeRunner {
      * @throws Exception If exception.
      */
     public static List<Integer> killAll() throws Exception{
-        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));
-
-        Set<Integer> jvms = monitoredHost.activeVms();
+//        MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));
+//
+//        Set<Integer> jvms = monitoredHost.activeVms();
 
         List<Integer> res = new ArrayList<>();
 
-        for (Integer jvmId : jvms) {
-            try {
-                MonitoredVm vm = monitoredHost.getMonitoredVm(new VmIdentifier("//" + jvmId
+ "?mode=r"), 0);
-
-                if (IgniteNodeRunner.class.getName().equals(MonitoredVmUtil.mainClass(vm,
true))) {
-                    Process killProc = U.isWindows() ?
-                        Runtime.getRuntime().exec(new String[] {"taskkill", "/pid", jvmId.toString(),
"/f", "/t"}) :
-                        Runtime.getRuntime().exec(new String[] {"kill", "-9", jvmId.toString()});
-
-                    killProc.waitFor();
-
-                    res.add(jvmId);
-                }
-            }
-            catch (Exception e) {
-                // Print stack trace just for information.
-                X.printerrln("Could not kill IgniteNodeRunner java processes. Jvm pid = "
+ jvmId, e);
-            }
-        }
+//        for (Integer jvmId : jvms) {
+//            try {
+//                MonitoredVm vm = monitoredHost.getMonitoredVm(new VmIdentifier("//" + jvmId
+ "?mode=r"), 0);
+//
+//                if (IgniteNodeRunner.class.getName().equals(MonitoredVmUtil.mainClass(vm,
true))) {
+//                    Process killProc = U.isWindows() ?
+//                        Runtime.getRuntime().exec(new String[] {"taskkill", "/pid", jvmId.toString(),
"/f", "/t"}) :
+//                        Runtime.getRuntime().exec(new String[] {"kill", "-9", jvmId.toString()});
+//
+//                    killProc.waitFor();
+//
+//                    res.add(jvmId);
+//                }
+//            }
+//            catch (Exception e) {
+//                // Print stack trace just for information.
+//                X.printerrln("Could not kill IgniteNodeRunner java processes. Jvm pid =
" + jvmId, e);
+//            }
+//        }
 
         return res;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2a479209/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..8789068 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
@@ -17,24 +17,11 @@
 
 package org.apache.ignite.internal.processors.hadoop;
 
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.Vector;
 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;
@@ -54,12 +41,29 @@ import org.objectweb.asm.Type;
 import org.objectweb.asm.commons.Remapper;
 import org.objectweb.asm.commons.RemappingClassAdapter;
 
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+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;
+
 /**
  * Class loader allowing explicitly load classes without delegation to parent class loader.
  * 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