📄 wcetinstruction.java
字号:
package com.jopdesign.wcet;import org.apache.bcel.generic.Instruction;import org.apache.bcel.generic.InstructionHandle;/** * It has wcet info on byte code instruction granlularity. Should we consider * making a class that wraps the microcodes into objects? */public class WCETInstruction { // indicate that wcet is not available for this bytecode public static final int WCETNOTAVAILABLE = -1;public static final int a = -1; // should be removed from WCETAnalyser! // the read and write wait states // ram_cnt - 1 public static final int r = 1; public static final int w = 1; // cache read wait state (r-1) public static final int c = 0; //Native bytecodes (see jvm.asm) private static final int JOPSYS_RD = 209; private static final int JOPSYS_WR = 210; private static final int JOPSYS_RDMEM = 211; private static final int JOPSYS_WRMEM = 212; private static final int JOPSYS_RDINT = 213; private static final int JOPSYS_WRINT = 214; private static final int JOPSYS_GETSP = 215; private static final int JOPSYS_SETSP = 216; private static final int JOPSYS_GETVP = 217; private static final int JOPSYS_SETVP = 218; private static final int JOPSYS_INT2EXT = 219; private static final int JOPSYS_EXT2INT = 220; private static final int JOPSYS_NOP = 221; private static String ILLEGAL_OPCODE = "ILLEGAL_OPCODE"; /** * Names of opcodes. */ protected static final String[] OPCODE_NAMES = { "nop", "aconst_null", "iconst_m1", "iconst_0", "iconst_1", "iconst_2", "iconst_3", "iconst_4", "iconst_5", "lconst_0", "lconst_1", "fconst_0", "fconst_1", "fconst_2", "dconst_0", "dconst_1", "bipush", "sipush", "ldc", "ldc_w", "ldc2_w", "iload", "lload", "fload", "dload", "aload", "iload_0", "iload_1", "iload_2", "iload_3", "lload_0", "lload_1", "lload_2", "lload_3", "fload_0", "fload_1", "fload_2", "fload_3", "dload_0", "dload_1", "dload_2", "dload_3", "aload_0", "aload_1", "aload_2", "aload_3", "iaload", "laload", "faload", "daload", "aaload", "baload", "caload", "saload", "istore", "lstore", "fstore", "dstore", "astore", "istore_0", "istore_1", "istore_2", "istore_3", "lstore_0", "lstore_1", "lstore_2", "lstore_3", "fstore_0", "fstore_1", "fstore_2", "fstore_3", "dstore_0", "dstore_1", "dstore_2", "dstore_3", "astore_0", "astore_1", "astore_2", "astore_3", "iastore", "lastore", "fastore", "dastore", "aastore", "bastore", "castore", "sastore", "pop", "pop2", "dup", "dup_x1", "dup_x2", "dup2", "dup2_x1", "dup2_x2", "swap", "iadd", "ladd", "fadd", "dadd", "isub", "lsub", "fsub", "dsub", "imul", "lmul", "fmul", "dmul", "idiv", "ldiv", "fdiv", "ddiv", "irem", "lrem", "frem", "drem", "ineg", "lneg", "fneg", "dneg", "ishl", "lshl", "ishr", "lshr", "iushr", "lushr", "iand", "land", "ior", "lor", "ixor", "lxor", "iinc", "i2l", "i2f", "i2d", "l2i", "l2f", "l2d", "f2i", "f2l", "f2d", "d2i", "d2l", "d2f", "i2b", "i2c", "i2s", "lcmp", "fcmpl", "fcmpg", "dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge", "ifgt", "ifle", "if_icmpeq", "if_icmpne", "if_icmplt", "if_icmpge", "if_icmpgt", "if_icmple", "if_acmpeq", "if_acmpne", "goto", "jsr", "ret", "tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn", "dreturn", "areturn", "return", "getstatic", "putstatic", "getfield", "putfield", "invokevirtual", "invokespecial", "invokestatic", "invokeinterface", ILLEGAL_OPCODE, "new", "newarray", "anewarray", "arraylength", "athrow", "checkcast", "instanceof", "monitorenter", "monitorexit", "wide", "multianewarray", "ifnull", "ifnonnull", "goto_w", "jsr_w", "breakpoint", ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE, ILLEGAL_OPCODE }; // TODO: make those missing (the rup/ms speciffic ones, but are they // reachable?) /** * Same as getWCET, but using the handle. * * @param ih * @param pmiss true if the cache is missed and false if there is a cache hit * @return wcet or WCETNOTAVAILABLE (-1) */ static int getCyclesFromHandle(InstructionHandle ih, boolean pmiss, int n) { Instruction ins = ih.getInstruction(); int opcode = ins.getOpcode(); return getCycles(opcode, pmiss, n); } /** * Get the name using the opcode. Used when WCA toWCAString(). * * @param opcode * @return name or "ILLEGAL_OPCODE" */ static String getNameFromOpcode(int opcode) { return OPCODE_NAMES[opcode]; } /** * See the WCET values * @return table body of opcodes with info */ static String toWCAString() { StringBuffer sb = new StringBuffer(); sb.append("Table of WCETInstruction cycles\n"); sb .append("=============================================================\n"); sb .append("Instruction Hit cycles Miss cycles Mich. info\n"); sb.append(" n=0/1000 n=0/1000\n"); sb .append("-------------------------------------------------------------\n"); for (int op = 0; op <= 255; op++) { // name (25) String str = new String("[" + op + "] " + getNameFromOpcode(op)); sb.append(WU.postpad(str, 25)); //hit n={0,1000} String hitstr = getCycles(op, false, 0) + "/" + getCycles(op, false, 1000); hitstr = WU.prepad(hitstr, 12); //miss n={0,1000} String missstr = getCycles(op, true, 0) + "/" + getCycles(op, true, 1000); missstr = WU.prepad(missstr, 12); sb.append(hitstr + missstr + "\n"); } sb .append("=============================================================\n"); sb.append("Info: b(n=1000)=" + calculateB(false, 1000) + " c=" + c + " r=" + r + " w=" + w + "\n"); sb .append("Signatures: V void, Z boolean, B byte, C char, S short, I int, J long, F float, D double, L class, [ array\n"); return sb.toString(); } /** * Returns the wcet count for the instruction. * * @see table D.1 in ms thesis * @param opcode * @param pmiss true if cacle is misses and false if a cache hit * @return wcet cycle count or -1 if wcet not available */ static int getCycles(int opcode, boolean pmiss, int n) { int wcet = 0; int b = -1; // cache load time b = calculateB(!pmiss, n); switch (opcode) { // NOP = 0 case org.apache.bcel.Constants.NOP: wcet = 1; break; // ACONST_NULL = 1 case org.apache.bcel.Constants.ACONST_NULL: wcet = 1; break; // ICONST_M1 = 2 case org.apache.bcel.Constants.ICONST_M1: wcet = 1; break; // ICONST_0 = 3 case org.apache.bcel.Constants.ICONST_0: wcet = 1; break; // ICONST_1 = 4 case org.apache.bcel.Constants.ICONST_1: wcet = 1; break; // ICONST_2 = 5 case org.apache.bcel.Constants.ICONST_2: wcet = 1; break; // ICONST_3 = 6 case org.apache.bcel.Constants.ICONST_3: wcet = 1; break; // ICONST_4 = 7 case org.apache.bcel.Constants.ICONST_4: wcet = 1; break; // ICONST_5 = 8 case org.apache.bcel.Constants.ICONST_5: wcet = 1; break; // LCONST_0 = 9 case org.apache.bcel.Constants.LCONST_0: wcet = 2; break; // LCONST_1 = 10 case org.apache.bcel.Constants.LCONST_1: wcet = 2; break; // FCONST_0 = 11 case org.apache.bcel.Constants.FCONST_0: wcet = -1; break; // FCONST_1 = 12 case org.apache.bcel.Constants.FCONST_1: wcet = -1; break; // FCONST_2 = 13 case org.apache.bcel.Constants.FCONST_2: wcet = -1; break; // DCONST_0 = 14 case org.apache.bcel.Constants.DCONST_0: wcet = -1; break; // DCONST_1 = 15 case org.apache.bcel.Constants.DCONST_1: wcet = -1; break; // BIPUSH = 16 case org.apache.bcel.Constants.BIPUSH: wcet = 2; break; // SIPUSH = 17 case org.apache.bcel.Constants.SIPUSH: wcet = 3; break; // LDC = 18 case org.apache.bcel.Constants.LDC: wcet = 7 + r; break; // LDC_W = 19 case org.apache.bcel.Constants.LDC_W: wcet = 8 + r; break; // LDC2_W = 20 case org.apache.bcel.Constants.LDC2_W: wcet = 17; if (r > 2) { wcet += r - 2; } if (r > 1) { wcet += r - 1; } break; // ILOAD = 21 case org.apache.bcel.Constants.ILOAD: wcet = 2; break; // LLOAD = 22 case org.apache.bcel.Constants.LLOAD: wcet = 11; break; // FLOAD = 23 case org.apache.bcel.Constants.FLOAD: wcet = 2; break; // DLOAD = 24 case org.apache.bcel.Constants.DLOAD: wcet = 11; break; // ALOAD = 25 case org.apache.bcel.Constants.ALOAD: wcet = 2; break; // ILOAD_0 = 26 case org.apache.bcel.Constants.ILOAD_0: wcet = 1; break; // ILOAD_1 = 27 case org.apache.bcel.Constants.ILOAD_1: wcet = 1; break; // ILOAD_2 = 28 case org.apache.bcel.Constants.ILOAD_2: wcet = 1; break; // ILOAD_3 = 29 case org.apache.bcel.Constants.ILOAD_3: wcet = 1; break; // LLOAD_0 = 30 case org.apache.bcel.Constants.LLOAD_0: wcet = 2; break; // LLOAD_1 = 31 case org.apache.bcel.Constants.LLOAD_1: wcet = 2; break; // LLOAD_2 = 32 case org.apache.bcel.Constants.LLOAD_2: wcet = 2; break; // LLOAD_3 = 33 case org.apache.bcel.Constants.LLOAD_3: wcet = 11; break; // FLOAD_0 = 34 case org.apache.bcel.Constants.FLOAD_0: wcet = 1; break; // FLOAD_1 = 35 case org.apache.bcel.Constants.FLOAD_1: wcet = 1; break; // FLOAD_2 = 36 case org.apache.bcel.Constants.FLOAD_2: wcet = 1; break; // FLOAD_3 = 37 case org.apache.bcel.Constants.FLOAD_3: wcet = 1; break; // DLOAD_0 = 38 case org.apache.bcel.Constants.DLOAD_0: wcet = 2; break; // DLOAD_1 = 39 case org.apache.bcel.Constants.DLOAD_1: wcet = 2; break; // DLOAD_2 = 40 case org.apache.bcel.Constants.DLOAD_2: wcet = 2; break; // DLOAD_3 = 41 case org.apache.bcel.Constants.DLOAD_3: wcet = 11; break; // ALOAD_0 = 42 case org.apache.bcel.Constants.ALOAD_0: wcet = 1; break; // ALOAD_1 = 43 case org.apache.bcel.Constants.ALOAD_1: wcet = 1; break; // ALOAD_2 = 44 case org.apache.bcel.Constants.ALOAD_2: wcet = 1; break; // ALOAD_3 = 45 case org.apache.bcel.Constants.ALOAD_3: wcet = 1; break; // IALOAD = 46 case org.apache.bcel.Constants.IALOAD: wcet = 33 + 3*r; break; // LALOAD = 47 case org.apache.bcel.Constants.LALOAD: wcet = -1; break; // FALOAD = 48 case org.apache.bcel.Constants.FALOAD: wcet = 33 + 3*r; break; // DALOAD = 49 case org.apache.bcel.Constants.DALOAD: wcet = -1; break; // AALOAD = 50 case org.apache.bcel.Constants.AALOAD: wcet = 33 + 3*r; break; // BALOAD = 51 case org.apache.bcel.Constants.BALOAD: wcet = 33 + 3*r; break; // CALOAD = 52 case org.apache.bcel.Constants.CALOAD: wcet = 33 + 3*r; break; // SALOAD = 53 case org.apache.bcel.Constants.SALOAD: wcet = 33 + 3*r; break; // ISTORE = 54 case org.apache.bcel.Constants.ISTORE: wcet = 2; break; // LSTORE = 55 case org.apache.bcel.Constants.LSTORE: wcet = 11; break; // FSTORE = 56 case org.apache.bcel.Constants.FSTORE: wcet = 2; break; // DSTORE = 57 case org.apache.bcel.Constants.DSTORE: wcet = 11; break; // ASTORE = 58 case org.apache.bcel.Constants.ASTORE: wcet = 2; break; // ISTORE_0 = 59 case org.apache.bcel.Constants.ISTORE_0: wcet = 1; break; // ISTORE_1 = 60 case org.apache.bcel.Constants.ISTORE_1: wcet = 1; break; // ISTORE_2 = 61 case org.apache.bcel.Constants.ISTORE_2: wcet = 1; break; // ISTORE_3 = 62 case org.apache.bcel.Constants.ISTORE_3: wcet = 1; break; // LSTORE_0 = 63 case org.apache.bcel.Constants.LSTORE_0: wcet = 2; break; // LSTORE_1 = 64 case org.apache.bcel.Constants.LSTORE_1: wcet = 2; break; // LSTORE_2 = 65 case org.apache.bcel.Constants.LSTORE_2: wcet = 2; break; // LSTORE_3 = 66 case org.apache.bcel.Constants.LSTORE_3: wcet = 11; break; // FSTORE_0 = 67 case org.apache.bcel.Constants.FSTORE_0: wcet = 1; break; // FSTORE_1 = 68 case org.apache.bcel.Constants.FSTORE_1: wcet = 1; break; // FSTORE_2 = 69 case org.apache.bcel.Constants.FSTORE_2: wcet = 1; break; // FSTORE_3 = 70 case org.apache.bcel.Constants.FSTORE_3: wcet = 1; break; // DSTORE_0 = 71 case org.apache.bcel.Constants.DSTORE_0: wcet = 2; break; // DSTORE_1 = 72 case org.apache.bcel.Constants.DSTORE_1: wcet = 2; break; // DSTORE_2 = 73 case org.apache.bcel.Constants.DSTORE_2: wcet = 2; break; // DSTORE_3 = 74 case org.apache.bcel.Constants.DSTORE_3: wcet = 11; break; // ASTORE_0 = 75 case org.apache.bcel.Constants.ASTORE_0: wcet = 1; break; // ASTORE_1 = 76 case org.apache.bcel.Constants.ASTORE_1: wcet = 1; break; // ASTORE_2 = 77 case org.apache.bcel.Constants.ASTORE_2: wcet = 1; break; // ASTORE_3 = 78 case org.apache.bcel.Constants.ASTORE_3: wcet = 1; break; // IASTORE = 79 case org.apache.bcel.Constants.IASTORE: wcet = 36+2*r+w; break; // LASTORE = 80 case org.apache.bcel.Constants.LASTORE: wcet = -1; break; // FASTORE = 81 case org.apache.bcel.Constants.FASTORE: wcet = 36+2*r+w; break; // DASTORE = 82 case org.apache.bcel.Constants.DASTORE: wcet = -1; break; // AASTORE = 83 case org.apache.bcel.Constants.AASTORE: wcet = 36+2*r+w; break; // BASTORE = 84 case org.apache.bcel.Constants.BASTORE: wcet = 36+2*r+w; break; // CASTORE = 85 case org.apache.bcel.Constants.CASTORE: wcet = 36+2*r+w; break; // SASTORE = 86 case org.apache.bcel.Constants.SASTORE: wcet = 36+2*r+w; break; // POP = 87 case org.apache.bcel.Constants.POP: wcet = 1; break; // POP2 = 88 case org.apache.bcel.Constants.POP2: wcet = 2; break; // DUP = 89 case org.apache.bcel.Constants.DUP: wcet = 1; break; // DUP_X1 = 90 case org.apache.bcel.Constants.DUP_X1: wcet = 5; break; // DUP_X2 = 91 case org.apache.bcel.Constants.DUP_X2: wcet = -1; break; // DUP2 = 92 case org.apache.bcel.Constants.DUP2: wcet = 6; break; // DUP2_X1 = 93 case org.apache.bcel.Constants.DUP2_X1: wcet = -1; break; // DUP2_X2 = 94 case org.apache.bcel.Constants.DUP2_X2: wcet = -1; break; // SWAP = 95 case org.apache.bcel.Constants.SWAP: wcet = -1; break; // IADD = 96 case org.apache.bcel.Constants.IADD: wcet = 1; break; // LADD = 97 case org.apache.bcel.Constants.LADD: wcet = -1; break; // FADD = 98 case org.apache.bcel.Constants.FADD: wcet = -1; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -