1 package gov.nasa.jpf.jvm.bytecode; 20 21 import gov.nasa.jpf.jvm.ClassInfo; 22 import gov.nasa.jpf.jvm.KernelState; 23 import gov.nasa.jpf.jvm.MethodInfo; 24 import gov.nasa.jpf.jvm.SystemState; 25 import gov.nasa.jpf.jvm.ThreadInfo; 26 27 28 31 public abstract class VirtualInvocation extends InvokeInstruction { 32 33 protected VirtualInvocation () {} 34 35 protected VirtualInvocation (MethodInfo mi, String cname, String mname, String signature, 36 int offset, int position) { 37 super(mi, cname, mname, signature, offset, position); 38 } 39 40 41 public boolean isDeterministic (SystemState ss, KernelState ks, ThreadInfo ti) { 42 int objRef = getCalleeThis(ti); 43 MethodInfo mi = getInvokedMethod( ks, objRef); 44 45 if ((objRef == -1) || (mi == null)) { 46 return true; } 48 49 return mi.isDeterministic(ti); 50 } 51 52 public boolean isExecutable (SystemState ss, KernelState ks, ThreadInfo ti) { 53 int objRef = getCalleeThis(ti); 54 MethodInfo mi = getInvokedMethod( ks, objRef); 55 56 if ((objRef == -1) || (mi == null)) { 57 return true; } 59 60 return mi.isExecutable(ti); 61 } 62 63 public Instruction execute (SystemState ss, KernelState ks, ThreadInfo ti) { 64 int objRef = getCalleeThis(ti); 65 66 if (objRef == -1) { return ti.createAndThrowException("java.lang.NullPointerException", 68 "calling '" + mname + "' on null object"); 69 } 70 71 MethodInfo mi = getInvokedMethod(ks, objRef); 72 if (mi == null) { 73 return ti.createAndThrowException("java.lang.NoSuchMethodException", 74 getCalleeClassInfo(ks, objRef).getName() + "." + mname); 75 } 76 77 return mi.execute(ti, false); 78 } 79 80 int getCalleeThis (ThreadInfo ti) { 81 return ti.getCalleeThis( getArgSize()); 82 } 83 84 ClassInfo getCalleeClassInfo (KernelState ks, int objRef) { 85 return ks.da.get(objRef).getClassInfo(); 86 } 87 88 91 MethodInfo getInvokedMethod (KernelState ks, int objRef) { 92 if (objRef != -1) { 93 94 if (lastObj != objRef) { 98 ClassInfo mci = getCalleeClassInfo(ks, objRef); 99 invokedMethod = mci.getMethod(mname, true); 100 101 if (invokedMethod == null) { 103 lastObj = -1; 104 } else { 105 lastObj = objRef; 106 } 107 } 108 } else { 109 lastObj = -1; 110 } 111 112 return invokedMethod; 113 } 114 115 public boolean isSchedulingRelevant (SystemState ss, KernelState ks, ThreadInfo ti) { 116 117 int objRef = getCalleeThis(ti); 119 MethodInfo mi = getInvokedMethod( ks, objRef); 120 121 if ((objRef == -1) || (mi == null)) { 122 return false; } 124 125 return mi.isSchedulingRelevant(ti, ks.da.get(objRef)); 126 } 127 } 128 | Popular Tags |