Exception Counter

A very simple JMTI agent that counts how many exceptions have occurred in a JVM.

License

License

MIT
GroupId

GroupId

com.github.marschall
ArtifactId

ArtifactId

exception-counter
Last Version

Last Version

0.1.3
Release Date

Release Date

Type

Type

nar
Description

Description

Exception Counter
A very simple JMTI agent that counts how many exceptions have occurred in a JVM.
Project URL

Project URL

https://github.com/marschall/exception-counter
Source Code Management

Source Code Management

https://github.com/marschall/exception-counter

Download exception-counter

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Exception Counter JVM Agent Build Status

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.

VisualVM

### 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 or ArithmeticException) 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.

Versions

Version
0.1.3
0.1.2