📄 jopsim.java
字号:
noim(141); break; case 142 : // d2i noim(142); break; case 143 : // d2l noim(143); break; case 144 : // d2f noim(144); break; case 145 : // i2b noim(145); break; case 146 : // i2c stack[sp] = stack[sp] & 0x0ffff; break; case 147 : // i2s noim(147); break; case 148 : // lcmp noim(148); break; case 149 : // fcmpl noim(149); break; case 150 : // fcmpg noim(150); break; case 151 : // dcmpl noim(151); break; case 152 : // dcmpg noim(152); break; case 153 : // ifeq case 198 : // ifnull new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] == 0) pc = new_pc; break; case 154 : // ifne case 199 : // ifnonnull new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] != 0) pc = new_pc; break; case 155 : // iflt new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] < 0) pc = new_pc; break; case 156 : // ifge new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] >= 0) pc = new_pc; break; case 157 : // ifgt new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] > 0) pc = new_pc; break; case 158 : // ifle new_pc = pc-1; new_pc += readOpd16s(); sp--; if (stack[sp+1] <= 0) pc = new_pc; break; case 159 : // if_icmpeq case 165 : // if_acmpeq new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] == stack[sp+2]) pc = new_pc; break; case 160 : // if_icmpne case 166 : // if_acmpne new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] != stack[sp+2]) pc = new_pc; break; case 161 : // if_icmplt new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] < stack[sp+2]) pc = new_pc; break; case 162 : // if_icmpge new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] >= stack[sp+2]) pc = new_pc; break; case 163 : // if_icmpgt new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] > stack[sp+2]) pc = new_pc; break; case 164 : // if_icmple new_pc = pc-1; new_pc += readOpd16s(); sp -= 2; if (stack[sp+1] <= stack[sp+2]) pc = new_pc; break; case 167 : // goto new_pc = pc-1; new_pc += readOpd16s(); pc = new_pc; break; case 168 : // jsr noim(168); break; case 169 : // ret noim(169); break; case 170 : // tableswitch noim(170); break; case 171 : // lookupswitch noim(171); break; case 176 : // areturn case 172 : // ireturn case 174 : // freturn ireturn(); break; case 173 : // lreturn lreturn(); break; case 175 : // dreturn lreturn(); break; case 177 : // return vreturn(); break; case 178 : // getstatic getstatic(); break; case 179 : // putstatic putstatic(); break; case 180 : // getfield getfield(); break; case 181 : // putfield putfield(); break; case 182 : // invokevirtual invokevirtual(); break; case 183 : // invokespecial invokespecial(); break; case 184 : // invokestatic invokestatic(); break; case 185 : // invokeinterface invokeinterface(); break; case 186 : // unused_ba noim(186); break; case 187 : // new jjvmConst(187);/* use function in JVM.java idx = readOpd16u(); val = readMem(cp+idx); // pointer to class struct writeMem(heap, val+2); // pointer to method table on objectref-1 ++heap; val = readMem(val); // instance size// TODO init object to zero stack[++sp] = heap; // objectref heap += val;System.out.println("new heap: "+heap);*/ break; case 188 : // newarray stack[++sp]=readOpd8u(); // use typ info // invoke JVM.f_newarray(int count,val); invoke(jjp+(188<<1)); /* val = stack[sp--]; // count from stack writeMem(heap, val); ++heap; stack[++sp] = heap; // ref to first element heap += val;// System.out.println("newarray heap: "+heap); * */ break; case 189 : // anewarray jjvmConst(189); break; case 190 : // arraylength ref = stack[sp--]; // ref from stack if (useHandle) { // handle needs indirection ref = readMem(ref); } --ref; // point to count stack[++sp] = readMem(ref); break; case 191 : // athrow noim(191); break; case 192 : // checkcast jjvmConst(192); break; case 193 : // instanceof noim(193); break; case 194 : // monitorenter sp--; // we don't use the objref intEna = false; ++moncnt; // noim(194); break; case 195 : // monitorexit sp--; // we don't use the objref --moncnt; if (moncnt==0) { intEna = true; } // noim(195); break; case 196 : // wide noim(196); break; case 197 : // multianewarray noim(197);/* stack[++sp] = readOpd8u(); // push dimenensions onto the stack // invoke JVM.f_multianewarray(int dim); invoke(jjp+(197<<1)); readOpd16u(); // ignore type information*/ break; case 200 : // goto_w noim(200); break; case 201 : // jsr_w noim(201); break; case 202 : // breakpoint noim(202); break; case 203 : // resCB noim(203); break; case 204 : // resCC noim(204); break; case 205 : // resCD noim(205); break; case 206 : // resCE noim(206); break; case 207 : // resCF noim(207); break; case 208 : // jopsys_null noim(208); break; case 209 : // jopsys_rd sysRd(); break; case 210 : // jopsys_wr sysWr(); break; case 211 : // jopsys_rdmem if (stack[sp]<0) { sysRd(); break; } ref = stack[sp--]; stack[++sp] = readMem(ref); break; case 212 : // jopsys_wrmem if (stack[sp]<0) { sysWr(); break; } ref = stack[sp--]; val = stack[sp--]; writeMem(ref, val); break; case 213 : // jopsys_rdint ref = stack[sp--];//// first variables in jvm.asm//// mp ? // pointer to method struct// cp ? // pointer to constants// heap ? // start of heap//// jjp ? // pointer to meth. table of Java JVM functions// jjhp ? // pointer to meth. table of Java JVM help functions//// moncnt ? // counter for monitor if (ref==0) { val = mp; } else if (ref==1) { val = cp; } else if (ref==2) { val = heap; } else if (ref==3) { val = jjp; } else if (ref==4) { val = jjhp; } else if (ref==5) { val = moncnt; } else { val = stack[ref]; } stack[++sp] = val; break; case 214 : // jopsys_wrint ref = stack[sp--]; val = stack[sp--]; if (ref==0) { mp = val; } else if (ref==1) { cp = val; } else if (ref==2) { heap = val;// System.out.println("jopsys_wrint: heap "+heap); } else if (ref==3) { jjp = val; } else if (ref==4) { jjhp = val; } else if (ref==5) { moncnt = val; } else { stack[ref] = val; } break; case 215 : // jopsys_getsp val = sp; stack[++sp] = val; break; case 216 : // jopsys_setsp val = stack[sp--]; sp = val; break; case 217 : // jopsys_getvp stack[++sp] = vp; break; case 218 : // jopsys_setvp vp = stack[sp--]; break; case 219 : // jopsys_int2ext// public static native void int2extMem(int intAdr, int extAdr, int cnt); a = stack[sp--]; b = stack[sp--]; if (useHandle) { // handle needs indirection b = readMem(b); } c = stack[sp--]; for(; a>=0; --a) { writeMem(b+a, stack[c+a]); } break; case 220 : // jopsys_ext2int// public static native void ext2intMem(int extAdr, int intAdr, int cnt); a = stack[sp--]; b = stack[sp--]; c = stack[sp--]; if (useHandle) { // handle needs indirection c = readMem(c); } for(; a>=0; --a) { stack[b+a] = readMem(c+a); } break; case 221 : // jopsys_nop break; case 222 : // jopsys_invoke a = stack[sp--]; invoke(a); break; case 223 : // resDF noim(223); break; case 224 : // resE0 - getstatic_ref getstatic(); break; case 225 : // resE1 - putstatic_ref putstatic(); break; case 226 : // resE2 - getfield_ref getfield(); break; case 227 : // resE3 - putfield_ref putfield(); break; case 228 : // resE4 - getstatic_long getstatic_long(); break; case 229 : // resE5 - putstatic_long putstatic_long(); break; case 230 : // resE6 - getfield_long getfield_long(); break; case 231 : // resE7 - putfield_long putfield_long(); break; case 232 : // resE8 noim(232); break; case 233 : // resE9 noim(233); break; case 234 : // resEA noim(234); break; case 235 : // resEB noim(235); break; case 236 : // resEC noim(236); break; case 237 : // resED noim(237); break; case 238 : // resEE noim(238); break; case 239 : // resEF noim(239); break; case 240 : // sys_int --pc; // correct wrong increment on jpc invoke(jjhp); // interrupt() is at offset 0 break; case 241 : // resF1 noim(241); break; case 242 : // resF2 noim(242); break; case 243 : // resF3 noim(243); break; case 244 : // resF4 noim(244); break; case 245 : // resF5 noim(245); break; case 246 : // resF6 noim(246); break; case 247 : // resF7 noim(247); break; case 248 : // resF8 noim(248); break; case 249 : // resF9 noim(249); break; case 250 : // resFA noim(250); break; case 251 : // resFB noim(251); break; case 252 : // resFC noim(252); break; case 253 : // resFD noim(253); break; case 254 : // sys_noim noim(254); break; case 255 : // sys_init noim(255); break; default: noim(instr); } } } void stat() {System.out.println();/*int sum = 0;int sumcnt = 0;for (int i=0; i<256; ++i) { if (bcStat[i] > 0) { System.out.println(bcStat[i]+"\t"+(bcStat[i]*JopInstr.cnt(i))+"\t"+JopInstr.name(i)); sum += bcStat[i]; sumcnt = bcStat[i]*JopInstr.cnt(i); }}System.out.println();System.out.println(sum+" instructions, "+sumcnt+" cycles, "+instrBytesCnt+" bytes");*/ System.out.println(maxSp+" maximum sp");// System.out.println(heap+" heap"); not the heap pointer anymore// System.out.println(); System.out.println(instrCnt+" Instructions executed"); int insByte = cache.instrBytes(); System.out.println(insByte+" Instructions bytes"); System.out.println(((float) insByte/instrCnt)+" average Instruction length"); System.out.println("memory word: "+rdMemCnt+" load "+wrMemCnt+" store"); System.out.println("memory word per instruction: "+ ((float) rdMemCnt/instrCnt)+" load "+ ((float) wrMemCnt/instrCnt)+" store"); System.out.println(); } /** * Stop the simulation (from the VSIS plugin) */ public static void cancel() { exit = true; stopped = true; } public static void main(String args[]) { JopSim js = null; if (args.length==1) { js = new JopSim(args[0]); } else if (args.length==2) { js = new JopSim(args[0], Integer.parseInt(args[1])); } else { System.out.println("usage: java JopSim file.bin [max instr]"); System.exit(-1); } log = System.getProperty("log", "false").equals("true"); useHandle = System.getProperty("handle", "false").equals("true");// js.portName = System.getProperty("port", "COM1");// js.openSerialPort(); for (int i=0; i<js.cache.cnt(); ++i) { js.cache.use(i); js.start(); js.interpret(); if (stopped) { System.out.println(); System.out.println("JopSim stopped"); } if (i==0) js.stat(); js.cache.stat(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -