Java Interview Preparation JVM

Source: Internet
Author: User
Tags unique id xms jconsole

Describes the 7 zones in the JVM, and then describes the scenarios in which each zone can cause a memory overflow

Program Counter: As the current thread doesbyte code line number indicator。 is a threadPrivateMemory, and the only piece does not report outofmemoryerror exceptions.Java Virtual machine stack: Used to describe a Java method.Memory Model: When each method is executed, it will create aStack FrameFor storinglocal variable table, operand stack, dynamic link, method exitand other information. Each method is called until the completion process corresponds to a stack frame in the virtual machine from the stack to the stack. If a thread requests aStack DepthGreater than the allowed depth of the virtual machine is reported Stackoverflowerror, if the virtual machine stack can be dynamicallyExtended, the OutOfMemoryError will be thrown when the extension fails to request enough memory. is a threadPrivateOfLocal Method Stack: Similar to a virtual machine stack, except that it is used for virtual machinesNativeMethod Service. Will throw Stackoverflowerror and OutOfMemoryError. is a threadPrivateOfJava Heap: A piece of memory that is shared by all threads and created when the virtual machine is started. The only purpose of this area of memory is to hold object instances where almost all of the object instances are allocated memory. If there are no memory-complete instances allocated on the heap, the OutOfMemoryError will be reported.Method Area (permanent generation): Used to store a VM that has been loaded by a virtual machineclass information, constants, static variables, immediate compiler-compiled codeand other data. OutOfMemoryError is thrown when the method area does not meet the memory allocation requirements. is shared memory.run a constant-rate pool: Used to hold various literal and symbolic references generated by the compiler, which is part of the method area. Failed to request memory when throwing OutOfMemoryError.Direct Memory: Is not part of the virtual machine runtime data, nor is the zone defined in the Java VM Specification, which is the direct memory space of the computer. This section is also used frequently, such as Java NiO's introduction of channel-and buffer-based I/O using the native function to directly allocate out-of-heap memory. If memory is low, it will be reported OutOfMemoryError.

    1. Two ways to determine GC: reference count and Root search algorithm. reference count : Adds a reference counter to the object, and whenever there is a place to refer to the object, the counter value is incremented by 1, and the counter value is reduced by 1 when the reference is invalidated. An object with a counter of 0 at any time is impossible to be used again. It is difficult to solve cross- referencing problems between objects. Root Search algorithm (GC Roots traceing): through a series of objects called "GC Roots" as a starting point, starting from these nodes to search down, searching through the path becomes the reference chain , when an object to the GC Roots proves that this object is not available when no reference chain is attached to it. A GC roots object is typically a reference object in a virtual machine stack, an object referenced in a class static property in a method area, an object referenced by a method-area constant, and so on.
Four types of references in Java

Strong reference : a normal reference in the program code. As Object obj = new Object (), the garbage collector does not recycle as long as a strong reference exists. Soft References : Describes some useful, but not necessary, objects. Objects associated with soft references will be listed in the Reclaim scope for a second collection before the system will have a memory overflow exception . softrefence Weak references : Describes non-mandatory objects, which are weaker than soft references. Objects that are associated with a weak reference can only survive until the next garbage collection occurs . Objects that are associated only with weak references are reclaimed regardless of whether the current memory is sufficient. weakrefence Virtual Reference : The weakest reference, regardless of whether or not a virtual reference exists, does not affect the lifetime of the object at all, nor can a virtual reference be used to obtain an object instance. The only purpose is to be able to receive system notifications before this object is collected by the garbage collector. phantomreference

Object creation method, object memory allocation, object access positioning.

Object obj = new Object (); obj is stored in the local variable table in the Java stack and appears as a reference data. New object allocates a piece of structured memory on the Java heap that stores all the numeric values of an instance of type object, depending on the type and the object memory layout implemented by the virtual machine. This piece of memory is not fixed. There are two ways to access objects: handles and direct pointers : handles: In the Java heap, a chunk of memory is partitioned as a handle pool, and the object stored in reference is the handle address. The handle contains the individual address information for the object instance data and type data. The biggest benefit is that if the object address changes without changing the value of the reference, you only need to change the instance data pointer in the handle. Direct pointer Access : Reference directly stores the address of the object, the greatest benefit is faster .

