Java execution details in System.out
Asked Answered
P

4

6

As I remember there is a magic command line option in Java that turns on writing of operations that are currently executed to the console. The output looks 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 didn't find it here https://www.oracle.com/java/technologies/javase/vmoptions-jsp.html or here https://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/java.html. Also I have found some flags, but most of them only work 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 these lists miss?

Plesiosaur answered 31/5, 2010 at 16:11 Comment(0)
O
2

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.

Oldtimer answered 31/5, 2010 at 16:15 Comment(7)
jstack is pretty neat as well.Halle
There are tools out there to parse those dumps and show them more nicely, e.g. the Thread Dump Viewer: sourceforge.net/projects/tdvKirkuk
+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 :)Flamboyant
@NoozNooz42: compare this with killall. On some systems, it actually kills all processes, while on others it kills all processes with a specified name!Halle
@Nooznooz42: My version of *nix will have a tickle command.Ensnare
@GregS: I think signal would have been a decent name for it.Oldtimer
@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 :)Flamboyant
P
1

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

Pachston answered 31/5, 2010 at 16:19 Comment(0)
T
1

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.

Twibill answered 31/5, 2010 at 16:20 Comment(0)
S
1

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?

Sclerite answered 1/6, 2010 at 8:12 Comment(3)
I need the runtime output like logger in debug mode, but on the low levelPlesiosaur
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.Sclerite
Edited in the above to my answer.Sclerite

© 2022 - 2024 — McMap. All rights reserved.