In-depth understanding of the third edition of the Java Virtual Machine, summary notes [updated]

Recently been watching "in-depth understanding of the Java Virtual Machine," third edition, the third edition accidentally discovered only recently released, I heard that explain JDK version upgrade, adding nearly 50% of the content.

This book of God, read, look into it, really look quickly, and did not imagine the obscure, after all, is recognized as a classic author written description ability is certainly amazing. While this book will not make you code the ability to upgrade immediately, but really let you know these, but also know why. And other problems encountered in this area, certainly not like a headless flies, confused, at least have some idea. More Java, a number of computer-related books is on the way, be sure to take a good look at this year to enhance the internal strength.

However, such fifth chapter, tuning combat, there is no sufficient practical experience and some large project experience, although in some places can understand what the author was talking about, but no one they have had actual experience of the scene to substitution, understanding still insufficient.

Of course, certainly can not see a complete digest, although it made some notes on the notes in the proper way at the time, but it is uploaded to the blog garden, when water on a blog friends.

Java area of ​​memory and memory overflow exception

2.2 runtime data area

Java virtual machine memory management runtime data consists of the following areas:

  1. Program Counter: a row number designator bytecode executed by the current thread. By changing this value is the line number indicator bytecode instructions to select a next to be executed, so that the cycle can be achieved, jumps, branches, and other basic exception handling functions. Multi-threaded Java Virtual Machine is in turn by switching between threads, pink with processor execution time to achieve, so in order to allow the thread to return to the correct position after switching execution, each thread counter is independent, independently of each other, including the main thread. If the thread is executing Java code, the counter is recorded bytecode line number, if the local method is performed, the counter is empty. Undefined. This region does not report memory overflow exception.

  2.Java virtual machine stack: it is the thread private life cycle with the same thread, the thread is executed Java memory model it describes. Each method creates a stack frame (a data structure) is performed, the local variable table for storing information, the operand stack, dynamic link, the method exports. (Which is dynamically linked: the class loading mechanism, the steps will resolve symbolic references into direct reference, and part of it will become a direct reference in the implementation process, which is dynamically linked). The stack frame to push out the execution stack is a complete method. Focus on the virtual machine stack local variable table which is stored in the basic data types, object reference, returnAddress type (address a byte code). When the depth is greater than the request thread stack virtual machine allowable depth will be reported StackOverflowError. When the application stack can not expand enough memory will be reported OutOfMemoryError.

  3. The native method stacks: stack effect which is similar to the Java virtual machine, only the Java Virtual Machine for Java stack method of service, while native method stacks local service method. There are also two anomalies above.

  4.Java heap: the largest piece of virtual machine memory management. Java heap is shared by all threads, whose sole purpose is to store an object instance. Create an object, its reference on the stack, heap on the instance. Java heap garbage collection to manage memory area, so some called him the GC heap. GC content back again to remember. Whether heap so divided, examples of which are just objects stored, the purpose of subdivision just to better recovery of memory and memory allocation. When the Java heap allocated instances can not be completed, the heap can not expand, will be reported OutOfMemoryError.

  5. The method area: the Java heap, is the thread shared memory area. The type of information used to store the virtual machine has been loaded, constants, static variables, the time compiler to compile code cache and other data. If the method of memory allocation area can not meet demand, it will report an OutOfMemoryError.

 

2.3HotSpot virtual machine object Quest

The basic process objects created:

  1. Check that the new instruction parameters to find a symbolic reference in the constant pool, and checks whether the reference is representative of the class is already loaded, parsed, initialized.
  2. Allocate memory for the new object. This thing involves a lot of memory allocation, such as different garbage collector will have a different distribution method, if it is with compacting collector finishing process, assign it simple, because it is contiguous free address memory. However, in the case of concurrent, unsafe, this time may be necessary to use CAS. Where they talk about the process, the details will speak later chapters.
  3. After the memory allocation is completed, the virtual machine will be assigned to the memory space are initialized to zero.
  4. After initialization, the virtual opportunity to make some necessary settings, such as which object is an instance of this class, the carve-generation GC age of information, the information will be placed in the object header.
  5. The above four steps of the virtual machine, create an object has been completed, but for procedural point of view, the more step, that is, the class initialization method, constructor. Programmers can write according to their own needs to the initialization method here, this object is completely created.

