Memory Tracer
To use this memory tracer, download tracer.jar (or generate it directly from the source code) and run your Java program with the following command:
$ java -javaagent:<path_to_aspectjweaver.jar> -cp <path_to_tracer.jar>:$CLASSPATH <your_main_class>
This will produce the trace on stderr. So the trace can be saved to a file by appending "2> <desired_trace_file>" to the command above.
On Linux systems, <path_to_aspectjweaver.jar> is typically /usr/share/java/aspectjweaver.jar or /usr/share/java/aspectj/aspectjweaver.jar if AspectJ was installed by the package management system.
By default, everything in java.*, javax.*, org.aspectj.* and sun.* is not traced. This can be changed by modifying the aop.xml file in the source code and regenerating tracer.jar.
Limitations:
- Accesses to static fields are not traced.
- Accesses to enum constants are not traced.
- Accesses to array elements are not traced. The only array-related things traced are accesses to the array objects themselves (so the trace shows when an array is accessed, but does not show exactly which element was accessed or if the element was modified).
- If the traced program writes to stderr, this gets mixed in the trace.
- The tracer assumes that writes to stderr are synchronized by the Java runtime. This is true for OpenJDK and for Sun/Oracle's JRE, but may not be the case for other implementations. This limitation also implies that the order of the operations in the trace depend on how this synchronization is done by the runtime. Future versions of the tracer will work around this by providing explicit synchronization (or better yet, use a real logging facility).