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.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.util.HashData;
21 import gov.nasa.jpf.util.IntVector;
22 import gov.nasa.jpf.util.PrintUtils;
24 import java.io.PrintStream;
27 * element values for reference array objects
28 * (references are stored as int's)
30 public class ReferenceArrayFields extends ArrayFields {
32 int[] values; // the references
34 public ReferenceArrayFields (int length) {
35 values = new int[length];
37 /** not required for MJIEnv.NULL = 0
38 for (int i=0; i<length; i++) {
39 values[i] = MJIEnv.NULL;
45 public int[] asReferenceArray() {
50 public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
51 ReferenceArrayFields a = (ReferenceArrayFields) src;
52 System.arraycopy(a.values, srcPos, values, dstPos, len);
56 protected void printValue(PrintStream ps, int idx){
57 PrintUtils.printReference(ps, values[idx]);
61 public Object getValues(){
66 public int arrayLength() {
71 public boolean isReferenceArray() {
76 public int getHeapSize() {
77 return values.length * 4;
81 public void appendTo (IntVector v) {
86 public ReferenceArrayFields clone(){
87 ReferenceArrayFields f = (ReferenceArrayFields)cloneFields();
88 f.values = values.clone();
94 public boolean equals(Object o) {
95 if (o instanceof ReferenceArrayFields) {
96 ReferenceArrayFields other = (ReferenceArrayFields)o;
99 int[] vOther = other.values;
100 if (v.length != vOther.length) {
104 for (int i=0; i<v.length; i++) {
105 if (v[i] != vOther[i]) {
110 return compareAttrs(other);
118 public void setReferenceValue(int pos, int newValue) {
119 values[pos] = newValue;
123 public int getReferenceValue(int pos) {
128 public void hash (HashData hd) {
130 for (int i=0; i < v.length; i++) {