JVM- heap memory

1. java heap memory Introduction

java heap memory is analogous to the computer's memory, the data is stored in place of the entire machine.

(1) jvm together to create dynamic java heap. Moving together analog computer loads the memory.

(2) shared by all threads. Analog computer all processes share a memory.

(3) a place to store instances of an object.

 

2. heap icon

 

 

 

3. heap memory division

Divided into the young generation (accounting for one third of heap memory) and the old year (accounting for two-thirds of heap memory). The young generation is divided into eden (accounting for the young generation 8/10), from (accounting for the young generation 1/10), to (accounting for the young generation 1/10). The following began to introduce respectively.

Old year: storing large objects and long life cycle of some objects.

The young generation: object storage accounted for less memory and short life cycle.

 

So the question is, the size of the object is relatively easy to say, a direct comparison of total space on the line; the length of the life cycle, how this thing count it? This is the eden to introduce the following, from, to

After an object is new out in the eden. The new target of the operation is very frequent, and more new objects, eden not fit, you need to be eden gc (garbage collection), occurs in eden in such a small level gc is called minor gc.

 

4. minor gc(young gc)

First introduce eden, from, to

eden: place of birth objects

from: save the surviving local data

to: Empty surviving area

 

The process is as follows :( minor gc red marking on the reference chart)

(1) eden in the living objects to put in, and mark the age of 1. (Some may be out of recycled trash)

(2) the subject alive from the age + 1 (some may be recycled garbage out). If the age threshold is reached (default 15 years old), directly into the old era; if age does not meet the threshold, to put in.

(3) after step (2), to which saved the live objects, from but cleared. This time marking the switching to and from, from to change, to change from. (NOTE: When to full time, directly to the inside of all the data into the old s)

 

to sum up:

minor gc using copy delete algorithm can reduce space debris.

All threads All Minor GC will stop the application, but this process is very short.

 

5. major gc(full gc)

It uses a mark - sweep algorithm.

Object years old procedures are considered more tenacious vitality, not so easy to die, it is not necessary to frequently perform full gc. And the data of old age much more than the new generation, it is also more time-consuming to perform.

Because the mark drawbacks clear algorithm, will cause a lot of memory fragmentation, when a large object coming in, not enough contiguous space to store his time, will perform Full gc. After performing and have enough contiguous space to store a new object.

 

Guess you like

Origin www.cnblogs.com/CUI-S/p/11728381.html