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 gov.nasa.jpf.vm;
21 import gov.nasa.jpf.util.HashData;
22 import gov.nasa.jpf.util.IntVector;
25 * value container for non-array classes
27 public class NamedFields extends Fields {
29 /** this is where we store the instance data. Since field types are
30 * heterogenous, we have to map everything into int
32 protected int[] values;
34 public NamedFields (int dataSize) {
35 values = new int[dataSize];
39 public int[] asFieldSlots() {
44 * give an approximation of the heap size in bytes - we assume fields are word
45 * aligned, hence the number of values*4 should be good. Note that this is
46 * overridden by ArrayFields (arrays would be packed)
49 public int getHeapSize () {
50 return values.length*4;
53 // our low level getters and setters
55 public int getIntValue (int index) {
59 public boolean isEqual(Fields o, int off, int len, int otherOff) {
60 if (o instanceof NamedFields) {
61 NamedFields other = (NamedFields) o;
63 int jEnd = otherOff + len;
64 int[] v = other.values;
66 if ((iEnd > values.length) || (jEnd > v.length)) {
70 for (int i = off, j = otherOff; i < iEnd; i++, j++) {
71 if (values[i] != v[j]) {
82 // same as above, just here to make intentions clear
84 public int getReferenceValue (int index) {
89 public long getLongValue (int index) {
90 return Types.intsToLong(values[index + 1], values[index]);
94 public boolean getBooleanValue (int index) {
95 return Types.intToBoolean(values[index]);
99 public byte getByteValue (int index) {
100 return (byte) values[index];
104 public char getCharValue (int index) {
105 return (char) values[index];
109 public short getShortValue (int index) {
110 return (short) values[index];
113 // <2do> get rid of it!! this is only for internal use, to increase efficiency
114 public int[] getValues() {
118 //--- the field modifier methods (both instance and static)
121 public void setReferenceValue (int index, int newValue) {
122 values[index] = newValue;
126 public void setBooleanValue (int index, boolean newValue) {
127 values[index] = newValue ? 1 : 0;
131 public void setByteValue (int index, byte newValue) {
132 values[index] = newValue;
136 public void setCharValue (int index, char newValue) {
137 values[index] = newValue;
141 public void setShortValue (int index, short newValue) {
142 values[index] = newValue;
146 public void setFloatValue (int index, float newValue) {
147 values[index] = Types.floatToInt(newValue);
151 public void setIntValue (int index, int newValue) {
152 values[index] = newValue;
156 public void setLongValue (int index, long newValue) {
157 values[index++] = Types.hiLong(newValue);
158 values[index] = Types.loLong(newValue);
162 public void setDoubleValue (int index, double newValue) {
163 values[index++] = Types.hiDouble(newValue);
164 values[index] = Types.loDouble(newValue);
169 public float getFloatValue (int index) {
170 return Types.intToFloat(values[index]);
174 public double getDoubleValue (int index) {
175 return Types.intsToDouble( values[index+1], values[index]);
182 public NamedFields clone () {
183 NamedFields f = (NamedFields) cloneFields();
184 f.values = values.clone();
189 * Checks for equality.
192 public boolean equals (Object o) {
193 if (o instanceof NamedFields) {
194 NamedFields other = (NamedFields) o;
198 int[] v2 = other.values;
200 if (l != v2.length) {
203 for (int i = 0; i < l; i++) {
204 if (v1[i] != v2[i]) {
209 return super.compareAttrs(other);
216 // serialization interface
218 public void appendTo(IntVector v) {
224 * Adds some data to the computation of an hashcode.
227 public void hash (HashData hd) {
229 for (int i=0, l=v.length; i < l; i++) {
235 * Size of the fields.
238 return values.length;
242 public String toString () {
243 StringBuilder sb = new StringBuilder("NamedFields[");
245 sb.append("values=");
248 for (int i = 0; i < values.length; i++) {
253 sb.append(values[i]);
261 return sb.toString();
264 // <2do> replace with copyTo() !!
265 public int[] getRawValues() {
269 public void copyFrom(Fields other) {
270 System.arraycopy(((NamedFields)other).values, 0, this.values, 0, values.length);
271 super.copyAttrs(other);