Java Code Examples for org.objectweb.asm.Opcodes#ATHROW

The following examples show how to use org.objectweb.asm.Opcodes#ATHROW . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllocateInstrument.java    From dacapobench with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: StateTrackingMethodVisitor.java    From scott with MIT License 6 votes vote down vote up
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);
}
 
Example 3
Source File: MethodJob.java    From RuntimeTransformer with MIT License 6 votes vote down vote up
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);
}
 
Example 4
Source File: MyClassVisitor.java    From javacore with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@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);
}
 
Example 5
Source File: TryWithResourcesMethodVisitor.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  if (opcode == Opcodes.ATHROW) {
    this.opcodesStack.add(opcode);
    finishTracking();
  }
  super.visitInsn(opcode);
}
 
Example 6
Source File: AnalyzerAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@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;
  }
}
 
Example 7
Source File: ClassParserUsingASM.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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();
}
 
Example 8
Source File: PerfMarkTransformer.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: BlockBuildingMethodVisitorTest.java    From AVM with MIT License 5 votes vote down vote up
@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();
}
 
Example 10
Source File: AnalyzerAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@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;
  }
}
 
Example 11
Source File: BlockBuildingMethodVisitor.java    From AVM with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example 12
Source File: HeaderClassLoader.java    From bazel with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 13
Source File: AnalyzerAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@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;
  }
}
 
Example 14
Source File: PerfMarkTransformer.java    From perfmark with Apache License 2.0 5 votes vote down vote up
@Override
public void visitInsn(int opcode) {
  if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
    if (autoMatch) {
      emitAutoMatchEvent();
    }
  }
  super.visitInsn(opcode);
}
 
Example 15
Source File: WildflyDeploymentFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 16
Source File: MonitorInstrument.java    From dacapobench with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: BasicInstruction.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public boolean isComplexInstruction() {
    return opcode == Opcodes.ATHROW;
}
 
Example 18
Source File: AllocateInstrument.java    From dacapobench with Apache License 2.0 4 votes vote down vote up
public void onMethodExit(int opcode) {
	if (opcode != Opcodes.ATHROW)
		addDec();
}
 
Example 19
Source File: SerianalyzerMethodVisitor.java    From serianalyzer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@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);
}
 
Example 20
Source File: ThrowFrame.java    From deobfuscator with Apache License 2.0 4 votes vote down vote up
public ThrowFrame(Frame throwable) {
    super(Opcodes.ATHROW);
    this.throwable = throwable;
    this.throwable.children.add(this);
}