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

What are the basics of JVM?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What are the basic knowledge of JVM, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

What is JVM?

JVM is a hypothetical computer that can run Java code, including a set of bytecode instructions, a set of registers, a stack, a garbage collection, a heap, and a storage method domain. JVM runs on top of the operating system and has no direct interaction with the hardware.

Second, the operation process

① Java source file-- > compiler-- > bytecode file

② bytecode file-- > JVM-- > machine code

3. JVM memory area

It is mainly divided into thread private area [program counter, virtual machine stack, local method area] and thread sharing area.

Domain [JAVA heap, method zone], direct memory.

IV. Jvm internal loading mechanism

The Java source code is compiled into class bytecode, and JVM loads the bytecode .Class file that describes the class data into memory, and verifies, transforms, parses and initializes the data, and finally forms the java type that can be directly used by the virtual machine, which is the class loading mechanism of the virtual machine.

From the time the class is loaded into the virtual machine memory, until it is unloaded out of memory, its life cycle includes seven stages: Loading, Verification, Preparation, Resolution, Initialization, Using and Unloading, in which verification, preparation and parsing are called links.

Fifth, JVM runtime memory

New generation: replication algorithm is mainly used in gc recovery

The Old Age: gc Recycling mainly uses Mark removal algorithm

Permanent generation: jdk8 removed, replaced by metadata area

Heap memory structure

What's the difference between stack and heap?

Stack advantage: access speed is faster than heap, second only to registers located directly in CPU. However, the disadvantage is that the data size and lifetime in the stack must be determined.

The advantage of the heap: memory can be allocated dynamically, and the lifetime does not have to tell the compiler in advance that Java's garbage collector will automatically collect data that is no longer in use. However, due to the dynamic allocation of memory at run time, the access speed is slow.

VI. GC garbage collection

(1) how to determine garbage

Citation counting method

Accessibility analysis

(2) Recycling object

Objects out of scope / objects whose reference count is empty.

Start searching from gc root and search for objects that cannot be found.

Recycle the Cenozoic area.

(3) recovery algorithm

Citation counting method

Label elimination method

Label compression method

Replication algorithm

Generation algorithm

7. JAVA reference type

Strong reference: assigns an object to a reference variable, which is a strong reference

Use it. When an object is referenced by a strong reference variable, it is in a reachable state, and it cannot be reclaimed by the garbage collection mechanism, even if the object will never be used for JVM later. Therefore, strong references are one of the main causes of Java memory leaks.

Soft reference: it needs to be implemented with the SoftReference class. For objects with only soft references, it will not be reclaimed when the system memory is sufficient, and it will be reclaimed when the system memory space is insufficient. Soft references are usually used in memory-sensitive programs

Weak references: need to be implemented with the WeakReference class, which has a shorter lifetime than soft references. For objects with only weak references, the memory occupied by the object will be reclaimed as soon as the garbage collection mechanism runs, regardless of whether the JVM has enough memory space or not.

Virtual reference: requires the PhantomReference class to implement, it cannot be used alone, it must be used in conjunction with the reference queue. The main function of virtual references is to track the status of objects being garbage collected.

Tuning common JVM parameters

Xss: the Stack size of each thread

-verbose:gc real-world garbage collection information

-Xloggc:gc.log specifies the garbage collection log file

-heap size of Xmn:young generation, which is generally set to 1 / 3 or 4 of Xmx.

-XX:+UseParNewGC: shortens the time for minor collection

-XX:+UseConcMarkSweepGC: shortens the time for major collection

Important parameters:

-Xms heap initial value

-maximum available value of Xmx heap

Maximum available value of Xmn Cenozoic reactor

-Xmn Cenozoic size, which is generally set to about 1max 3 to 1max 4 of the entire heap.

Note: heap initial value = heap maximum, reduce the number of garbage collection, improve efficiency.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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