Memory overflow and memory leaks

Memory Overflow : The popular understanding is that the memory is not enough , the memory required by the program is far beyond the size of the memory allocated by your virtual machine, it is called memory overflow memory leak: Memory leak is also called "storage leakage", using dynamic storage allocation function to open up the space, is not released after use , resulting in the memory unit being occupied . Until the end of the program. (In fact, the memory space is not recycled after use) is called memory leaks

What to do if the memory overflows

Analysis of dump heap-to-storage snapshots, such as Jhat,jconsole, with memory-imaging tools, focuses on verifying that memory is a memory leak or a memory overflow. If it is a memory leak Further use the tool to view the referenced chain of the leaked object to the GC roots. You can then find out what path the leaked objects are associated with GC roots and cause the garbage collector to not automatically reclaim them. By mastering the information of the leaking object and the information of the GC roots reference chain, the location of the leaking code can be more accurately located. If there is no memory leak, then you need to use tools such as Jinfo,jconsole to analyze the Java heap parameters and machine physical memory contrast can also be larger, from the code to check whether there are some object life cycle too long, holding the state is too long, try to reduce the running consumption of the program.

Is there a memory leak in Java?

There are a number of reasons why memory leaks are caused in Java. A typical example is a long-life- cycle object that holds a reference to a short-life-cycle object that is likely to have a memory leak, although a short-life-cycle object is no longer needed, but because a long-life-cycle object holds its reference and can not be recycled, this is the scenario in which memory leaks occur in Java, in layman's words , that is, the programmer may have created an object that has not been used in the future, the object has been referenced, that is, the object is useless but cannot be recycled by the garbage collector, which is a possible memory leak in Java, for example, the cache system, we loaded an object in the cache ( For example, in a global map object), and then no longer using it, the object has been cached for reference, but is no longer used. Check for memory leaks in Java, be sure to let the program complete the various branches of the program to the end, and then see if an object has been used, if not, you can determine that the object is a memory leak. (What tools are used?) if a method of an instance object of an external class returns an instance object of an inner class, the inner class object is referenced for a long time, even if the Outer class instance object is no longer being used, but because the inner class persists an instance object of the outer class, the Outer class object will not be garbage collected. This can also cause memory leaks. Http://www.mamicode.com/info-detail-504269.html

When will a JVM heap (persistent zone) memory overflow occur?

In simple terms, Java's heap memory is divided into two blocks: permantspace (persistent generation) and heap space. The persistence belt is mainly used for storing static type data, such as Java Class, Method, etc., and the garbage collector to collect the Java object is not very related. And the heapspace is divided into young generation and old generation of the young generation of garbage collection called the Youth GC, old generation garbage collection called Full GC. Objects that survived after N (configurable) garbage collection in the young generation are copied into the old generation. As a result, older generations can be thought of as having long life-cycle objects. The cause of the old generation overflow is a cyclic processing of tens of thousands of strings, the creation of thousands of objects, the application of hundreds of m or even upper g of memory persistence overflow in a code to dynamically load a large number of Java classes resulting in overflow, and production of a large number of permanent memory leaks : In a Java Web program deployed to an application server, all classes in your Ear/war package will become useless when the application is uninstalled. As long as the application server is alive, the JVM will continue to run, but a whole bunch of class definitions will no longer be used and should be removed from the permanent generation (PermGen). If we do not remove it, we will have a memory leak in the permanent generation (PermGen) area.

The partitions inside the heap: Eden,survival from to, the old age, the respective characteristics.

New generation: The Age of death in the old days is usually put objects and long-term survival objects. When an object allocates more memory space than a certain threshold or the age increases to a certain level (by default, 15 years old) it enters the old age.

What happened to you, Oom?

Java.lang.OutOfMemoryError:Java Heap Space------>java heap memory overflow, which is most common, typically due to memory leaks or improper heap size settings. Java.lang.OutOfMemoryError:PermGen space------>java Permanent overflow, that is, the method area overflow, usually appear in a large number of class or JSP page , Or the use of cglib and other reflection mechanism, because the above situation will generate a lot of class information stored in the method area. Java.lang.StackOverflowError------> does not throw oom error, but it is also a more common Java memory overflow. Java Virtual machine stack Overflow, generally due to the existence of a dead loop or deep recursive call in the program, the stack size setting is too small also can occur this kind of overflow. The size of the stack can be set by the virtual machine parameter -XSS .

