{"id":36,"date":"2008-08-15T10:44:17","date_gmt":"2008-08-15T09:44:17","guid":{"rendered":"http:\/\/hirt.se\/blog\/?p=36"},"modified":"2010-02-02T22:28:40","modified_gmt":"2010-02-02T21:28:40","slug":"simple-exception-profiling-with-jrockit","status":"publish","type":"post","link":"https:\/\/hirt.se\/blog\/?p=36","title":{"rendered":"Simple Exception Profiling with JRockit"},"content":{"rendered":"<p>Exception profiling is the business of finding out what exceptions are being thrown within your application and from where. In JRockit Mission Control you can find out how many exceptions have been thrown using JRA, and you can count the exceptions using the JRockit Management Console. Sadly there is no way of doing powerful exception profiling (i.e. looking at the stack traces for the exceptions, aggregating them and visualizing them directly in the JRockit Mission Control Client) just yet. This will be incorporated in a future version of Mission Control.<\/p>\n<p>There is fortunately a way to do exception profiling with JRockit today. There are exception related verbose flags available in JRockit. These are examples on how to use them:<\/p>\n<blockquote>\n<p><strong>java -Xverbose:exceptions=debug<\/strong> &#8230;<\/p>\n<p><strong>java -Xverbose:exceptions=trace<\/strong> &#8230;<\/p>\n<\/blockquote>\n<p>For a list of valid verbose options, please see <a title=\"http:\/\/e-docs.bea.com\/jrockit\/jrdocs\/refman\/optionX.html#wp999543\" href=\"http:\/\/e-docs.bea.com\/jrockit\/jrdocs\/refman\/optionX.html#wp999543\">http:\/\/e-docs.bea.com\/jrockit\/jrdocs\/refman\/optionX.html#wp999543<\/a>.<\/p>\n<p>Sometimes you really just want to enable this profiling for a little while, for example to avoid cluttering your log files. Then there is a nifty tool for JRockit called jrcmd you can use to turn on\/off the exception profiling. It can be found under JROCKIT_HOME\\bin\\.<\/p>\n<p>First use jrcmd to list all running java processes. Here is an example of what it may look like:<\/p>\n<blockquote>\n<p>&gt;<strong>jrcmd<\/strong><\/p>\n<p>10984 jrockit.tools.jrcmd.JrCmd <\/p>\n<p>9396 C:\\Java\\eclipse3.3.1.1\\plugins\\org.eclipse.equinox.launcher_1.0.1.R33x_v200      <br \/>70828.jar -data D:\\Data\\workspaces\\workspace_3.3_facade -os win32 -ws win32 -arc       <br \/>h x86 -showsplash -launcher C:\\Java\\eclipse3.3.1.1\\eclipse.exe -name Eclipse &#8211;l       <br \/>auncher.library C:\\Java\\eclipse3.3.1.1\\plugins\\org.eclipse.equinox.launcher.win3       <br \/>2.win32.x86_1.0.2.R331_v20071019\\eclipse_1021.dll -startup C:\\Java\\eclipse3.3.1.       <br \/>1\\plugins\\org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar -exitdata 1908_7       <br \/>c -vm D:\\jrockits\\R27.4.0_R27.4.0-90_1.5.0\\bin\\javaw.exe -vmargs -Xms256m -Xmx51       <br \/>2m -XgcPrio:deterministic -XpauseTarget:40 -Dosgi.bundlefile.limit=100 -jar C:\\J       <br \/>ava\\eclipse3.3.1.1\\plugins\\org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar <\/p>\n<p>10976 Gegga<\/p>\n<\/blockquote>\n<p>The numbers are the PIDs of the processes, and are used as the first argument to jrcmd to specify on what JRockit to address. You can use jrcmd to check what commands are available. Here is an example:<\/p>\n<blockquote>\n<p>&gt;<strong>jrcmd 10976 help<\/strong>       <br \/>10976:       <br \/>The following commands are available:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; kill_rmp_server       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; start_rmp_server       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; kill_management_server       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; start_management_server       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; checkjrarecording       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; stopjrarecording       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; startjrarecording       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_object_summary       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; memleakserver       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_codegenlist       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_class_summary       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; run_optfile       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; dump_codelayout       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; dump_codelist       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; dump_codemap       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_utf8pool       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_properties       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_threads       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; datadump_request       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; runsystemgc       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; runfinalization       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; heap_diagnostics       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; oom_diagnostics       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_exceptions       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; version       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; timestamp       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; command_line       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; memprof       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; sanity       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; verbosity       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; set_filename       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; help       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; print_memusage       <br \/>For more information about a specific command use &#8216;help &lt;command&gt;&#8217;.       <br \/>Parameters to commands are optional unless otherwise stated.<\/p>\n<\/blockquote>\n<p>Let&#8217;s get more information about the print_exceptions command:<\/p>\n<blockquote>\n<p>&gt;<strong>jrcmd 10976 help print_exceptions<\/strong><\/p>\n<p>10976:      <br \/>Enable printing of Java exceptions thrown in the VM.       <br \/>To turn exception printing off completely you need to set exceptions = false       <br \/>even if it was turned on by stacktraces = true. NOTE: This handler is       <br \/>deprecated. The preferred way of displaying exceptions is to use the       <br \/>&#8216;exceptions&#8217; logging module: -Xverbose:exceptions.       <br \/>Values for the parameters can be &quot;true|all|false&quot;       <br \/>true&#160; &#8211; print all exception except java\/util\/EmptyStackException,       <br \/>java\/lang\/ClassNotFoundException and       <br \/>java\/security\/PrivilegedActionException       <br \/>all&#160;&#160; &#8211; print all exception       <br \/>false &#8211; don&#8217;t print exceptions       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; exceptions&#160; &#8211; print exceptions (string, false)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; stacktraces &#8211; print stacktrace (string, false)<\/p>\n<\/blockquote>\n<p>Never mind that it is using an old handler in R27.6. The functionality will be the same. Let&#8217;s enable the exception profiling:<\/p>\n<blockquote>\n<p>&gt;<strong>jrcmd 10976 print_exceptions stacktraces=true<\/strong><\/p>\n<\/blockquote>\n<p>If your application is throwing exceptions, you should now be seeing traces being logged to the console of that application. To turn off the exception logging, we do as the help suggests:<\/p>\n<blockquote>\n<p>&gt;<strong>jrcmd 10976 print_exceptions exceptions=false<\/strong><\/p>\n<\/blockquote>\n<p>Now, an even easier way to access the jrockit diagnostic commands is to use the JRockit Management Console. Simply connect the JRockit Management Console to the JRockit you wish to enable exception profiling on (from JRockit Mission Control). (Click the images to look at them in full size.)<\/p>\n<p><a href=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/start-console.png\"><img loading=\"lazy\" decoding=\"async\" height=\"433\" alt=\"start_console\" src=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/start-console-thumb.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p>Once the console is started, open the <strong>MBean Browser<\/strong> tab and move to the <strong>DiagnosticCommand<\/strong> MBean under <strong>bea.jrockit.management<\/strong>:<\/p>\n<p><a href=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/diagnostic-command.png\"><img loading=\"lazy\" decoding=\"async\" height=\"433\" alt=\"diagnostic_command\" src=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/diagnostic-command-thumb.png\" width=\"644\" border=\"0\" \/><\/a> <\/p>\n<p>Double clicking on the ArrayList value of <strong>AllCommands<\/strong> will open up a list of all the available commands:<\/p>\n<p><a href=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/list-commands.png\"><img loading=\"lazy\" decoding=\"async\" height=\"433\" alt=\"list_commands\" src=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/list-commands-thumb.png\" width=\"644\" border=\"0\" \/><\/a>&#160; <br \/>Now, select the operations tab and the executeDefault method that takes a String argument and press invoke. This will provide you with a dialog with push buttons for the arguments. In this case a single button with the label String. Press the String button and fill out the command. For example, print_exceptions stacktraces=true.<\/p>\n<p><a href=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/print-traces.png\"><img loading=\"lazy\" decoding=\"async\" height=\"433\" alt=\"print_traces\" src=\"https:\/\/hirt.se\/blog\/wp-content\/uploads\/2008\/08\/print-traces-thumb.png\" width=\"644\" border=\"0\" \/><\/a><\/p>\n<p>Press <strong>Ok <\/strong>on both of the dialogs and exception profiling should now be enabled. To turn it off again, just invoke the operation again and enter <strong>print_exceptions exceptions=false<\/strong>, analogously with how you would use jrcmd.<\/p>\n<p>An even easier way for Oracle employees is to pick up a recent internal build of JRockit and use the <strong>Diagnostic Command<\/strong> tab in the JRockit Management Console. \ud83d\ude42 Soon coming to a JRockit near you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Exception profiling is the business of finding out what exceptions are being thrown within your application and from where. In JRockit Mission Control you can find out how many exceptions have been thrown using JRA, and you can count the exceptions using the JRockit Management Console. Sadly there is no way of doing powerful exception [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-java-mission-control-fair-dj"],"_links":{"self":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36"}],"version-history":[{"count":1,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}