`
astroxl
  • 浏览: 54256 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Tips About JDK5.0' Tool

    博客分类:
  • Java
阅读更多

http://www.javaperformancetuning.com/news/newtips063.shtml

 

Tips February 2006 About JDK5.0' Tool

 

http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf
JSE 5.0 Trouble-Shooting and Diagnostic Guide (Page last updated June 2005, Added 2006-02-27, Author Sun, Publisher Sun). Tips: <!-- 0-->

    <!-- CTGRY -->
  • jstack, jinfo, and jmap command line utilities are included in the JDK release for Solaris and Linux only. <!-- CTGRY -->
  • jstack, jinfo, jmap and jdb can obtain info from running JVMs and from core files generated from JVM crashes. <!-- CTGRY -->
  • jstat and jconsole enable the monitoring of many aspects of a running JVM. <!-- CTGRY -->
  • The HPROF profiler is a simple profiler included in the JDK, capable of presenting CPU usage, heap allocation statistics, contention profiles, heap dumps, states of all the monitors and threads. HPROF can be useful when analyzing performance, lock contention, memory leaks, and other issues. <!-- CTGRY -->
  • The Heap Analysis Tool (HAT) is a useful for diagnosing unnecessary object retention (or memory leaks). It can be used to browse an object dump, view all reachable objects in the heap, and understand which references are keeping an object alive. <!-- CTGRY -->
  • jinfo prints the system properties and the command line flags that were used to start the VM, e.g. with jinfo <pid|core>. <!-- CTGRY -->
  • jmap prints memory related statistics for a running VM or core file; by default it prints the list of shared objects loaded (the output is similar to the Solaris pmap utility). <!-- CTGRY -->
  • jmap -heap prints GC algorithm specific information: the name and details of the GC algorithm in use; the heap configuration; and a heap usage summary (total capacity, in-use and available free memory for each generation). <!-- CTGRY -->
  • jmap -histo provides a class-wise histogram of the heap: for each class, it prints the number of objects, memory size in bytes, and fully qualified class name. <!-- CTGRY -->
  • If an application loads or generates too many classes then it is possible it will abort with an OutOfMemoryError. The specific error is: "Exception in thread XXXX java.lang.OutOfMemoryError: PermGen space". <!-- CTGRY -->
  • jmap -permstat provides details on classloader statistics. For each classloader instance six fields are printed: class loader object hexadecimal address; number of classes loaded; total approximate number of bytes used class by meta-data; hexadecimal address of the parent class loader; GCable (dead indicates classloader will be garbage collected); the class name of this class loader. <!-- CTGRY -->
  • jstack prints a stack trace of all threads - similar to using the thread dump handler (i.e. Cntrl-\ or kill -QUIT or Thread.getAllStackTraces). <!-- CTGRY -->
  • Thread states in a thread stack dump can be one of the following: UNINTIALIZED Thread is not created; NEW Thread has been created but it has not started running yet; IN_NATIVE Thread is running native code; IN_VM Thread is running VM code; IN_JAVA Thread is running (either interpreted or compiled) Java code; BLOCKED Thread is blocked; ..._TRANS If you see any of the states followed by "_TRANS", it means the thread is changing to a different state. <!-- CTGRY -->
  • jstack stack lines have the format <Fully qualified class name>.<Method name> @bc=<Byte code index>, line=<Source line number> (Method compiled/interpreted?), e.g. "java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)" <!-- CTGRY -->
  • jstack -m will print a (mixed) stack including native stack frames in addition to the java stack. (Native frames are the C/C++ frames associated with VM code, and JNI/native code; you may need to pipe the output through the c++filt to demangle C++ mangled symbol names.) <!-- CTGRY -->
  • jconsole can attach to any application that is started with the JMX agent. The -Dcom.sun.management.jmxremote option is the system property which enables the JMX agent. <!-- CTGRY -->
  • The jconsole Summary panel lists: Uptime: how long the JVM has been running; Total compile time: the amount of time spent in runtime compilation; Process CPU time: the total amount of CPU time consumed by the JVM. <!-- CTGRY -->
  • The jconsole Memory panel lists: Current heap size: Number of Kbytes currently occupied by the heap; Committed memory: Total amount of memory allocated for use by the heap; Maximum heap size: Maximum number of Kbytes occupied by the heap; Objects pending for finalization: Number of objects pending for finalization; Garbage collector information: Information on GC, including the garbage collector names, number of collections performed, and total time spent performing GC. <!-- CTGRY -->
  • The jconsole Threads panel lists: Current number of live daemon threads plus non-daemon threads; Highest number of live threads since JVM started; Current number of live daemon threads; Total number of threads started since the JVM started (including daemon, non-daemon, and terminated). <!-- CTGRY -->
  • The jconsole Classes panel lists: Number of classes currently loaded into memory; Total number of classes loaded into memory since the JVM started, including those subsequently unloaded; Number of classes unloaded from memory since the JVM started. <!-- CTGRY -->
  • The jconsole Operating System panel lists: Amount of random-access memory (RAM) that the machine has; Amount of free RAM the machine has; Amount of virtual memory guaranteed to be available to the running process. <!-- CTGRY -->
  • jps lists accessible JVMs on the local system (and prints other parameters of teh JVM depending on options used); also for remote systems that are running jstatd. <!-- CTGRY -->
  • jstat uses built-in HotSpot VM instrumentation to provide information on performance and resource consumption of running applications, in particular issues related to heap sizing and garbage collection. <!-- CTGRY -->
  • jstat options prints statistics on: class loaders, the HotSpot compiler, and garbage collected heap stats and capacities by generations. <!-- CTGRY -->
  • visualgc provides a graphical view of the garbage collection system. As with jstat it uses the built-in instrumentation of the HotSpot VM. <!-- CTGRY -->
  • HPROF is a simple dynamically-linked library profiler agent shipped with JDK 5.0. HPROF is capable of presenting CPU usage, heap allocation statistics and monitor contention profiles. It can also report complete heap dumps and states of all the monitors and threads.<!-- CTGRY -->
  • HPROF is invoked with "java -agentlib:hprof <ToBeProfiledClass>"; use "java -agentlib:hprof=help" to get a listing of all the available HPROF options <!-- CTGRY -->
  • For HPROF cpu=samples is the recommended method profiling option; heap=sites is the recommended object memory profiling option. <!-- CTGRY -->
  • HPROF heap dump output is complex; the article covers some types of entry but recommends using HAT or other tool (HP have one too) to visualize the information. <!-- CTGRY -->
  • HAT (available from http://hat.dev.java.net) is capable of reading HPROF output in order to identify object roots that may be causing unintentional object retention. <!-- CTGRY -->
  • The "-XX:OnError=" option enables other operating system processes to be run if the JVM terminates on a fatal hotspot error, for example "java -XX:OnError="gcore %p" ..." to create a core dump on Solaris; or "java -XX:OnError="userdump.exe %p" MyApplication on Windows (or configure the Windows system to use Dr Watson to automatically create a crash dump). <!-- CTGRY -->
  • [Article describes using Solaris dbx debugger to operate on a JVM]. <!-- CTGRY -->
  • [Article describes using Solaris/Linix jdb debugger to operate on a running JVM or core file]. <!-- CTGRY -->
  • A stack dump is printed to stdout if the ctrl-break handler is executed (normally kill -QUIT or cntrl-\ on Unix or cntrl-brk on Windows). The ctrl-break handler also executes a deadlock detection algorithm: If any deadlocks are detected then it prints out additional information on each deadlocked thread. <!-- CTGRY -->
  • A thread header line in a ctrl-break handler stack dump reads as follows: "<thread name>" [daemon] prio=<java_priority> tid=<address of the thread structure in memory> nid=<id of the native thread> <Thread state> [<address range ? this is an estimate of the valid stack region for the thread.>], e.g."Java2D Disposer" daemon prio=10 tid=0x002007d8 nid=0xb in Object.wait() [0xf0701000..0xf07019b8]. <!-- CTGRY -->
  • The possible thread states in the output from a ctrl-break handler stack dump are: allocated; initialized; runnable; waiting for monitor entry; waiting on condition; in Object.wait(); sleeping. <!-- CTGRY -->
  • If the ctrl-break handler deadlock detector identifies a deadlock, then after the thread dump the information is printed starting with the line "Found one Java-level deadlock:" <!-- CTGRY -->
  • Information about GCs can be obtained using the options -verbose:gc -XX:+PrintGCDetails and -XX:+PrintGCTimeStamp. <!-- CTGRY -->
  • The -verbose:gc option can be dynamically enabled at runtime using the management API or JVM TI or using the jconsole tool. <!-- CTGRY -->
  • The -Xcheck:jni option makes the VM do additional validation on the arguments passed to JNI functions. When an invalid argument is detected, the VM prints a "FATAL ERROR in native method:" message, prints the stack trace of the offending thread, and aborts the VM. (Also possible that the message "Warning: Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical" may be printed). <!-- CTGRY -->
  • [Article lists useful operating system tools and their use in section 1.15 - Solaris: cputrack, cpustat, c++filt, dbx, dtrace, libumem, iostat, netstat, mdb, pfiles, pldd, pmap, prun, prstat, psig, pstack, pstop, ps, ptree, sar, truss, vmstat, gcore; Linux: ltrace, mtrace, muntrace, pmap, pstack, strace, top, vmstat, gdb; Windows: windbg, dumpchk, userdump]. <!-- CTGRY -->
  • You can use the java.lang.management package to implement additional management and monitoring; it covers interfaces for the following systems: class loading; compilation; garbage collection; memory manager; runtime; threads. <!-- CTGRY -->
  • The Sun implementation of 5.0 includes platform extensions in the com.sun.management package (see http://java.sun.com/j2se/1.5.0/docs/guide/management/extension/index.html). The platform extensions include a management interface to obtain detailed statistics from garbage collectors and additional memory statistics from the operating system. <!-- CTGRY -->
  • The java.lang.instument package (http://java.sun.com/j2se/1.5.0/docs/api/index.html) provides services that allow Java programming language agents to instrument programs running on the JVM, for both load-time and dynamic instrumentation.<!-- CTGRY -->
  • java.lang.Thread.getAllStackTraces returns a map of stack traces for all live threads. <!-- CTGRY -->
  • java.lang.Thread.getState that returns the thread state; states are defined by the java.lang.Thread.State enumeration. <!-- CTGRY -->
  • OutOfMemoryError are now classified: heap space (increase mx); permgen space (increase perm space size); operating system space (increase RAM/swap); in all cases an alternative is to reduce memory requirements; any OOME could be from unintentional object retention (an object leak). <!-- CTGRY -->
  • "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space" signifies not enough space available to create another object; either mx needs increasing or you have unintentional object retention (an object leak). <!-- CTGRY -->
  • "Exception in thread "main" java.lang.OutOfMemoryError: PermGen space" signifies too many classes loaded or being generated; or the String.intern table is too big. Increase using the -XX:MaxPermSize option. <!-- CTGRY -->
  • "Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit" signifies not enough space available to create another array; either mx needs increasing or you have unintentional object retention (an object leak). <!-- CTGRY -->
  • "Exception in thread "main" java.lang.OutOfMemoryError: request <size> bytes for <reason>. Out of swap space?" signifies either a memory leak of some sort, or more likely you ran out of available operating system memory. <!-- CTGRY -->
  • "Exception in thread "main" java.lang.OutOfMemoryError: <reason>" followed by "<stack trace>(Native method)" signifies Note that this is where the top element in the stack trace is a native method; either a memory leak of some sort, or more likely you ran out of available operating system memory. <!-- CTGRY -->
  • If you get a crash instead of an OutOfMemoryError, this is likely to be because a JNI level function used the NULL returned from a malloc call as a valid memory pointer. This indicates either a memory leak of some sort, or more likely you ran out of available operating system memory. <!-- CTGRY -->
  • If a class has a finalize method then objects of that type do not have their space reclaimed at garbage collection time. Instead after garbage collection the objects are queued for finalization which occurs sometime later.<!-- CTGRY -->
  • In the Sun JVM implementation finalizers are executed by a daemon thread that services the finalization queue. If the finalizer thread cannot keep up with the finalization queue then it is possible that the java heap will fill up and OutOfMemoryError will be thrown.<!-- CTGRY -->
  • jconsole can be used to monitor the number of objects that are pending finalization. (excessive use of finalizers can be the cause of OutOfMemoryError). In jconsole the pending finalization count is reported in the memory statistics on the "Summary" tab pane. The count is approximate but it can be used to characterize an application and understand if it relies a lot on finalization. <!-- CTGRY -->
  • Diagnosing leaks in Java Language code can be a difficult task, it is suggested that you use a profiler. Using HAT you would use java -agentlib:hprof=file=dump.hprof,format=b <Application> <!-- CTGRY -->
  • [A few considerations of using HAT to identify unintentional object retention are discussed, including comparing between two dumps]. <!-- CTGRY -->
  • Anyone writing a JNI library would probably be wise to create some kind of localized way to make sure your library doesn't leak memory using a simple wrapper approach. [Article provides an example in section 2.1.3]. <!-- CTGRY -->
  • libumem can be used to diagnose a native memory leak in Solaris. <!-- CTGRY -->
  • [Article explains the format of a hot spot crash log, see 2.2] <!-- CTGRY -->
  • To detect the cause of looping, get one or more thread dumps, that is usually sufficient to see where the execution locus is. <!-- CTGRY -->
  • If the VM does not respond to a Ctrl-\ this may suggest a possible VM bug rather than an issue with application or library code. In this case use jstack with the -m option to get a thread stack for all threads. <!-- CTGRY -->
  • In J2SE 5.0 deadlock detection works only with locks that are obtained using the synchronized keyword. This means that deadlocks that arise through the use of the java.util.concurrency package are not detected. <!-- CTGRY -->
  • [Article explains how to configure Dr Watson on Windows to get dumps on crashing, section 3.2.4].
分享到:
评论

相关推荐

    JDK 5.0.zip

    **JDK 5.0** 是Java开发工具集(Java Development Kit)的一个重要版本,它在Java编程领域具有里程碑式的意义。此版本的发布在2004年,带来了许多新特性和改进,极大地提升了Java语言的开发效率和程序性能。下面我们...

    JDK5.0_下载-安装-配置

    **JDK5.0下载** Java Development Kit (JDK) 是Java编程语言的软件开发工具包,它包含Java运行环境(JRE)、编译器(javac)和其他工具,用于编写、测试和运行Java应用程序。JDK5.0是Oracle公司于2004年发布的一个...

    良葛格java jdk 5.0学习笔记

    良葛格java jdk 5.0学习笔记,良葛格java jdk 5.0学习笔记.zip,良葛格java jdk 5.0学习笔记.zip,良葛格java jdk 5.0学习笔记.zip,良葛格java jdk 5.0学习笔记.zip,良葛格java jdk 5.0学习笔记.zip。

    良葛格JDK5.0学习笔记

    《良葛格JDK5.0学习笔记》是一份详细记录了Java开发工具包(JDK)5.0版本核心特性和技术要点的学习资料。这份笔记涵盖了Java编程语言的重要更新和改进,对于深入理解JDK5.0及其对Java开发的影响至关重要。 1. **...

    (Java 2 SDK)JDK 5.0 的源代码

    JDK 5.0是这个平台的一个重要版本,它引入了许多创新特性,极大地提升了开发效率和代码质量。 一、泛型(Generics) JDK 5.0的最大亮点之一就是泛型的引入。泛型允许在定义类、接口和方法时指定类型参数,从而提高...

    良葛格Java JDK 5.0学习笔记[可打印]

    Java JDK 5.0是Java开发的一个里程碑版本,它引入了许多重要的新特性和改进,极大地提升了开发效率和代码质量。良葛格的Java JDK 5.0学习笔记是一份宝贵的资源,适合初学者和有经验的开发者回顾这个版本的关键概念。...

    jdk5.0 tomcat5.0配置全攻略

    ### JDK 5.0 和 Tomcat 5.0 配置全攻略 #### 环境搭建背景 对于初入Java领域的新手来说,环境配置往往是一个不小的挑战。本篇文章旨在帮助那些在Java学习过程中遇到环境配置问题的朋友,提供一份详尽的JDK 5.0 和 ...

    良葛格————JavaJDK5.0学习笔记PDF

    良葛格————JavaJDK5.0学良葛格————JavaJDK5.0学习笔记PDF.rar习笔记PDF.rar良葛格良葛格————JavaJDK5.0学习笔记PDF.rar————JavaJDK5.0学习笔记PDF.rar良葛格————JavaJDK5.0学习笔记PDF.rar良...

    良葛格Java JDK 5.0学习笔记

    Java JDK 5.0是Java发展历程中的一个重要里程碑,它引入了许多新特性,极大地提升了开发效率和代码质量。这里,我们将详细探讨这个版本的关键知识点,帮助初学者更好地理解和掌握Java编程。 1. **自动类型推断(var...

    jdk 5.0 ban

    JDK 5.0是一个重要的版本,它在2004年发布,引入了许多创新特性,对Java编程语言进行了重大改进,提升了开发效率。 1. **泛型(Generics)**:JDK 5.0引入了泛型,允许开发者在类、接口和方法中定义类型参数,增强...

    jdk5.0新特性

    ### JDK 5.0新特性详解 #### 一、自动装箱与自动拆箱 在JDK 5.0中,引入了一个非常实用的功能——自动装箱和自动拆箱,这极大地方便了开发者在处理基本数据类型和它们对应的封装类之间的转换。以前,我们可能需要...

    JDK 5.0中文版API

    **JDK 5.0中文版API详解** Java Development Kit(JDK)是Java编程语言的核心组件,包含了编译器、运行环境以及一系列用于开发和运行Java应用的工具。JDK 5.0是一个重要的里程碑,它引入了许多创新特性,极大地提升...

    ibm JDK5.0 fro linux

    ibm JDK5.0 fro linux,这个东西很难下的。

    JAVA(JDK5.0)学习笔记

    ### JAVA(JDK5.0)学习笔记:深入理解数组与对象的关系 在深入探讨JAVA(JDK5.0)中数组的特性和应用之前,我们首先需要认识到数组在Java中的地位和作用远超于传统编程语言中纯粹的数据集合概念。数组在Java中被视为...

    JDK5.0的11个主要新特征

    JDK5.0是Java开发的一个重要里程碑,它引入了11个主要的新特性,极大地提升了编程效率和代码安全性。以下是对这些特性的详细说明: 1. 泛型(Generic) 泛型的引入是为了解决类型安全问题,避免在运行时进行不必要...

    JDK5.0新特性(3)——枚举

    在Java编程语言中,JDK 5.0的发布带来了一系列重要的新特性,极大地提升了开发效率和代码质量。其中,枚举(Enum)是引入的一个关键特性,它为表示固定集合中的常量提供了强大而安全的支持。这篇博客将深入探讨JDK ...

    良葛格Java JDK 5.0学习笔记ch05

    Java JDK 5.0是Java发展历程中的一个重要里程碑,它引入了许多新特性,极大地提升了开发效率和代码质量。在这个"良葛格Java JDK 5.0学习笔记ch05"中,我们将深入探讨其中的关键知识点。 一、泛型 Java 5.0引入了...

    jdk5.0 资源下载

    JDK5.0是Oracle公司发布的一个重要版本,它在Java语言的发展史上占有重要的地位,引入了许多创新特性,极大地提升了开发效率和代码的可读性。 一、JDK5.0的关键特性 1. 泛型(Generics):这是JDK5.0最显著的改进...

    JDK5.0 新特性

    在JDK 5.0中,Java引入了一系列重要的新特性,极大地提升了开发效率和代码的可读性。这些新特性包括自动包装和解包、增强的for循环、可变参数方法、printf风格的格式化输出、枚举类型以及静态导入等。 首先,自动...

    JDK5.0API官方中文版(CHM)

    JDK5.0API官方中文版(CHM)--------part2

Global site tag (gtag.js) - Google Analytics