GC Three kinds of collection methods: Mark Clear, Labeling, replication algorithm principles and characteristics, where to use, if you want to optimize the collection method, what is the idea?

tag cleanup : First mark all objects that need to be recycled, and then uniformly reclaim all tagged objects after the tag is complete. The disadvantage is that it is inefficient and has memory fragmentation . Mainly used for Laosheng generation garbage collection. copy algorithm : divides memory by capacity into a piece of equal size, with only one piece at a time. When the memory is exhausted, copy the surviving objects to another memory, and then clean up the used memory space once. Simple and efficient to achieve. Generally used in the Cenozoic. In general, the memory is divided into a larger Eden space and two smaller survivor spaces. The default scale of the hotspot virtual machine is 8:1. Each time you use Eden and a piece of Survivor, when you recycle, you copy the two memory-surviving objects to survivor and then clean up the space that was just Eden and survivor. If the replication process does not have enough memory to use, the old age is assigned a guarantee. Tag Grooming : First mark all objects that need to be recycled, and let all surviving objects move toward one end after the tag is complete, and then directly clean out the unexpected memory at the end of the boundary. Used in the old age. Generational collection algorithm : According to the life cycle of the object to divide the memory into the new generation and the old age, according to the characteristics of the age to adopt the most appropriate collection algorithm.

What are GC collectors? Features of the CMS collector with the G1 collector.

Serial: A single-threaded collector that uses only one CPU or one collector thread to complete, garbage collection, and more importantly, all other worker threads must be paused while garbage collection is in progress. (Stop the World). Simple and efficient for the new generation.parnew: is a multi-threaded version of the serial collector, which is recycled in a multi-threaded manner during garbage collection. The number of threads used by default is the number of CPUs. In addition to the serial collector, only it can work with the CMS collector at this time.Parallel Scavenge: Using the Copy algorithm collector, it is also a parallel multi-threaded collector. Unlike other collector concerns, the Parallel scavenge collector focuses on reducing the downtime of the user thread during garbage collection. And it CaresThroughput, i.e.Run user code time/(run user code time + garbage collection Time)。 The shorter the pause time, the more efficient it is for programs that need to interact with the user, and the higher the throughput the CPU time can be used most efficiently.Serial Old: old age, single thread collector, usingMarker Grooming Algorithm。 There are two main uses, one is used in conjunction with the parallel scavenge collector, and the second is a backup scheme for the CMS that occurs in the concurrency collectorConcurrent Mode FailureTime to use.Parallel Old: A parallel version of the old generation collector, using the tag grooming algorithm. Mainly used in conjunction with parallel scavenge.CMS: A collector that targets the shortest recovery pause time, using the tag cleanup algorithm. The entire process consists of 4:Initial Tag: Flags the object that the GC roots can directly relate toConcurrency token: The process of roots traceingre-tagging: Fixed tag changes during concurrent tagging due to user continuing workConcurrent Cleanup: initial tag and re-tagging need stop the world. Concurrent tagging and concurrent cleanup process user threads and collector threads can be executed in parallel.G1 (Garbage first):A collector based on the mark-and-finish algorithm does not produce space debris. It can precisely control the pauses, allowing the user to explicitly specify a time fragment of length m milliseconds, less than n seconds on the consumption set. A low pause is accomplished without sacrificing throughput. G1 The entire Java heap (Renaissance and Laosheng) Divide into areas of the same size and track the changes that occur on those areas. Maintain a prioritized list in the background and recycle the largest areas of trash per time, based on the allowable collection times.

When did the Minor GC and full GC occur?

