views:

89

answers:

4

As I remember there is a magic command line option in Java that turn on writing of operations that are currently executed to console. The output was looked like byte code.

-verbose does not match as it prints only class loading, while this option outputs information like memory allocation, setting local variables etc. It was very detailed, like 10 lines for "Hello world".

I did not find it neither here http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp nor here http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/java.html Also I have found some flags here, but most of them work only in openjdk or in the develop mode. Maybe there is a way I can start java.exe on Windows in this develop mode? Or maybe there is another set of flags that this lists miss?

+2  A: 

Not quite what you asked, but I'm a big fan of "kill -3" on the java process id - that dumps out all sorts of information about every thread and what state they are in, what locks they hold and what locks they are waiting on, and that sort of thing.

Paul Tomblin
`jstack` is pretty neat as well.
Joachim Sauer
There are tools out there to parse those dumps and show them more nicely, e.g. the Thread Dump Viewer: http://sourceforge.net/projects/tdv/
ZeissS
+1 and note that "kill -3" is a misnomer (the "kill" command is actually misnomed) for it doesn't kill at all the process. I mention this because I've read (and heard) that question asked several times: *"will it kill the process?"*. No, it won't, it simply sends a signal that, as a result, outputs many infos from the JVM on the console :)
NoozNooz42
@NoozNooz42: compare this with [`killall`](http://en.wikipedia.org/wiki/Killall). On some systems, it *actually kills all processes*, while on others it kills all processes with a specified name!
Joachim Sauer
@Nooznooz42: My version of *nix will have a `tickle` command.
GregS
@GregS: I think `signal` would have been a decent name for it.
Paul Tomblin
@GregS: I'm not a native english speaker and don't know what "tickle" means (sending a tick?) but all I can tell you is that, as stated, I've read and heard several times people asking *"will this kill my process?"* so to me something like "signal" or "tickler" or whatever would have been less confusing :)
NoozNooz42
+1  A: 

On windows use Ctrl-Break to create a thread dump. To monitor classloading use -verbose:class for garbage collection -verbose:gc

stacker
+1  A: 

Supported options here. The closest I can find to your description is -verbose:gc, or perhaps -verbose:class.

javap will output bytecode, but it's a static disassembler, and not related to runtime.

Brian Agnew
+1  A: 

I've been using jvisualvm quite a bit recently; maybe that would give you what you want? It does profiling of both memory and CPU use, can dump thread stacks, and can even persuade the JVM to list what classloader activity is going on (via the MBean support: go to java.langClassLoading, select Attributes and update Verbose; it still dumps to System.out of course). The great thing about this is that you don't need to anything to enable it (normally); you can just attach to already running JVMs. (If you've got Java 1.5, use jconsole instead.)

Note however that you're unlikely to get a dump of what bytecodes are executed. This is because the HotSpot JIT engine – which has been around for a fair few years now – converts the bytecodes to native instructions before execution so by the time the code is actually executed, there's simply no bytecodes left for the instrumentation to report on. Theoretically you might be able to build a special VM that worked in the old way, but it would be horribly slow (like the bad old days) so why would you really want to?

Donal Fellows
I need the runtime output like logger in debug mode, but on the low level
John
Well, the good thing about jvisualvm is that it can connect to running JVMs and poke around inside. One of the things you can do (with the MBeans plugin) is go inside the controls on whether to log loaded classes (`java.lang→ClassLoading→Verbose`) and turn it on by editing the flag. The beauty of this? You don't need to have remembered to set the flag when you started the JVM.
Donal Fellows
Edited in the above to my answer.
Donal Fellows