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.jvm.bytecode;
20 import gov.nasa.jpf.vm.ClassInfo;
21 import gov.nasa.jpf.vm.ElementInfo;
22 import gov.nasa.jpf.vm.FieldInfo;
23 import gov.nasa.jpf.vm.Instruction;
24 import gov.nasa.jpf.vm.LoadOnJPFRequired;
25 import gov.nasa.jpf.vm.Scheduler;
26 import gov.nasa.jpf.vm.StackFrame;
27 import gov.nasa.jpf.vm.ThreadInfo;
28 import gov.nasa.jpf.vm.bytecode.ReadInstruction;
32 * Get static fieldInfo from class
35 public class GETSTATIC extends JVMStaticFieldInstruction implements ReadInstruction {
37 public GETSTATIC(String fieldName, String clsDescriptor, String fieldDescriptor){
38 super(fieldName, clsDescriptor, fieldDescriptor);
42 public Instruction execute (ThreadInfo ti) {
45 //--- check if this causes a class load by a user defined classloader
47 fieldInfo = getFieldInfo();
48 } catch (LoadOnJPFRequired lre) {
52 if (fieldInfo == null) {
53 return ti.createAndThrowException("java.lang.NoSuchFieldError",
54 (className + '.' + fname));
57 //--- check if this has to trigger class initialization
58 ClassInfo ciField = fieldInfo.getClassInfo();
59 if (!mi.isClinit(ciField) && ciField.initializeClass(ti)) {
60 // note - this returns the next insn in the topmost clinit that just got pushed
63 ElementInfo eiFieldOwner = ciField.getStaticElementInfo();
65 //--- check if this breaks the transition
66 Scheduler scheduler = ti.getScheduler();
67 if (scheduler.canHaveSharedClassCG( ti, this, eiFieldOwner, fieldInfo)){
68 eiFieldOwner = scheduler.updateClassSharedness(ti, eiFieldOwner, fieldInfo);
69 if (scheduler.setsSharedClassCG( ti, this, eiFieldOwner, fieldInfo)){
70 return this; // re-execute
74 Object fieldAttr = eiFieldOwner.getFieldAttr(fieldInfo);
75 StackFrame frame = ti.getModifiableTopFrame();
78 int ival = eiFieldOwner.get1SlotField(fieldInfo);
81 if (fieldInfo.isReference()) {
87 if (fieldAttr != null) {
88 frame.setOperandAttr(fieldAttr);
92 long lval = eiFieldOwner.get2SlotField(fieldInfo);
97 if (fieldAttr != null) {
98 frame.setLongOperandAttr(fieldAttr);
106 public boolean isMonitorEnterPrologue(){
107 return GetHelper.isMonitorEnterPrologue(mi, insnIndex);
111 public int getLength() {
112 return 3; // opcode, index1, index2
116 public int getByteCode () {
121 public boolean isRead() {
126 public void accept(JVMInstructionVisitor insVisitor) {
127 insVisitor.visit(this);