javassist.bytecode.Bytecode.add()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中javassist.bytecode.Bytecode.add()方法的一些代码示例,展示了Bytecode.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytecode.add()方法的具体详情如下:
包路径:javassist.bytecode.Bytecode
类名称:Bytecode
方法名:add

Bytecode.add介绍

[英]Appends an 8bit value to the end of the bytecode sequence.
[中]将8位值追加到字节码序列的末尾。

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Appends a 32bit value to the end of the bytecode sequence.
 */
public void add32bit(int value) {
  add(value >> 24, value >> 16, value >> 8, value);
}

代码示例来源:origin: redisson/redisson

/**
 * Appends NEWARRAY for primitive types.
 *
 * @param atype     <code>T_BOOLEAN</code>, <code>T_CHAR</code>, ...
 * @see Opcode
 */
public void addNewarray(int atype, int length) {
  addIconst(length);
  addOpcode(NEWARRAY);
  add(atype);
}

代码示例来源:origin: redisson/redisson

protected final int compileStringParameter(Bytecode code)
  throws CannotCompileException
{
  int nparam = stringParams.length;
  code.addIconst(nparam);
  code.addAnewarray(javaLangString);
  for (int j = 0; j < nparam; ++j) {
    code.add(Bytecode.DUP);         // dup
    code.addIconst(j);                      // iconst_<j>
    code.addLdc(stringParams[j]);   // ldc ...
    code.add(Bytecode.AASTORE);             // aastore
  }
  return 4;
}

代码示例来源:origin: redisson/redisson

/**
 * Appends RET.
 *
 * @param var       local variable
 */
