Example #1
0
  public void rewrite() {
    int bytecode = Bytecodes._illegal;
    int hotspotcode = Bytecodes._illegal;
    int len = 0;

    for (int bci = 0; bci < code.length; ) {
      hotspotcode = Bytecodes.codeAt(method, bci);
      bytecode = Bytecodes.javaCode(hotspotcode);

      if (Assert.ASSERTS_ENABLED) {
        int code_from_buffer = 0xFF & code[bci];
        Assert.that(
            code_from_buffer == hotspotcode || code_from_buffer == Bytecodes._breakpoint,
            "Unexpected bytecode found in method bytecode buffer!");
      }

      // update the code buffer hotspot specific bytecode with the jvm bytecode
      code[bci] = (byte) (0xFF & bytecode);

      short cpoolIndex = 0;
      switch (bytecode) {
          // bytecodes with ConstantPoolCache index
        case Bytecodes._getstatic:
        case Bytecodes._putstatic:
        case Bytecodes._getfield:
        case Bytecodes._putfield:
        case Bytecodes._invokevirtual:
        case Bytecodes._invokespecial:
        case Bytecodes._invokestatic:
        case Bytecodes._invokeinterface:
          {
            cpoolIndex = getConstantPoolIndex(bci + 1);
            writeShort(code, bci + 1, cpoolIndex);
            break;
          }
      }

      len = Bytecodes.lengthFor(bytecode);
      if (len <= 0) len = Bytecodes.lengthAt(method, bci);

      if (DEBUG) {
        String operand = "";
        switch (len) {
          case 2:
            operand += code[bci + 1];
            break;
          case 3:
            operand += (cpoolIndex != 0) ? cpoolIndex : method.getBytecodeShortArg(bci + 1);
            break;
          case 5:
            operand += method.getBytecodeIntArg(bci + 1);
            break;
        }

        // the operand following # is not quite like javap output.
        // in particular, for goto & goto_w, the operand is PC relative
        // offset for jump. Javap adds relative offset with current PC
        // to give absolute bci to jump to.

        String message = "\t\t" + bci + " " + Bytecodes.name(bytecode);
        if (hotspotcode != bytecode) message += " [" + Bytecodes.name(hotspotcode) + "]";
        if (operand != "") message += " #" + operand;

        if (DEBUG) debugMessage(message);
      }

      bci += len;
    }
  }
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check bipush");
   }
 }
Example #3
0
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check fast_aaccess_0");
   }
 }
Example #4
0
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check getfield");
   }
 }