Http://www.cnblogs.com/xrq730/p/4839245.html
Objective
Previous articles, especially when explaining GC, mentioned a number of concepts, such as memory overflow and memory leaks, parallelism and concurrency, client mode and server mode, Minor GC, and full GC, which are explained in detail in this article.
Differences in memory overflow and memory leaks
1. Memory Overflow
Memory overflow refers to a program that does not have enough space to allocate when it requests memory.
2. Memory leaks
Memory leak refers to the program after the application of memory, there is no way to release the memory has been applied to, it always occupies the memory, that is, the allocated objects can be up to but useless . Memory leaks are typically caused by a large object in memory, but cannot be freed.
As you can see from the definition, memory leaks will eventually cause memory overflow.
Note that the first step in locating a virtual machine problem memory problem is to determine whether it is memory overflow or memory leak, the former good judgment, tracking stack information can be, the latter is more complex, is generally the old age of large objects did not release, to find out in the old age of the big object is not released.
Differences in parallelism and concurrency
These two nouns are concepts in concurrent programming, and in the context of talking about garbage collectors, you can understand these two nouns:
1. Parallel parallel
Multiple garbage collection threads work in parallel, but the user thread is still waiting
2. Concurrent concurrent
means that the user thread executes concurrently with the garbage collection thread (but not necessarily in parallel, may be alternately executed), the user program continues to run, and the garbage collector runs on the other CPU
Minor the difference between GC and full GC
1. New Generation GC (Minor GC)
Refers to the garbage collection action occurring in the Cenozoic, because most Java objects are not very good, so the minor GC is very frequent and the recovery rate is faster
2, Old generation GC (Major gc/full GC)
The garbage collection action that occurs in the old age, major GC, often accompanied at least once minor GC (but not absolute). Major GC is generally more than 10 times times slower than minor GC
The difference between client mode and server mode
In some commercial virtual machines, the Java program was originally interpreted by the interpreter to interpret the. class file, and when the virtual machine discovers that a method or block of code is running particularly frequently, the code is identified as hotspot code hot Spot Code (which is also the origin of the virtual machine hotspot name we use). In order to improve the efficiency of hot code execution, at runtime, the virtual machine will compile the code into the machine code associated with the local platform and perform various levels of optimization, and the compiler for this task is called the Instant compiler (Just in time Compiler, the JIT compiler). The JIT compiler is not a required part of a virtual machine, and the Java Virtual Machine specification does not require the existence of a JIT compiler, nor does it qualify or instruct the JIT compiler how to implement it. However, the performance of the JIT compiler, the level of code optimization is the measurement of a commercial virtual machine is one of the most important indicators of good or not.
The interpreter and compiler actually have advantages over the compiler:
1, when the program needs to start and execute quickly, the interpreter can play a role, save the compile time, immediately execute
2, after the program runs, over time, the compiler gradually play a role, the more and more code to compile the cost of code, you can get higher execution efficiency
The hotspot we used built up two JIT compilers, the C1 compiler and the C2 compiler, by default using an interpreter and an editor to work together. At startup, the HotSpot automatically chooses the operating mode based on its version and the hardware performance of the host machine, such as detecting whether the host machine is a server, such as J2SE, which detects whether the host has at least 2 CPUs and at least 2GB of memory.
1, if it is, the virtual opportunity to run in server mode, the mode and the C2 compiler run together, more attention to the quality of the compilation, startup speed is slow, but high efficiency, suitable for use in the server environment, for the production environment is optimized
2, if not, then the virtual opportunity to run in client mode, the mode and the C1 compiler run together, more attention to the speed of the compilation, startup speed, more suitable for the client version, the GUI is optimized
There are two ways to see whether a virtual machine is running in client mode or in server mode:
1. Run the "java-version" command at the program command line to see if your locally installed virtual machine is information
2, for example, we run the program with Eclipse or myeclipse, generally use the tool comes with the JRE, virtual machine is not a locally installed virtual machine. What to do now, you can view the virtual machine information by running the following statement in the program
System.out.println (System.getproperty ("Java.vm.name"));
The result of my operation here is
Java HotSpot (TM) 64-bit Server VM
Of course, to change the mode of virtual machine operation can also, only need to change jvm.cfg on it. We can find jvm.cfg from the following places:
The file path for 1, 32-bit JDK is java_home/jre/lib/i386/jvm.cfg
The file path for 2, 64-bit JDK is java_home/jre/lib/amd64/jvm.cfg
3, MyEclipse in .../common/binary/com.sun.java.jdk.win32.x86_64_1.6.0.013/jre/lib/amd64/jvm.cfg
Currently 64-bit support only server mode, the file content is the same, the above comments do not control it, the rest is these:
-Server known-client ignore-hotspot aliased_to-server-Classic warn- native error-Green ERROR
Since my computer has a 64-bit JDK, it is "-client ingore". Supporting both the server mode and the client mode, should be "-server known" and "-client known", generally only need to change the sequencing of these two configurations, but only if java_home/jre/ The bin directory has both server and client two folders, respectively, corresponding to the respective virtual machine, missing one, after switching will be error.
Java Virtual Machine 6: Differences between memory overflow and memory leaks, parallelism and concurrency, Minor GC and full GC, client mode, and server mode