Protomatter Software v1.1.8

Class StackTraceUtil


public class StackTraceUtil
extends java.lang.Object

A utility class for parsing stack traces.

Determining the stack information at runtime is a relatively expensive operation. I've tested this on a 650MHz PIII Coppermine Sony Vaio laptop running RedHat Linux 7.2, kernel 2.4.9, I saw these results with single-threaded tests:

Classic VM (build JDK-1.2.2_012, green threads, nojit) Average 0.73543ms
Classic VM (build 1.3.1, J2RE 1.3.1 IBM build cxia32131-20020410 (JIT enabled: jitc)) Average 0.31817ms
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_03-b03) Average 0.18201ms
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) Average 0.1024ms
JRockit Virtual Machine (build
Native Threads, Generational Concurrent Garbage Collector
Average 0.0486ms

If possible, this class loads an implementation of itself that uses new APIs available in JDK 1.4 to improve performance. Under JDK 1.2 and 1.3, this class parses a stack trace to determine call stack information.

Also, under the IBM and JRockit JVMs, line numbers are usually not available. They may or may not be availble under other JVMs because the JIT may or may not strip that information from stack traces.

Sustained, rapid creation of java.lang.Throwable objects under the IBM JDK repeatedly caused JVM deadlocks. This should not be an issue in actual systems, but it is concerning.

Constructor Summary
protected StackTraceUtil()
          Protected constructor so nobody instantiates this class.
Method Summary
protected  StackTraceInfo getInfo(int stackOffset)
static void main(java.lang.String[] args)
          Performance test rig.
static StackTraceInfo whereAmI()
          Determine what class and method you are in.
static StackTraceInfo whereAmI(int stackOffset)
          Determine what class and method you are in.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


protected StackTraceUtil()
Protected constructor so nobody instantiates this class.
Method Detail


public static StackTraceInfo whereAmI()
Determine what class and method you are in.


public static StackTraceInfo whereAmI(int stackOffset)
Determine what class and method you are in. The offset is how many levels above where this method is called.


protected StackTraceInfo getInfo(int stackOffset)


public static void main(java.lang.String[] args)
Performance test rig. Optional command-line arguments are the number of threads (default is 5), and number of calls per thread (default is 10,000).

Protomatter Software v1.1.8
Copyright 1998-2002 Nate Sammons

Protomatter Software v1.1.8