Among the objects in memory it may be divided into three parts: the first objects, instance data, filling it with

  Object header portion includes two types of information, a first data type information to be stored during the operation itself, such as: the hash code, the GC generational age thread holds the lock, the lock status, timestamp bias, bias thread ID and the like.

  The other part is the type of pointer, i.e. a pointer which is determined by the instance of this class which. If the length of the array, the array will be stored.

  Examples of the data part is valid information object stored in the real, i.e., various types of field contents of our definition.

  Filling it with no practical significance, HotSopt memory management requirements of any size of the object must be an integer multiple of 8, the head has been designed to target an integer multiple of 8, but not necessarily the instance data, this time you need to fill them Completion.

  Access Object location:

  Java heap is stored instance data, reference data on the Java stack is a reference to an instance of this store. And this reference, there are two major implementations:

  1. Using the handle, Java heap memory space may be divided into a pool as a handle, the handle of the object is stored in the address reference, the handle contains examples of specific data and address information of the object. Pros: without changing the reference, so that if the GC object address change, change only the address of the handler on the line.

  2. Use the pointer direct access, addresses reference object is stored, if only to access the object itself, then it does not need to access an address as again like a handle. Advantages: no second pointer is positioned.

Garbage collector and memory allocation strategy

  Program counter, Java virtual machine stack, native method stacks these three regions are born are born with thread, with the thread off and off. These areas need not consider the issue of too much garbage collection, method execution is over, the end of the thread, memory naturally recovered. So the focus of the Java heap and method area, they are shared area, so it will not with the thread of birth and death, but also has a lot of uncertainty.

3.2 Object dead?

  Before the garbage collector heap for recycling, it must determine whether the object instance there is no use, if an object does not have any role in a Java program, it naturally needs to be recovered. It is the current mainstream of the following two methods

  1. reference counting algorithm, adding a reference count in a subject, each time an object is referenced, the counter plus one, when referring to fail, a counter is decremented. When the counter is 0, that is no longer being used. Such algorithms are in use in many applications, such as FlashPlayer, Python and so on. But there is a problem in Java, reference counting algorithm can not solve, it is the circular reference. For example two objects A and B refer to each other, even if they are null, or no use, but they are still not the counter 0. But the Java virtual machine of any course they can be recycled, indicating that this algorithm Java virtual machine is not in use.

  2. The reachability analysis algorithm, called the root object through a series of "GC Roots" as the start node set, is a note, not just one node. From these nodes, we walked the path known as the "chain of references", and in reference to this chain of objects, objects are alive do not need recovery, and not need to be recovered in the reference chain. There are many objects can be used as GC Root, are: all classes have been loaded, the thread stack frame of reference current, synchronous lock object holds the like. What specifically can also see P70. When an object is not referenced on the chain, it does not necessarily mean it will be recovered . Recovering at least one object to be marked twice, the first time after being marked, will conduct a screening, determining whether the object necessary to perform a finalize () method if the method has been performed once before this, or the object does not overwrite this approach, then it needs to be recovered behalf. If the object overrides the finalize method, and has not previously been performed, he will be put F_Queue queue, waiting to execute this method, this method is time-limited, too slow to prevent the implementation of a threat to the system. At this time, the object can be done in self-help finalize method in that himself and re-reference an object on the chain link.

  3.2.5 recovery process area

  Java Virtual Machine specification is not mandatory garbage collection in the region, mainly due to price is too low, that is, to determine the conditions of high, low reclaim space. The method of recovery is mainly constant region and no longer used. For the constant, if not refer to any object of this constant, then it can be recovered. Whether a type to be recovered, it is determined necessary to many complex: All instances of the class 1 is recovered. 2. The class loader to load the class is recovered. 3. do not use it by reflection.

  3.3 garbage collection algorithm

  On one comes to the how to determine which objects need to be recovered, this section talk about how to reclaim these objects. Prior to this need to know about generational collection theory , a lot of the garbage collector is based on this theory to the design. I.e., the Java heap generational divided into several different areas, depending on the object is then assigned to different areas of age (age is the number of survived garbage collector). There are two large areas, the new generation and the old era. Target area of the new generation, are frequently recycled, if survive a certain number of recycling in the new generation, will be placed in the old era. The benefits of this design is that you can divide different garbage collection algorithm according to the demise of characteristics of different regions of the object. This has some say to the algorithm behind. But there is a hidden problem is inter-generational references that have references between the new generation and the old era, so it comes before the GC Roots we have to include some of the old era objects, and increased the number of additional overhead. There is a cross-generational references hypothesis, if there is a reference between two objects, they should perish, there is reference to a handful of different generations, so there is no need to go to a very few, and increase the number of overhead .

  Specific algorithm description can read, P77 start.

  1. mark - sweep algorithm : by the reachability analysis to identify the objects need to be recovered, and marks on the object labeled for recycling. May be reversed, marker objects do not need recovered objects not marked for recycling. There are two main drawbacks: one is efficiency unstable, its efficiency is clearly increased with the decrease of the object. One is the creation of space debris will, because the recovery of the object may be fragmented, leading to free memory space is also fragmented.

  2. Mark - copy algorithm : the memory space is divided into two equal parts, wherein one part only once, each time the live objects in turn structured into another part, and that part of the overall recovery is then used. Its biggest drawback is that the available memory is reduced by half, wasted too much space. Later, IBM studies have shown that 98% of the new generation of objects not survive the first recall, so for this feature, the mark - on the basis of replication algorithm, the new generation of Eden into a zone, two Survivor areas. Accounting for its memory 8: 1: 1. Each allocation of memory using only a Eden area and a Survivor areas. Copy these two areas of live objects to another Survivor areas, and then clear the Eden and Survivor has been used.

  3. Mark - Collation Algorithm : This algorithm is generally used in the old era, marking process and mark - sweep algorithm the same, but live objects in memory cleanup phase will move to one end, and then clear the memory directly to the outside of the boundary. But during the move will STW (ie suspend user threads). Finishing and not finishing are good and bad, so different emphasis, there is a Parallel Scavenge collector and CMS collector.

