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


Java Bytecode.addAstore方法代码示例

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


在下文中一共展示了Bytecode.addAstore方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: makeCode

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected void makeCode(CtClass[] paramTypes, ConstPool cp) {
    Bytecode save = new Bytecode(cp, 0, 0);
    Bytecode load = new Bytecode(cp, 0, 0);

    int var = maxLocals;
    int len = (paramTypes == null) ? 0 : paramTypes.length;
    load.addAload(var);
    makeCode2(save, load, 0, len, paramTypes, var + 1);
    save.addAstore(var);

    saveCode = save.get();
    loadCode = load.get();
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:14,代码来源:TransformBefore.java

示例3: storeStack

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
static final void storeStack(CtClass[] params, boolean isStaticCall,
        int regno, Bytecode bytecode) {
    storeStack0(0, params.length, params, regno + 1, bytecode);
    if (isStaticCall)
        bytecode.addOpcode(ACONST_NULL);

    bytecode.addAstore(regno);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:9,代码来源:Expr.java

示例4: doit

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected boolean doit(Bytecode b, int opcode) {
    switch (opcode) {
    case Opcode.RETURN :
        jsrJmp(b);
        break;
    case ARETURN :
        b.addAstore(getVar(1));
        jsrJmp(b);
        b.addAload(var);
        break;
    case IRETURN :
        b.addIstore(getVar(1));
        jsrJmp(b);
        b.addIload(var);
        break;
    case LRETURN :
        b.addLstore(getVar(2));
        jsrJmp(b);
        b.addLload(var);
        break;
    case DRETURN :
        b.addDstore(getVar(2));
        jsrJmp(b);
        b.addDload(var);
        break;
    case FRETURN :
        b.addFstore(getVar(1));
        jsrJmp(b);
        b.addFload(var);
        break;
    default :
        throw new RuntimeException("fatal");
    }

    return false;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:37,代码来源:MemberCodeGen.java

示例5: atSyncStmnt

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private void atSyncStmnt(Stmnt st) throws CompileError {
    int nbreaks = getListSize(breakList);
    int ncontinues = getListSize(continueList);

    compileExpr(st.head());
    if (exprType != CLASS && arrayDim == 0)
        throw new CompileError("bad type expr for synchronized block");

    Bytecode bc = bytecode;
    final int var = bc.getMaxLocals();
    bc.incMaxLocals(1);
    bc.addOpcode(DUP);
    bc.addAstore(var);
    bc.addOpcode(MONITORENTER);

    ReturnHook rh = new ReturnHook(this) {
        protected boolean doit(Bytecode b, int opcode) {
            b.addAload(var);
            b.addOpcode(MONITOREXIT);
            return false;
        }
    };

    int pc = bc.currentPc();
    Stmnt body = (Stmnt)st.tail();
    if (body != null)
        body.accept(this);

    int pc2 = bc.currentPc();
    int pc3 = 0;
    if (!hasReturned) {
        rh.doit(bc, 0);     // the 2nd arg is ignored.
        bc.addOpcode(Opcode.GOTO);
        pc3 = bc.currentPc();
        bc.addIndex(0);
    }

    if (pc < pc2) {         // if the body is not empty
        int pc4 = bc.currentPc();
        rh.doit(bc, 0);         // the 2nd arg is ignored.
        bc.addOpcode(ATHROW);
        bc.addExceptionHandler(pc, pc2, pc4, 0);
    }

    if (!hasReturned)
        bc.write16bit(pc3, bc.currentPc() - pc3 + 1);

    rh.remove(this);

    if (getListSize(breakList) != nbreaks
        || getListSize(continueList) != ncontinues)
        throw new CompileError(
            "sorry, cannot break/continue in synchronized block");
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:55,代码来源:CodeGen.java

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

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

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

示例9: replace2

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private void replace2(String statement)
    throws CompileError, NotFoundException, BadBytecode,
           CannotCompileException
{
    thisClass.getClassFile();   // to call checkModify().
    ConstPool constPool = getConstPool();
    int pos = currentPos;
    CtClass retType;
    int codeLength;
    int index = 0;
    int dim = 1;
    String desc;
    if (opcode == Opcode.NEWARRAY) {
        index = iterator.byteAt(currentPos + 1);    // atype
        CtPrimitiveType cpt = (CtPrimitiveType)getPrimitiveType(index);
        desc = "[" + cpt.getDescriptor();
        codeLength = 2;
    }
    else if (opcode == Opcode.ANEWARRAY) {
        index = iterator.u16bitAt(pos + 1);
        desc = constPool.getClassInfo(index);
        if (desc.startsWith("["))
            desc = "[" + desc;
        else
            desc = "[L" + desc + ";";

        codeLength = 3;
    }
    else if (opcode == Opcode.MULTIANEWARRAY) {
        index = iterator.u16bitAt(currentPos + 1);
        desc = constPool.getClassInfo(index);
        dim = iterator.byteAt(currentPos + 3);
        codeLength = 4;
    }
    else
        throw new RuntimeException("bad opcode: " + opcode);

    retType = Descriptor.toCtClass(desc, thisClass.getClassPool());

    Javac jc = new Javac(thisClass);
    CodeAttribute ca = iterator.get();

    CtClass[] params = new CtClass[dim];
    for (int i = 0; i < dim; ++i)
        params[i] = CtClass.intType;

    int paramVar = ca.getMaxLocals();
    jc.recordParams(javaLangObject, params,
                    true, paramVar, withinStatic());

    /* Is $_ included in the source code?
     */
    checkResultValue(retType, statement);
    int retVar = jc.recordReturnType(retType, true);
    jc.recordProceed(new ProceedForArray(retType, opcode, index, dim));

    Bytecode bytecode = jc.getBytecode();
    storeStack(params, true, paramVar, bytecode);
    jc.recordLocalVariables(ca, pos);

    bytecode.addOpcode(Opcode.ACONST_NULL);        // initialize $_
    bytecode.addAstore(retVar);

    jc.compileStmnt(statement);
    bytecode.addAload(retVar);

    replace0(pos, bytecode, codeLength);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:69,代码来源:NewArray.java

示例10: atTryStmnt

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
protected void atTryStmnt(Stmnt st) throws CompileError {
    Bytecode bc = bytecode;
    Stmnt body = (Stmnt)st.getLeft();
    if (body == null)
        return;

    ASTList catchList = (ASTList)st.getRight().getLeft();
    Stmnt finallyBlock = (Stmnt)st.getRight().getRight().getLeft();
    ArrayList gotoList = new ArrayList(); 

    JsrHook jsrHook = null;
    if (finallyBlock != null)
        jsrHook = new JsrHook(this);

    int start = bc.currentPc();
    body.accept(this);
    int end = bc.currentPc();
    if (start == end)
        throw new CompileError("empty try block");

    boolean tryNotReturn = !hasReturned;
    if (tryNotReturn) {
        bc.addOpcode(Opcode.GOTO);
        gotoList.add(new Integer(bc.currentPc()));
        bc.addIndex(0);   // correct later
    }

    int var = getMaxLocals();
    incMaxLocals(1);
    while (catchList != null) {
        // catch clause
        Pair p = (Pair)catchList.head();
        catchList = catchList.tail();
        Declarator decl = (Declarator)p.getLeft();
        Stmnt block = (Stmnt)p.getRight();

        decl.setLocalVar(var);

        CtClass type = resolver.lookupClassByJvmName(decl.getClassName());
        decl.setClassName(MemberResolver.javaToJvmName(type.getName()));
        bc.addExceptionHandler(start, end, bc.currentPc(), type);
        bc.growStack(1);
        bc.addAstore(var);
        hasReturned = false;
        if (block != null)
            block.accept(this);

        if (!hasReturned) {
            bc.addOpcode(Opcode.GOTO);
            gotoList.add(new Integer(bc.currentPc()));
            bc.addIndex(0);   // correct later
            tryNotReturn = true;
        }
    }

    if (finallyBlock != null) {
        jsrHook.remove(this);
        // catch (any) clause
        int pcAnyCatch = bc.currentPc();
        bc.addExceptionHandler(start, pcAnyCatch, pcAnyCatch, 0);
        bc.growStack(1);
        bc.addAstore(var);
        hasReturned = false;
        finallyBlock.accept(this);
        if (!hasReturned) {
            bc.addAload(var);
            bc.addOpcode(ATHROW);
        }

        addFinally(jsrHook.jsrList, finallyBlock);
    }

    int pcEnd = bc.currentPc();
    patchGoto(gotoList, pcEnd);
    hasReturned = !tryNotReturn;
    if (finallyBlock != null) {
        if (tryNotReturn)
            finallyBlock.accept(this);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:81,代码来源:MemberCodeGen.java


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