Some basic knowledge of Java JVM and GC (RPM)

Source: Internet
Author: User

first, what is the JVM
Java VM (English: Java Virtual machine, abbreviated as JVM), aka Java Virtual machine, a VM capable of running Java bytecode, doing it on a stack-structured machine. The first implementation, developed by the solar micro-system, is part of the Java platform and is capable of running software programs written in the Java language. Java Virtual machine has its own perfect hardware architecture, such as processor, stack, register, etc., also has the corresponding instruction system. The JVM masks information that is relevant to the operating system platform, allowing Java programs to run without modification on multiple platforms by generating only the target code (bytecode) that runs on the Java virtual machine. The implementation of the software implemented by the central Processing unit (CPU) enables the implementation of compiled Java code (applets and applications). Virtual machines, as a programming language, are not actually dedicated to the Java language, and any language can be run by the JVM as long as the resulting compiled file conforms to the JVM's requirements for loading the compiled file format. Except for Oracle, there are other open source or closed sources implementations. --Wikipedia
This description is still very easy to understand, the virtual machine of this mechanism to give the code a new vitality, is a yi, run everywhere. Of course, good things are always flawed. Becauseto set up a virtual system on a physical machine to solve the differences between the hardware and the system is really a good thing, but at the same time the loss of nature is the efficiency of the operation. Second, the JVM's system specificationsJava's system is an open specification, as long as the specifications can be programmed Yi out of the program can run on the JVM.The JVM defines five specifications that control Java code interpretation execution and implementation, which are:
    • JVM Command System
    • JVM Registers
    • JVM Stack Structure
    • JVM Fragment Reclaim Heap
    • JVM Storage Area
third, how the JVM works
    • Operating system load JVM (Windows)
1. Create the JVM mount environment and configuration 2. Load Jvm.dll3. Initialize JVM.dll and hang bounds to jnienv (JNI call Interface) Instance 4. Call JNIEnv instance to load and Process class classes
    • JVM Load Class
Here's a look at how a Java code works:
Reference text: http://www.ibm.com/developerworks/cn/java/j-lo-classloader/

Iv. Memory management of the JVMhere is an article that says very detailed: http://developer.51cto.com/art/201303/387175.htmThe memory structure of the JVM is divided into 6 blocks: PC Register (PC register), JVM heap, JVM stack, method area, run constant, local method stack. As indicated: the main concern for development is the heap and stack. JVM Some parameter settings:-XSS: This parameter is used to specify the size of the stack-xms: set the minimum heap memory size for JVM startup-xmx: Set the maximum memory size of the JVM heap-xx:permsize and-xx: MaxPermSize the initial value of the specified method area (Methodarea) corresponds to the maximum value Methodarea is the Persistence generation (permanetgeneration), so it is important to set the perm size. Otherwise it will be reported java.lang.OutOfMemoryError:PermGen space. Five, garbage collector (garbage COLLECTOR,GC)Garbage collector This thing is a relief for programmers, so you don't have to explicitly free up memory. The magic effect is still to see his basic principles to understand the situation.Here's a quote:
there are several basic strategies for garbage collection increment way to do their work (no need to collect the entire Heap, which makes the collection pause time shorter), some algorithms can run when the user program runs ( concurrency collection). Other algorithms must be collected once when the user program is paused (that is, the so-called stop-the-world Collector). Finally, there are hybrid collectors, such as the generational collectors used by the 1.2 and later versions of the JDK, which use different collection algorithms for different areas of the heap. -- excerpt from developerworks China
Here on the recovery of the algorithm to see the main listed above the several, which is more important is "copy" and "Logo-collation" It is necessary to understand. Copy Collectoris to divide two peering spaces, one to put the active object, the other empty, and so on when the first one is full copy the active object to the other empty, and then swap the two space roles. One of the main points here is to replicate only active objects. Active objects are usually reachable objects that are not recycled memory, in other words is garbage, then the advantage is to replicate once, the garbage will be collected once. And the memory space after replication will be organized continuously, there is no fragmentation problem.The identity-collation collector algorithm combines tag-purge and copy, at the expense of adding some collection complexity. Like tag-purge, tag-grooming is a two-stage process that accesses and marks each active object during the tagging phase. Then, copy the tagged object so that all active objects are organized to the bottom of the heap. If you complete the collection every time, the resulting heap is similar to the result of the copy collector-there is a clear line between the active part of the heap and the free part, so that the allocation cost is equivalent to the copy collector. Long-lived objects tend to sink to the bottom of the heap, so they do not replicate as repeatedly as they do in the copy collector. since it is garbage collection, then naturally there is a problem what is garbage?
Span style= "color: #222222; line-height:1.5; Font-family:arial, Sans-serif; font-size:15px; " There is a reference to this block of memory, or there is a reference to it in another reachable block.
      Class - Objects loaded by the System class loader (loader), which cannot be recycled, can hold other objects in a static field. One thing we should be aware of is that classes loaded through the user-defined class loader are not roots unless the corresponding Java.lang.Class instances become roots in some other (or more) way.
    • thread -Live thread
    • Stack Local -The local variable or parameter of the Java method
    • JNI Local -local variable or parameter of the JNI method
    • JNI Global -Global JNI reference
    • Monitor used -monitoring object for synchronization
    • Held by JVM -objects reserved for the special purpose of the JVM by the GC, but this is actually related to the implementation of the JVM. Some of the types that may be known are the system ClassLoader, the important exception classes that some JVMs know, some pre-allocated objects for handling exceptions, and some custom class loaders. However, the JVM does not provide additional information for these objects, so it is only left to the analyst to determine what belongs to the "JVM hold".
generation of garbage collectionIt has been analyzed that objects in the application heap have 98% of objects that survive for a shorter period of time, and others that will survive long, even with the application throughout its life cycle. These two types of objects can be referred to as young generations and persistent generations.
the generational collector (generializational collector) divides the heap into multiple generations. Objects created in the younger generation that meet certain lifting criteria, such as objects that have undergone a specific number of garbage collections, will be promoted to the next older generation. Generational collectors are free to use different collection strategies for different generations, and each generation is garbage collected. --excerpt from Developerworks
It can be seen that generational garbage collection mainly classifies objects in the life cycle, and then uses different recycling algorithms for different categories, which allows for better tracking and recycling. JDK 1.4.1 Default collector

By default, JDK 1.4.1 divides the heap into two parts, a young generation and an older generation (in fact, there is a third part-the permanent space, which is used to store loaded classes and method objects). With the help of the copy collector, the young generation is divided into one creation space (often called Eden) and two surviving half spaces.

The old generation uses the tag-collation collector. The object has been promoted to the old generation after several copies. The small collection copies live objects from Eden and one surviving half space to another surviving half space, and may elevate some objects to the old generation. The large collection (major collection) will collect both the young generation and the old generation. The System.GC () method always triggers a large collection, which is one of the reasons that should be used sparingly (if not completely) System.GC () because large collections take much longer than small collections. There is no way to trigger a small collection programmatically.

--Excerpt from Developerworks

The general mechanism is to allow long-lived objects to be placed in the old generation, which optimizes the timing of the collection and reduces the collection pauses that are brought to the application.impact. Basically, the simple mechanism of GC is in this context. Reference text: http://blog.csdn.net/java2000_wl/article/details/8022293http://www.ibm.com/developerworks/cn/java/ J-jtp11253/http://www.cnblogs.com/5207/p/4275882.html

Some basic knowledge of Java JVM and GC (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.