Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to tune the performance of Java virtual machine

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

The content of this article mainly focuses on how to tune the performance of the Java virtual machine. The content of the article is clear and clear. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!

one。 How to find a piece of garbage?

1) reference counting algorithm: add a reference counter to the object. Once referenced, the counter value is increased by 1; when the reference expires, the counter value is subtracted by 1. Many process programming languages such as Python use this method to manage memory, but the mainstream Java virtual machines do not choose it, mainly because it is difficult to solve the problem of circular references between objects.

2) Root reachability analysis algorithm: because the reference counting algorithm can not solve the problem of circular references between objects, this algorithm is introduced. The idea is to start the search downward with GC Roots as the starting point, and the path taken becomes a reference chain. when an object does not have any reference chain to GC Roots, the object is not available, that is, garbage.

two。 After finding a piece of rubbish, how to get rid of it?

1) Mark-Sweep (tag cleanup): first mark out recyclable objects, and then clear. The following black part is a recyclable object, the gray part is a living object, and the green part is an unused object.

It has two main shortcomings:

1. Both marking and clearing processes are inefficient.

two。 The other is the problem of space, which results in a large number of discontiguous memory fragments after mark removal, which will result in not finding enough continuous memory when large objects need to be allocated in the future, and then trigger another garbage collection action in advance.

2) Copying (copy): divide the memory into two pieces, copy all the surviving objects to the lower area, and then clear all the above.

This is the case with Survivor1 and Survivor2 in the new generation.

Disadvantages: waste of memory

3) Mark-Compact (tag compression or tag finishing): do not want to be fragmented or waste memory, mark the recycled objects first, and then move the surviving objects to one end while recycling.

Disadvantages: low efficiency

3. CMS is the concurrency of ConcurrentMarkSweep in the old years, garbage collection and applications are carried out at the same time, reducing the time of STW (200ms), CMS has a lot of problems, so no version defaults to CMS, which can only be set manually. Since CMS is a MarkSweep, there must be the problem of fragmentation. When the fragments reach a certain extent, when the allocation objects of the old age of CMS cannot be allocated, Serial Old is used for old-age recycling. (interview the hardest-hit areas)

There are four main processes:

Initial tagging, concurrent tagging, relabeling, concurrent cleanup

The disadvantage of CMS is that it generates floating garbage and uses Serial Old to clean up the whole old age, which is a flaw in CMS design; but if CMS is tuned, it supports much more memory than Parallel Old.

Imagine this:

PS + PO-> add memory for garbage collector-> PN + CMS + Serial Old (STW for hours-days), dozens of GB of memory, single thread recycling-> G1 + Full GC dozens of G-> server ZGC with T memory

CMS concurrent tagging is: tricolor tagging + Incremental Update

4. G1 garbage collector (200ms-10 ms)

Algorithm: tricolor tag + SATB

As more and more memory needs to be recycled, STW is bound to be generated, so G1 arises at the historic moment.

Logical generation, physical non-generation.

4. ZGC (10ms-1ms) competes for C++

Algorithm: ColoredPointers + LoadBarrier

5. Shenandoah

Algorithm: ColorPointers + WriteBarrier

The default age for the new generation of CMS is 6, and the default age for the new generation is 15. If you enter the old age, you can configure it with the parameter:-XX:MaxTenuringThreshold.

Jdk1.0 comes with Serial and Serial Old, now the most used are Parallel Scavenge and Parallel Old, and it is no problem to tune ParNew and CMS,jdk1.8 with G1

Jdk1.8 defaults to Parallel Scavenge and Parallel Old, whether single-threaded Serial or parallel Parallel, as long as there are many people, there will be problems, so there is a link between the past and the future of ParNew and CMS.

What are the characteristics of Java? what are the characteristics of Java? what is the 1.Java language that represents the static object-oriented programming language? it implements the object-oriented theory and allows programmers to carry out complex programming in an elegant way of thinking. 2.Java has the characteristics of simplicity, object-oriented, distributed, security, platform independence and portability, dynamic and so on. 3. Using Java, you can write desktop applications, Web applications, distributed systems, embedded system applications, and so on.

Thank you for your reading. I believe you have some understanding of "how to tune performance in the Java virtual machine". Go ahead and practice it. if you want to know more about it, you can follow the website! The editor will continue to bring you better articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report