Java Code Examples for org.objectweb.asm.commons.GeneratorAdapter#catchException()

The following examples show how to use org.objectweb.asm.commons.GeneratorAdapter#catchException() . 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: CallChainInstrument.java    From dacapobench with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings("unchecked")
public void visitEnd() {
	if (!done && found) {
		done = true;
		try {
			GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this);

			Label start = mg.mark();
			mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME)));
			mg.returnValue();
			Label end   = mg.mark();
			mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
			mg.returnValue();
			
			mg.endMethod();
		} catch (NoSuchMethodException nsme) {
			System.err.println("Unable to find Agent.rlogCallChain method");
			System.err.println("M:"+nsme);
			nsme.printStackTrace();
		}
	}
	
	super.visitEnd();
}
 
Example 2
Source File: ClinitInstrument.java    From dacapobench with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void visitEnd() {
	if (!foundClinit && instrument()) {
		// didn't find <clinit> so lets make one
		try {
			GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this);
			
			Label start = mg.mark();
			mg.push(className);
			mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class)));
			Label end   = mg.mark();
			mg.returnValue();
			
			mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
			mg.returnValue();
			
			mg.endMethod();
		} catch (NoSuchMethodException nsme) {
			System.out.println("Unable to find Agent.reportClass method");
		}
	}
	
	super.visitEnd();
}