public void addRet(int var) {
  if (var < 0x100) {
    addOpcode(RET);
    add(var);
  }
  else {
    addOpcode(WIDE);
    addOpcode(RET);
    addIndex(var);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Appends MULTINEWARRAY.
 *
 * @param desc      the type descriptor of the created array.
 * @param dim       dimensions.
 * @return          the value of <code>dim</code>.
 */
public int addMultiNewarray(String desc, int dim) {
  add(MULTIANEWARRAY);
  addIndex(constPool.addClassInfo(desc));
  add(dim);
  growStack(1 - dim);
  return dim;
}

代码示例来源:origin: redisson/redisson

/**
 * Appends LDC or LDC_W.
 *
 * @param i         index into the constant pool.
 */
public void addLdc(int i) {
  if (i > 0xFF) {
    addOpcode(LDC_W);
    addIndex(i);
  }
  else {
    addOpcode(LDC);
    add(i);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Appends MULTINEWARRAY.  The size of every dimension must have been
 * already pushed on the stack.
 *
 * @param clazz             the array type.
 * @param dim               the number of the dimensions.
 * @return                  the value of <code>dim</code>.
 */
public int addMultiNewarray(CtClass clazz, int dim) {
  add(MULTIANEWARRAY);
  addIndex(constPool.addClassInfo(clazz));
  add(dim);
  growStack(1 - dim);
  return dim;
}

代码示例来源:origin: redisson/redisson

/**
 * Appends a 16bit value to the end of the bytecode sequence.
 * It never changes the current stack depth.
 */
public void addIndex(int index) {
  add(index >> 8, index);
}

代码示例来源:origin: redisson/redisson

/**
 * Appends LLOAD or (WIDE) LLOAD_&lt;n&gt;
 *
 * @param n         an index into the local variable array.
 */
public void addLload(int n) {
  if (n < 4)
    addOpcode(30 + n);          // lload_<n>
  else if (n < 0x100) {
    addOpcode(LLOAD);           // lload
    add(n);
  }
  else {
    addOpcode(WIDE);
    addOpcode(LLOAD);
    addIndex(n);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Appends INVOKESPECIAL.
 *
 * @param index     the index of <code>CONSTANT_Methodref_info</code>
 *                  or <code>CONSTANT_InterfaceMethodref_info</code>
 * @param desc      the descriptor of the method signature.
 *
 * @see Descriptor#ofMethod(CtClass,CtClass[])
 * @see Descriptor#ofConstructor(CtClass[])
 */
public void addInvokespecial(int index, String desc) {
  add(INVOKESPECIAL);
  addIndex(index);
  growStack(Descriptor.dataSize(desc) - 1);
}

代码示例来源:origin: redisson/redisson

/**
 * Appends an 8bit opcode to the end of the bytecode sequence.
 * The current stack depth is updated.
 * <code>max_stack</code> is updated if the current stack depth
 * is the deepest so far.
 *
 * <p>Note: some instructions such as INVOKEVIRTUAL does not
 * update the current stack depth since the increment depends
 * on the method signature.
 * <code>growStack()</code> must be explicitly called.
 */
public void addOpcode(int code) {
  add(code);
  growStack(STACK_GROW[code]);
}

代码示例来源:origin: redisson/redisson

/**
 * Appends DLOAD or (WIDE) DLOAD_&lt;n&gt;
 *
 * @param n         an index into the local variable array.
 */
public void addDload(int n) {
  if (n < 4)
    addOpcode(38 + n);          // dload_<n>
  else if (n < 0x100) {
    addOpcode(DLOAD);           // dload
    add(n);
  }
  else {
    addOpcode(WIDE);
    addOpcode(DLOAD);
    addIndex(n);
  }
}

代码示例来源:origin: redisson/redisson

private void addInvokestatic(int clazz, String name, String desc,
               boolean isInterface) {
  add(INVOKESTATIC);
  int index;
  if (isInterface)
    index = constPool.addInterfaceMethodrefInfo(clazz, name, desc);
  else
    index = constPool.addMethodrefInfo(clazz, name, desc);
  addIndex(index);
  growStack(Descriptor.dataSize(desc));
}

代码示例来源:origin: redisson/redisson

/**
 * Appends FSTORE or FSTORE_&lt;n&gt;
 *
 * @param n         an index into the local variable array.
 */
public void addFstore(int n) {
  if (n < 4)
    addOpcode(67 + n);          // fstore_<n>
  else if (n < 0x100) {
    addOpcode(FSTORE);          // fstore
    add(n);
  }
  else {
    addOpcode(WIDE);
    addOpcode(FSTORE);
    addIndex(n);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Appends GETFIELD.
 *
 * @param c         the fully-qualified class name.
 * @param name      the field name.
 * @param type      the descriptor of the field type.
 *
 * @see Descriptor#of(CtClass)
 */
public void addGetfield(String c, String name, String type) {
  add(GETFIELD);
  int ci = constPool.addClassInfo(c);
  addIndex(constPool.addFieldrefInfo(ci, name, type));
  growStack(Descriptor.dataSize(type) - 1);
}

代码示例来源:origin: redisson/redisson

/**
 * Appends GETSTATIC.
 *
 * @param c         the class
 * @param name      the field name
 * @param type      the descriptor of the field type.
 *
 * @see Descriptor#of(CtClass)
 */
public void addGetstatic(CtClass c, String name, String type) {
  add(GETSTATIC);
  int ci = constPool.addClassInfo(c);
  addIndex(constPool.addFieldrefInfo(ci, name, type));
  growStack(Descriptor.dataSize(type));
}

代码示例来源:origin: redisson/redisson

/**
 * Appends GETSTATIC.
 *
 * @param c         the fully-qualified class name
 * @param name      the field name
 * @param type      the descriptor of the field type.
 *
 * @see Descriptor#of(CtClass)
 */
public void addGetstatic(String c, String name, String type) {
  add(GETSTATIC);
  int ci = constPool.addClassInfo(c);
  addIndex(constPool.addFieldrefInfo(ci, name, type));
  growStack(Descriptor.dataSize(type));
}

代码示例来源:origin: redisson/redisson

/**
 * Appends GETFIELD.
 *
 * @param c         the class.
 * @param name      the field name.
 * @param type      the descriptor of the field type.
 *
 * @see Descriptor#of(CtClass)
 */
public void addGetfield(CtClass c, String name, String type) {
  add(GETFIELD);
  int ci = constPool.addClassInfo(c);
  addIndex(constPool.addFieldrefInfo(ci, name, type));
  growStack(Descriptor.dataSize(type) - 1);
}

代码示例来源:origin: redisson/redisson

private void addPutstatic0(CtClass target, String classname,
              String fieldName, String desc) {
  add(PUTSTATIC);
  // target is null if it represents THIS.
  int ci = classname == null ? constPool.addClassInfo(target)
              : constPool.addClassInfo(classname);
  addIndex(constPool.addFieldrefInfo(ci, fieldName, desc));
  growStack(-Descriptor.dataSize(desc));
}

代码示例来源:origin: redisson/redisson

private void addPutfield0(CtClass target, String classname,
             String name, String desc) {
  add(PUTFIELD);
  // target is null if it represents THIS.
  int ci = classname == null ? constPool.addClassInfo(target)
                : constPool.addClassInfo(classname);
  addIndex(constPool.addFieldrefInfo(ci, name, desc));
  growStack(-1 - Descriptor.dataSize(desc));
}

相关文章