1 package gov.nasa.jpf.jvm.bytecode; 20 21 import gov.nasa.jpf.Config; 22 import gov.nasa.jpf.JPFException; 23 import gov.nasa.jpf.jvm.ElementInfo; 24 import gov.nasa.jpf.jvm.ThreadInfo; 25 import gov.nasa.jpf.jvm.ClassInfo; 26 27 import org.apache.bcel.classfile.ConstantPool; 28 import org.apache.bcel.generic.ConstantPoolGen; 29 import org.apache.bcel.generic.Type; 30 import org.apache.bcel.generic.ReferenceType; 31 import gov.nasa.jpf.jvm.FieldInfo; 32 import gov.nasa.jpf.jvm.FieldLockInfo; 33 34 41 public abstract class FieldInstruction extends Instruction implements VariableAccessor 42 { 43 static FieldLockInfo prototype; 45 protected String fname; 46 protected String className; 47 protected String varId; 48 49 protected FieldInfo fi; 51 protected int size; 52 protected boolean isReferenceField; 53 54 public static void init (Config config) throws Config.Exception { 55 if (config.getBoolean("vm.por") && config.getBoolean("vm.por.sync_detection")) { 56 prototype = (FieldLockInfo) config.getEssentialInstance("vm.por.fieldlockinfo.class", 57 FieldLockInfo.class); 58 } 59 } 60 61 public void setPeer (org.apache.bcel.generic.Instruction i, ConstantPool cp) { 62 org.apache.bcel.generic.FieldInstruction fi; 63 ConstantPoolGen cpg; 64 65 fi = (org.apache.bcel.generic.FieldInstruction) i; 66 cpg = ClassInfo.getConstantPoolGen(cp); 67 68 fname = fi.getFieldName(cpg); 69 className = fi.getClassName(cpg); 70 71 Type ft = fi.getFieldType(cpg); 72 if (ft instanceof ReferenceType) { 73 isReferenceField = true; 74 } 75 76 size = ft.getSize(); 77 } 78 79 public abstract FieldInfo getFieldInfo (); 80 81 public boolean isReferenceField () { 82 return isReferenceField; 83 } 84 85 public String getId(ElementInfo ei) { 86 return (ei.toString() + '.' + fname); 88 } 89 90 public String getVariableId () { 91 if (varId == null) { 92 varId = className + '.' + fname; 93 } 94 return varId; 95 } 96 97 101 protected boolean isLockProtected (ElementInfo ei, ThreadInfo ti) { 102 String id = getId(ei); 103 FieldLockInfo flInfo = ei.getFieldLockInfo( id); 104 FieldLockInfo flInfoNext; 105 106 FieldInfo fi = getFieldInfo(); 108 if (flInfo == null) { 109 try { 110 flInfoNext = (FieldLockInfo) prototype.clone(); 111 } catch (Exception x) { 112 throw new JPFException(x); } 114 } else { 115 flInfoNext = flInfo.checkProtection(ei,fi,ti); 116 } 117 118 if (flInfoNext != flInfo) { 119 ei.setFieldLockInfo(id, flInfoNext); 120 } 121 122 return flInfoNext.isProtected(); 123 } 124 } 125 126 127 128 129 130 131 132 133 | Popular Tags |