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.bytecode;
21 import gov.nasa.jpf.vm.ClassInfo;
22 import gov.nasa.jpf.vm.ElementInfo;
23 import gov.nasa.jpf.vm.FieldInfo;
24 import gov.nasa.jpf.vm.StaticElementInfo;
25 import gov.nasa.jpf.vm.ThreadInfo;
28 * common machine independent type for static field accessors
30 public abstract class StaticFieldInstruction extends FieldInstruction {
32 protected StaticFieldInstruction(String fieldName, String clsDescriptor, String fieldDescriptor){
33 super(fieldName, clsDescriptor, fieldDescriptor);
37 * on-demand initialize the ClassInfo and FieldInfo fields. Note that
38 * classinfo might not correspond with the static className, but can be one of
39 * the super classes. Rather than checking for this on each subsequent access,
40 * we get the right one that declares the field here
42 protected void initialize() {
43 ClassInfo ciRef = mi.getClassInfo().resolveReferencedClass(className);
45 FieldInfo f = ciRef.getStaticField(fname);
47 ClassInfo ciField = f.getClassInfo();
48 if (!ciField.isRegistered()){
49 // classLoaded listeners might change/remove this field
50 ciField.registerClass(ThreadInfo.getCurrentThread());
51 f = ciField.getStaticField(fname);
56 // otherwise the referenced class has changed since compilation, which
57 // should throw a NoSuchFieldError in the caller
62 * NOTE: this should only be used from a executeInstruction()/instructionExecuted() context
65 public ElementInfo getElementInfo(ThreadInfo ti){
66 return getFieldInfo().getClassInfo().getStaticElementInfo();
70 public String toPostExecString(){
71 StringBuilder sb = new StringBuilder();
72 sb.append(getMnemonic());
74 sb.append( fi.getFullName());
79 public ClassInfo getClassInfo() {
83 return fi.getClassInfo();
87 public FieldInfo getFieldInfo() {
95 * that's invariant, as opposed to InstanceFieldInstruction, so it's
99 public ElementInfo peekElementInfo (ThreadInfo ti) {
100 return getLastElementInfo();
104 public StaticElementInfo getLastElementInfo() {
105 return getFieldInfo().getClassInfo().getStaticElementInfo();
108 // this can be different than ciField - the field might be in one of its
110 public ClassInfo getLastClassInfo(){
111 return getFieldInfo().getClassInfo();
114 public String getLastClassName() {
115 return getLastClassInfo().getName();