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


Java Bytecode.addLoad方法代码示例

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


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

示例1: insertAfterAdvice

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private int insertAfterAdvice(Bytecode code, Javac jv, String src,
                              ConstPool cp, CtClass rtype, int varNo)
    throws CompileError
{
    int pc = code.currentPc();
    if (rtype == CtClass.voidType) {
        code.addOpcode(Opcode.ACONST_NULL);
        code.addAstore(varNo);
        jv.compileStmnt(src);
        code.addOpcode(Opcode.RETURN);
        if (code.getMaxLocals() < 1)
            code.setMaxLocals(1);
    }
    else {
        code.addStore(varNo, rtype);
        jv.compileStmnt(src);
        code.addLoad(varNo, rtype);
        if (rtype.isPrimitive())
            code.addOpcode(((CtPrimitiveType)rtype).getReturnOp());
        else
            code.addOpcode(Opcode.ARETURN);
    }

    return code.currentPc() - pc;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:26,代码来源:CtBehavior.java

示例2: 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

示例3: setter

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * Creates a public setter method.  The setter method assigns the
 * value of the first parameter to the specified field
 * in the class to which this method is added.
 * The created method is not static even if the field is
 * static.  You may not change it to be static
 * by <code>setModifiers()</code> in <code>CtBehavior</code>.
 *
 * @param methodName        the name of the setter
 * @param field             the field accessed.
 */
public static CtMethod setter(String methodName, CtField field)
    throws CannotCompileException
{
    FieldInfo finfo = field.getFieldInfo2();
    String fieldType = finfo.getDescriptor();
    String desc = "(" + fieldType + ")V";
    ConstPool cp = finfo.getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(AccessFlag.PUBLIC);

    Bytecode code = new Bytecode(cp, 3, 3);
    try {
        String fieldName = finfo.getName();
        if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0) {
            code.addAload(0);
            code.addLoad(1, field.getType());
            code.addPutfield(Bytecode.THIS, fieldName, fieldType);
        }
        else {
            code.addLoad(1, field.getType());
            code.addPutstatic(Bytecode.THIS, fieldName, fieldType);
        }

        code.addReturn(null);
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    minfo.setCodeAttribute(code.toCodeAttribute());
    CtClass cc = field.getDeclaringClass();
    // a stack map is not needed.
    return new CtMethod(minfo, cc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:46,代码来源:CtNewMethod.java

示例4: delegator0

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static CtMethod delegator0(CtMethod delegate, CtClass declaring)
    throws CannotCompileException, NotFoundException
{
    MethodInfo deleInfo = delegate.getMethodInfo2();
    String methodName = deleInfo.getName();
    String desc = deleInfo.getDescriptor();
    ConstPool cp = declaring.getClassFile2().getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(deleInfo.getAccessFlags());

    ExceptionsAttribute eattr = deleInfo.getExceptionsAttribute();
    if (eattr != null)
        minfo.setExceptionsAttribute(
                            (ExceptionsAttribute)eattr.copy(cp, null));

    Bytecode code = new Bytecode(cp, 0, 0);
    boolean isStatic = Modifier.isStatic(delegate.getModifiers());
    CtClass deleClass = delegate.getDeclaringClass();
    CtClass[] params = delegate.getParameterTypes();
    int s;
    if (isStatic) {
        s = code.addLoadParameters(params, 0);
        code.addInvokestatic(deleClass, methodName, desc);
    }
    else {
        code.addLoad(0, deleClass);
        s = code.addLoadParameters(params, 1);
        code.addInvokespecial(deleClass, methodName, desc);
    }

    code.addReturn(delegate.getReturnType());
    code.setMaxLocals(++s);
    code.setMaxStack(s < 2 ? 2 : s); // for a 2-word return value
    minfo.setCodeAttribute(code.toCodeAttribute());
    // a stack map is not needed. 
    return new CtMethod(minfo, declaring);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:38,代码来源:CtNewMethod.java

示例5: makeCode2

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private void makeCode2(Bytecode save, Bytecode load,
                       int i, int n, CtClass[] paramTypes, int var)
{
    if (i < n) {
        int size = load.addLoad(var, paramTypes[i]);
        makeCode2(save, load, i + 1, n, paramTypes, var + size);
        save.addStore(var, paramTypes[i]);
    }
    else
        locals = var - maxLocals;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:12,代码来源:TransformBefore.java

示例6: compile

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
int compile(CtClass type, String name, Bytecode code,
            CtClass[] parameters, Javac drv)
    throws CannotCompileException
{
    if (parameters != null && nthParam < parameters.length) {
        code.addAload(0);
        int nth = nthParamToLocal(nthParam, parameters, false);
        int s = code.addLoad(nth, type) + 1;
        code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
        return s;       // stack size
    }
    else
        return 0;       // do not initialize
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:15,代码来源:CtField.java


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