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


Java Bytecode.addExceptionHandler方法代码示例

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


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

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

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