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.util.InstructionState;
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.Instruction;
25 import gov.nasa.jpf.vm.LoadOnJPFRequired;
26 import gov.nasa.jpf.vm.MJIEnv;
27 import gov.nasa.jpf.vm.Scheduler;
28 import gov.nasa.jpf.vm.StackFrame;
29 import gov.nasa.jpf.vm.ThreadInfo;
30 import gov.nasa.jpf.vm.bytecode.WriteInstruction;
34 * Set static field in class
37 public class PUTSTATIC extends JVMStaticFieldInstruction implements WriteInstruction {
39 public PUTSTATIC(String fieldName, String clsDescriptor, String fieldDescriptor){
40 super(fieldName, clsDescriptor, fieldDescriptor);
44 * where do we get the value from?
45 * NOTE: only makes sense in a executeInstruction() context
48 public int getValueSlot (StackFrame frame){
49 return frame.getTopPos();
53 public Instruction execute (ThreadInfo ti) {
54 StackFrame frame = ti.getModifiableTopFrame();
57 //--- check if this causes a class load by a user defined classloader
59 fieldInfo = getFieldInfo();
60 } catch (LoadOnJPFRequired lre) {
64 if (fieldInfo == null) {
65 return ti.createAndThrowException("java.lang.NoSuchFieldError", (className + '.' + fname));
68 //--- check if this has to trigger class initialization
69 ClassInfo ciField = fieldInfo.getClassInfo();
70 if (!mi.isClinit(ciField) && ciField.initializeClass(ti)) {
71 return ti.getPC(); // this returns the next insn in the topmost clinit that just got pushed
73 ElementInfo eiFieldOwner = ciField.getModifiableStaticElementInfo();
75 //--- check scheduling point due to shared class access
76 Scheduler scheduler = ti.getScheduler();
77 if (scheduler.canHaveSharedClassCG( ti, this, eiFieldOwner, fieldInfo)){
78 eiFieldOwner = scheduler.updateClassSharedness(ti, eiFieldOwner, fi);
79 if (scheduler.setsSharedClassCG( ti, this, eiFieldOwner, fieldInfo)){
80 return this; // re-execute
84 // check if this gets re-executed from a exposure CG (which already did the assignment
85 if (frame.getAndResetFrameAttr(InstructionState.class) == null){
86 lastValue = PutHelper.setField(ti, frame, eiFieldOwner, fieldInfo);
89 //--- check scheduling point due to exposure through shared class
90 if (isReferenceField()){
91 int refValue = frame.peek();
92 if (refValue != MJIEnv.NULL){
93 ElementInfo eiExposed = ti.getElementInfo(refValue);
94 if (scheduler.setsSharedClassExposureCG(ti,this,eiFieldOwner,fieldInfo,eiExposed)){
95 frame.addFrameAttr( InstructionState.processed);
96 return this; // re-execute AFTER assignment
105 protected void popOperands (StackFrame frame){
107 frame.pop(); // .. val => ..
109 frame.pop(2); // .. highVal, lowVal => ..
114 public int getLength() {
115 return 3; // opcode, index1, index2
119 public int getByteCode () {
124 public boolean isRead() {
129 public void accept(JVMInstructionVisitor insVisitor) {
130 insVisitor.visit(this);