"Original" "Android" uncover ART details----garbage collection

Source: Internet
Author: User

background

Dalvik:http://zh.wikipedia.org/wiki/dalvik%e8%99%9a%e6%8b%9f%e6%9c%ba

Art:http://source.android.com/devices/tech/dalvik/art.html

Body

Ian Rogers   in < Span style= "font-family: italics; font-size:14pt; " >google IO on narrated

First look at how the GC works in Dalvik :

Figure 1: the GC process

Figure 2:              suspend all threads for tagging, garbage collection to free up space

As you can see from Figure 1, when Dalvik starts garbage collection, the GC will go to find all the active objects, this time the entire program's thread will hang, and all the threads inside the virtual machine will hang at the same time (Figure 2) , so that the objects referenced are found in fewer stacks. It is important to note that this recycling action is performed concurrently with the application.

The reason for suspending all threads here is to make sure that all the programs are not making any changes, while the GC hides all the processed objects, and finally ensures that all objects that need to be reclaimed are flagged and the GC recovers all the threads and frees up space.

So in the Dalvik, hang all the threads this action priority is very high, in memory tense when the action will be frequently executed, which will cause the drop frame, interface lag phenomenon.

Figure 3: Why the GC in D Alvik so lame?

from diagram 3 You can see that when you find that you need to give a larger object ( Span style= "color: #3366ff;" > blue squares ) When allocating space, it is still sufficient to find free space, but there is not such a large contiguous space for new objects to use, this time you have to do a GC Recycling ( Red Square ) (Figure 3

We can also use a realistic image of the community parking phenomenon to explain: A longer car a( Blue Square ) to find a parking space, found a lot of empty location, but the distance between the car and the car is not suitable for a car Stop position, this time will have to let the parking manager m (GC) to find out whether there is a non-local vehicle (Red Square) and recycling parking space for a car to use. (Here we can see that if the car stops tight enough, there is no need to bother the parking keeper )

From the above 3 graphs we can see that the GC problem in Dalvik is as follows:

  1. Suspend all threads when GC

  2. Large and continuous space tension

3. Memory fragmentation is critical

Let's look at how ART solves these problems:

                  Figure 4 threads that do not need to suspend all programs in art

Here you can in contrast to Figure 11, in the The GC in ART requires the program to mark its own stack when allocating space, a process that is very short, There is no need to suspend all program threads. This saves a significant portion of the time to find the active object. ( resolve Issue 1)

Figure 5 provides Los:large object space dedicated to bitmap use

As you can see from Figure 5, art has a separate Los for bitmap, which improves GC management efficiency and overall performance.

We also understand from the community parking phenomenon : The plot of a car dedicated to the area, so that the cart saves the time to find a parking space, but also reduce the number of Notification Manager m (GC). ( resolve Issue 2)

Fig. 6 Moving collector in art

In art there will also be a moving collector to compress the active objects ( green squares ), which makes the memory space more compact.

Small area parking phenomenon understanding: Parking Manager M will regularly move stop irregular car, make parking space more compact, maximize the use of effective space. ( resolve Issue 3)

After solving the three questions above, art has the following advantages:

  1. Less Memory fragmentation

2. Shorter and fewer interrupts and blockages

3. Lower Memory utilization

Summary: Google has done a great job of optimizing GC in art, and from the demo data, memory allocation is 10 times times more efficient and the GC is 2-3 times more efficient. The main thing is to shorten the time of interruption and blocking by changing the timing of tagging, to solve the memory allocation and storage problem of large objects through Los, and to compress the memory by moving collector to make the memory space more compact, which can achieve a huge improvement of GC overall performance.

Ps:

If you like this article, please click on the lower right corner of the recommendation, welcome reprint!

Related Article

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.