Classic garbage collector

  Serial (Serial Old) Collector : As its name suggests, he is a single-threaded collectors, means that it is in operation, the user thread must stop, it is often said of STW. In the new generation it uses a mark - replication algorithm, used in the old era is marked - sorting algorithms. Although this thread is the most basic and oldest collector, but compared to other single-threaded collectors, it is still very good, in the HotSpot virtual machine client mode (Server slow start, compiling more complete, compilation is an adaptive compiler, high efficiency, application optimized for the server, in a server environment designed to maximize execution speed; client start fast, small footprint, fast compiler, optimized for desktop applications, as in the client environment and reduced start-up time optimization), the new generation of collectors is its default.

  ParNew collector : In the new generation, which is just a multithreaded version of the Serial, the other is not much difference between Serial only. Still need STW, it is a mark used in the new generation - replication algorithm. Server is a virtual machine of choice for the new generation of collectors.

  Parallel Scavenge (Parallel Old) Collector : Parallerl Scavenge is a new generation of collectors, using the mark - replication algorithm. It is also multi-threaded, but with other collectors difference is that it is more concerned about the throughput (run-time user code / user code + runtime garbage collection time). Suitable for operation in the background without the need for too many tasks to interact. Parallel Old old's version, using the mark - sorting algorithms. Throughput is also the focus of a multi-threaded garbage collector.

  CMS collector : the collector of old age, focusing on the reduction of STW time, based on mark - sweep algorithm. The process is more complicated compared to other collectors, roughly divided into four steps: 1. The initial mark, find the object directly linked according to GC Roots. 2. Concurrent mark, find more complete associated objects according to the object of the initial mark phase. 3. Re-labeling, is due to the concurrent mark and concurrent user threads, there will be some new recyclable objects in the process. 4. Concurrent cleaning, thanks to the mark - sweep algorithm, without moving the objects, and the user can be performed concurrent threads. Although this is HotSpot pursuit of low pause time of a successful attempt, but there are also some disadvantages, such as: the concurrent cleanup phase will generate new spam, mark - sweep memory space debris generated by the algorithm, CMS default recovery thread is (number of processor cores + 3) / 4, sensitive to the processor.

  G1 collector : a garbage collector is mainly for server-side applications, to act on the entire Java heap, it is a milestone of. While the G1 still retains the old age and the probability of the new generation, but they are no longer fixed, but the Java heap into a plurality of equal size Region zones, each zone Region can play the new generation and the old era as needed role, as a whole, he uses a mark - sort algorithm, but between two Region, uses a mark - replication algorithm. Users can set the collection pauses model, the value of the maximum benefit that Region will give priority to recovery. The working process is divided into an initial mark, concurrent mark, marking the final screening recovered. The first three stages of the CMS is similar to the cost of sorting and screening recovery value of each Region of the recovery stage would be to develop recycling programs in accordance with the previous user's settings. In addition to the concurrent mark phase, the remaining three phases of STW is required. The case is referred to the landmark G1 design is an important reason is that, from the original idea of the designer's one-time garbage collection and clean, just to recover faster than distribution speed on the line, so to meet the demand, the performance has been greatly improved.

  Summary: From the name of view, in addition to G1 acting on the entire Java heap, CMS acting on the old era, the remaining five are judged according to the role's name to the old or the new generation. According to the characteristics before garbage collection algorithm, multi-year old mark - sort algorithm, the new generation of multi-purpose mark - to copy, in addition to CMS, it is the role of the old year mark - sweep algorithm. The role of the server or the client, because the server multi-core CPU is more common, so multi-threaded Collectors better on the service side.

