Exception Counter JVM Agent ![Build Status](https://camo.githubusercontent.com/46be36ef7852b8ad306312512342081421ff57fb4398e4e3edb3a2a58720a98d/68747470733a2f2f7472617669732d63692e6f72672f6d6172736368616c6c2f657863657074696f6e2d636f756e7465722e7376673f6272616e63683d6d6173746572)
A very simple JMTI agent that counts how many exceptions have occurred in a JVM.
Also contains an MBean that can be used for monitoring.
### How do I run it?
Adding -agentpath:/path/to/agent
is the simplest way to do it. To read the values the JAR has to be in the classpath as well.
### Can I attach at runtime?
Attaching with $JAVA_HOME/bin/java -cp $JAVA_HOME/lib/tools.jar:exception-counter.jar com.github.marschall.excount.ExceptionCounterAttacher -p pidOfProcessToAttachTo -a /path/to/agent
is the simplest way to do it. To read the values the JAR has to be in the classpath as well.
### Why a JMTI agent and not bytecode instrumentation?
A JMTI agent has several advantages over bytecode instrumentation:
- It also reports exceptions raised by the VM (eg.
NullPointerException
orArithmeticException
) or native code (eg.IOException
). - It should have a much smaller overhead.
- It less intrusive for things like debugging.
- It is unaffected by class file format changes.
### How long until the 32bit counter overflows?
With 60 exceptions per second after a year.
### Why also reporting caught exceptions?
If you run inside a framework or container you will likely have a top-level exception handler that catches everything. Therefore you're unlikely to have any uncaught exceptions.
### Which exceptions are not reported?
To quote from the JMTI documentation
If an exception is set and cleared in a native method (and thus is never visible to Java programming language code), no exception event is generated.
### I'm seeing lots of exceptions but everything seems to work fine?
You may be using libraries or frameworks that rely on exceptions for control flow. In addition central parts of Java like class loading use exceptions for control flow.
### What are the requirements of the C compiler?
The compiler should support C11 Atomics and provide the stdatomic.h header (currently only GCC 4.9 does). However we provide a work around that works GCC 4.7 and Clang 3.1.
### I need more information about my exceptions, where and when they happen.
You may want to look into licensing Java Mission Control.
### Should I run random JVM agents from people on the Internet?
You should most definitely not. You should review the source and build from the source.