专栏首页readmeJVM-JMM 虚拟机-内存模型

JVM-JMM 虚拟机-内存模型

In software development, the programming language Java was historically considered slower than the fastest 3rd generation typed languages such as C and C++. The main reason being a different language design, where after compiling, Java programs run on a Java virtual machine (JVM) rather than directly on the computer's processor as native code, as do C and C++ programs. Performance was a matter of concern because much business software has been written in Java after the language quickly became popular in the late 1990s and early 2000s.

Since the late 1990s, the execution speed of Java programs improved significantly via introduction of just-in-time compilation (JIT) (in 1997 for Java 1.1), the addition of language features supporting better code analysis, and optimizations in the JVM (such as HotSpot becoming the default for Sun's JVM in 2000). Hardware execution of Java bytecode, such as that offered by ARM's Jazelle, was also explored to offer significant performance improvements. The performance of a Java bytecode compiled Java program depends on how optimally its given tasks are managed by the host Java virtual machine (JVM), and how well the JVM exploits the features of the computer hardware and operating system (OS) in doing so.

Thus, any Java performance test or comparison has to always report the version, vendor, OS and hardware architecture of the used JVM. In a similar manner, the performance of the equivalent natively compiled program will depend on the quality of its generated machine code, so the test or comparison also has to report the name, version and vendor of the used compiler, and its activated compiler optimization directives.

JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls the main method present in a java code. JVM is a part of JRE(Java Runtime Environment).

The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.

JVM Method Area stores class structures like metadata, the constant runtime pool, and the code for methods.

All the Objects, their related instance variables, and arrays are stored in the heap. This memory is common and shared across multiple threads.

Java language Stacks store local variables, and it’s partial results. Each thread has its own JVM stack, created simultaneously as the thread is created. A new frame is created whenever a method is invoked, and it is deleted when method invocation process is complete.

PC register store the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its separate PC register.

Native method stacks hold the instruction of native code depends on the native library. It is written in another language instead of Java.

It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.

The Native Method Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.

Native Libraries is a collection of the Native Libraries(C, C++) which are needed by the Execution Engine.








javap: 可以对代码反编译,也可以查看java编译器生成的字节码。

jinfo: 查看正在运行的java运用程序的扩展参数,甚至支持在运行时动态地更改部分参数

jcmd: 在JDK 1.7之后,新增了一个命令行工具jcmd。它是一个多功能工具,可以用来导出堆,查看java进程,导出线程信息,执行GC等。jcmd拥有jmap的大部分功能,Oracle官方建议使用jcmd代替jmap。


-l :输出主类全名




jinfo pid

-flag< name >: 打印指定java虚拟机的参数值

-flag [+|-]< name >:设置或取消指定java虚拟机参数的布尔值

-flag < name >=< value >:设置指定java虚拟机的参数的值

jmap pid
jmap -heap pid
jmap -dump:format=b,file=file_name [pid]


-heap :打印jvm heap的情况

-histo: 打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。

-histo:live : 同上,但是只答应存活对象的情况

-permstat: 打印permanent generation heap情况

jstat -gc PID 5000 20


jhat -J-Xmx1024M [file]

JHat是Sun JDK 6及以上版本中自带的一个用于分析jvm堆dump文件的工具,基于此工具可分析jvm heap中对象的内存占用状况、引用关系等。

jstack [option] vmid





jstat -gc pid 5000









YGC:Young GC(Minor GC)次数

YGCT:Young GC总耗时

FGC:Full GC次数

FGCT:Full GC总耗时


Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java enabled system without any adjustment. This is all possible because of JVM.

When we compile a .java file, .class files(contains byte-code) with the same class names present in .java file are generated by the Java compiler. This .class file goes into various steps when we run it. These steps together describe the whole JVM.


如有侵权,请联系 yunjia_community@tencent.com 删除。


0 条评论
登录 后参与评论


  • socks5 helloworld

    SOCKS is an Internet protocol that exchanges network packets between a client an...

  • Anchoring & random 锚定/沉锚效应和随机

    Anchoring or focalism is a cognitive bias where an individual depends too heavil...

  • ImageNet Classification 深度学习模型

    https://github.com/google-research/noisystudent Tensorflow

  • 【Codeforces】1217A - Creating a Character

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 ...

  • HDUOJ---(4708)Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J...

  • 学习的力量

    (一) ? [Red] These walls are funny. First you hate 'em, then you get used to 'em....

  • 政务大数据系列8:政务大数据的安全体系

    政务是个大市场,阿里、腾讯、电信、华为都在赔本赚吆喝。本文作者宇同学是资深从业人士,研发总监,他会写一系列文章来阐述政务云全景。 前面七篇...

  • 融合ICT数据中心云等保2.0解决方案


  • golang日志组件使用runtime.Caller性能问题分析


  • 2017年网络安全五大趋势

    2017年眼看就要到来,回首2016年,网络安全无疑扮演着一个十分重要的角色,甚至连总统大选都没能逃过黑客丑闻和数据泄漏等厄运。 根据技术研究机构波耐蒙研究所(...