Reachability analysis

  For ease of description, first define a three color marker, white is the reachability analysis has not yet been marked objects, from start to finish is white if it is the object need to be recovered. Black is already marked, it is also a reference to the object being scanned. Gray was already marked, but it is not yet a reference to the object being scanned.

When concurrent mark, between the object reference could not stop change, while simultaneously appear both cases, the original object on the chain of references will be lost: 1. Black objects adds a reference to the object A. 2. Delete the gray objects to the object A references. If an object simultaneously appear both cases will be lost. Why do you want to appear at the same time? Because it has been labeled the object will not look back to check, and if the object being marked references are changed will take effect immediately. So for these two cases, one of which will not be solved as long as the object is missing problems. 1. incremental update, is destroyed first, add a reference to the object black will be recorded, like the end of the concurrent mark, and then to the object record for the root side rescan. 2. The original snapshot: Article destroyed. Gray objects to delete a reference to this gray objects will be recorded after the end of the concurrent object-record mark for the roots, scanning side.

Low latency garbage collector

  Three important indicators garbage collector: memory usage, throughput and latency. Memory footprint and throughput with the enhancement of hardware performance, software helped a lot, do not need that attention to these two points, with the upgrading of hardware, these two indicators will be with the upgrade. But the delay is not the same, that is, STW delay time, as more and more memory capacity, Java heap memory available is also growing, implies the need to reclaim space is also growing, so it STW longer.

  Shenandoah Collector : is an unofficial garbage collector, developed by RedHat project, exclusion from Sun's, so the official commercial version of the JDK is not supported by the collector, have only OpenJDK . Although there is no orthodox have blood, but in the code ZGC is more like it compared to the G1's successor, highly consistent with the G1 in many stages, and even share a part of the source code, but there are some improvements compared to the G1. There are three major improvements:

  1. Supports concurrent mark - sorting algorithms.

  2. Default NA generational collection, Shennandoah Region and G1 use the same partition, but in Shennandoah and did not play Region will go to the new generation or old's.

  Memory referenced assembly relationship 3.G1 stores take up a lot of memory space, in Shennandoah matrix switch is connected, you can see the specific P107.

  Shennandoah collection work process can be divided into nine steps :

  1 . Acquaintance marker : and G1, as the object is directly associated with the mark of GC Roots, the STW.

  2. concurrent mark : the G1 same, according to the previous step of the object, the full mark up objects.

  3. Final mark : be the same with the G1, using the original snapshot method to mark objects on the stage of change, but also the highest statistics Region recovery value at this stage, to form a back collection.

  4. Concurrent cleaning up : This phase will clean up the entire area Region and a live objects are not, it can concurrently.

  5. concurrent recovery : the recovery copy to another Region and unused objects in focus survive.

  6. Initial reference update : After copying the concurrent recovery stage, the need to amend the new address after the copy, but at this stage did not make any specific operation, only the equivalent of a rendezvous, concurrent recovery stage to ensure that all threads have completed their copy.

  7. Concurrent reference update : This stage is the real correction phase reference.

  8. Final reference update : Previous reference only amended the Java heap objects, but also to amend references exist in the GC Roots, and finally a brief pause, only on the number of GC Roots.

  9. Concurrent Cleanup : After the corrected copy and references concurrent recovery will gather in the Region can be completely cleaned up.

  Let me say a characteristic Shennandoah, which is mentioned in front of the concurrent mark - sorting algorithms. 5,6,7,8 finishing stages can be broken down into four steps. The biggest problem is that the copy or amend a reference when the user threads might be using this object. Originally had a plan to solve similar problems, is to protect the trap, is about process threads when a user access to the object on the address, enter an exception handler, the new address is forwarded by the processor to. Shennandoah is used in a relatively better solution: forwarding pointer, is to add a new object is in front of each reference field, not in a case where concurrent movement of the reference point to themselves, then it moves concurrently point to the new address.

  ZGC Collector: ZGC Shennandoah target and similar, without affecting the desirable throughput, the pause time is limited to 10 milliseconds. ZGC is also a generational collection based on the layout of the Region, also did not support, but the Region there are medium and small three types :

  1. Small Region fixed capacity of 2MB, for placing small objects of less than 256KB.

  2. Medium Region fixing capacity of 32MB, placing greater than or equal to 256KB, less than 4MB of the object.

  3. Region large capacity is not fixed, but it must be a multiple of 2, for storing an object larger than the 4MB.

  ZGC used in the dyeing pointer when implementing concurrent order, before the collector if you want to store some extra information in objects, most of them will be in the object storage in advance, such as forwarding pointer. Three color marker Then there reachability analysis before it comes in, it just illustrates a state where the object referenced data with the object itself did not have any relationship, so these markers is stained pointer information is recorded on the pointer referenced object. Pointer why can store information it? This is to say that the system architecture, specifically to see P114, dyeing pointer only supports 64-bit systems, and AMD64 architectures support only to the 52, and major operating system has its own limitations, dyeing pointer in Linux support 46 pointer width, to come up with four store tag information, so use the ZGC further compression of the original 46 address space, leading to memory management ZGC can not exceed 4TB, in today's perspective, 4TB of memory is still very adequate .

  Dyeing pointer three major advantages:

  1. Once a Region live objects are removed, the Region can be recycled immediately reused, while Shennandoah requires an initial reference update, wait for replication to complete all threads.

  2. dyeing pointer can significantly reduce the number of memory barrier (the fifth step of the process mentioned later) in the garbage collection process, part of the function pointer because the stain on the hands and partly because the information is stored ZGC also did not support the generational collection, so there is no inter-generational references.

  3. staining pointer can be extended in the future, recording more information, mentioned earlier in the 64-bit systems, Linux has only used the 46, but also 18 undeveloped. Another problem is stained pointer to redefine a few pointers, operating system support, virtual machine it is only a process, where it uses virtual memory mapping, specifically to see P116.

  ZGC working process can be divided into the following steps:

  1. Initial marker : Several previously collector as an object to find a direct correlation of GC Roots.

  2. concurrent mark : mark up objects complete with G1 and Shennandoah different is that it is not the object head to do the update on the pointer.

  3. Final mark : and Shennandoah same.

  4. Concurrent preparation redistribution : This phase requires the statistics of this collection process which Region to be cleaned according to the specific query. Here's assignment is not set as a priority by income back to collect as G1, determines the allocation set just inside the object will be copied to the new Region, Region here to be released.

  5. concurrent redistribution : copy this process should focus on the distribution of objects to the new Region, and to assign each Region to maintain a centralized forwarding, thanks to the help of dyeing pointer can only reference you can get on to know if an object allocated on the set, if at the time of reproduction, a user thread to access the object allocation will be centralized intercepted memory barrier, and then forwarded to the new access to the object based forwarding, and fix the thread to access the reference to the object, a process known as self-healing pointer.

  6. Concurrent remapping : To correct this stage point to reallocate whole heap all the old centralized object. This stage is special, because it is not an urgent need to perform, the healing process is on stage for the correction of a reference to the object, so even without this step will not be a problem, but there is a forward for the first time to heal the process will be a little slower, later also normal. Because this is not urgent, ZGC cleverly incorporated into the work of this step marks a concurrent process, because concurrent mark also need to traverse all the objects, this step also need to be amended to refer to all the old objects.

  ZGC is a big problem temporarily not yet received on behalf of the collection, which limits the target distribution rate can not be too high to bear. If the recovery rate is not as long distribution rate, floating garbage generated more and more space can be allocated also getting smaller. So from a fundamental solution to this problem is to introduce generational collection, so that the new generation of memory dedicated to the recovery of these objects frequently created.

 

