当前位置: 首页>>代码示例>>Java>>正文


Java Bytecode.addIconst方法代码示例

本文整理汇总了Java中scouter.javassist.bytecode.Bytecode.addIconst方法的典型用法代码示例。如果您正苦于以下问题:Java Bytecode.addIconst方法的具体用法?Java Bytecode.addIconst怎么用?Java Bytecode.addIconst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scouter.javassist.bytecode.Bytecode的用法示例。


在下文中一共展示了Bytecode.addIconst方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: atAssignParamList

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected void atAssignParamList(CtClass[] params, Bytecode code)
    throws CompileError
{
    if (params == null)
        return;

    int varNo = indexOfParam1();
    int n = params.length;
    for (int i = 0; i < n; ++i) {
        code.addOpcode(DUP);
        code.addIconst(i);
        code.addOpcode(AALOAD);
        compileUnwrapValue(params[i], code);
        code.addStore(varNo, params[i]);
        varNo += is2word(exprType, arrayDim) ? 2 : 1;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:18,代码来源:JvstCodeGen.java

示例2: callFind2Methods

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * @param thisMethod        might be null.
 */
private static void callFind2Methods(Bytecode code, String superMethod, String thisMethod,
                                     int index, String desc, int classVar, int arrayVar) {
    String findClass = RuntimeSupport.class.getName();
    String findDesc
        = "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/reflect/Method;)V";

    code.addAload(classVar);
    code.addLdc(superMethod);
    if (thisMethod == null)
        code.addOpcode(Opcode.ACONST_NULL);
    else
        code.addLdc(thisMethod);

    code.addIconst(index);
    code.addLdc(desc);
    code.addAload(arrayVar);
    code.addInvokestatic(findClass, "find2Methods", findDesc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:22,代码来源:ProxyFactory.java

示例3: makeParameterList

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static void makeParameterList(Bytecode code, Class[] params) {
    int regno = 1;
    int n = params.length;
    code.addIconst(n);
    code.addAnewarray("java/lang/Object");
    for (int i = 0; i < n; i++) {
        code.addOpcode(Opcode.DUP);
        code.addIconst(i);
        Class type = params[i];
        if (type.isPrimitive())
            regno = makeWrapper(code, type, regno);
        else {
            code.addAload(regno);
            regno++;
        }

        code.addOpcode(Opcode.AASTORE);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:20,代码来源:ProxyFactory.java

示例4: compileParameterList

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
public static int compileParameterList(Bytecode code,
                            CtClass[] params, int regno) {
    if (params == null) {
        code.addIconst(0);                          // iconst_0
        code.addAnewarray(javaLangObject);          // anewarray Object
        return 1;
    }
    else {
        CtClass[] args = new CtClass[1];
        int n = params.length;
        code.addIconst(n);                          // iconst_<n>
        code.addAnewarray(javaLangObject);          // anewarray Object
        for (int i = 0; i < n; ++i) {
            code.addOpcode(Bytecode.DUP);           // dup
            code.addIconst(i);                      // iconst_<i>
            if (params[i].isPrimitive()) {
                CtPrimitiveType pt = (CtPrimitiveType)params[i];
                String wrapper = pt.getWrapperName();
                code.addNew(wrapper);               // new <wrapper>
                code.addOpcode(Bytecode.DUP);       // dup
                int s = code.addLoad(regno, pt);    // ?load <regno>
                regno += s;
                args[0] = pt;
                code.addInvokespecial(wrapper, "<init>",
                            Descriptor.ofMethod(CtClass.voidType, args));
                                                    // invokespecial
            }
            else {
                code.addAload(regno);               // aload <regno>
                ++regno;
            }

            code.addOpcode(Bytecode.AASTORE);       // aastore
        }

        return 8;
    }
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:39,代码来源:JvstCodeGen.java

示例5: compileStringParameter

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
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;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:16,代码来源:CtField.java

示例6: compile

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
int compile(CtClass type, String name, Bytecode code,
            CtClass[] parameters, Javac drv)
    throws CannotCompileException
{
    code.addAload(0);
    code.addIconst(value);
    code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
    return 2;   // stack size
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:10,代码来源:CtField.java

示例7: compileIfStatic

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
int compileIfStatic(CtClass type, String name, Bytecode code,
                    Javac drv) throws CannotCompileException
{
    code.addIconst(value);
    code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type));
    return 1;   // stack size
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:8,代码来源:CtField.java

示例8: compile

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
int compile(Bytecode code) throws CannotCompileException {
    code.addIconst(param);
    return 1;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:5,代码来源:CtMethod.java

示例9: insertAfterHandler

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private int insertAfterHandler(boolean asFinally, Bytecode b,
                               CtClass rtype, int returnVarNo,
                               Javac javac, String src)
    throws CompileError
{
    if (!asFinally)
        return 0;

    int var = b.getMaxLocals();
    b.incMaxLocals(1);
    int pc = b.currentPc();
    b.addAstore(var);   // store an exception
    if (rtype.isPrimitive()) {
        char c = ((CtPrimitiveType)rtype).getDescriptor();
        if (c == 'D') {
            b.addDconst(0.0);
            b.addDstore(returnVarNo);
        }
        else if (c == 'F') {
            b.addFconst(0);
            b.addFstore(returnVarNo);
        }
        else if (c == 'J') {
            b.addLconst(0);
            b.addLstore(returnVarNo);
        }
        else if (c == 'V') {
            b.addOpcode(Opcode.ACONST_NULL);
            b.addAstore(returnVarNo);
        }
        else { // int, boolean, char, short, ...
            b.addIconst(0);
            b.addIstore(returnVarNo);
        }
    }
    else {
        b.addOpcode(Opcode.ACONST_NULL);
        b.addAstore(returnVarNo);
    }

    javac.compileStmnt(src);
    b.addAload(var);
    b.addOpcode(Opcode.ATHROW);
    return b.currentPc() - pc;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:46,代码来源:CtBehavior.java

示例10: addClassInitializer

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static void addClassInitializer(ClassFile cf, ConstPool cp,
                                String classname, int size, ArrayList forwarders)
    throws CannotCompileException
{
    FieldInfo finfo = new FieldInfo(cp, HOLDER, HOLDER_TYPE);
    finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.STATIC);
    cf.addField(finfo);
    MethodInfo minfo = new MethodInfo(cp, "<clinit>", "()V");
    minfo.setAccessFlags(AccessFlag.STATIC);
    setThrows(minfo, cp, new Class[] { ClassNotFoundException.class });

    Bytecode code = new Bytecode(cp, 0, 2);
    code.addIconst(size * 2);
    code.addAnewarray("java.lang.reflect.Method");
    final int varArray = 0;
    code.addAstore(varArray);

    // forName() must be called here.  Otherwise, the class might be
    // invisible.
    code.addLdc(classname);
    code.addInvokestatic("java.lang.Class",
            "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
    final int varClass = 1;
    code.addAstore(varClass);

    Iterator it = forwarders.iterator();
    while (it.hasNext()) {
        Find2MethodsArgs args = (Find2MethodsArgs)it.next();
        callFind2Methods(code, args.methodName, args.delegatorName,
                         args.origIndex, args.descriptor, varClass, varArray);
    }

    code.addAload(varArray);
    code.addPutstatic(classname, HOLDER, HOLDER_TYPE);

    code.addLconst(SERIAL_VERSION_UID_VALUE);
    code.addPutstatic(classname, SERIAL_VERSION_UID_FIELD, SERIAL_VERSION_UID_TYPE);
    code.addOpcode(Bytecode.RETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
    cf.addMethod(minfo);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:42,代码来源:ProxyFactory.java

示例11: makeForwarder

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * @param delegatorName     null if the original method is abstract.
 */
private static MethodInfo makeForwarder(String thisClassName,
                Method meth, String desc, ConstPool cp,
                Class declClass, String delegatorName, int index,
                ArrayList forwarders) {
    MethodInfo forwarder = new MethodInfo(cp, meth.getName(), desc);
    forwarder.setAccessFlags(Modifier.FINAL
                | (meth.getModifiers() & ~(Modifier.ABSTRACT
                                           | Modifier.NATIVE
                                           | Modifier.SYNCHRONIZED)));
    setThrows(forwarder, cp, meth);
    int args = Descriptor.paramSize(desc);
    Bytecode code = new Bytecode(cp, 0, args + 2);
    /*
     * static {
     *   methods[index * 2]
     *     = RuntimeSupport.findSuperMethod(this, <overridden name>, <desc>);
     *   methods[index * 2 + 1]
     *     = RuntimeSupport.findMethod(this, <delegator name>, <desc>);
     *     or = null // the original method is abstract.
     * }
     *     :
     * return ($r)handler.invoke(this, methods[index * 2],
     *                methods[index * 2 + 1], $args);
     */
    int origIndex = index * 2;
    int delIndex = index * 2 + 1;
    int arrayVar = args + 1;
    code.addGetstatic(thisClassName, HOLDER, HOLDER_TYPE);
    code.addAstore(arrayVar);

    forwarders.add(new Find2MethodsArgs(meth.getName(), delegatorName, desc, origIndex));

    code.addAload(0);
    code.addGetfield(thisClassName, HANDLER, HANDLER_TYPE);
    code.addAload(0);

    code.addAload(arrayVar);
    code.addIconst(origIndex);
    code.addOpcode(Opcode.AALOAD);

    code.addAload(arrayVar);
    code.addIconst(delIndex);
    code.addOpcode(Opcode.AALOAD);

    makeParameterList(code, meth.getParameterTypes());
    code.addInvokeinterface(MethodHandler.class.getName(), "invoke",
        "(Ljava/lang/Object;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;",
        5);
    Class retType = meth.getReturnType();
    addUnwrapper(code, retType);
    addReturn(code, retType);

    CodeAttribute ca = code.toCodeAttribute();
    forwarder.setCodeAttribute(ca);
    return forwarder;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:60,代码来源:ProxyFactory.java


注:本文中的scouter.javassist.bytecode.Bytecode.addIconst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。