FULLGC is usually a GC that occurs in the old age, and a fullgc often accompanies at least once minor GC. The speed is more than 10 times times slower than MINORGC. What happens to full GC: 1) The old age space is insufficient in the old era space only when the new generation of objects into and created as large objects, large arrays will be insufficient, when the full GC after the space is still insufficient, the following error is thrown: java.lang.OutOfMemoryError: Java Heap space. Measures: In order to avoid the above two conditions caused by the FULLGC, tuning should try to make the object in the minor GC phase is recycled, so that the object in the Cenozoic to survive for a period of time and do not create too large objects and Arrays 2) permanet Generation (method area or permanent generation) space full The permanetgeneration is stored in some class information, such as, when the system to load classes, reflected classes and the number of methods to call, Permanet generation may be full, in the case is not configured to adopt a CMS GC will be executed in the context of a fully GC. If the full GC is still not recycled, then the JVM throws the following error message: Java.lang.OutOfMemoryError:PermGen space measures: To avoid the perm Gen to be filled with a fully GC phenomenon, the method used to increase the perm Gen space or switch to using CMS GC. 3) The CMS GC appears promotion failed and concurrent mode failure for programs that use the CMS for the old-age GC, especially if there are promotion failed and concurrent mode in the GC log Failure two conditions, which may trigger full GC when both conditions are present. Promotion failed is in the minor GC, Survivor space, objects can only be put into the old age, and at this time the old age also can not be caused; concurrent mode failure: CMS in the garbage collection needs a portion of the memory space and now the user program is running need to reserve a portion of memory to the user program, if the reserved memory can not meet the requirements of the program will appear once "Concurrent mod failure", and trigger a full GC. The measures are: increase the ratio of survivor space, older generation spaces, or lower the triggering concurrent GC, 4) The average size of the minor GC promoted to the old generation is greater than the old generation's remaining space HOtspot in order to avoid the new generation of objects promoted to the old generation of space shortage phenomenon, in the minor GC, made a judgment, if the previous statistics obtained minor GC promoted to the old generation of the average size than the old generation of the remaining space, then directly triggered full GC. If it is less than and does not allow the guarantee to fail, a full GC will also occur

MINORGC MINORGC refers to the garbage collection action occurring in the Cenozoic, very frequent, and the recovery rate is fast. Usually occurs when the Cenozoic space is insufficient, another FULLGC often accompanies at least one minor GC. When the virtual detection is promoted to the average size of the old age is less than the remaining space size of the old age, if it is less than and allows the guarantee to fail, then the minor GC is executed. Http://zhidao.baidu.com/link?url=hxwfrDGb87nYAAaKh6kQerv45RzwFkGWOcvl9wbaKVwb8rjdiQNgxLy19ga_ A0w8oziskwckrslmjiswb1pedcoxn9z7qf12cdem19vxiuo

Several commonly used memory debugging tools: Jmap, Jstack, Jconsole.

(How to analyze JVM state with tools) JPS: Lists the virtual machine processes that are running on the virtual machine and displays the name of the virtual machine execution main class and the unique ID of the local virtual machine for those processes. jstat : A command that monitors various health status information for a virtual machine. can display the local or remote virtual machine process in the class load, garbage collection, JIT compilation, memory and other data. jinof: View and adjust the parameters of a virtual machine in real time. Jmap: Generates a heap-to-store snapshot, querying the Fianlize execution queue, Java heap, and immortalized details, such as space usage, which is currently used by that collector. Jhat: Used in conjunction with JMAP to analyze jmap generated heap-to-storage snapshots. Built-in a miniature http/html server, after generating the analysis results of the dump file, can be viewed through the browser. jstack: Used to generate a thread snapshot at the current moment. A thread snapshot is a collection of method stacks that each thread in the current virtual machine is executing. The primary purpose of generating a thread snapshot is to locate the cause of a thread's long pause. such as deadlocks, Dead loops, requests for external resources caused by long waits. JConsole: A visual monitoring and management tool that almost includes all the features of the above tools VisualVM

What is a GC? Why do we have a GC

