Jstack Jmap Resin

Today, I use jstack, jmap, and resin to look up why my server is deading in stress test. And I also find printing information into log is useful. You can print log in entrance of function and exit of function.
jstack is a tool which is looked up stack of system, specailly in threads. It is mainly for looking up dead lock and some functions which are executed too slowly.
jmap is a tool which is looked up current memory of system or some memery jvm can not delete immediately.
You can use jstack like this:

jstack -l [pid]

If you know pid of the process, you can see what’s the situation of stacks in process. If you want to see the detail, looking at those stacks.
jmap is used like this:

jmap -heap [pid]

Today, Big niu Qiao tells me about JVM GC policy.
There are New Generation, Old Generate and Perm Generation in JVM. You can find them in jmap command. And New Generation are new objects. And Old Generation are old objects which are still be refered. Eden Space stores new generate objects. And From Space stores still alive objects after gc once. To space stores objects which are not refered and in From space before gc once. If an objects is in From Space many times, it will be moved to Old Generation by JVM. Perm Generation are static objects and Classes.
By the way, if your application runs in resin, you should look up those logs of resin, for example, jvm-default.log. The log file contains GC log information. If GC throws overMemory exception, you should modify your configuration of resin (resin.xml in resin4.0+). Modify or add:


This means set JVM heap space to 1G.

今天使用了一下jstack, jmap来查看系统为啥在压力测试中缓慢的挂掉。我发现还是很有用的还有就是打log.函数入口和函数出口都打log。

jstack -l [pid]



jmap -heap [pid]

今天继续听巧大牛讲JVM GC策略。
jmap中有New Generation 和Old Generation. 分别对应新生成的和很久都没有被释放的。Eden Space就是新生成的对象。而From Space是以前曾经存活的对象(一次GC之后,Eden区的对象都会转换为From区)。To Space是以前曾经存活的对象但是现在已经没有引用了(一次GC过后, Eden区全部对象和From区尚有引用的对象回全部放入到To区)。而对象如果一直在From区,就会被jvm放入到Old Generation中。
Old Generation是扫描一边标记,再扫一边回收,另外涉及到内存压缩云云。
Perm Generation是static对象和class