Virtual machine performance monitoring, troubleshooting

  1. jps: VM process status tool that lists the virtual machines running processes. Select parameters: -l: Process main class full name; -v: parameters of the virtual machine process starts. -m: main parameters passed to the function when the process started;
  2. jstat: virtual machine monitor various operating status command-line tool. Runtime data can be displayed locally or remotely class loader the virtual machine process, memory, garbage collection, real-time compilation. Select parameters: -class: monitor class loading, unloading quantity, total space. -gc: Java heap monitoring the situation. More options see P142
  3. jinfo: real-time view and adjust the parameters of the virtual machine, the above mentioned jps -v can see the virtual machine startup parameters explicitly specified, the default virtual machine parameters can be viewed using jinfo -flag.
  4. jmap: for raw heap dump snapshot (a Java process at some point in time snapshot of memory .Heap Dump is with many types but overall heap dump when the trigger snapshots are saved java objects and classes. the information usually triggers a FullGC before writing the heap dump file, so save the heap dump file is left after FullGC object information). You can also read detailed information finalize the execution queue, Java heap and method area. Option parameter see P144. Common such as: -dump: generate a dump snapshot; -finalizerinfo: View finalize the implementation of the queue; -heap: Java heap display detailed information.
  5. jhat: This command is used with jmap to analyze heap dump snapshot jmap generated.
  6. jstack: used to generate a virtual machine snapshot of the current time of the thread (the thread inside the virtual machine snapshot is a method for each executing thread stack collection). The purpose of generating a snapshot of the thread because the thread is usually a long pause, as the deadlock between threads, the cycle of death, pending a request for a long time due to external resources and so on. Options: -F: when the output request is not a normal response, to force the output thread stack. -l: Displays additional information about the locks; -m: If you call a local method, you can thread C / C ++ stack.

 