A: GC is the meaning of garbage collection, memory processing is a problem for programmers, forget or wrong memory recycling will cause the program or system instability or even crash, Java provides the GC function can automatically monitor whether the object exceeds the scope to achieve the purpose of automatic recovery of memory, Java The language does not provide a display action method that frees the allocated memory. Java programmers don't have to worry about memory management because the garbage collector is automatically managed. To request garbage collection, you can call one of the following methods: System.GC () or Runtime.getruntime (). GC (), but the JVM can mask the displayed garbage collection calls.

Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is typically run as a separate, low-priority thread, and in unpredictable cases the dead or unused objects in the heap are purged and reclaimed, and the programmer is not able to call the garbage collector in real time for garbage collection of an object or all objects. In the early days of Java, garbage collection is one of the biggest highlights of Java, because the server-side programming needs to effectively prevent memory leaks, however, now the Java garbage collection mechanism has become the thing to be criticized. Mobile Smart end users often feel that IOS systems have a better user experience than Android systems, and one of the underlying reasons is the unpredictability of garbage collection in the Android system.

How the JVM loads the class file

The loading of classes in the JVM is implemented by the class loader (ClassLoader) and its subclasses, the ClassLoader in Java is an important Java Runtime system component that is responsible for locating and loading classes in class files at run time. Because of the cross-platform nature of Java, the compiled Java source program is not an executable program, but one or more class files. When a Java program needs to use a class, the JVM ensures that the class has been loaded, connected (validated, prepared, parsed), and initialized. Class loading refers to reading the data in the class's. class file into memory, usually by creating a byte array to read into the. class file, and then produce a class object corresponding to the loaded class. When the load is complete, the class object is not yet complete, so the classes are not available at this time. When a class is loaded, it enters the connection phase, which includes three steps for validating, preparing (allocating memory for static variables and setting default initial values), and parsing (replacing symbolic references with direct references). Finally, the JVM initializes the class, which includes: 1. If the class has a direct parent class and the class is not initialized, the parent class is initialized first, and 2. If there are initialization statements in the class, the initialization statements are executed sequentially. Class loading is done by the ClassLoader, which includes the root loader (BootStrap), the extension loader (Extension), the system loader (systems), and the user-defined class loader (subclass Java.lang.ClassLoader). Starting with JDK 1.2, the class loading process took the Father delegation mechanism (PDM). PDM better guarantees the security of the Java platform, in which the JVM's own Bootstrap is the root loader, and the other loaders have only one parent class loader. The load of a class first requests that the parent ClassLoader be loaded, and the parent ClassLoader is not loaded by its child ClassLoader. The JVM does not provide a reference to the Bootstrap to the Java program. The following is a description of several class loaders: a)Bootstrap: Typically implemented in native code, responsible for loading the JVM base Core class library (Rt.jar); b)Extension: Loads the class library from the directory specified by the Java.ext.dirs system property, and its parent loader is Bootstrap; c)System: Also called the application ClassLoader, whose parent class is extension. It is the most widely used class loader. It is the default parent loader for the user-defined loader, which records the class from the environment variable classpath or the directory specified by the system attribute Java.class.path.

A class loads five processes: load, validate, prepare, parse, initialize.

load : Gets the binary byte stream of the defined class based on the fully qualified name, then transforms the static structure represented by the byte stream into the run-time data structure of the method area, and finally generates a class object representing the class on the Java heap as the access entry for the data in the method area. verification : primarily to ensure that the information contained in the byte stream of a class file conforms to the requirements of the current virtual machine and does not compromise the security of the virtual machine itself. Contains four phases of the verification process: 1) file format verification : Ensure that the input byte stream is correctly parsed and stored in the method area, in a format that meets the requirements for describing a Java type of information 2) Metadata validation : The validation of bytecode semantic information to ensure that the information described conforms to the Java language specification. The validation points are: whether this class has a parent class, and so on. 3) bytecode verification : mainly for data flow and control flow analysis, to ensure that the method of the calibration class will not be at runtime to compromise the virtual machine security behavior. 4) symbol Reference validation : Converts a symbol reference to a validation of a direct reference process. Prepare : Allocates memory for class variables and sets the initial values of variables, which exist within the method area for allocation. Parse : Converts a symbolic reference in a virtual machine constant pool to a direct reference. Parsing is mainly for classes or interfaces, fields, class methods, classes of several methods of four classes. initialization : Performs assignment of static variables and static code blocks to complete the initial recognition. The initialization process ensures that the initialization defined in the parent class takes precedence over the initialization of the subclass. However, the interface does not need to perform the initialization of the parent class.

Parent delegation Model:

