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


Java Bytecode.currentPc方法代码示例

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


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

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static MethodInfo makeConstructor(String thisClassName, Constructor cons,
                                          ConstPool cp, Class superClass, boolean doHandlerInit) {
    String desc = RuntimeSupport.makeDescriptor(cons.getParameterTypes(),
                                                Void.TYPE);
    MethodInfo minfo = new MethodInfo(cp, "<init>", desc);
    minfo.setAccessFlags(Modifier.PUBLIC);      // cons.getModifiers() & ~Modifier.NATIVE
    setThrows(minfo, cp, cons.getExceptionTypes());
    Bytecode code = new Bytecode(cp, 0, 0);

    // legacy: if we are not using caching then we initialise the instance's handler
    // from the class's static default interceptor and skip the next few instructions if
    // it is non-null
    if (doHandlerInit) {
        code.addAload(0);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addOpcode(Opcode.IFNONNULL);
        code.addIndex(10);
    }
    // if caching is enabled then we don't have a handler to initialise so this else branch will install
    // the handler located in the static field of class RuntimeSupport.
    code.addAload(0);
    code.addGetstatic(NULL_INTERCEPTOR_HOLDER, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
    code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
    int pc = code.currentPc();

    code.addAload(0);
    int s = addLoadParameters(code, cons.getParameterTypes(), 1);
    code.addInvokespecial(superClass.getName(), "<init>", desc);
    code.addOpcode(Opcode.RETURN);
    code.setMaxLocals(s + 1);
    CodeAttribute ca = code.toCodeAttribute();
    minfo.setCodeAttribute(ca);

    StackMapTable.Writer writer = new StackMapTable.Writer(32);
    writer.sameFrame(pc);
    ca.setAttribute(writer.toStackMapTable(cp));
    return minfo;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:41,代码来源:ProxyFactory.java

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

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

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