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.JPFException;
24 * field info for object fields
26 public class ReferenceFieldInfo extends SingleSlotFieldInfo {
27 int init; // = MJIEnv.NULL; // not required for MJIEnv.NULL = 0
29 String sInit; // <2do> pcm - just a temporary quirk to init from string literals
30 // check if there are other non-object reference inits
32 public ReferenceFieldInfo (String name, String type, int modifiers) {
33 super(name, type, modifiers);
37 public String valueToString (Fields f) {
38 int i = f.getIntValue(storageOffset);
39 if (i == MJIEnv.NULL) {
42 return (VM.getVM().getHeap().get(i)).toString();
47 public boolean isReference () {
52 public Class<? extends ChoiceGenerator<?>> getChoiceGeneratorType() {
53 return ReferenceChoiceGenerator.class;
57 public boolean isArrayField () {
62 public void setConstantValue (Object constValue){
63 // <2do> pcm - check what other constants we might encounter, this is most
64 // probably not just used for Strings.
65 // Besides the type issue, there is an even bigger problem with identities.
66 // For instance, all String refs initialized via the same string literal
67 // inside a single classfile are in fact refering to the same object. This
68 // means we have to keep a registry (hashtab) with string-literal created
69 // String objects per ClassInfo, and use this when we assign or init
71 // For the sake of progress, we ignore this for now, but have to come back
72 // to it because it violates the VM spec
74 if (constValue instanceof String){
76 sInit = (String)constValue;
78 throw new JPFException ("unsupported reference initialization: " + constValue);
83 public void initialize (ElementInfo ei, ThreadInfo ti) {
87 Heap heap = vm.getHeap();
88 ref = heap.newString(sInit, ti).getObjectRef();
90 ei.getFields().setReferenceValue( storageOffset, ref);
94 public Object getValueObject (Fields f){
95 int i = f.getIntValue(storageOffset);
96 if (i == MJIEnv.NULL) {
99 Heap heap = VM.getVM().getHeap();