00001 package gov.nasa.arc.ase.jpf.jvm.reflection;
00002
00003 import gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.jpf.jvm.*;
00005 import gov.nasa.arc.ase.jpf.jvm.reflection.*;
00006 import de.fub.bytecode.generic.InstructionHandle;
00007
00008 public class JavaLangObjectReflection extends Reflection {
00009 public InstructionHandle executeMethod(MethodInfo mi, boolean atomic) {
00010 String name = mi.getFullName();
00011
00012 if(name.equals("java.lang.Object.clone()Ljava/lang/Object;")) {
00013
00014 throw new NativeMethodException("java.lang.Object.clone()Ljava/lang/Object;");
00015 }
00016
00017 if(name.equals("java.lang.Object.getClass()Ljava/lang/Class;")) {
00018
00019 throw new NativeMethodException("java.lang.Object.getClass()Ljava/lang/Class;");
00020 }
00021
00022 if(name.equals("java.lang.Object.hashCode()I")) {
00023
00024 throw new NativeMethodException("java.lang.Object.hashCode()I");
00025 }
00026
00027 if(name.equals("java.lang.Object.notify()V")) {
00028 da.monitorNotify(objref, ks, ss.getScheduler());
00029 return exit();
00030 }
00031
00032 if(name.equals("java.lang.Object.notifyAll()V")) {
00033 da.monitorNotifyAll(objref, ks);
00034 return exit();
00035 }
00036
00037 if(name.equals("java.lang.Object.wait(J)V")) {
00038 long length = th.getLongLocalVariable(1);
00039 boolean timeout = false;
00040
00041 if(length != 0) timeout = (ss.getScheduler().getCurrentRandom() == 0);
00042
00043 if(timeout)
00044 return exit();
00045 else {
00046 if (th.getStatus() == STATUS.RUNNING) {
00047 da.monitorWait(objref, th);
00048 return repeat();
00049 } else if(th.getStatus() == STATUS.NOTIFIED) {
00050 if (da.monitorLockAfterNotified(objref, th))
00051 return exit();
00052 else
00053 return repeat();
00054 } else
00055 throw new InternalErrorException("invalid thread state");
00056 }
00057 }
00058
00059 if(name.equals("java.lang.Object.wait()V")) {
00060 if (th.getStatus() == STATUS.RUNNING) {
00061 da.monitorWait(objref, th);
00062
00063 return repeat();
00064 } else if(th.getStatus() == STATUS.NOTIFIED) {
00065 if (da.monitorLockAfterNotified(objref, th)) {
00066 return exit();
00067 } else
00068 return repeat();
00069 } else
00070 throw new InternalErrorException("invalid thread state");
00071 }
00072
00073 return super.executeMethod(mi, atomic);
00074 }
00075 public InstructionHandle executeStaticMethod(MethodInfo mi, boolean atomic) {
00076 String name = mi.getFullName();
00077
00078 if(name.equals("java.lang.Object.<clinit>()V")) {
00079 return repeat();
00080 }
00081
00082 if(name.equals("java.lang.Object.registerNatives()V")) {
00083
00084 throw new NativeMethodException("java.lang.Object.registerNatives()V");
00085 }
00086
00087 return super.executeStaticMethod(mi, atomic);
00088 }
00089 public boolean isMethodDeterministic(MethodInfo mi) {
00090 String name = mi.getFullName();
00091
00092 if(name.equals("java.lang.Object.clone()Ljava/lang/Object;")) {
00093
00094 throw new NativeMethodException("java.lang.Object.clone()Ljava/lang/Object;");
00095 }
00096
00097 if(name.equals("java.lang.Object.getClass()Ljava/lang/Class;")) {
00098
00099 throw new NativeMethodException("java.lang.Object.getClass()Ljava/lang/Class;");
00100 }
00101
00102 if(name.equals("java.lang.Object.hashCode()I")) {
00103
00104 throw new NativeMethodException("java.lang.Object.hashCode()I");
00105 }
00106
00107 if(name.equals("java.lang.Object.wait(J)V")) {
00108 long length = th.peek2();
00109
00110 return length == 0;
00111 }
00112
00113 return super.isMethodDeterministic(mi);
00114 }
00115 public boolean isMethodExecutable(MethodInfo mi) {
00116 String name = mi.getFullName();
00117
00118 if(name.equals("java.lang.Object.clone()Ljava/lang/Object;")) {
00119
00120 throw new NativeMethodException("java.lang.Object.clone()Ljava/lang/Object;");
00121 }
00122
00123 if(name.equals("java.lang.Object.getClass()Ljava/lang/Class;")) {
00124
00125 throw new NativeMethodException("java.lang.Object.getClass()Ljava/lang/Class;");
00126 }
00127
00128 if(name.equals("java.lang.Object.hashCode()I")) {
00129
00130 throw new NativeMethodException("java.lang.Object.hashCode()I");
00131 }
00132
00133 if(name.equals("java.lang.Object.wait(J)V")) {
00134 long length = th.peek2();
00135 boolean timeout = false;
00136
00137 if(length != 0) timeout = (ss.getScheduler().getCurrentRandom() == 0);
00138
00139 if(timeout)
00140 return true;
00141 else if (th.getStatus() == STATUS.RUNNING)
00142 return true;
00143 else if(th.getStatus() == STATUS.NOTIFIED)
00144 return da.monitorCheckLockAfterNotified(objref, th);
00145 else
00146 throw new InternalErrorException("invalid thread state");
00147 }
00148
00149 if(name.equals("java.lang.Object.wait()V")) {
00150 if (th.getStatus() == STATUS.RUNNING)
00151 return true;
00152 else if(th.getStatus() == STATUS.NOTIFIED)
00153 return da.monitorCheckLockAfterNotified(objref, th);
00154 else
00155 return false;
00156 }
00157
00158 return super.isMethodExecutable(mi);
00159 }
00160 public boolean isStaticMethodDeterministic(MethodInfo mi) {
00161 String name = mi.getFullName();
00162
00163 if(name.equals("java.lang.Object.registerNatives()V")) {
00164
00165 throw new NativeMethodException("java.lang.Object.registerNatives()V");
00166 }
00167
00168 return super.isStaticMethodDeterministic(mi);
00169 }
00170 public boolean isStaticMethodExecutable(MethodInfo mi) {
00171 String name = mi.getFullName();
00172
00173 if(name.equals("java.lang.Object.registerNatives()V")) {
00174
00175 throw new NativeMethodException("java.lang.Object.registerNatives()V");
00176 }
00177
00178 return super.isStaticMethodExecutable(mi);
00179 }
00180 }