Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82E8B18E2A for ; Wed, 7 Oct 2015 07:55:18 +0000 (UTC) Received: (qmail 83952 invoked by uid 500); 7 Oct 2015 07:55:18 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 83920 invoked by uid 500); 7 Oct 2015 07:55:18 -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 83911 invoked by uid 99); 7 Oct 2015 07:55:18 -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; Wed, 07 Oct 2015 07:55:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C9D6EE00AF; Wed, 7 Oct 2015 07:55:17 +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 Message-Id: <847799cb453c4dedbb39586cf0492b8d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: ignite-1272: storing user portable class descriptors only for classes that are loaded by default class loader Date: Wed, 7 Oct 2015 07:55:17 +0000 (UTC) Repository: ignite Updated Branches: refs/heads/ignite-1272 787347a98 -> 9c93f8bc7 ignite-1272: storing user portable class descriptors only for classes that are loaded by default class loader Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9c93f8bc Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9c93f8bc Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9c93f8bc Branch: refs/heads/ignite-1272 Commit: 9c93f8bc747ab73acd6e8fad75ba2e0ed56cc217 Parents: 787347a Author: Denis Magda Authored: Wed Oct 7 10:54:46 2015 +0300 Committer: Denis Magda Committed: Wed Oct 7 10:54:46 2015 +0300 ---------------------------------------------------------------------- .../internal/portable/PortableContext.java | 90 +++++--------------- 1 file changed, 23 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9c93f8bc/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java index d5a3c5d..0c762dd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java @@ -112,9 +112,8 @@ public class PortableContext implements Externalizable { /** */ private final ConcurrentMap, PortableClassDescriptor> descByCls = new ConcurrentHashMap8<>(); - /** */ - private final ConcurrentMap> userTypes - = new ConcurrentHashMap8<>(0); + /** Holds classes loaded by default class loader only. */ + private final ConcurrentMap userTypes = new ConcurrentHashMap8<>(); /** */ private final Map predefinedTypes = new HashMap<>(); @@ -129,7 +128,7 @@ public class PortableContext implements Externalizable { private final Map, Byte> mapTypes = new HashMap<>(); /** */ - private final Map mappers = new ConcurrentHashMap8<>(0); + private final ConcurrentMap mappers = new ConcurrentHashMap8<>(0); /** */ private final Map typeMappers = new ConcurrentHashMap8<>(0); @@ -468,12 +467,12 @@ public class PortableContext implements Externalizable { if (ldr == null) ldr = dfltLdr; - if (userType) { - desc = userTypesMap(ldr).get(typeId); + // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here + // giving a chance to a custom class loader to reload type's class. + if (userType && ldr.equals(dfltLdr)) { + desc = userTypes.get(typeId); - // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here - // giving a chance to a custom class loader to reload type's class. - if (desc != null && ldr.equals(dfltLdr)) + if (desc != null) return desc; } @@ -485,13 +484,15 @@ public class PortableContext implements Externalizable { desc = descByCls.get(cls); } catch (ClassNotFoundException e) { - if (userType && !ldr.equals(dfltLdr) && (desc = descriptorLoadingFailover(typeId, ldr)) != null) + // Class might have been loaded by default class loader. + if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr)) != null) return desc; throw new PortableInvalidClassException(e); } catch (IgniteCheckedException e) { - if (userType && !ldr.equals(dfltLdr) && (desc = descriptorLoadingFailover(typeId, ldr)) != null) + // Class might have been loaded by default class loader. + if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr)) != null) return desc; throw new PortableException("Failed resolve class for ID: " + typeId, e); @@ -507,29 +508,6 @@ public class PortableContext implements Externalizable { } /** - * The method must be used in case when it wasn't possible to load user type's class using custom class loader. - * - * There are several reasons why this may happen. First, type's name can be not registered in a system cache. - * Second, class might have been predefined explicitly and loaded by default class loader. - * - * @param typeId Type ID. - * @param ldr Class loader that failed to load type's class. - * @return Type descriptor on success, {@code null} on failure. - */ - private PortableClassDescriptor descriptorLoadingFailover(int typeId, ClassLoader ldr) { - assert !ldr.equals(dfltLdr); - - // Type name can be not registered in a system cache. Try to get from local map. - PortableClassDescriptor desc = userTypesMap(ldr).get(typeId); - - if (desc == null) - // Class might have been loaded by default class loader. - desc = descriptorForTypeId(true, typeId, dfltLdr); - - return desc; - } - - /** * Creates and registers {@link PortableClassDescriptor} for the given {@code class}. * * @param cls Class. @@ -577,7 +555,7 @@ public class PortableContext implements Externalizable { String typeName = typeName(cls.getName()); - PortableIdMapper idMapper = idMapper(typeName); + PortableIdMapper idMapper = userTypeIdMapper(typeName); int typeId = idMapper.typeId(typeName); @@ -605,10 +583,13 @@ public class PortableContext implements Externalizable { // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader // might have reloaded described class. - userTypesMap(IgniteUtils.detectClassLoader(cls)).put(typeId, desc); + if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr)) + userTypes.put(typeId, desc); descByCls.put(cls, desc); + mappers.putIfAbsent(typeId, idMapper); + // TODO uncomment for https://issues.apache.org/jira/browse/IGNITE-1377 // if (registerMetadata && isMetaDataEnabled(typeId)) // metaHnd.addMeta(typeId, new PortableMetaDataImpl(typeName, desc.fieldsMeta(), null)); @@ -658,7 +639,7 @@ public class PortableContext implements Externalizable { if (marshCtx.isSystemType(typeName)) return typeName.hashCode(); - return idMapper(shortTypeName).typeId(shortTypeName); + return userTypeIdMapper(shortTypeName).typeId(shortTypeName); } /** @@ -667,14 +648,14 @@ public class PortableContext implements Externalizable { * @return Field ID. */ public int fieldId(int typeId, String fieldName) { - return idMapper(typeId).fieldId(typeId, fieldName); + return userTypeIdMapper(typeId).fieldId(typeId, fieldName); } /** * @param typeId Type ID. * @return Instance of ID mapper. */ - public PortableIdMapper idMapper(int typeId) { + public PortableIdMapper userTypeIdMapper(int typeId) { PortableIdMapper idMapper = mappers.get(typeId); if (idMapper != null) @@ -683,11 +664,6 @@ public class PortableContext implements Externalizable { if (predefinedTypes.containsKey(typeId)) return DFLT_ID_MAPPER; - for (ConcurrentMap types : userTypes.values()) { - if (types.containsKey(typeId)) - return DFLT_ID_MAPPER; - } - return BASIC_CLS_ID_MAPPER; } @@ -695,7 +671,7 @@ public class PortableContext implements Externalizable { * @param typeName Type name. * @return Instance of ID mapper. */ - private PortableIdMapper idMapper(String typeName) { + private PortableIdMapper userTypeIdMapper(String typeName) { PortableIdMapper idMapper = typeMappers.get(typeName); return idMapper != null ? idMapper : DFLT_ID_MAPPER; @@ -828,7 +804,8 @@ public class PortableContext implements Externalizable { fieldsMeta = desc.fieldsMeta(); - userTypesMap(IgniteUtils.detectClassLoader(cls)).put(id, desc); + if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr)) + userTypes.put(id, desc); descByCls.put(cls, desc); } @@ -996,27 +973,6 @@ public class PortableContext implements Externalizable { } /** - * Returns user type map for specific class loader. - * - * @param ldr Class loader that loaded user type's class. - * @return User type map. - */ - private ConcurrentMap userTypesMap(ClassLoader ldr) { - ConcurrentMap ldrMap = userTypes.get(ldr); - - if (ldrMap == null) { - ConcurrentMap old = userTypes.putIfAbsent(ldr, - ldrMap = new ConcurrentHashMap8<>()); - - if (old != null) - ldrMap = old; - } - - return ldrMap; - } - - - /** */ private static class IdMapperWrapper implements PortableIdMapper { /** */