VM class loading mechanism

7.2 class loading time

  A class is loaded from a memory to unload, go through a total of seven stages: Load - connection (including: Authentication - Preparation - Analysis) - Initialization - use - Uninstall.

When a class is loaded and there is no obligation, but at initialization and only six cases in order to carry out, such as when using the new keyword to instantiate an object, when reading a static field, through reflection to invoke a class, subclass to when initializing the parent class must be initialized and other details, see P264. in summary, the initiative is on the reference type, only to be initialized. When used only to initialize, which is consistent with our normal thinking. Of course, it must be initialized before the front steps, but when there is no load limit.

7.3 class loading process

  1. Load : The load is the first step in the whole process, with the title of class loading is not the same meaning. This step is mainly to do three things: 1.1 to obtain such a binary byte stream. 1.2 the byte stream representing the static storage structure into a run-time data structure area method. 1.3 Generating a Class object representative of this class, as a method of access entry region of each class of data. Java Virtual Machine specification does not do these three things very strict requirements, such as obtaining a binary byte stream, and there is no requirement to obtain certain documents from the Class, so now have a jar, war and other packages from the compressed file read. It can be read from other files, such as jsp files.

  2. Verify : This stage is very important, the workload of the entire process which also account for a large part of it. This stage to ensure that the information byte stream in line with regulatory requirements, codes harm virtual machine does not exist. If only the Java code level, it is difficult to make operational irregularities, such as data access outside of array boundaries and so on, the compiler will throw an exception, refuse to compile. There are four main stages of the entire test operation: validation file format, metadata validation, bytecode verification, verification of symbolic references. File format validation: validation of a byte stream for compliance with Class file format, such as whether the number begins with the magic 0xCAFEBABE, whether to accept the code version number in the range of the current virtual machine. Metadata validation: mainly metadata information such semantic validation, pledged to comply with the Java language specification. For example, if the class has a parent class, in addition to Object, each class should have a parent and so on. Bytecode verification: body verification method, a method to ensure that during operation will not endanger the virtual machine, such as to ensure that at no time will skip bytecode instructions other than the upper body method. Verification of symbolic references: This verification is mainly to ensure that the resolution behavior can perform normally, this validation will occur in the analysis phase, the symbolic reference into direct reference, such as checking whether symbolic references can be found in the corresponding class, etc. by fully qualified name.

  3. Preparation : This stage is the memory allocation (zone method) for class variables and set the initial value. Note here that the class variables, i.e. modified static, and does not include other variables, other variables will be assigned along with the objects of this class when the class is instantiated. Another point is that, the initial value is a zero value, i.e. the default value of the basic data types, such as int is 0, even if the statement is as follows: static int value = 123; initialization is 0, 123. Unless it is not a constant, such as static final int value = 123, then 123 is its initial value.

  4. Analytical : This phase is the constant pool replace references to direct reference symbols. Symbol reference: with a target set of symbols referenced to describe, may be any form of literals, as long as the target can be positioned. Direct quote: can be direct pointer to the target, or a handle, a word that can be positioned directly to the target, but as long as there a direct reference, the virtual machine memory must have the reference target.

  5. Initialization : The final step is to load the class, has set an initial value of zero for the variable in the preparation phase, which will be based on the program code to initialize variables and other resources. This stage does the actual initialization from our point of view coding.

Guess you like

Origin www.cnblogs.com/lbhym/p/12458990.html