📄 jopsim.java
字号:
void putstatic_long() { int idx = readOpd16u(); int addr = readMem(cp+idx); writeMem(addr+1, stack[sp--]); writeMem(addr, stack[sp--]); } void getstatic_long() { int idx = readOpd16u(); int addr = readMem(cp+idx); stack[++sp] = readMem(addr); stack[++sp] = readMem(addr+1); } void putfield() { int off = readOpd16u(); int val = stack[sp--]; int ref = stack[sp--]; if (useHandle) { // handle needs indirection ref = readMem(ref); } writeMem(ref+off, val); } void getfield() { int off = readOpd16u(); int ref = stack[sp]; if (useHandle) { // handle needs indirection ref = readMem(ref); } stack[sp] = readMem(ref+off); } void putfield_long() { int off = readOpd16u(); int val_l = stack[sp--]; int val_h = stack[sp--]; int ref = stack[sp--]; if (useHandle) { // handle needs indirection ref = readMem(ref); } writeMem(ref+off, val_h); writeMem(ref+off+1, val_l); } void getfield_long() { int off = readOpd16u(); int ref = stack[sp]; if (useHandle) { // handle needs indirection ref = readMem(ref); } stack[sp] = readMem(ref+off); stack[++sp] = readMem(ref+off+1); }/*** the simulaton.** sp points to TOS*/ void interpret() { int new_pc; // for cond. branches int ref, val, idx, val2; int a, b, c; for (;;) {//// check for endless loop and stop///* if (pc==old_pc && mp==old_mp) { System.out.println(); System.out.println("endless loop"); break; } old_pc = pc; old_mp = mp;*/ if (maxInstr!=0 && instrCnt>=maxInstr) { break; } if (exit) { break; }//// statistic// ++instrCnt; if (sp > maxSp) maxSp = sp; int instr = cache.bc(pc++) & 0x0ff;//// interrupt handling// if ((nextTimerInt-usCnt()<0) && !intPend) { intPend = true; interrupt = true; } if (interrupt && intEna) { instr = SYS_INT; interrupt = false; // reset int }// stat bcStat[instr]++; ioCnt += JopInstr.cnt(instr); if (log) { String spc = (pc-1)+" "; while (spc.length()<4) spc = " "+spc; String s = spc+JopInstr.name(instr); System.out.print(s+"\t"); dump(); } switch (instr) { case 0 : // nop break; case 1 : // aconst_null stack[++sp] = 0; break; case 2 : // iconst_m1 stack[++sp] = -1; break; case 3 : // iconst_0 stack[++sp] = 0; break; case 4 : // iconst_1 stack[++sp] = 1; break; case 5 : // iconst_2 stack[++sp] = 2; break; case 6 : // iconst_3 stack[++sp] = 3; break; case 7 : // iconst_4 stack[++sp] = 4; break; case 8 : // iconst_5 stack[++sp] = 5; break; case 9 : // lconst_0 stack[++sp] = 0; stack[++sp] = 0; break; case 10 : // lconst_1 stack[++sp] = 0; stack[++sp] = 1; break; case 11 : // fconst_0 noim(11); break; case 12 : // fconst_1 noim(12); break; case 13 : // fconst_2 noim(13); break; case 14 : // dconst_0 noim(14); break; case 15 : // dconst_1 noim(15); break; case 16 : // bipush stack[++sp] = readOpd8s(); break; case 17 : // sipush stack[++sp] = readOpd16s(); break; case 18 : // ldc stack[++sp] = readMem(cp+readOpd8u()); break; case 19 : // ldc_w stack[++sp] = readMem(cp+readOpd16u()); break; case 20 : // ldc2_w idx = readOpd16u(); stack[++sp] = readMem(cp+idx); stack[++sp] = readMem(cp+idx+1); break; case 25 : // aload case 23 : // fload case 21 : // iload idx = readOpd8u(); stack[++sp] = stack[vp+idx]; break; case 22 : // lload idx = readOpd8u(); stack[++sp] = stack[vp+idx]; stack[++sp] = stack[vp+idx+1]; break; case 24 : // dload idx = readOpd8u(); stack[++sp] = stack[vp+idx]; stack[++sp] = stack[vp+idx+1]; break; case 42 : // aload_0 case 34 : // fload_0 case 26 : // iload_0 stack[++sp] = stack[vp]; break; case 43 : // aload_1 case 35 : // fload_1 case 27 : // iload_1 stack[++sp] = stack[vp+1]; break; case 44 : // aload_2 case 36 : // fload_2 case 28 : // iload_2 stack[++sp] = stack[vp+2]; break; case 45 : // aload_3 case 37 : // fload_3 case 29 : // iload_3 stack[++sp] = stack[vp+3]; break; case 30 : // lload_0 stack[++sp] = stack[vp]; stack[++sp] = stack[vp+1]; break; case 31 : // lload_1 stack[++sp] = stack[vp+1]; stack[++sp] = stack[vp+2]; break; case 32 : // lload_2 stack[++sp] = stack[vp+2]; stack[++sp] = stack[vp+3]; break; case 33 : // lload_3 stack[++sp] = stack[vp+3]; stack[++sp] = stack[vp+4]; break; case 38 : // dload_0 noim(38); break; case 39 : // dload_1 noim(39); break; case 40 : // dload_2 noim(40); break; case 41 : // dload_3 noim(41); break; case 50 : // aaload case 51 : // baload case 52 : // caload case 48 : // faload case 46 : // iaload case 53 : // saload idx = stack[sp--]; // index ref = stack[sp--]; // ref if (useHandle) { // handle needs indirection ref = readMem(ref); } stack[++sp] = readMem(ref+idx); break; case 47 : // laload idx = stack[sp--]; // index ref = stack[sp--]; // ref if (useHandle) { // handle needs indirection ref = readMem(ref); } stack[++sp] = readMem(ref+idx*2); stack[++sp] = readMem(ref+idx*2+1); break; case 49 : // daload noim(49); break; case 58 : // astore case 56 : // fstore case 54 : // istore idx = readOpd8u(); stack[vp+idx] = stack[sp--]; break; case 55 : // lstore idx = readOpd8u(); stack[vp+idx+1] = stack[sp--]; stack[vp+idx] = stack[sp--]; break; case 57 : // dstore idx = readOpd8u(); stack[vp+idx+1] = stack[sp--]; stack[vp+idx] = stack[sp--]; break; case 75 : // astore_0 case 67 : // fstore_0 case 59 : // istore_0 stack[vp] = stack[sp--]; break; case 76 : // astore_1 case 68 : // fstore_1 case 60 : // istore_1 stack[vp+1] = stack[sp--]; break; case 77 : // astore_2 case 69 : // fstore_2 case 61 : // istore_2 stack[vp+2] = stack[sp--]; break; case 78 : // astore_3 case 70 : // fstore_3 case 62 : // istore_3 stack[vp+3] = stack[sp--]; break; case 63 : // lstore_0 stack[vp+1] = stack[sp--]; stack[vp] = stack[sp--]; break; case 64 : // lstore_1 stack[vp+2] = stack[sp--]; stack[vp+1] = stack[sp--]; break; case 65 : // lstore_2 stack[vp+3] = stack[sp--]; stack[vp+2] = stack[sp--]; break; case 66 : // lstore_3 stack[vp+4] = stack[sp--]; stack[vp+3] = stack[sp--]; break; case 71 : // dstore_0 noim(71); break; case 72 : // dstore_1 noim(72); break; case 73 : // dstore_2 noim(73); break; case 74 : // dstore_3 noim(74); break; case 83 : // aastore case 84 : // bastore case 85 : // castore case 81 : // fastore case 79 : // iastore case 86 : // sastore val = stack[sp--]; // value idx = stack[sp--]; // index ref = stack[sp--]; // ref if (useHandle) { // handle needs indirection ref = readMem(ref); } writeMem(ref+idx, val); break; case 80 : // lastore val = stack[sp--]; // value val2 = stack[sp--]; // value idx = stack[sp--]; // index ref = stack[sp--]; // ref if (useHandle) { // handle needs indirection ref = readMem(ref); } writeMem(ref+idx*2, val2); writeMem(ref+idx*2+1, val); break; case 82 : // dastore noim(82); break; case 87 : // pop sp--; break; case 88 : // pop2 sp--; sp--; break; case 89 : // dup val = stack[sp]; stack[++sp] = val; break; case 90 : // dup_x1 a = stack[sp--]; b = stack[sp--]; stack[++sp] = a; stack[++sp] = b; stack[++sp] = a; break; case 91 : // dup_x2 a = stack[sp--]; b = stack[sp--]; c = stack[sp--]; stack[++sp] = a; stack[++sp] = c; stack[++sp] = b; stack[++sp] = a; break; case 92 : // dup2 a = stack[sp--]; b = stack[sp--]; stack[++sp] = b; stack[++sp] = a; stack[++sp] = b; stack[++sp] = a; break; case 93 : // dup2_x1 noim(93); break; case 94 : // dup2_x2 noim(94); break; case 95 : // swap noim(95); break; case 96 : // iadd val = stack[sp-1] + stack[sp]; stack[--sp] = val; break; case 97 : // ladd noim(97); break; case 98 : // fadd noim(98); break; case 99 : // dadd noim(99); break; case 100 : // isub val = stack[sp-1] - stack[sp]; stack[--sp] = val; break; case 101 : // lsub noim(101); break; case 102 : // fsub noim(102); break; case 103 : // dsub noim(103); break; case 104 : // imul val = stack[sp-1] * stack[sp]; stack[--sp] = val; break; case 105 : // lmul noim(105); break; case 106 : // fmul noim(106); break; case 107 : // dmul noim(107); break; case 108 : // idiv val = stack[sp-1] / stack[sp]; stack[--sp] = val; break; case 109 : // ldiv noim(109); break; case 110 : // fdiv noim(110); break; case 111 : // ddiv noim(111); break; case 112 : // irem val = stack[sp-1] % stack[sp]; stack[--sp] = val; break; case 113 : // lrem noim(113); break; case 114 : // frem noim(114); break; case 115 : // drem noim(115); break; case 116 : // ineg stack[sp] = -stack[sp]; break; case 117 : // lneg noim(117); break; case 118 : // fneg noim(118); break; case 119 : // dneg noim(119); break; case 120 : // ishl val = stack[sp-1] << stack[sp]; stack[--sp] = val; break; case 121 : // lshl noim(121); break; case 122 : // ishr val = stack[sp-1] >> stack[sp]; stack[--sp] = val; break; case 123 : // lshr noim(123); break; case 124 : // iushr val = stack[sp-1] >>> stack[sp]; stack[--sp] = val; break; case 125 : // lushr noim(125); break; case 126 : // iand val = stack[sp-1] & stack[sp]; stack[--sp] = val; break; case 127 : // land noim(127); break; case 128 : // ior val = stack[sp-1] | stack[sp]; stack[--sp] = val; break; case 129 : // lor noim(129); break; case 130 : // ixor val = stack[sp-1] ^ stack[sp]; stack[--sp] = val; break; case 131 : // lxor noim(131); break; case 132 : // iinc idx = readOpd8u(); stack[vp+idx] = stack[vp+idx]+readOpd8s(); break; case 133 : // i2l noim(133); break; case 134 : // i2f noim(134); break; case 135 : // i2d noim(135); break; case 136 : // l2i val = stack[sp]; // low part --sp; // drop high word stack[sp] = val; // low on stack break; case 137 : // l2f noim(137); break; case 138 : // l2d noim(138); break; case 139 : // f2i noim(139); break; case 140 : // f2l noim(140); break; case 141 : // f2d
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -