org.objectweb.asm.Opcodes# ATHROW 源码实例Demo

下面列出了org.objectweb.asm.Opcodes# ATHROW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RuntimeTransformer   文件: MethodJob.java

private void insert() {
    InsnList trInsns = transformerNode.instructions;

    AbstractInsnNode node = trInsns.getLast();

    while (true) {
        if (node == null)
            break;

        if (node instanceof LabelNode) {
            node = node.getPrevious();
            continue;
        } else if (node.getOpcode() == Opcodes.RETURN) {
            trInsns.remove(node);
        } else if (node.getOpcode() == Opcodes.ATHROW && node.getPrevious().getOpcode() == Opcodes.ACONST_NULL) {
            AbstractInsnNode prev = node.getPrevious();
            trInsns.remove(node);
            trInsns.remove(prev);
        }

        break;
    }

    resultNode.instructions.insert(trInsns);
}
 

private void instrumentToTrackUnhandledExceptions() {
	// Based on: http://modularity.info/conference/2007/program/industry/I5-UsingASMFramework.pdf
	logger.log(" - instrumentToTrackUnhandledExceptions");

	Label endFinally = new Label();
	super.visitTryCatchBlock(startFinally, endFinally, endFinally, "java/lang/Throwable");
	super.visitLabel(endFinally);

	// Record exception
	super.visitInsn(Opcodes.DUP);
	super.visitLdcInsn(lineNumber);
	super.visitLdcInsn(methodName);
	super.visitLdcInsn(Type.getType("L" + className + ";"));
	super.visitMethodInsn(Opcodes.INVOKESTATIC, instrumentationActions.trackerClass, "trackUnhandledException", "(Ljava/lang/Throwable;ILjava/lang/String;Ljava/lang/Class;)V", false);

	// Rethrow
	super.visitInsn(Opcodes.ATHROW);
}
 
源代码3 项目: dacapobench   文件: AllocateInstrument.java

public void visitEnd() {
	if (!methodDone && methodStartLabel != null && constructor) {
		methodDone = true;
		Label methodEndLabel = super.mark();
		super.catchException(methodStartLabel, methodEndLabel, Type
				.getType(RuntimeException.class));
		super.visitMethodInsn(Opcodes.INVOKESTATIC, name,
				LOG_INTERNAL_ALLOC_DEC, VOID_SIGNATURE);
		super.visitInsn(Opcodes.ATHROW);
		if (exceptions != null) {
			for (String ex : exceptions) {
				super.catchException(methodStartLabel, methodEndLabel,
						Type.getObjectType(ex));
				super.visitMethodInsn(Opcodes.INVOKESTATIC, name,
						LOG_INTERNAL_ALLOC_DEC, VOID_SIGNATURE);
				super.visitInsn(Opcodes.ATHROW);
			}
		}
	}
	super.visitEnd();
}
 
源代码4 项目: perfmark   文件: PerfMarkTransformer.java

@Override
public void visitInsn(int opcode) {
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    if (autoMatch) {
      matches.add(new StackTraceElement(className, methodName, fileName, lineNumber));
    }
  }
  super.visitInsn(opcode);
}
 
源代码5 项目: perfmark   文件: PerfMarkTransformer.java

@Override
public void visitInsn(int opcode) {
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    if (autoMatch) {
      emitAutoMatchEvent();
    }
  }
  super.visitInsn(opcode);
}
 
源代码6 项目: Concurnas   文件: AnalyzerAdapter.java

@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 
源代码7 项目: bazel   文件: HeaderClassLoader.java

@Override
public void visitEnd() {
  if (!hasCode) {
    super.visitTypeInsn(Opcodes.NEW, EXCEPTION_INTERNAL_NAME);
    super.visitInsn(Opcodes.DUP);
    super.visitMethodInsn(
        Opcodes.INVOKESPECIAL, EXCEPTION_INTERNAL_NAME, "<init>", "()V", /*itf*/ false);
    super.visitInsn(Opcodes.ATHROW);
    super.visitMaxs(0, 0); // triggers computation of the actual max's
  }
  super.visitEnd();
}
 
源代码8 项目: AVM   文件: BlockBuildingMethodVisitor.java

@Override
public void visitInsn(int opcode) {
    this.currentBuildingBlock.add(opcode);
    
    // Note that this could be an athrow, in which case we should handle this as a label.
    // (this, like the jump case, shouldn't normally matter since there shouldn't be unreachable code after it).
    if (Opcodes.ATHROW == opcode) {
        handleLabel();
    }
}
 
源代码9 项目: JReFrameworker   文件: AnalyzerAdapter.java

@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 

@Test
public void test_throwException() throws Exception {
    List<BasicBlock> initBlocks = METHOD_BLOCKS.get("throwException()I");
    int[][] expectedInitBlocks = new int[][]{
            {Opcodes.NEW, Opcodes.DUP, Opcodes.INVOKESPECIAL, Opcodes.ATHROW},
    };
    boolean didMatch = compareBlocks(expectedInitBlocks, initBlocks);
    Assert.assertTrue(didMatch);
    BytecodeFeeScheduler s = new BytecodeFeeScheduler();
    s.initialize();
}
 
源代码11 项目: javacore   文件: MyClassVisitor.java

@Override
public void visitInsn(int opcode) {
    if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN)
        || opcode == Opcodes.ATHROW) {
        //方法在返回之前,打印"end"
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("end");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
    }
    mv.visitInsn(opcode);
}
 
源代码12 项目: spotbugs   文件: ClassParserUsingASM.java

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.MONITORENTER:
        mBuilder.setUsesConcurrency();
        break;
    case Opcodes.ARETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.DRETURN:
    case Opcodes.FRETURN:
        if (identityState == IdentityMethodState.LOADED_PARAMETER) {
            mBuilder.setIsIdentity();
        }
        sawReturn = true;
        break;
    case Opcodes.RETURN:
        sawReturn = true;
        break;
    case Opcodes.ATHROW:
        if (stubState == StubState.INITIALIZE_RUNTIME) {
            sawStubThrow = true;
        } else if (justSawInitializationOfUnsupportedOperationException) {
            sawUnsupportedThrow = true;
        } else {
            sawNormalThrow = true;
        }
        break;
    default:
        break;
    }

    resetState();
}
 
源代码13 项目: JByteMod-Beta   文件: AnalyzerAdapter.java

@Override
public void visitInsn(final int opcode) {
  super.visitInsn(opcode);
  execute(opcode, 0, null);
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    this.locals = null;
    this.stack = null;
  }
}
 

@Override
public void visitInsn(int opcode) {
  if (opcode == Opcodes.ATHROW) {
    this.opcodesStack.add(opcode);
    finishTracking();
  }
  super.visitInsn(opcode);
}
 
源代码15 项目: CodenameOne   文件: BasicInstruction.java

public boolean isComplexInstruction() {
    return opcode == Opcodes.ATHROW;
}
 
