<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 41  文章 - 29  trackbacks - 0
    <2009年1月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(5)

    隨筆分類(28)

    隨筆檔案(23)

    收藏夾(6)

    Inside JVM

    Java

    java performance

    Solr

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜


    Common Problems in Java SE Application

    This message is based on the following materials.
    http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Insufficient_Memory
    http://java.sun.com/developer/technicalArticles/javase/troubleshoot//

    1. Java Memory Basic

    1.1 Heap, Non-Heap, and Native

    Heap memory is the runtime data area from which memory for all class instances and arrays is allocated.
    Non-heap memory includes the method area and memory required for the internal processing or optimization of the JVM.
    It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors.
    Native memory is the virtual memory managed by the operating system. When the memory is insufficient for an application to allocate, a java.lang.OutOfMemoryError will be thrown.

    1.2 GC and Full GC

    The garbage collector (GC) detects garbage, defined as objects that are no longer reachable, then reclaims it and makes space available to the running program. The GC typically works in a stop-the-world fashion -- that is, it freezes the heap when working.

    The above diagram describes the layout of HotSpot VM Heap and it consists of three parts: perm generation, old generation and new/yang generation. The perm generation is basically for class loading. Next are the old and young generation. The young generation is further broken up into three spaces: Eden, Survivor Space 1 (SS#1) and Survivor Space 2 (SS#2).
    Garbage Collection1. When you have a new object, the object gets created in Eden space.
    2. So after running for a while, Eden space will fill up.a minor garbage collection occurs, in which all the objects alive in Eden are copied over to SS#1. Eden is then empty and ready to receive new objects.
    3. After the minor GC, objects are allocated to Eden again. After a time, the Eden space fills up again, and another minor GC occurs. The objects surviving in SS#1 and Eden are copied to SS#2, and both SS#1 and Eden are reset. Although objects are frequently recopied, either from Eden or from one SS to another, at any one time, only Eden and one SS are operating.
    4. Every time an object moves from Eden to SS or from one SS to another, a counter and its header is incremented. By default, if the copying occurs 16 times or more, the HotSpot VM stops copying them and moves them to the old generation.
    5. If an object can't be created in Eden, it goes directly to the old generation. Moving an object from SS to the old generation because of its age is called tenuring. Because of tenuring, the old generation becomes full over time. This calls for garbage collection of the old generation, which is called a full GC. A full GC is a compaction process that is slower than a minor GC.

    2. Memory Problems: out of memory, memory leak and Frequently full GC

    • java.lang.OutOfMemoryError: Java heap space => It indicates that an object could not be allocated in the Java heap.
      1. Configuration issue, where the specified heap size (or the default size, if not specified) is insufficient for the application.
      2. The application is unintentionally holding references to objects, and this prevents the objects from being garbage collected. This is the Java language equivalent of a memory leak.
      3. One other potential source of OutOfMemoryError arises with applications that make excessive use of finalizers.
    • java.lang.OutOfMemoryError: PermGen space => the permanent generation is full.
      1. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the -XX:MaxPermSize option.
      2. Interned java.lang.String objects are also stored in the permanent generation.If an application interns a huge number of strings, the permanent generation might need to be increased from its default setting.
    • java.lang.OutOfMemoryError: Requested array size exceeds VM limit
            attempted to allocate an array that is larger than the heap size
    • java.lang.OutOfMemoryError: request <size> bytes for <reason>. Out of swap space?
           The Java Native Interface (JNI) code or the native library of an application and the JVM implementation allocate memory from the native heap. An OutOfMemoryError will be thrown when an allocation in the native heap fails.
    • java.lang.OutOfMemoryError: <reason> <stack trace> (Native method)
           an indication that a native method has encountered an allocation failure. The difference between this and the previous message is that the allocation failure was detected in a JNI or native method rather than in Java VM code.

    3. Thread Problems: dead lock, infinite loop and high lock contention

    • Dead Lock
      1. block by object monitor: Each object is associated with a monitor. If a thread invokes a synchronized method on an object, that object is locked.
      2. block by java.util.concurrent.locks
    • Looping Thread
          
      If thread CPU time is continuously increasing, but it is not unresponsive. An infinite loop may consume all available CPU cycles and cause the rest of the application to be unresponsive.
    • High Lock Contention
           Synchronization is heavily used in multithreaded applications to ensure mutually exclusive access to a shared resource or to coordinate and complete tasks among multiple threads.
      Or too many threads are waiting for a limited resource.

    Troubleshooting Tools in Java SE Application

    1. Command line tools

    NAME

    Description

    Target Problem

    jstat

    Java Virtual Machine Statistics Monitoring Tool

    JVM memory statistics including memory usage, garbage collection time, class loading, and the just-in-time compiler statistics

    jmap

    Java Memory Map

    It prints shared object memory maps or heap memory details of a given process, core file, or remote debug server. It offers an inclusive, detailed memory configuration and information on free space capacity

    jhat

    Java Heap Analysis Tool

    Parse a binary heap dump, launch a web browser, and present standard queries.

    jps

    Java Virtual Machine Process Status Tool

    The jps tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. In other words, it lists java application and its process id.

    jstack

    Java Stack Trace

    It provides the stack traces of all the threads attached to a VM, such as application threads and interval VM threads. It also performs deadlock detection and will perform a stack trace if the VM is hung

    HPROF

    The Heap and CPU Profiling Agent

    a heap-CPU profiling tool that collects information on CPU usage, heap dumps, and thread states, uses the JVM Tool Interface (JVMTI), so every JVM has a diagnostic interface

    jinfo

    Java Configuration Info

    jinfo prints Java configuration information for a given Java process or core file or a remote debug server. And it can set java configuration property at runtime.

    XX:+HeapDumpOnOutOfMemoryError


    When an OutOfMemoryError is thrown, a heap dump file named java_pid<pid>.hprof will be created automatically


    2. Visual Tools

    NAME

    Description

    Target Problem

    jconsole

    Launch a GUI to monitor and manage Java applications and Java VMs on a local or remote machine.

    Memory and Thread Problem

    jvisualvm

    Java Visual VM

    Java VisualVM relies on tools such as jstat, jinfo, jstack, and jmap to obtain detailed information about applications running inside a JVM. It then presents the data in a unified, graphically rich manner.


    posted on 2009-01-08 22:15 Justin Chen 閱讀(3289) 評論(3)  編輯  收藏 所屬分類: Inside JVM

    FeedBack:
    # re: The JDK Troubleshooting Tools You May Not Know - Windows Platform 2009-01-09 08:46 charlie's logic
    and then ? to be continue?  回復  更多評論
      
    # re: The JDK Troubleshooting Tools You May Not Know - Windows Platform 2009-01-09 10:11 Justin Chen
    @charlie's logic
    yep, i will finish it a little bit late. thank you.   回復  更多評論
      
    # re: An Overview on Common JVM Level Problems in Java SE Application - 1 of Series "Inside JVM"  2010-02-09 17:44 macrochen
    "if the copying occurs 16 times or more"
    這個是什么意思? 從eden到ss, 從ss1 到ss2最多也就兩次啊?  回復  更多評論
      
    主站蜘蛛池模板: 亚洲无线码在线一区观看| 亚洲午夜日韩高清一区| A毛片毛片看免费| 亚洲一级毛片免费在线观看| 日韩在线免费播放| a毛片基地免费全部视频| 国产午夜免费高清久久影院| 日韩成人精品日本亚洲| 亚洲美女一区二区三区| 久久亚洲高清综合| 亚洲国产精品丝袜在线观看| 精品熟女少妇AV免费观看| 999国内精品永久免费视频| 久久成人a毛片免费观看网站| 国产黄在线观看免费观看不卡| 青青青亚洲精品国产| 亚洲国产午夜精品理论片在线播放 | 亚洲一级片免费看| avtt亚洲天堂| 亚洲亚洲人成综合网络| 国产精品亚洲高清一区二区| 亚洲日韩在线观看免费视频| 亚洲男人天堂2020| 亚洲AV无码日韩AV无码导航| 国产精品亚洲A∨天堂不卡| 婷婷久久久亚洲欧洲日产国码AV| 亚洲老妈激情一区二区三区| 人人狠狠综合久久亚洲婷婷| 亚洲午夜爱爱香蕉片| 亚洲AV永久无码精品一百度影院| 国产亚洲综合一区柠檬导航| 久久久久亚洲av无码专区喷水| 亚洲精品第五页中文字幕| 亚洲一级黄色大片| 亚洲人成7777影视在线观看| 亚洲日本在线观看| 日韩亚洲国产综合高清| 国产精品亚洲综合天堂夜夜| 国产精品免费在线播放| 日韩精品无码免费一区二区三区| 99久久免费精品视频|