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=54d89c1479c4bcf63554076c4372b72e8c0c7444;hp=84ebdf0f2035f30446e0098220050a80e9e7399d;hpb=b24dfeaed560031631378aebe6b2d07af6698a46;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 84ebdf0f20..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;
@@ -380,13 +389,8 @@ public final class YangInstanceIdentifier implements PathRFC6020
*/
public static final class AugmentationIdentifier implements PathArgument {
private static final long serialVersionUID = -8122335594681936939L;
@@ -627,18 +631,6 @@ public final class YangInstanceIdentifier implements Path childNames) {
- this(childNames);
- }
-
/**
* Returns set of all possible child nodes
*
@@ -787,24 +779,41 @@ public final class YangInstanceIdentifier implements Path