2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package java.util.concurrent.atomic;
21 import java.io.Serializable;
22 import java.util.Arrays;
25 * model class for AtomicReferenceArray
27 public class AtomicReferenceArray<E> implements Serializable {
28 private static final long serialVersionUID = -6209656149925076980L;
30 private final Object[] array;
32 public AtomicReferenceArray(int length) {
33 array = new Object[length];
34 // <2do> need a volatile write in order to conform to JMM // Does this really matter in JPF?
37 public AtomicReferenceArray(E[] array) {
39 throw new NullPointerException();
41 int length = array.length;
42 this.array = new Object[length];
44 for (int i = 0; i < length; ++i)
45 this.array[i] = array[i];
47 // <2do> need a volatile write in order to conform to JMM // Does this really matter in JPF?
50 public final int length() {
54 public final E get(int i) {
59 private final native E getNative(int i);
61 public final boolean compareAndSet(int i, E expect, E update) {
63 return(compareAndSetNative(i, expect, update));
66 private final native boolean compareAndSetNative(int i, E expect, E update);
68 public final boolean weakCompareAndSet(int i, E expect, E update) {
69 return(compareAndSet(i, expect, update));
72 public final E getAndSet(int i, E newValue) {
75 if (compareAndSet(i, current, newValue))
80 public final void set(int i, E newValue) {
81 getAndSet(i, newValue);
84 public final void lazySet(int i, E newValue) {
89 public String toString() {
90 // <2do> need a volatile read in order to conform to JMM // Does this really matter in JPF?
91 return(Arrays.toString(array));
94 private void checkIndex(int i) {
95 if (i < 0 || i >= array.length)
96 throw new IndexOutOfBoundsException("index " + i);