Timers

Hey,

I'm investigating alternatives to MethodEnter/Exit which allow me to probe thread states over the course of a program run. The latest avenue of testing is to use a timer to periodically query all threads (followed by recording them in an uninteresting way). It seems more difficult than I first imagine, however, and the implementation I'm using at the moment causes a random SIGSEGV or SIGBUS in the main thread in libjvm.so.

Presumably I'm not supposed to install a handler for SIGALRM. I use pthread_sigset(SIG_UNBLOCK, ...) and timer_settime(...) after having blocked SIGALRM in Agent_OnLoad. The handler is called and everything is fine, sometimes the program even runs to completion!

Can anyone point me in the direction of the documentation which describes the correct way to do this?

Any ideas?

Bruce

PS If it helps anyone to see where I'm corrupting memory, I occasionally get strange exceptions such as:

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.StringCoding$CharsetSD.<init>(Ljava/nio/charset/Charset;Ljava/lang/String;Ljava/lang/StringCoding$1;)V

[1146 byte] By [b_duncana] at [2007-10-3 2:01:00]
# 1

The MethodEnter/Exit exits are in the JVM TI spec to support debuggers and should not be used for profiling purposes (there's a warning in the spec about this).

Anyway, this page on signal chaining might be useful:

http://java.sun.com/j2se/1.5.0/docs/guide/vm/signal-chaining.html

Instead of an alarm signal, then a simpler alternatively might be to create an agent thread that wakes up periodically and gets all thread stacks.

alan.batemana at 2007-7-14 18:59:44 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...