专栏首页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.

jps:查看本机java进程信息。

jstack:打印线程的信息,制作线程dump文件。

jmap:打印内存映射,制作dump文件

jstat:性能监控工具

jhat:内存分析工具

jconsole:简易的可视化控制台

jvisualvm:功能强大的控制台

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

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

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

jps

-l :输出主类全名

-v:输出虚拟机进程启动的jvm参数

-m:输出启动时传递给main函数的参数

-q:只输出LVMID,省略主类的名称

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]

JMap是JDK中自带的一个用于分析JVM内存状况的工具,位于JDK的bin目录下。使用JMap可查看目前JVM中各个代的内存状况、JVM中对象的内存的占用状况,以及导出整个JVM中的内存信息。

-heap :打印jvm heap的情况

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

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

-permstat: 打印permanent generation heap情况

jstat -gc PID 5000 20

是用于监控虚拟机各种运行状态信息的命令行工具。他可以显示本地或远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据。

jhat -J-Xmx1024M [file]

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

jstack [option] vmid

显示虚拟机的线程栈信息,用于生成当前JVM的所有线程快照。

-F:当正常输出的请求不被响应时,强制输出线程堆栈。 

-l:除堆栈外,显示关于锁的附加信息。 

-m:如果调用到本地方法的话,可以显示C/C++的堆栈 

jstat -gc pid 5000

S0C:S0区容量(S1区相同,略)

S0U:S0区已使用

EC:E区容量

EU:E区已使用

OC:老年代容量

OU:老年代已使用

PC:Perm容量

PU:Perm区已使用

YGC:Young GC(Minor GC)次数

YGCT:Young GC总耗时

FGC:Full GC次数

FGCT:Full GC总耗时

GCT: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...

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

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

    readme
  • ImageNet Classification 深度学习模型

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

    readme
  • 【Codeforces】1217A - Creating a Character

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

    喜欢ctrl的cxk
  • HDUOJ---(4708)Herding

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

    Gxjun
  • 学习的力量

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

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

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

    大数据和云计算技术
  • 融合ICT数据中心云等保2.0解决方案

    前段时间研读了公安部发布的等保2.0安全标准,有了一些自己的理解来今天来和大家分享一下,等保2.0的中心思想是“一个中心,三重防护”,一个中心指的...

    ICT售前新说
  • golang日志组件使用runtime.Caller性能问题分析

    runtime.Caller能够拿到当前执行的文件名和行号,这个方法几乎所有的日志组件里都有使用。

    霸王猪
  • 2017年网络安全五大趋势

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

    FB客服

扫码关注云+社区

领取腾讯云代金券