/** * Appends a 32bit value to the end of the bytecode sequence. */ public void add32bit(int value) { add(value >> 24, value >> 16, value >> 8, value); }
/** * 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); }
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; }
/** * 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); } }
/** * 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; }
/** * 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); } }
/** * 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; }
/** * 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); }
/** * Appends LLOAD or (WIDE) LLOAD_<n> * * @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); } }
/** * 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); }
/** * 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]); }
/** * Appends DLOAD or (WIDE) DLOAD_<n> * * @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); } }
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)); }
/** * Appends FSTORE or FSTORE_<n> * * @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); } }
/** * 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); }
/** * 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)); }
/** * 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)); }
/** * 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); }
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)); }
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)); }