In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the main components and functions of JVM". In daily operation, I believe many people have doubts about the main components and functions of JVM. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation, hoping to help you answer the doubts about "what are the main components and functions of JVM?" Next, please follow the editor to study!
Java memory area to talk about the main components of JVM and its role?
JVM consists of two subsystems and two components, the two subsystems are Class loader (class loading) and Execution engine (execution engine), and the two components are Runtime data area (runtime data area) and Native Interface (local interface).
Class loader (class loading): loads the class file into the method area in Runtime data area based on a given fully qualified class name (such as: java.lang.Object).
Execution engine (execution engine): executes instructions in classes.
Native Interface (native interface): interacts with native libraries and is an interface for interaction with other programming languages.
Runtime data area (Runtime data region): this is what we often call JVM memory.
Function: first, the Java code is converted into bytecode through the compiler, and then the class loader (ClassLoader) loads the bytecode into memory and places it in the method area of the runtime data area (Runtime data area). The bytecode file is only a set of instruction set specifications of JVM and cannot be directly handed over to the underlying operating system for execution, so a specific command parser execution engine (Execution Engine) is needed to translate the bytecode into underlying system instructions. Then leave it to CPU to execute, and in this process, you need to call the native library interface (Native Interface) of other languages to realize the function of the whole program.
The following is a detailed description of the running mechanism of the Java program
Steps of Java program running mechanism
First, use IDE integrated development tool to write Java source code, and the source file is suffixed with .java.
Then use the compiler (javac command) to compile the source code into a bytecode file with the suffix .class.
The job of running bytecode is done by the interpreter (java command).
As you can see from the figure above, the java files become .class files through the compiler, and then the class loader loads these .class files into JVM. In fact, it can be explained in one sentence: class loading refers to reading the binary data from the class's .class file into memory, putting it in the method area of the runtime data area, and then creating a java.lang.Class object in the heap area to encapsulate the data structure of the class in the method area.
Talk about the JVM runtime datazone
The Java virtual machine divides the memory area it manages into several different data regions during the execution of the Java program. These areas have their own uses and the time of creation and destruction, some areas exist with the start of the virtual machine process, and some areas are established and destroyed depending on the start and end of the thread. The memory managed by the Java virtual machine is divided into the following areas:
The runtime data zones of different virtual machines may be slightly different, but all comply with the Java virtual machine specification, which is divided into the following five parts:
Program counter (Program Counter Register): the line number indicator of the bytecode executed by the current thread. The bytecode parser's job is to change the value of this counter to select the next bytecode instruction to be executed, such as branch, loop, jump, exception handling, thread recovery and other basic functions.
Java virtual machine stack (Java Virtual Machine Stacks): used to store local variables, Operand stacks, dynamic links, method exits, etc.
Local method stack (Native Method Stack): the function is the same as the virtual machine stack, except that the virtual machine stack serves the Java method, while the local method stack invokes the Native method service for the virtual machine
Java heap (Java Heap): the largest block of memory in the Java virtual machine, shared by all threads, where almost all object instances allocate memory
Method area (Methed Area): used to store data such as class information, constants, static variables, immediately compiled code, which have been loaded by the virtual machine.
Deep copy and shallow copy
ShallowCopy simply adds a pointer to an existing memory address
Deep copy (deepCopy) is to add a pointer and apply for a new memory so that the added pointer points to the new memory
In the case of a deep copy, the memory is freed without the error of freeing the same memory when a shallow copy occurs.
Shallow copy: only points to the copied memory address, if the original address changes, then the shallow copied object will change accordingly.
Deep copy: create a new memory address in the computer to store copied objects.
Tell me the difference between stacks?
Physical address
The physical address allocation of the heap is discontiguous to the object. So the performance is slower. Discontinuous allocation should also be taken into account in GC, so there are various algorithms. For example, mark-eliminate, copy, mark-compress, generational (that is, the new generation uses the replication algorithm, the old age uses the tag-compression)
The stack uses the stack in the data structure, the principle of first in and then out, and the physical address allocation is continuous. So the performance is fast.
Memory separately
Because the heap is discontiguous, the allocated memory is confirmed at run time, so the size is not fixed. Generally, the heap size is much larger than the stack.
The stack is continuous, so the amount of memory allocated should be confirmed at compile time, and the size is fixed.
Stored content
The heap holds instances and arrays of objects. Therefore, the area is more concerned about the storage of data.
Stack storage: local variables, Operand stack, return results. The area is more concerned about the implementation of procedural methods.
PS:
Static variables are placed in the method area
Static objects are still placed on the heap.
Visibility of the program
The heap is shared and visible to the entire application.
The stack is visible only to threads. So it is also private to threads. His life cycle is the same as that of threads.
What are queues and stacks? What's the difference?
Queues and stacks are used to pre-store data.
The name of the operation is different. The insertion of the queue is called queuing and the deletion of the queue is called dequeuing. The insertion of the stack is called into the stack, and the deletion of the stack is called out of the stack.
It can be operated in different ways. The queue is joined at the end of the line and left at the head of the line, that is, it can be operated on both sides. The entry and exit of the stack are carried out at the top of the stack, so it is impossible to operate directly at the bottom of the stack.
The operation method is different. Queues are first-in, first-out (FIFO), that is, queues are modified on a first-in-first-out basis. Newcomers always join the end of the line (cannot be inserted from the middle), and members who leave each time are always at the head of the queue (leaving the team halfway is not allowed). The stack is last-in, first-out (LIFO), that is, each deletion (out of the stack) is always the latest element in the current stack, that is, the last element inserted (into the stack), while the first insert is placed at the bottom of the stack and can not be deleted until the end.
The creation of HotSpot Virtual Machine object Secret object
When it comes to object creation, let's first take a look at several object creation methods available in Java:
Header explains calling the constructor using the new keyword, using the newInstance method of Class, calling the constructor, using the newInstance method of the Constructor class, calling the constructor, using the clone method, not calling the constructor, using deserialization, not calling the constructor.
The following is the main process of object creation:
When the virtual machine encounters a new instruction, it first checks whether the constant pool has loaded the corresponding class, and if not, it must first perform the corresponding class loading. After the class is loaded, the memory is allocated next. If the memory in the Java heap is absolutely regular, use the pointer collision method to allocate the memory; if it is not regular, it is allocated from the free list, which is called the free list mode. There is one more thing to consider when dividing memory-concurrency, and there are also two ways: CAS synchronous processing, or local thread allocation buffers (Thread Local Allocation Buffer, TLAB). Then the memory space initialization operation is followed by some necessary object settings (meta-information, hash code.) And finally execute the method.
Allocate memory to objects
After the class is loaded, a block of memory is then allocated to the object in the Java heap. There are two ways to allocate memory depending on whether the Java heap is regular or not:
Pointer collisions: if the memory of the Java heap is regular, that is, all used memory is stored on one side and free ones on the other. When allocating memory, move the pointer indicator in the middle to free memory by a distance equal to the size of the object, thus completing the task of allocating memory.
Free list: if the memory of the Java heap is not regular, the virtual machine needs to maintain a list to record which memory is available, so that enough memory can be queried from the list to allocate to objects, and the list record can be updated after allocation.
The choice of allocation method is determined by whether the Java heap is regular or not, and whether the Java heap is regular or not is determined by whether the garbage collector used has the compression function.
Deal with concurrency security issues
Object creation is a very frequent behavior in the virtual machine, even if it is only to modify the location pointed to by a pointer, it is not safe in concurrent cases. Object A may be allocated memory, and the pointer has not yet been modified. Object B uses the original pointer to allocate memory at the same time. There are two ways to solve this problem:
Synchronize the actions that allocate memory space (using CAS + failed retry to ensure the atomicity of the update operation)
The operation of memory allocation is divided into different spaces according to threads, that is, each thread pre-allocates a small piece of memory in the Java heap, which is called local thread allocation buffer (Thread Local Allocation Buffer, TLAB). The thread that allocates memory is allocated on the TLAB of the thread. Synchronization locks are required only when the TLAB runs out and allocates a new TLAB. Use the-XX:+/-UserTLAB parameter to set whether the virtual machine uses TLAB.
Access location of object
Java programs need to access specific objects in the heap through references on the JVM stack. How the object is accessed depends on the implementation of the JVM virtual machine. At present, the mainstream access methods are handle and direct pointer.
Pointer: points to an object and represents the starting address of an object in memory.
Handle: it can be understood as a pointer to a pointer, maintaining a pointer to an object. The handle does not point directly to the object, but to the pointer to the object (the handle does not change and points to the fixed memory address), and then the pointer to the object's real memory address.
Handle access
A piece of memory is divided in the Java heap to serve as the handle pool. The reference stores the handle address of the object, and the handle contains the specific address information of the object instance data and the object type data, as shown in the following figure:
Advantage: a stable handle address is stored in the reference, which only changes the instance data pointer in the handle when the object is moved (it is a very common behavior during garbage collection), but the reference itself does not need to be modified.
Direct pointer
If you use direct pointer access, the object address is stored directly in the reference, then the layout within the Java heap object must consider how to place information about the access type data.
Advantages: faster, saving the time cost of a pointer positioning. Because access to objects is very frequent in Java, this type of overhead can add up to considerable execution costs. This is the approach used in HotSpot.
Will there be a memory leak in Java with a memory overflow exception? Please give a brief description
A memory leak means that objects or variables that are no longer used are occupied in memory all the time. In theory, Java has a GC garbage collection mechanism, that is, objects that are no longer in use are automatically recycled by GC and automatically cleared from memory.
However, even so, Java still has memory leaks, and the reason for memory leaks in java is clear: memory leaks are likely to occur when long-lifecycle objects hold references to short-lifecycle objects. Although short-lifecycle objects are no longer needed, they cannot be recycled because long-lifecycle objects hold their references. This is the scenario where memory leaks occur in java.
Garbage Collector briefly describes the garbage collection mechanism of Java
In java, programmers do not need to display to free the memory of an object, but are executed by the virtual machine itself. In JVM, there is a garbage collection thread that is low-priority and does not normally execute, triggering execution only when the virtual machine is idle or the current heap is out of memory, scanning objects that are not referenced and adding them to the collection to be recycled.
What is GC? Why GC?
GC means garbage collection (Gabage Collection). Memory processing is where programmers are prone to problems, forgotten or wrong memory.
Recycling can lead to instability or even crash of the program or system. The GC function provided by Java can automatically monitor whether the object exceeds the scope to achieve automatic
For the purpose of reclaiming memory, the Java language does not provide a display operation to free allocated memory.
The advantages and principles of garbage collection. And consider two kinds of recovery mechanism.
The most prominent feature of java language is the introduction of garbage collection mechanism, which makes java programmers no longer consider the problem of memory management when writing programs.
Because of this garbage collection mechanism, objects in java no longer have the concept of "scope", only referenced objects have "scope".
Garbage collection mechanism effectively prevents memory leaks and can effectively use available memory.
The garbage collector usually runs as a separate low-level thread that clears and collects objects in the memory heap that are dead or have not been used for a long time in unpredictable circumstances.
Programmers cannot call the garbage collector on an object or all objects in real time for garbage collection.
Garbage collection includes generation-by-generation replication garbage collection, marked garbage collection and incremental garbage collection.
What is the basic principle of the garbage collector? Can the garbage collector reclaim memory immediately? Is there any way to actively notify the virtual machine for garbage collection?
For GC, when a programmer creates an object, GC begins to monitor the address, size, and usage of the object.
In general, GC records and manages all objects in the heap (heap) in a directed graph. In this way, determine which objects are "reachable" and which are "unreachable." When GC determines that some objects are "unreachable", GC has the responsibility to reclaim this memory space.
Sure. Programmers can manually execute System.gc () to tell GC to run, but the Java language specification does not guarantee that GC will be executed.
What are the reference types in Java?
Strong reference: it will not be recycled when gc occurs.
Soft references: useful but not necessary objects that are recycled before a memory overflow occurs.
Weak references: useful but not necessary objects that will be recycled the next time you GC.
Virtual reference (ghost reference / phantom reference): you cannot get an object through a virtual reference, but use PhantomReference to implement a virtual reference, which is used to return a notification when gc.
How to determine whether the object can be recycled?
When the garbage collector is doing garbage collection, the first thing to decide is which memory needs to be reclaimed, which objects are "alive" and cannot be recycled, and which objects are "dead" and need to be recycled.
There are generally two ways to judge:
Reference counter method: create a reference count for each object, count + 1 when there is an object reference, count-1 when the reference is released, and be recycled when the counter is 0. It has a disadvantage that it can't solve the problem of circular reference.
Reachability analysis algorithm: search downward from GC Roots, and the path taken by the search is called reference chain. When an object does not have any reference chain to the GC Roots, it is proved that the object can be recycled.
When can an object be garbage collected in Java
When an object becomes unreachable to the application that currently uses it, the object can be recycled. Garbage collection does not occur in the permanent generation, and if the permanent generation is full or exceeds the critical value, complete garbage collection (Full GC) will be triggered. If you take a closer look at the output of the garbage collector, you will find that Yongdai is also recycled. This is why the correct permanent generation size is so important to avoid Full GC.
Will garbage collection occur in the permanent generation in JVM?
Garbage collection does not occur in the permanent generation, and if the permanent generation is full or exceeds the critical value, complete garbage collection (Full GC) will be triggered. If you take a closer look at the output of the garbage collector, you will find that Yongdai is also recycled. This is why the correct permanent generation size is so important to avoid Full GC. Please refer to Java8: from permanent generation to metadata area. (note: permanent generation has been removed from Java8 and a new native memory area called metadata area has been added)
What garbage collection algorithms does JVM have?
Mark-clear algorithm: Mark useless objects, and then clean up and recycle. Disadvantages: inefficient, unable to remove garbage fragments.
Replication algorithm: divide two memory areas of equal size according to capacity, copy the living objects to the other when one piece is used up, and then clean up the used memory space at once. Disadvantages: memory utilization is not high, only half of the original.
Tag-collation algorithm: Mark useless objects, move all living objects to one end, and then directly clear memory beyond the off-end boundary.
Generation algorithm: according to the different survival cycle of the object, the memory is divided into several blocks, generally the new generation and the old age, the new generation basically uses the replication algorithm, and the old age uses the tag finishing algorithm.
Mark-clear algorithm
Mark useless objects, and then clear and recycle.
The tag-cleanup algorithm (Mark-Sweep) is a common basic garbage collection algorithm that divides garbage collection into two phases:
Marking phase: Mark out objects that can be recycled.
Cleanup phase: reclaims the space occupied by the marked object.
The reason why the tag-removal algorithm is basic is that the garbage collection algorithms mentioned later are improved on the basis of this algorithm.
Advantages: it is easy to implement and does not need to move objects.
Disadvantages: the marking and cleaning process is inefficient, resulting in a large number of discontinuous memory fragments, which increases the frequency of garbage collection.
The execution process of the mark-clear algorithm is shown in the following figure
Replication algorithm
In order to solve the problem of low efficiency of mark-erase algorithm, a replication algorithm is produced. It divides the memory space into two equal areas, using only one area at a time. When garbage collection, traverse the currently used area, copy the surviving objects to another area, and finally recycle the recyclable objects in the currently used area.
Advantages: allocating memory sequentially is easy to implement and efficient, without considering memory fragmentation.
Disadvantages: the available memory size has been reduced to half of the original size, and objects will be copied frequently when the survival rate of objects is high.
The execution process of the replication algorithm is shown in the following figure
Marking-finishing algorithm
Replication algorithm can be used in the new generation, but in the old era, we can not choose the replication algorithm, because the survival rate of objects in the old era will be higher, so there will be more replication operations, resulting in lower efficiency. The mark-erase algorithm can be used in the old age, but it is not efficient and it is easy to produce a lot of memory fragments after memory recovery. So there is a tag-collation algorithm (Mark-Compact) algorithm. Unlike the tag-collation algorithm, after marking recyclable objects, all the surviving objects are compressed to one end of memory, so that they are compactly arranged together, and then the memory beyond the end boundary is reclaimed. After recycling, both used and unused memory are on their own side.
Advantages: the problem of memory fragmentation in the tag-cleaning algorithm is solved.
Disadvantages: local object movement is still needed, which reduces the efficiency to a certain extent.
The execution process of the tag-collation algorithm is shown in the following figure
Generation collection algorithm
At present, commercial virtual machines use generation-by-generation garbage collection algorithm. The generational collection algorithm, as its name implies, divides the memory into several blocks according to the survival cycle of the object. It generally includes the younger generation, the old generation and the permanent generation, as shown in the figure:
What kind of garbage collectors does JVM have?
If the garbage collection algorithm is the methodology of memory collection, then the garbage collector is the concrete implementation of memory collection. The following figure shows seven collectors for different generations, including Serial, PraNew, Parallel Scavenge for the new generation, Serial Old, Parallel Old, CMS for the old age, and G1 collector for the entire Java heap. The connections between different collectors indicate that they can be used together.
Serial collector (replication algorithm): the new generation of single-threaded collector, marking and cleaning are single-threaded, the advantage is simple and efficient
ParNew collector (replication algorithm): newborn generation parallel collector, which is actually a multithreaded version of Serial collector, has better performance than Serial in multi-core CPU environment.
Parallel Scavenge collector (replication algorithm): a new generation of parallel collector, the pursuit of high throughput, efficient use of CPU. Throughput = user thread time / (user thread time + GC thread time). High throughput can efficiently use CPU time to complete program tasks as soon as possible, which is suitable for scenarios such as background applications that do not require high interaction.
Serial Old collector (mark-collation algorithm): old-fashioned single-threaded collector, older version of Serial collector
Parallel Old collector (mark-collation algorithm): old-age parallel collector, throughput first, older version of Parallel Scavenge collector
CMS (Concurrent Mark Sweep) collector (mark-clear algorithm): the old parallel collector, which aims to obtain the shortest recovery pause time, has the characteristics of high concurrency and low pause, and pursues the shortest GC recovery pause time.
G1 (Garbage First) collector (mark-destruct algorithm): Java heap parallel collector. The G1 collector is a new collector provided by JDK1.7. The G1 collector is implemented based on the "mark-destruct" algorithm, that is, it does not produce memory fragmentation. In addition, an important feature of G1 collectors that is different from previous collectors is that the scope of G1 recovery is the entire Java heap (including the Cenozoic era and the old age), while the scope of the first six collectors is limited to the Cenozoic or the old era.
Tell me more about the CMS garbage collector?
CMS, the abbreviation of Concurrent Mark-Sweep in English, is a garbage collector that obtains the shortest recovery pause time at the expense of throughput. This garbage collector is very suitable for applications that require server response speed. Add "- XX:+UseConcMarkSweepGC" to the parameter that starts JVM to specify the use of the CMS garbage collector.
CMS uses the mark-clear algorithm, so a large number of memory fragments will be generated during gc. When the remaining memory can not meet the requirements of the program, Concurrent Mode Failure will appear in the system, and the temporary CMS will use the Serial Old collector for garbage removal, and the performance will be degraded.
What are the new generation garbage collectors and old garbage collectors? What's the difference?
New generation recyclers: Serial, ParNew, Parallel Scavenge
Old-age recyclers: Serial Old, Parallel Old, CMS
Whole heap recycler: G1
The new generation of garbage collector generally uses the replication algorithm, the advantage of the replication algorithm is high efficiency, the disadvantage is low memory utilization; the old collector generally uses the marking-finishing algorithm for garbage collection.
Briefly describe how does the generational garbage collector work?
The generational recycler has two partitions: the old generation and the new generation, the default space proportion of the new generation is 1 amp 3 of the total space, and the default proportion of the old generation is 2 max 3.
The new generation uses the replication algorithm, and there are three partitions in the new generation: Eden, To Survivor, and From Survivor. Their default share is 8:1:1, and its execution process is as follows:
Put the living objects of Eden + From Survivor into the To Survivor area
Clear Eden and From Survivor partitions
From Survivor and To Survivor partition exchange, From Survivor changes from To Survivor,To Survivor to From Survivor.
An object that survives every time From Survivor moves to To Survivor is + 1, and when it reaches 15 (the default is 15), it is upgraded to the old generation. The big object will also go straight into the old age.
When the space occupancy reaches a certain value, the older generation will trigger global garbage collection, which generally uses the execution algorithm of tag collation. The above cycles constitute the overall implementation process of the whole generation of garbage collection.
Memory allocation strategy A brief description of java memory allocation and recovery rate as well as Minor GC and Major GC
The so-called automatic memory management ultimately has to solve the two problems of memory allocation and memory recovery. We introduced memory recycling earlier, so let's talk about memory allocation here.
The memory allocation of objects is usually allocated on the Java heap (with the birth of virtual machine optimization technology, it will also be allocated on the stack in some scenarios, which will be described in more detail later). Objects are mainly allocated in the Eden area of the new generation. If local thread buffering is started, it will be allocated on the TLAB according to thread priority. In a few cases, it will also be distributed directly in the old days. Generally speaking, the allocation rules are not 100% fixed, and the details depend on which combination of garbage collectors and the relevant parameters of the virtual machine, but the virtual machine will follow the following "universal" rules for the allocation of memory:
Objects are assigned first in the Eden area
In most cases, objects are allocated in the Cenozoic Eden area. When the Eden zone allocation does not have enough space to allocate, the virtual machine will initiate a Minor GC. If there is still not enough space after this GC, the allocation guarantee mechanism will be enabled to allocate memory in the old age.
Here we mention Minor GC, and if you take a closer look at the daily life of GC, we can usually find Major GC/Full GC in the log.
Minor GC refers to the GC that occurs in the new generation, because most Java objects die overnight, all Minor GC are very frequent, and the recovery speed is generally very fast.
Major GC/Full GC refers to the GC that occurred in the old years, and the emergence of Major GC is usually accompanied by Minor GC at least once. Major GC is usually more than 10 times slower than Minor GC.
The big object went straight into the old age.
The so-called large object refers to the object that needs a lot of continuous memory space. Frequent occurrence of large objects is fatal, which will cause GC to be triggered in advance to obtain enough continuous space to place new objects when there is still a lot of space in memory.
We mentioned earlier that the new generation uses the tag-cleanup algorithm to deal with garbage collection. If large objects are allocated directly to the new generation, it will result in a large amount of memory replication between the Eden area and the two Survivor regions. Therefore, large objects will be allocated directly in the old days.
Long-term survival objects will enter the old age.
Virtual machines use the idea of generation-by-generation collection to manage memory, so memory collection must determine which objects should be placed in the new generation and which objects should be placed in the old era. So the virtual machine defines a counter for the age of each object. If the object is born in the Eden area and can be accommodated by Survivor, it will be moved to the Survivor space, where the age of the object is set to 1. The Minor GC age of the object is increased by 1 every time they "survive" in the Survivor area, and when they reach a certain age (the default is 15), they will be promoted to the old age.
Virtual machine class loading mechanism briefly describes the java class loading mechanism?
The virtual machine loads the data describing the class from the Class file into memory, and verifies, parses and initializes the data, and finally forms the java type that can be directly used by the virtual machine.
Describe the principle and mechanism of loading Class files by JVM
All classes in Java need to be loaded into JVM by a class loader to run. The classloader itself is also a class, and its job is to read the class file from the hard disk into memory. When writing a program, we hardly need to care about class loading, because these are implicitly loaded, unless we have special uses, such as reflection, to explicitly load the required classes.
There are two ways to load classes:
1. Implicit loading. When a program encounters an object generated by new or other means, it implicitly calls the class loader to load the corresponding class into jvm
two。 Explicit loading, using methods such as class.forname (), to explicitly load the required classes
The loading of the Java class is dynamic, it does not load all the classes at once and then run, but ensures that the basic class that the program runs (such as the base class) is fully loaded into the jvm, while the other classes are loaded only when needed. This is, of course, to save memory overhead.
What are classloaders and what are classloaders?
The block of code that implements the binary byte stream of a class through its permission name is called a class loader.
There are mainly four types of loaders:
The startup class loader (Bootstrap ClassLoader) is used to load the java core class library and cannot be directly referenced by java programs.
Extension class loader (extensions class loader): it is used to load the extension library of Java. The implementation of the Java virtual machine provides an extended library directory. The class loader looks for and loads the Java class in this directory.
System class loader (system class loader): it loads the Java class based on the classpath (CLASSPATH) of the Java application. Generally speaking, it loads all the classes of Java applications. You can get it through ClassLoader.getSystemClassLoader ().
The user-defined class loader is implemented by inheriting the java.lang.ClassLoader class.
Tell me about the execution process of class loading?
Class loading consists of the following five steps:
Load: find the appropriate class file according to the search path and import it
Verify: check the correctness of the loaded class file
Prepare: allocate memory space to static variables in a class
Parsing: the process by which a virtual machine replaces symbolic references in a constant pool with direct references. A symbolic reference is understood as a sign, while a direct reference points directly to an address in memory.
Initialization: initializes static variables and static code blocks.
What is the parental delegation model?
Let's talk about the classloader before we introduce the parent delegation model. For any class, the uniqueness in JVM needs to be established by the class loader that loads it and the class itself. Each class loader has a separate class namespace. The class loader loads the class file into JVM memory according to the specified fully qualified name, and then converts it to a class object.
Class loader classification:
The boot class loader (Bootstrap ClassLoader), which is part of the virtual machine itself, is used to load class libraries in the Java_HOME/lib/ directory or in the path specified by the-Xbootclasspath parameter and recognized by the virtual machine
Other class loaders:
Extension class loader (Extension ClassLoader): responsible for loading the\ lib\ ext directory or Java. Ext. All class libraries in the path specified by the dirs system variable
Application class loader (Application ClassLoader). Responsible for loading the specified class library on the user classpath (classpath), we can use this class loader directly. In general, this loader is used by default if we do not have a custom class loader.
Parent delegation model: if a class loader receives a request for class loading, it will not load the class itself in the first place, but delegate the request to the parent class loader to complete it, as is the case with the class loader at each level. so that all load requests are passed to the top-level startup class loader, only if the parent load fails to complete the load request (the required class is not found in its search scope) The child loader will try to load the class.
When a class receives a class load request, it will not load the class first, but delegate it to the parent class, which will be loaded by the parent class. If the parent class cannot be loaded at this time, feedback to the subclass, and the subclass will complete the loading of the class.
JVM tuning talk about JVM tuning tools?
JDK comes with many monitoring tools, all of which are located in JDK's bin directory, among which jconsole and jvisualvm are the most commonly used view monitoring tools.
Jconsole: used to monitor memory, threads, classes and so on in JVM
Jvisualvm:JDK comes with omnipotent analysis tools that can analyze: memory snapshots, thread snapshots, program deadlocks, monitoring memory changes, gc changes, and so on.
What are the commonly used parameters for JVM tuning?
-Xms2g: initialize the push size to 2g
-Xmx2g: maximum heap memory is 2g
-XX:NewRatio=4: set the memory ratio of the young to the old to 1:4
-XX:SurvivorRatio=8: set the new generation Eden and Survivor ratio to 8:2
-XX:+UseParNewGC: specifies to use the ParNew + Serial Old garbage collector combination
-XX:+UseParallelOldGC: specifies to use the ParNew + ParNew Old garbage collector combination
-XX:+UseConcMarkSweepGC: specifies to use the CMS + Serial Old garbage collector combination
-XX:+PrintGC: enable printing gc information
-XX:+PrintGCDetails: prints gc details.
At this point, the study on "what are the main components and functions of JVM" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.