JVM Tuning Series: (ii) JVM runtime data region

Source: Internet
Author: User
Tags xms

1) Method Area

2) Heap

3) Java Stacks

4) PC Registers

5) Native Method Stacks

Java's JVM's memory model can be roughly divided into 3 zones:

Heap Area:

1. All objects are stored, each containing a class-corresponding information. (The purpose of class is to get operation instructions)

2.JVM only one heap area (heap) is shared by all threads, and the heap does not hold basic types and object references, only the object itself

Stack area:

When a thread executes a Java method, its PC register always points to the next instruction that needs to be executed, and its Java stack holds the call state of the Java method in the thread, such as its local variables, the parameters passed in to the method, the return value, and the intermediate result of the operation.

1. Each thread contains a stack where only objects of the underlying data type are saved and references to custom objects (not objects), objects are stored in the heap area

2. The data in each stack (original type and object reference) is private and other stacks are inaccessible.

Local method Stack:

When a thread invokes a local method, it enters a new local method stack that is no longer restricted by the virtual machine. The local method can access the runtime data area of the virtual machine through the local method interface, which has the same permissions (capability) as the virtual machine.

Any local method interface will use some kind of local method stack. When a thread calls a Java method, the virtual opportunity creates a new stack frame and presses it into the Java stack. However, when it calls the local method, the virtual machine keeps the Java stack intact, and no longer presses the new frame into the Java stack of the thread, the VM simply dynamically links and invokes the specified local method directly.

If a virtual machine implements a local method interface that uses the C connection model, then its local method stack is the C stack. When a C program calls a C function, its stack operation is deterministic. The arguments passed to the function are pressed into the stack in a certain order, and its return value is passed back to the caller in a deterministic manner.

Method Area:

1. Also called the static zone, like the heap, is shared by all threads. The method area contains all class and static variables.

2. The method area contains elements that are always unique throughout the program, such as types of basic information, constant pools, field information, method information, static variables, ClassLoader references, and other variables.

? Perm

Perm mainly save classs,method,filed objects, this department of space generally will not overflow, unless a lot of classes loaded, but when it comes to hot deployment of the application server, sometimes encounter Java.lang.OutOfMemoryError: PermGen space error, the cause of this error is likely to be redeployed every time, but after redeployment, the class is not unloaded, resulting in a large number of class objects saved in the perm.

? Tenured

Tenured the main preservation of the long life cycle of the object, usually some old objects, when some objects in young copy transfer a certain number of times, the object will be transferred to the tenured area, generally if the system with application level of cache, Objects in the cache are often transferred to this interval.

? Young

The young area is divided into three parts, the Eden area and two strictly identical survivor areas, of which the survivor interval, only one of which is used at a time, and the other one for garbage collection, when the young interval becomes full, minor The GC will move the surviving objects to an idle survivor interval, and depending on the JVM's strategy, the objects that survived the survivor will be moved to the tenured interval after several garbage collections.

Standard parameters-all JVM implementations must implement the functions of these parameters and are backwards compatible,-client

Non-standard parameter-X, the default JVM implements this functionality, but does not guarantee that all JVMs are implemented and is not guaranteed backwards compatibility,-XMXN

Non-stable parameter-xx, the implementation of each JVM will be different, and may disappear at any time, +XX:-USEPARALLELGC

-xmx3550m: Sets the maximum available memory for the JVM to 3550M. The default is 1/4 of physical memory but less than 1G.

-xx:minheapfreeratio=40: Modifies the minimum percentage of available memory in the heap after garbage collection, the default value is 40. If at least 40% of the heap memory is not released after garbage collection, the system will increase the size of the heap. -XMS,-xmx are invalid when they are equal.

-xx:maxheapfreeratio=70: The maximum percentage of heap memory that is available after changing garbage collection and before the heap memory shrinks, the default value is 70. This means that if there is more than 70% heap memory after garbage collection, the system will reduce the size of the heap. -XMS,-xmx are invalid when they are equal.

-xms3550m: Set the JVM initial memory to 3550m. This value can be set to the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes. The default is 1/64 of physical memory but less than 1G. The difference between-xmx-xms is the size of virtual space.

-xmn2g: Set the young generation size to 2G. the entire JVM memory size = younger generation size + old generation size + persistent generation size. The permanent average fixed size is 64m, so increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is 3/8 for the entire heap.
-xss128k: Sets the stack size for each thread. After JDK5.0, each thread has a stack size of 1M, before each thread has a stack size of 256K. The size of the memory required for the more applied threads to be adjusted.

-xx:newratio=4: Sets the ratio of the young generation (including Eden and the two survivor zone) to the old generation (except for the persistent generation). Set to 4, the ratio of the young generation to the old generation is 1:4, and the younger generation takes up 1/5 of the entire stack.
-xx:survivorratio=4: Sets the ratio of the size of Eden and survivor in the younger generation. Set to 4, the ratio of two survivor to one Eden area is 2:4, and one survivor area represents 1/6 of the entire young generation, and the default is 32.

-xx:permsize=16m-xx:maxpermsize=16m: Set the persistent generation size to 16m.

-xx:pretenuresizethreshold=3m: objects more than how much is directly in the old generation allocation, the Cenozoic use parallel scavenge GC is invalid.

-xx:largepagesizeinbytes=128m: Paging page size of javaheap, default 4m

-xx:tlabwastetargetpercent: The main memory occupied by the JVM is allocated from the heap space, the heap is shared by all threads, so allocating memory on the heap needs to be locked, and the Sun JDK for efficiency will allocate a separate space for each new thread on Eden, which is called Tlab (thread Local Allocation Buffer). The size is calculated by the JVM based on the operation, or by the parameter-xx:tlabwastetargetpercent to set the percentage of Eden space that Tlab can occupy, with a default value of 1%. Allocating memory on Tlab does not require locking, so the JVM allocates memory to the objects in the thread as much as possible on the Tlab. If the object is too large or tlab run out, it is still allocated on the heap.

-xx:maxtenuringthreshold=0: sets the maximum age for garbage. If set to 0, then the young generation object does not go through the survivor area, directly into the old generation. For older generations of more applications, can improve efficiency. The default value is 32, and the default value for Java6 under Linux64 is 15, which is not valid for parallel collectors.

-xx:+doescapeanalysis opened the escape analysis, and in some cases all performance improved greatly.

-xx:+aggressiveopts Accelerated compilation, Jdk5u6 introduced, JDK6 enabled by default.

Performance improvement of the -xx:+usebiasedlocking lock mechanism.

-XX:SOFTREFLRUPOLICYMSPERMB The surviving time of SoftReference in the free space per megabyte of heap.

-xx:+usefastaccessormethods The optimization of the original type Get,set method.

-XX:+DISABLEEXPLICITGC prohibits the invocation of System.GC () in a Java program.

-xx:+usecompressedoops compression pointer, to save memory consumption of new parameters, JDK1.6U14 start

-xx:compilethreshold When a method is called + cycles accumulate above this value, trigger the standard JIT compilation, default compilethreshold= 10000;
-xx:interpreterbackwardbranchlimit When a method call + loop count exceeds this value, the JIT-compilation of the form of OSR is triggered, 10070

-xx:+printescapeanalysis print escape analysis

-xx:+printassembly print JIT compiler becomes x86 directive

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JVM Tuning Series: (ii) JVM runtime data region

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.