<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; bin</title>
	<atom:link href="http://blog.jayway.com/tag/bin/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Tue, 07 Feb 2012 10:49:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Forensic tools,  part 2</title>
		<link>http://blog.jayway.com/2008/05/01/forensic-tools-part-2/</link>
		<comments>http://blog.jayway.com/2008/05/01/forensic-tools-part-2/#comments</comments>
		<pubDate>Thu, 01 May 2008 09:14:21 +0000</pubDate>
		<dc:creator>Tobias Södergren</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[bin]]></category>
		<category><![CDATA[jayview]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=3093</guid>
		<description><![CDATA[Have you ever been in the situation that an application behaves in strange ways and by the time you find out, you do not have access to your development environment. In this article we are discussing ways to pin- point the problem with tools available in the Sun SDK bin directory. In the first part [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Have you ever been in the situation that an application behaves in strange ways and by the time you find out, you do not have access to your development environment. In this article we are discussing ways to pin- point the problem with tools available in the Sun SDK bin directory. </strong></p>
<p>In the first part of this article, which can be found in the previous JayView, the monitoring tools of the Sun JDK 1.5 was presented. These monitoring tools can be a good start for looking at the current status, and behavior over time, for an application. While these tools can tell you some parts of the doings of an application, finding a problem is sometimes more effective using the troubleshooting tools. This second part of the article will present some of these tools. </p>
<h2>Tools overview </h2>
<p>The list below contains all tools presented in this article, where the first four can<br />
be found in part one.</p>
<p><img src="http://blog.jayway.com/wordpress/wp-content/uploads/2008/05/Picture-641.png" alt="Tools" title="Tools" width="526" height="336" class="alignnone size-full wp-image-3291" /></p>
<p>Note: A known issue for OSX require that some of the tools is run as root, which can be accomplished by putting ‘sudo ‘ before each command. </p>
<h2>Troubleshooting tools</h2>
<p>The troubleshooting tools provided by Sun Microsystems in the JDK bin directory are to be considered experimental. They come with no support and they might harm your system. Although being in an experimental state, the tools can be quite useful when looking for problems. </p>
<p>Some of the tools can connect to a locally or remotely running Java process, others operate on a core dump. This dump can be created by the JVM, by specifying Sun Hotspot specific flags such as <strong>-XX:+HeapDumpOnCtrlBreak</strong> or<br />
<strong>-XX:+HeapDumpOnOutOfMemoryError</strong>. These flags should be appended to the java command just like system properties: </p>
<pre>> java -XX:+HeapDumpOnOutOfMemoryError -jar application.jar</pre>
<p>The core dump can also be created with jmap and the syntax is described below. Be aware that the jmap of JDK 1.5 have some problems creating this core dump, sometimes it creates a corrupted file. This specific issue with jmap is fixed in Java 6. </p>
<h2>jinfo </h2>
<p>The jinfo tool connects to a running local process, a JVM core dump or a remote<br />
process. The purpose of the tool is to display the VM flags used and the values of<br />
the system properties for the process in question. The process id, or VMID, can be found using the jps command. Here is an example connecting to a running process with process id 1649:</p>
<pre>> jinfo -flags 1649
Attaching to process ID 1649, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_07-87
-Duser.property=somevalue </pre>
<p>In the example above, you can see that the Java application was started using the flag ‘user.property’. To see the system properties, use the -sysprops flag: </p>
<pre>> jinfo -sysprops 1649
Attaching to process ID 1649, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_07-87
java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path = /System/Library/Frameworks/JavaVM.framework/
Versions/1.5.0/Libraries
java.vm.version = 1.5.0_07-87
java.vm.vendor = ”Apple Computer, Inc.”
java.vendor.url = http://apple.com/
path.separator = :
   ...
</pre>
<p>The jinfo command can give a quick hint about what a java process can see from its environment.</p>
<h2>jstack </h2>
<p>The jstack command prints out the execution stack trace for threads for a process in the local JVM, a remote JVM or in a core dump. It also prints out thread deadlocks detected by the Hotspot VM, something that can come in handy for<br />
solving threading issues. The command for connecting to a local process looks like: </p>
<pre>
> jstack 1649
Attaching to process ID 1649, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_07-87 

Thread t@4099: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=44, line=116 (Interpreted
frame)
 - java.lang.ref.ReferenceQueue.remove() @bci=2, line=132 (Interpreted
frame)
 - java.lang.ref.Finalizer$FinalizerThread.run() @bci=3, line=159
(Interpreted frame)
...
Thread t@4611: (state = IN_NATIVE)
 - java.io.FileInputStream.readBytes(byte[], int, int) @bci=0
 - java.io.FileInputStream.read(byte[], int, int) @bci=4, line=194
 - java.io.BufferedInputStream.read1(byte[], int, int) @bci=39, line=254
 - java.io.BufferedInputStream.read(byte[], int, int) @bci=49, line=313
 - sun.nio.cs.StreamDecoder$CharsetSD.readBytes() @bci=135, line=411
 - sun.nio.cs.StreamDecoder$CharsetSD.implRead(char[], int, int) @bci=112,
line=453
 - sun.nio.cs.StreamDecoder.read(char[], int, int) @bci=180, line=183
 - java.io.InputStreamReader.read(char[], int, int) @bci=7, line=167
 - java.io.BufferedReader.fill() @bci=145, line=136
 - java.io.BufferedReader.readLine(boolean) @bci=44, line=299
 - java.io.BufferedReader.readLine() @bci=2, line=362
 - se.jayway.jconsole.test.Application.run() @bci=29, line=24
 - se.jayway.jconsole.test.Application.main(java.lang.String[]) @bci=9,
line=14
</pre>
<p>In the example above, we can see that the Application.main( ) method is spending time in FileInputStream.readBytes( ).</p>
<h2>jmap</h2>
<p>This versatile command prints out information using the following flags:</p>
<ul>
<li> <strong>- heap</strong> prints out heap information, including the different memory pools
<li> <strong>- heap:format=b</strong> dumps the heap in a binary format
<li> <strong>- histo</strong> prints class histogram information of the object heap
<li> <strong>- permstat</strong> prints information class loader-wise about data in the permanent generation memory pool. The permanent generation memory pool contains class meta data and the String literals.
</ul>
<pre>> jmap -heap 1649
Attaching to process ID 1649, please wait...
...
using thread-local object allocation.
Mark Sweep Compact GC 

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize      = 67108864 (64.0MB)
NewSize          = 655360 (0.625MB)
...
</pre>
<p>In the example above only the first part of the heap information is printed, there’s a lot more to see. </p>
<pre>> jmap -histo 1649
Object Histogram:
Size    Count   Class description
-------------------------------------------------------
194408  1025    char[]
102840  160     byte[]
16032   668     java.lang.String
13208   297     java.lang.Object[]
8208    27      * ObjArrayKlassKlass
...
</pre>
<p>Above, the first part of the class histogram is printed for the process with VMID 1649. </p>
<pre>> jmap -heap:format=b 1649
Attaching to process ID 1649, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_11-b03
Unknown oop at 0x889ec790
Oop’s class is null
heap written to heap.bin </pre>
<p>The heap is dumped for the process with VMID 1649 in the example above, and the result is a file called heap.bin. </p>
<p>The jmap -heap and jstat with a suitable garbage collection flag can help with finding memory issues for object instances. Jmap -histo and jmap -permstat can be used for finding memory leaks in permanent generation memory space, e.g. when there are too many classes loaded by class loaders that never get garbage collected. </p>
<p>The jmap -heap:format=b flag has issues with the heap dump sometimes being corrupted, an issue which is fixed for Java 6. When the command is working the heap dump can be analyzed using tools described above and with a tool called jhat, which is bundled with Java 6 SDK. It is also possible to debug the heap dump using the java debugger, called jdb, which also can be found in the bin directory. </p>
<p>I recommend taking a look at jhat, which is a heap analysis tool that processes heap dumps. When invoking jhat it starts with analyzing all objects found in the heap core dump. After the analysis is finished a web server is launched. Use an ordinary web browser to connect to the web server to get access to the object browsing functions available. </p>
<p>One example of a function is the one that makes it possible to filter out weak<br />
references between objects, so that objects that are not eligible for garbage collection can be found. It is also possible to use OQL (Object Query Language) where you can use an SQL-like syntax to get object set results, such as the number of instances for a specific object type, the value for all String objects etc. </p>
<p>The jhat tool is available in Java 6 but can be downloaded from Sun for Java 1.5. </p>
<p>To conclude this article, the monitoring and troubleshooting tools found in the bin directory for the JDK provided by Sun can be a good start when finding bugs in your java code. Use them, you might already have them on your computer. </p>
<p><em>Originally published in <a href="http://jayway.se/jayview">JayView</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2008/05/01/forensic-tools-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forensic tools, part 1</title>
		<link>http://blog.jayway.com/2008/02/01/forensic-tools-part-1/</link>
		<comments>http://blog.jayway.com/2008/02/01/forensic-tools-part-1/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 11:57:50 +0000</pubDate>
		<dc:creator>Tobias Södergren</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[bin]]></category>
		<category><![CDATA[jayview]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=3418</guid>
		<description><![CDATA[There are times when you really would like to know what the Java processes on the computer are doing at this very moment. Maybe the computer seems a bit sluggish, maybe the disk LED is not so much flashing but instead glowing constantly. Other times an application might seem just dead. A possible scenario You [...]]]></description>
			<content:encoded><![CDATA[<p><strong>There are times when you really would like to know what the Java processes on the computer  are doing at this very moment. Maybe the computer seems a bit sluggish, maybe the disk LED  is not so much flashing but instead glowing constantly. Other times an application might seem  just dead. </strong></p>
<h2>A possible scenario</h2>
<p>You have started up an application, let’s say it is a web application which is running in an  application server. After a while you notice that the application is behaving oddly. You cannot really  put your finger on the problem, but sometimes it looks like the web pages are not served as they  should. The application also feels slower than you expect.<br />
First thing could be to check out the log files, but as you all know, the debug level<br />
is set to INFO or  WARNING because the application is in production: </p>
<pre>10:10:40.542 INFOStarting  application...
10:12:21.650 INFOAll  service started.
10:14:22.145 INFOApplication  booted successfully. </pre>
<p>What conclusion do you draw from this output? The application has started and it<br />
looks like nothing  serious has detected in the code that is worth mentioning in the<br />
log. Is it time to start guessing or  just ignore the gut feeling  you have? Not quite yet,<br />
there are some help to be found not far away, and  it will not cost you a dime. </p>
<h2>Bring  out  the  tools</h2>
<p>In your Java SDK 1.5 (or higher) “bin” directory, there are tools that can be quite us-<br />
able for poking  around in the Java processes. There are different number of tools for<br />
different platforms and the  number of available functions per tool is also depending<br />
on the distribution. Sun Solaris and Linux  Java distributions have been blessed with<br />
the most number of tools and functions, Mac OSX and  Windows have the least.<br />
Also, the tools are getting constantly improved for newer releases of Java. </p>
<p>Here is a comprehensive list of the tools mentioned in this article and on which<br />
platforms they exist: </p>
<p><img src="http://blog.jayway.com/wordpress/wp-content/uploads/2009/12/Picture-811.png" alt="Figure 1" title="Figure 1" width="432" height="423" class="alignnone size-full wp-image-3419" /></p>
<p>This article consists of two parts, and this first part goes through the available moni-<br />
toring tools in  the Sun Java 1.5 SDK bin directory. </p>
<h2>Monitoring  tools</h2>
<h3>jps </h3>
<p>To see which java processes that are currently running on a machine use the  <strong>jps</strong><br />
command: </p>
<pre>> jps
1649 Application
2533 Jps </pre>
<p>The resulting output lists the VMID (Virtual Machine ID) and the Java process<br />
name. To get  extended information, append the  <strong>-v</strong>  flag to the jps command: </p>
<pre>
> jps v
1649  Application
2534 Jps
-Dapplication.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/
Home
-Xms8m </pre>
<h3>jstat</h3>
<p>This command gives performance statistic information from the JVM for a Java<br />
process. There are a  number of statistic options available, which is displayed using<br />
the  <strong>-options</strong>  switch:</p>
<pre>> jstat -options
-class
-compiler
-gc
-gccapacity
...
</pre>
<p>To print the statistics for one of the options above for a process, the VMID has to<br />
be specified after  the option. The VMID is the same id as listed with the  <strong>jps</strong> com-<br />
mand: </p>
<pre>> jstat -gcutil  1649
S0  S1  E  O  P  YGC  YGCT  FGC  FGCT  GCT
0,00  0,00  78,32  0,00  0,24  0  0,000  0  0,000  0,000
</pre>
<p>Using the jstat command, it is possible to create scripts that periodically checks the<br />
status for e.g.  the number of loaded classes or the garbage collection utilization. In<br />
the example above, the garbage  collection has taken place mostly in Eden memory<br />
space. Eden space is Sun Hotspot specific  memory space for shortlived  objects.<br />
Information about memory pools can be found at  http://java.sun.com. </p>
<h3>jstatd </h3>
<p>This command starts up a  <strong>jstat</strong> daemon on a machine and enables remote monitor-<br />
ing. To startup the  daemon on the computer which should be monitored, the port<br />
number where the remote clients can  connect to has to be specified: </p>
<pre>> jstatd -p  12345
</pre>
<p>After that, it is possible to use both <strong>jps</strong> and  <strong>jstat</strong> remotely by specifying the host-<br />
name and port: </p>
<pre>> jps example.computer.org:12345
2617 Jps
2611 Jstatd
1649 Application
</pre>
<p>The above example lists the processes on the ‘example.computer.org’ host using the<br />
port 12345.  Presented in the output, you can see the  <strong>jstatd</strong> is also a java process.</p>
<pre>> jstat  -gcutil  1649@example.computer.org:12345
S0  S1  E  O  P  YGC  YGCT  FGC  FGCT  GCT
0,00  0,00  78,32 0,00  0,24  0  0,000  0  0,000  0,000
</pre>
<p>Above we can see the same example for process 1649 as in the previous command,<br />
but this time  listed for host ‘example.computer.org’ using port 12345. </p>
<h3>jconsole </h3>
<p>On client computers, or servers with a graphical interface, it is possible to monitor<br />
the JVM status  by using a tool called  <strong>jconsole</strong>. The  <strong>jconsole</strong> tool visualizes services<br />
that exposes a JMX (Java  Management Extension) interface, and Java 1.5 and later<br />
contains JMX beans for exposing the data  defined in the java.lang.management<br />
package. </p>
<p>To be able to monitor java applications using  <strong>jconsole</strong> in Java 1.5, the application<br />
has to be started  with the system property <strong>-Dcom.sun.management.jmxremote</strong>.<br />
Example: </p>
<pre>> java -Dcom. sun.management.jmxremote jar  testapp.jar </pre>
<p>When the application has started, the  <strong>jconsole</strong> can be initiated: </p>
<pre>> jconsole </pre>
<p>The connection <strong>console</strong> displays all java processes that has JMX enabled.  After con-<br />
necting to the  Java process, jconsole provides the following tabs: </p>
<ul>
<li>		Summary	Tab
<li>		Memory	Tab	–	The	different	memory	pools	can	be	inspected
<li>		Thread	Tab	–	The	total,	peak	and	currently	live	threads	are	displayed
<li>		Classes	Tab	–	The	number	of	classes	are	displayed
<li>		Mbeans	Tab	–	Gives	access	to	the	JMX	beans	in	the	management	package
<li>		VM	Tab	–	Displays	information	for	the	VM	where	the	application	is	running	in
</ul>
<p>Below are example screenshots for the memory and thread tab:  </p>
<p><img src="http://blog.jayway.com/wordpress/wp-content/uploads/2009/12/Picture-82.png" alt="Figure 2" title="Figure 2" width="430" height="650" class="alignnone size-full wp-image-3420" /></p>
<p>The  <strong>jconsole</strong> application can be a tool to start with when looking at application<br />
behavior over time,  such as memory leaks or unusual thread behavior. </p>
<p>Using the Java monitoring and management tools you can get a better understanding<br />
of the runtime behavior of your application. Sometimes this information is enough<br />
for finding and fixing a problem. </p>
<p>This concludes the first part of the article. In the next issue of JayView we will look<br />
into the  troubleshooting tools. </p>
<p><em>Originally published in <a href="http://jayway.se/jayview">JayView</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2008/02/01/forensic-tools-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

