Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2E689200B0F for ; Thu, 2 Jun 2016 15:26:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2B045160A54; Thu, 2 Jun 2016 13:26:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 546FB160A51 for ; Thu, 2 Jun 2016 15:26:08 +0200 (CEST) Received: (qmail 81409 invoked by uid 500); 2 Jun 2016 13:26:07 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 81355 invoked by uid 99); 2 Jun 2016 13:26:07 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2016 13:26:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0390CDFE65; Thu, 2 Jun 2016 13:26:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dmagda@apache.org To: commits@ignite.apache.org Date: Thu, 02 Jun 2016 13:26:06 -0000 Message-Id: <970f3d49112b49ec94f0b1d26cec0cc0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/8] ignite git commit: IGNITE-3200: Resolved classloader leak. archived-at: Thu, 02 Jun 2016 13:26:09 -0000 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 Authored: Thu May 26 11:15:48 2016 +0300 Committer: vozerov-gridgain 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 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 bytesCache = new ConcurrentHashMap8<>(); + /** Class cache. */ + private final ConcurrentMap 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.