前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JVM-JMM 虚拟机-内存模型

JVM-JMM 虚拟机-内存模型

原创
作者头像
vanguard
修改2020-03-16 10:43:53
2280
修改2020-03-16 10:43:53
举报
文章被收录于专栏:vanguardvanguard

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。

代码语言:javascript
复制
jps

-l :输出主类全名

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

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

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

代码语言:javascript
复制
jinfo pid

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

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

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

代码语言:javascript
复制
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情况

代码语言:javascript
复制
jstat -gc PID 5000 20

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

代码语言:javascript
复制
jhat -J-Xmx1024M [file]

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

代码语言:javascript
复制
jstack [option] vmid

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

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

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

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

代码语言:javascript
复制
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.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com