Understanding the JVM

Source: Internet
Author: User

---restore content starts---

Java objects in the running environment, for memory, there are three states: young generation, the old generation, the eternal generation;

Is the JVM memory model

1. The young generation is divided into 3 parts: Enden District and two Survivor District, garbage collection--minor GC

2. New Object--first in the E-zone to apply for memory, insufficient to perform minor GC through a certain algorithm e->s-> old generation

3. All garbage collection is "Stop the World" event, full GC time is much higher than the minor GC

4. The immortal generation contains the application metadata required by the JVM, which describes the classes and methods used in the application, which are not part of the Java heap memory.

Configuration parameters

-XMS: initial Heap Size

-XMX: Maximum Heap Size

-XMN: Young generation heap memory size, remaining for the old age of space size

-xx:permgen: immortalized Memory Initial size

-xx:maxpermgen: Immortal Max Memory

-XSS: Set the stack size for each thread

Garbage collection type

There are five types of garbage collection that you can use in your app. Only the JVM switch is required to enable the garbage collection policy in our application. Let's take a look at:

  1. Serial GC (-XX:+USESERIALGC):Serial GC uses simple tagging, purging, and compression methods for garbage collection of young and old generations, that is, minor GC and major GC. The Serial GC is useful in client mode, such as in simple standalone applications and lower CPU configurations. This pattern works well for applications that occupy less memory.
  2. Parallel GC (-XX:+USEPARALLELGC): in addition to generating n threads for a young generation of garbage collection, Parallel GC and serial GC are almost the same. Here n is the number of cores of the system CPU. We can use the-xx:parallelgcthreads=n this JVM option to control the number of threads. The parallel garbage collector is also called the throughput collector. Because it uses multiple CPUs to speed up garbage collection performance. The Parallel GC uses a single thread for old generation garbage collection.
  3. Parallel old GC (-XX:+USEPARALLELOLDGC): same as Parallel GC. In contrast, the Parallel old GC uses multi-threaded collection when it comes to young generation garbage collection and older generation garbage collections.
  4. Concurrency Token Cleanup (CMS) collector (-XX:+USECONCMARKSWEEPGC):The CMS collector is also known as a transient pause concurrency collector. It is a garbage collection for old generations. The CMS collector collects garbage from multiple threads concurrently, minimizing the pauses caused by garbage collection. The CMS collector uses the same algorithm as the parallel collector for garbage collection for younger generations. This garbage collector is suitable for applications that cannot tolerate long pauses requiring rapid response. You can use the-xx:parallelcmsthreads=n JVM option to limit the number of threads for the CMS collector.
  5. G1 garbage collector (-XX:+USEG1GC) G1 (Garbage first): The garbage collector is a feature that can be used after Java 7, and its long-term goal is to replace the CMS collector. The G1 collector is a parallel, concurrent, and incremental compressed garbage collector that briefly pauses. The G1 collector does not operate in the same way as other collectors, and does not differentiate between young and old generation spaces. It divides the heap space into areas of equal size. When garbage collection is done, it takes precedence over areas where there are fewer surviving objects, so it is called "garbage first".

Understanding the JVM

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.