00001 package gov.nasa.arc.ase.jpf.jvm.reflection;
00002
00003 import gov.nasa.arc.ase.jpf.jvm.ClassInfo;
00004 import gov.nasa.arc.ase.jpf.jvm.ThreadInfo;
00005 import gov.nasa.arc.ase.jpf.jvm.MethodInfo;
00006 import gov.nasa.arc.ase.jpf.jvm.bytecode.Instruction;
00007
00008
00009
00010
00011 import java.util.List;
00012 import java.util.Iterator;
00013
00014
00015 public class JavaLangSystemReflection extends Reflection {
00016 public Instruction executeStaticMethod(MethodInfo mi) {
00017 String name = mi.getFullName();
00018
00019 if(name.equals("<clinit>()V")) {
00020
00021
00022 int objref = ks.da.newObject(
00023 ClassInfo.getClassInfo("java.io.PrintStream"),
00024 th);
00025 setReferenceStaticField("out", objref);
00026 setReferenceStaticField("err", objref);
00027
00028 return exit();
00029 }
00030
00031 if(name.equals("arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V")) {
00032 Reflection src = getObjectArgument(0);
00033 int src_position = getIntArgument(1);
00034 Reflection dst = getObjectArgument(2);
00035 int dst_position = getIntArgument(3);
00036 int length = getIntArgument(4);
00037
00038 if(src.getArrayTypeSize() == 1)
00039 for(int i = 0; i < length; i++)
00040 dst.setIntArrayElement(dst_position++,
00041 src.getIntArrayElement(src_position++));
00042 else
00043 for(int i = 0; i < length; i++)
00044 dst.setLongArrayElement(dst_position++,
00045 src.getLongArrayElement(src_position++));
00046
00047 return exit();
00048 }
00049
00050 if(name.equals("exit(I)V")) {
00051 int length = ks.tl.length();
00052
00053 for(int i = 0; i < length; i++) {
00054 ThreadInfo ti = ks.tl.get(i);
00055
00056 while(th.countStackFrames() != 0)
00057 ti.popFrame();
00058 }
00059 }
00060
00061 if(name.equals("currentTimeMillis()J")) {
00062 return exit(0L);
00063 }
00064
00065 if(name.equals("getCallerClass()Ljava/lang/Class;")) {
00066
00067 throw new NativeMethodException("getCallerClass()Ljava/lang/Class;");
00068 }
00069
00070 if(name.equals("identityHashCode(Ljava/lang/Object;)I")) {
00071 int objref = th.getLocalVariable(0);
00072 return exit(objref ^ 0xABCD);
00073 }
00074
00075 if(name.equals("initProperties(Ljava/util/Properties;)Ljava/util/Properties;")) {
00076
00077 throw new NativeMethodException("initProperties(Ljava/util/Properties;)Ljava/util/Properties;");
00078 }
00079
00080 if(name.equals("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;")) {
00081
00082 throw new NativeMethodException("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;");
00083 }
00084
00085 if(name.equals("registerNatives()V"))
00086 return exit();
00087
00088 if(name.equals("setErr0(Ljava/io/PrintStream;)V")) {
00089
00090 throw new NativeMethodException("setErr0(Ljava/io/PrintStream;)V");
00091 }
00092
00093 if(name.equals("setIn0(Ljava/io/InputStream;)V")) {
00094
00095 throw new NativeMethodException("setIn0(Ljava/io/InputStream;)V");
00096 }
00097
00098 if(name.equals("setOut0(Ljava/io/PrintStream;)V")) {
00099
00100 throw new NativeMethodException("setOut0(Ljava/io/PrintStream;)V");
00101 }
00102
00103 return super.executeStaticMethod(mi);
00104 }
00105 public boolean isStaticMethodDeterministic(MethodInfo mi) {
00106 String name = mi.getFullName();
00107
00108 if(name.equals("getCallerClass()Ljava/lang/Class;")) {
00109
00110 throw new NativeMethodException("getCallerClass()Ljava/lang/Class;");
00111 }
00112
00113 if(name.equals("initProperties(Ljava/util/Properties;)Ljava/util/Properties;")) {
00114
00115 throw new NativeMethodException("initProperties(Ljava/util/Properties;)Ljava/util/Properties;");
00116 }
00117
00118 if(name.equals("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;")) {
00119
00120 throw new NativeMethodException("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;");
00121 }
00122
00123 if(name.equals("registerNatives()V")) {
00124 return true;
00125 }
00126
00127 if(name.equals("setErr0(Ljava/io/PrintStream;)V")) {
00128
00129 throw new NativeMethodException("setErr0(Ljava/io/PrintStream;)V");
00130 }
00131
00132 if(name.equals("setIn0(Ljava/io/InputStream;)V")) {
00133
00134 throw new NativeMethodException("setIn0(Ljava/io/InputStream;)V");
00135 }
00136
00137 if(name.equals("setOut0(Ljava/io/PrintStream;)V")) {
00138
00139 throw new NativeMethodException("setOut0(Ljava/io/PrintStream;)V");
00140 }
00141
00142 return super.isStaticMethodDeterministic(mi);
00143 }
00144 public boolean isStaticMethodExecutable(MethodInfo mi) {
00145 String name = mi.getFullName();
00146
00147 if(name.equals("getCallerClass()Ljava/lang/Class;")) {
00148
00149 throw new NativeMethodException("getCallerClass()Ljava/lang/Class;");
00150 }
00151
00152 if(name.equals("initProperties(Ljava/util/Properties;)Ljava/util/Properties;")) {
00153
00154 throw new NativeMethodException("initProperties(Ljava/util/Properties;)Ljava/util/Properties;");
00155 }
00156
00157 if(name.equals("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;")) {
00158
00159 throw new NativeMethodException("mapLibraryName(Ljava/lang/String;)Ljava/lang/String;");
00160 }
00161
00162 if(name.equals("registerNatives()V")) {
00163 return true;
00164 }
00165
00166 if(name.equals("setErr0(Ljava/io/PrintStream;)V")) {
00167
00168 throw new NativeMethodException("setErr0(Ljava/io/PrintStream;)V");
00169 }
00170
00171 if(name.equals("setIn0(Ljava/io/InputStream;)V")) {
00172
00173 throw new NativeMethodException("setIn0(Ljava/io/InputStream;)V");
00174 }
00175
00176 if(name.equals("setOut0(Ljava/io/PrintStream;)V")) {
00177
00178 throw new NativeMethodException("setOut0(Ljava/io/PrintStream;)V");
00179 }
00180
00181 return super.isStaticMethodExecutable(mi);
00182 }
00183 }