In addition to the top-level startup ClassLoader, the rest of the ClassLoader should have their own parent classloader. The order is: Bootstrap ClassLoader: Starts the ClassLoader, loads the class Extension ClassLoader in Java_home/lib: Extend the ClassLoader, load the class library under the Java_home/lib/ext directory Application ClassLoader: The application class loader, load the user class path on the specified class library. The parent delegation model works by saying that if a class loader is subjected to a class load request, it will not attempt to load the class itself, but delegate the request to the parent ClassLoader to complete, so that all load requests should eventually be routed to the top-level startup ClassLoader. The loader tries to load itself only when the parent ClassLoader has feedback that it cannot complete the load request. This approach ensures that the Oject class is the same class in each loader load environment.

Allocation: Static allocation and dynamic dispatch.

Some of the most basic manifestation of polymorphism characteristics. Static types are known by compilers, and dynamic types are known at run time. Human H =new man (); Human is a static type, man-time dynamic type. All allocation actions that depend on the execution version of a static type definition method are called static allocations , and the most typical application is method overloading. Dynamic Dispatch determines the version of execution based on the dynamic type, so a specific version of the execution method can be determined only at run time. Typical representation when overridden. The process is as follows: 1) First find the actual type of the object that the first element of the top of the operand stack holds, and remember to do C. 2) If you find a method in type C that matches both the descriptor in the constant and the simple name, the scope permission check is performed. If passed returns a direct reference to the method, otherwise throws a Illegalaccesserror exception. 3) Otherwise, follow the inheritance relationship from the next to the parent class C for the 2nd step of the search and validation process. 4) If the old thrown Abstractmethoderror exception is never found. The parameters of the method's recipient and method are collectively called method parcels, which can be divided into single and multiple allocations based on how much of the volume is allocated. Java is a static multi-dispatch, and dynamic dispatch belongs to a single dispatch.

the implementation of dynamic Dispatch: dynamic Dispatch is very frequent action, and the method version selection process of dynamic dispatch requires the runtime to search for the appropriate target method in the method metadata of the class, so for performance reasons, a virtual method table is created in the method area. The actual entry address used to hold each method. If the subclass of a method is not re-implemented, then the address entry in the virtual method table of the subclass is identical to the address entry for the same method as the parent class. Is the implementation portal that points to the parent class, and if this method is overridden in a subclass, The address in the subclass method table will be replaced with the entry address that points to the subclass implementation version. The virtual method table is initialized during the connection phase of the class load.

JVM Automatic memory Management (when GC is triggered)

Http://jeromecen1021.blog.163.com/blog/static/18851527120117274624888/FULL GC and Minor GC trigger time programmers cannot control time specifically, When the system calls the System.GC () function at an unpredictable time, it is possible to adjust the ratio of newobject and oldobject with Newratio and Maxtenuringthreshold control the number of times to enter Oldobject, Causes the Oldobject storage space delay to reach full GC, which causes the timer to raise the time delay of the GC time delay oom to prolong the object lifetime.

GC pause reason, how to reduce the pause JVM How to tune, parameter how to tune the JVM architecture and the responsibilities of the various parts

The JVM has two mechanisms, one is to load the class (class or interface) with the appropriate name, and the process of loading the connection initialization of the class is called the class loading subsystem, and the other one is responsible for executing the instruction contained in the loaded class or interface called the Run engine. Each JVM also includes five parts of the method area, heap, Java stack, program counter, and local method stack, and the architecture diagram of these parts and the class loading mechanism together with the running engine mechanism is:

Each instance of the JVM has its own method domain and a heap, and all the threads running within the JVM share these areas, and when the virtual machine loads the class file, it parses the class information contained in the binary data and puts them in the method domain; The JVM places all the objects initialized by the program on the heap, and each thread is created with its own program counter and Java stack, where the value in the program counter points to the next instruction to be executed, and the Java stack of the thread is stored as the thread invokes the state of the Java method. The state of the local method call is stored on the local method stack, which relies on a specific implementation.

http://blog.csdn.net/dongdong_java/article/details/24797307 http://blog.csdn.net/longyulu/article/details/8350622

What if you don't want to be a GC?

