Differences between memory overflow and memory leaks, parallelism and concurrency, Minor GC and full GC, client mode, and server mode

Source: Internet
Author: User

Preface

Previous articles, especially when it comes to GC, refer to a number of concepts, such as memory overflow and memory leaks, parallelism and concurrency, client mode and server mode, Minor GC and full GC, and this article explains in detail the differences between these concepts.

the difference between memory overflow and memory leak

1, Memory overflow

Memory overflow refers to the program in the application of memory, there is not enough space to allocate.

2. Memory leak

Memory leak refers to the program after the application of memory, there is no way to release the memory has been requested, it is always occupied with memory, that is, the allocated object can be reached but useless . Memory leaks are generally because there is a large object in memory, but cannot be freed.

As you can see from the definition, memory leaks will eventually result in a memory overflow.

Note that the first step in locating a virtual machine problem memory problem is to determine whether it is a memory overflow or a memory leak. The former is good to judge, the tracking stack information can be, the latter is more complex, is generally the old age of large objects did not release, to through various means to find the old age of large objects have not been released reasons.

the difference between parallelism and concurrency

These two nouns are all concepts in concurrent programming, and in the context of the garbage collector, the two nouns can be understood in this way:

1, parallel parallel

Multiple garbage collection threads work in parallel, but at this point the user thread is still in the waiting state

2. Concurrent concurrent

The user thread executes at the same time as the garbage collection thread (but it is not necessarily parallel, may run alternately), the user program continues to run, and the garbage collector runs on another CPU

the difference between Minor GC and full GC

1. Cenozoic GC (Minor GC)

Refers to the generation of garbage collection action, because most Java objects have a low survival rate, so the minor GC is very frequent, the general recovery speed is also relatively fast

2, the old generation GC (Major gc/full GC)

Refers to the garbage collection action occurring in the old age, where a major GC appears, often accompanied by at least one minor GC (but not absolute). The speed of Major GC is generally 10 times times slower than the minor GC.

differences between client mode and server mode

In some commercial virtual machines, Java programs are initially interpreted by the interpreter for the. class file, and when the virtual machine discovers that a method or block of code is particularly frequent, the code is identified as hot spot code. Code (This is also the origin of the virtual machine hotspot name that 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 that completes the task is called the Just-in-time compiler (Just in time Compiler, or 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, JIT compiler performance, code optimization level is a commercial virtual machine to measure the best or not one of the most key indicators.

The interpreter and compiler have the advantage of the compiler in fact:

1, when the program needs to quickly start and execute, the interpreter can play a role, eliminating the compile time, immediately execute

2, after the program runs, over time, the compiler gradually play a role, the more and more code compiled cost code, you can get higher execution efficiency

The hotspot we use includes two JIT compilers, the C1 compiler and the C2 compiler, which work by default with an interpreter and an editor. Hotspot automatically chooses the running 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 model with the C2 compiler to run together, pay more attention to the quality of the compilation, start slow, but high efficiency, suitable for use in the server environment, the production environment for the optimization

2, if not, the virtual opportunity to run in the client mode, the model with the C1 compiler to run together, more attention to the speed of the compilation, starting faster, more suitable for use in the client version, the GUI has been optimized

There are two ways to see whether a virtual machine is running in either client mode or 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 use Eclipse or MyEclipse to run the program, generally using the tool with the JRE, the virtual machine is not a locally installed virtual machine. What to do now, you can view virtual machine information by running the following statement in your 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 virtual machine running mode can also, only need to change jvm.cfg on it. We can find jvm.cfg from the following locations:

The file path for the 1, 32-bit JDK is java_home/jre/lib/i386/jvm.cfg

The file path for the 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 only supports server mode, file content is the same, the above note does not care about it, the rest is these:

-server known
-client IGNORE-hotspot aliased_to-server-classic WARN
error
-native error

Because my computer is installed with 64 JDK, so it is "-client ingore". At the same time, the server mode and the client mode, should be "-server known" and "-client known", generally only need to change the order of the two configurations, but the prerequisite is java_home/jre/ The bin directory at the same time the server and client two folders, corresponding to their respective virtual machines, missing one, the switch will be an error.

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.