About the types and patterns of the JVM

Source: Internet
Author: User

Once upon a time, I have struck countless such commands:



However, I have only cared about the version number, which is the first line of the content. Today, let's take a look at the output of line 3rd: the type of JVM and the mode of operation.


In fact, it is inaccurate to say that server and client are the two working modes of the JVM, because they are different virtual machines, so there are two types of JVMs to be said.


The output from the third row can be seen: the JVM's name (HotSpot), type (Client), and build ID (24.79-B02). In addition, we know that the JVM is running in mixed mode (mixed mode), which is the default operating mode of the hotspot, which means that the JVM can dynamically compile bytecode into local code at runtime. We can also see that the class data sharing is turned on (that is, the last sharing of the third line). Class data sharing is a system class that stores the JRE in a read-only cache (in a JSA file, "Java Shared Archive") and is used by all Java process ClassLoader as a shared resource. It may show performance benefits in situations where all class data is often read from the jar document.


Type of JVM


Search by Baidu, can only search for a few repeatedly reproduced articles. This article, for example, basically describes the differences between the two types of JVMs:


The-server VM starts at a slower speed, but once it is running, performance can be greatly improved.


But I think it's not enough to just know the difference. However, I rarely see a more in-depth description of the JVM type and pattern differences in Baidu's search results. But I did find this article. The following are mentioned in this article:


When the virtual machine runs in-client mode, it uses a lightweight compiler codenamed C1, while the-server mode-initiated virtual machine uses a relatively heavyweight, code-named C2 compiler. C2 is more thorough than the C1 compiler, and after service, performance is higher.


For this result, I think it is not deep enough. So FQ through Google search, the first few are the results I want.


Differences between two types of JVMs



So what is the difference between the Client JVM and the server JVM? The high-frequency issue on Oracle's official website explains this:


These different binaries. They is essentially, different compilers (jits) interfacing to the same runtime system. The client system is optimal-applications which need fast startup times or small footprints, the server system is Opti Mal for applications where the overall performance are most important. In general the client system was better suited for interactive applications such as GUIs. Some of the other differences include the compilation Policy,heap defaults, and inlining policy.


The main idea is that these two JVMs are used by different compilers. The Client JVM is suitable for applications that require fast start-up and small memory space, and is suitable for interactive applications such as the GUI, while the server JVM is the best choice for applications that value execution efficiency. The differences include: Compile policy, default heap size, inline policy.


According to "the Java HotSpot performance Engine Architecture":


The Client VM compiler does not try-to-execute many of the more complex optimizations performed by the compiler in the Ser Ver VM, but in exchange, it requires less time to analyze and compile a piece of code. This means the Client VMS can start up faster and requires a smaller memory footprint.


Note:it seems that the main cause of the difference in performance are the amount of optimizations.


The Server VM contains an advanced adaptive compiler this supports many of the same types of optimizations performed by OP Timizing C + + compilers, as well as some optimizations, cannot is done by traditional compilers, such as aggressive inl Ining across virtual method invocations. This was a competitive and performance advantage over static compilers. Adaptive optimization technology is very flexible in it approach, and typically outperforms even advanced static analysis and compilation techniques.


Both Solutions deliver extremely reliable, secure, and maintainable environments to meet the demands of today ' s enterprise Customers.


Obviously, the compiler for the Client VM does not perform many complex optimization algorithms like the server VM, so it is faster to parse and compile code fragments. The server VM, however, contains an advanced compiler that supports many of the same optimizations that are performed on the C + + compiler, and also includes optimizations that many traditional compilers cannot achieve.


The official documentation analyzes the differences between the compilation policy and the inline policy, and the following command shows the difference in the default heap size from the actual situation:


For the server JVM:


$ java-xx:+printflagsfinal-version 2>&1 | Grep-i-E ' heapsize|permsize|version '

Uintx adaptivepermsizeweight = {Product}

Uintx ergoheapsizelimit = 0 {Product}

Uintx initialheapsize: = 66328448 {Product}

Uintx Largepageheapsizethreshold = 134217728 {Product}

Uintx maxheapsize: = 1063256064 {Product}

Uintx MaxPermSize = 67108864 {PD product}

Uintx PermSize = 16777216 {PD product}

Java Version "1.6.0_24"


For the client JVM:


$ java-client-xx:+printflagsfinal-version 2>&1 | Grep-i-E ' heapsize|permsize|version '

Uintx adaptivepermsizeweight = {Product}

Uintx ergoheapsizelimit = 0 {Product}

Uintx initialheapsize: = 16777216 {Product}

Uintx Largepageheapsizethreshold = 134217728 {Product}

Uintx maxheapsize: = 268435456 {Product}

Uintx MaxPermSize = 67108864 {PD product}

Uintx PermSize = 12582912 {PD product}

Java Version "1.6.0_24"


It is clear that the initialheapsize and maxheapsize of the Server JVM are significantly larger than the client JVM.


Efficiency comparison


Here is an example that shows the efficiency of both executions, which comes from Onkar Joshi's blog:


public class Looptest {

public static void Main (string[] args) {

Long start = System.currenttimemillis ();

Spendtime ();

Long end = System.currenttimemillis ();

System.out.println (End-start);

}

private static void Spendtime () {

for (int i =500000000;i>0;i--) {

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.