源代码16 项目: netbeans   文件: WildflyDeploymentFactory.java

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    // see issue #249135
    if (patchXnio && "org.xnio.nio.WorkerThread".equals(name)) { // NOI18N
        try {
            LOGGER.log(Level.INFO, "Patching the issue #249135");
            String path = name.replace('.', '/').concat(".class"); // NOI18N
            try (InputStream is = super.getResourceAsStream(path)) {
                ClassReader cr = new ClassReader(is);
                ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES) {

                    @Override
                    protected String getCommonSuperClass(String string, String string1) {
                        if ("org/xnio/nio/NioHandle".equals(string) // NOI18N
                                || "org/xnio/nio/NioHandle".equals(string1)) { // NOI18N
                            return "java/lang/Object"; // NOI18N
                        }
                        return super.getCommonSuperClass(string, string1);
                    }
                };
                ClassNode node = new ClassNode(Opcodes.ASM7);
                cr.accept(node, 0);

                for (MethodNode m : (Collection<MethodNode>) node.methods) {
                    if ("execute".equals(m.name) // NOI18N
                            && "(Ljava/lang/Runnable;)V".equals(m.desc)) { // NOI18N
                        InsnList list = m.instructions;
                        for (ListIterator it = list.iterator(); it.hasNext(); ) {
                            AbstractInsnNode n = (AbstractInsnNode) it.next();
                            if (n instanceof MethodInsnNode) {
                                MethodInsnNode mn = (MethodInsnNode) n;
                                if ("org/xnio/nio/Log".equals(mn.owner) // NOI18N
                                        && "threadExiting".equals(mn.name) // NOI18N
                                        && "()Ljava/util/concurrent/RejectedExecutionException;".equals(mn.desc)) { // NOI18N
                                    if (it.hasNext()) {
                                        AbstractInsnNode possibleThrow = (AbstractInsnNode) it.next();
                                        if (possibleThrow.getOpcode() == Opcodes.ATHROW) {
                                            it.set(new InsnNode(Opcodes.POP));
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }

                node.accept(cw);
                byte[] newBytecode = cw.toByteArray();
                return super.defineClass(name, newBytecode, 0, newBytecode.length);
            }
        } catch (Exception ex) {
            // just fallback to original behavior
            LOGGER.log(Level.INFO, null, ex);
        }
    }
    return super.findClass(name);
}
 
源代码17 项目: dacapobench   文件: MonitorInstrument.java

protected void onMethodExit(int opcode) {
	if (done || opcode == Opcodes.ATHROW || !isSynchronized()) return;
	
	has_monitor_operation = true;
	super.visitMethodInsn(Opcodes.INVOKESTATIC, className, LOG_INTERNAL_EXIT_METHOD, LOG_CLASS_SIGNATURE);
}
 
源代码18 项目: dacapobench   文件: AllocateInstrument.java

public void onMethodExit(int opcode) {
	if (opcode != Opcodes.ATHROW)
		addDec();
}
 

/**
 * {@inheritDoc}
 *
 * @see org.objectweb.asm.MethodVisitor#visitInsn(int)
 */
@Override
public void visitInsn ( int opcode ) {

    switch ( opcode ) {
    case Opcodes.ARETURN:
        Object ret = this.stack.pop();
        Type sigType = Type.getReturnType(this.ref.getSignature());
        Type retType = null;
        Set<Type> altTypes = null;
        if ( ret != null ) {
            if ( ret instanceof SimpleType ) {
                retType = ( (SimpleType) ret ).getType();
                altTypes = ( (SimpleType) ret ).getAlternativeTypes();
            }
            else if ( ret instanceof MultiAlternatives ) {
                retType = ( (MultiAlternatives) ret ).getCommonType();
            }
        }

        if ( retType != null ) {
            this.returnTypes.add(retType);
            if ( altTypes != null ) {
                this.returnTypes.addAll(altTypes);
            }
        }
        else {
            this.returnTypes.add(sigType);
        }
        this.stack.clear();
        break;

    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if ( this.log.isTraceEnabled() ) {
            this.log.trace("Found return " + this.stack.pop()); //$NON-NLS-1$
        }
        this.stack.clear();
        break;

    case Opcodes.ATHROW:
        Object thrw = this.stack.pop();
        this.log.trace("Found throw " + thrw); //$NON-NLS-1$
        this.stack.clear();
        break;

    default:
        JVMImpl.handleJVMInsn(opcode, this.stack);
    }

    super.visitInsn(opcode);
}
 
源代码20 项目: deobfuscator   文件: ThrowFrame.java

public ThrowFrame(Frame throwable) {
    super(Opcodes.ATHROW);
    this.throwable = throwable;
    this.throwable.children.add(this);
}
 
 方法所在类
 同类方法