It can be said that those objects can be GC, and then say that the Java object will not be recycled, determine whether it is also referenced, not referenced by the GC can be recycled, has been referenced will not be recycled.

    1. What the JVM performance tuning has done
    2. Describes the GC and GC root unhealthy references.
    3. From classload loading mode, loading mechanism, from the program runtime data area, talk about memory allocation, talk about the string constant pool, talk about the JVM garbage collection mechanism, algorithm, hotspot. Anyway, it's all kinds of extensions
    4. How much of an array is placed in the JVM older generation (not just set pretenuresizethreshold, ask how big it is, don't ask a question)
    5. How arrays are accessed in the old age
    6. GC algorithm, how to do GC for permanent objects, how to handle GC loops
    7. How does the JVM allocate direct memory??
    8. How does the new object not be allocated on the heap but on the stack?
    9. Constant Pool parsing
Run-time optimization best practices Student s= New Student (), doing those things in memory
    1. Load Student.class file into memory
    2. In the stack memory for S Open space
    3. Open space for academic objects in heap memory
    4. The member variables of the student object are displayed and initialized
    5. Assigning values to student object variables by constructing methods
    6. The object address is assigned to the S variable when the student object is initially completed.
Common parameter Configuration

Parameter meaning default Note-XMS: Represents the initial heap size, the default is physical memory 1/64 (<1GB) default (minheapfreeratio parameter can be adjusted) when the free heap memory is less than 40%, the JVM increases the heap until the maximum limit of-xmx.-xmx Maximum Heap Size The default (<1GB) of physical memory (maxheapfreeratio parameter can be adjusted) when the free heap memory is greater than 70%, the JVM reduces the heap until the minimum limit of-xms-xmn young generation size (1.4or lator) Note: The size here is (eden+ 2 Survivor space). It is different from the new Gen shown in the Jmap-heap. The entire heap size = younger generation size + old generation size + persistent generation size. Increasing the younger generation will reduce the size of older generations. This value has a large impact on system performance, and Sun's official recommendation is to configure the 3/8-xx:newsize for the entire heap to set the young generation size (for 1.3/1.4)
-xx:maxnewsize Young Generation Max (for 1.3/1.4)
-xx:permsize Set Persistent generation (perm Gen) initial value 1/64 of physical memory
-xx:maxpermsize set the maximum value of 1/4 of physical memory for persistent generations
-XSS the stack size of each thread JDK5.0 after each thread's stack size is 1M, and the previous thread stack size is 256K. The memory size required for the thread to be applied is adjusted. Under the same physical memory, Decreasing this value can generate more threads. But the operating system on a process of the number of threads still have limitations, can not be unlimited generation, experience in the 3000~5000 around the general small application, if the stack is not very deep, it should be 128k enough for the large application recommended 256k. This option has a large impact on performance and requires rigorous testing. The (principal) and threadstacksize options are interpreted very similarly, the official documentation does not seem to explain, in the forum there is such a sentence:-XSS is translated in a VM flag named Threadstacksize generally set this value is fine. -xx:newratio Young generation (including Eden and two survivor districts) vs. older generation (excluding persistent generations)
-xx:newratio = 4 means that the ratio of the young generation to the old generation is 1:4, and the young generation takes up the 1/5xms of the entire stack = XMX and sets the XMN, the parameter does not need to be set. The ratio of the-xx:survivorratio Eden to the Survivor area is set to 8, then the ratio of two survivor to one Eden area is 2:8, and one survivor area represents the 1/10-xx of the entire young generation: Maxtenuringthreshold Garbage maximum age if set to 0, then the young generation of objects do not go through the survivor area, directly into the elderly generation. For older generations of more applications, can improve efficiency. If you set this value to a larger value, the younger generation object will replicate multiple times in the Survivor area, which can increase the lifetime of the object's younger generations, increasing the probability that it will be recycled in the younger generation. The parameter is valid only for serial GC.
-xx:pretenuresizethreshold object more than how large is directly in the old generation to allocate 0 units of bytes The Cenozoic adopt parallel scavenge GC When invalid another case is a large array object that is allocated directly in the old generation, and there are no externally referenced objects in the array.

Related information: http://blog.csdn.net/wisgood/article/details/16818243

Java Interview Preparation JVM

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.