X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fapi%2FYangInstanceIdentifier.java;h=c882db6693bb9b2a9b97ecb31650f8d95c94004f;hb=c92cd2ea1eb4a3fa08ee08caeb1220e5a07a97ea;hp=e9f940a4555bad2af63797018916240a4209d3a3;hpb=f519c219a66415da52a3809bf63a69274d1a2040;p=yangtools.git diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java index e9f940a455..c882db6693 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java @@ -13,9 +13,12 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; - +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Array; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -25,7 +28,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; - +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.concepts.Path; @@ -64,27 +67,44 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; * * * - * @see http://tools.ietf.org/html/rfc6020#section-9.13 + * @see RFC6020 */ public final class YangInstanceIdentifier implements Path, Immutable, Serializable { + @SuppressWarnings("rawtypes") + private static final AtomicReferenceFieldUpdater LEGACYPATH_UPDATER = + AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, ImmutableList.class, "legacyPath"); + private static final AtomicReferenceFieldUpdater TOSTRINGCACHE_UPDATER = + AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, String.class, "toStringCache"); private static final YangInstanceIdentifier EMPTY = trustedCreate(Collections.emptyList()); + private static final Field PATHARGUMENTS_FIELD; - private static final long serialVersionUID = 2L; - private final Iterable pathArguments; + private static final long serialVersionUID = 3L; + private transient final Iterable pathArguments; private final int hash; - private transient volatile ImmutableList legacyPath = null; + private volatile ImmutableList legacyPath = null; private transient volatile String toStringCache = null; + static { + final Field f; + try { + f = YangInstanceIdentifier.class.getDeclaredField("pathArguments"); + } catch (NoSuchFieldException | SecurityException e) { + throw new ExceptionInInitializerError(e); + } + f.setAccessible(true); + + PATHARGUMENTS_FIELD = f; + } + private final ImmutableList getLegacyPath() { // Temporary variable saves a volatile read ImmutableList ret = legacyPath; if (ret == null) { - synchronized (this) { - // We could have used a synchronized block, but let's just not bother - ret = ImmutableList.copyOf(pathArguments); - legacyPath = ret; - } + // We could have used a synchronized block, but the window is quite + // small and worst that can happen is duplicate object construction. + ret = ImmutableList.copyOf(pathArguments); + LEGACYPATH_UPDATER.lazySet(this, ret); } return ret; @@ -296,19 +316,6 @@ public final class YangInstanceIdentifier implements Path HASH_UPDATER = + AtomicReferenceFieldUpdater.newUpdater(AbstractPathArgument.class, Integer.class, "hash"); private static final long serialVersionUID = -4546547994250849340L; private final QName nodeType; + private volatile transient Integer hash = null; protected AbstractPathArgument(final QName nodeType) { this.nodeType = Preconditions.checkNotNull(nodeType); @@ -371,11 +381,21 @@ public final class YangInstanceIdentifier implements Path entry : keyValues.entrySet()) { @@ -548,9 +568,9 @@ public final class YangInstanceIdentifier implements PathRFC6020 */ public static final class AugmentationIdentifier implements PathArgument { private static final long serialVersionUID = -8122335594681936939L; @@ -611,18 +631,6 @@ public final class YangInstanceIdentifier implements Path childNames) { - this(childNames); - } - /** * Returns set of all possible child nodes * @@ -771,24 +779,41 @@ public final class YangInstanceIdentifier implements Path