1. JVM运行模式
1.1 JVM运行时分为-server和-client两种模式,在32位机器上只有client模式的JVM。通常,64位的JVM默认都是使用server模式,因为server模式的JVM虽然启动慢点,但是,在运行过程,JVM会尽可能的进行优化
1.2 JVM分为三种字节码解释执行方式:mixed mode, interpret mode以及compiler mdoe
如下命令显示JVM使用了mixed mode,何为mixed mode:
[hadoop@hadoop jvms]$ java -version java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
重要信息
1. 64-Bit Server
1.Mixed mode of execution is the default mode of HotSpot and means that the JVM dynamically compiles byte code into native code at run time
2.执行程序前强制输出JVM的信息
[hadoop@hadoop jvms]$ java -showversion HelloJvm java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) This is HelloJvm
3. mixed mode/compiled mode/interpreted mode
[hadoop@hadoop jvms]$ java -showversion -Xmixed HelloJvm java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) This is HelloJvm
[hadoop@hadoop jvms]$ java -showversion -Xcomp HelloJvm java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, compiled mode) This is HelloJvm
[hadoop@hadoop jvms]$ java -showversion -Xint HelloJvm java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, interpreted mode) This is HelloJvm
为什么不选用-Xcomp和-Xint这两种模式?
The -Xint
flag forces the JVM to execute all bytecode in interpreted mode, which comes along with a considerable slowdown, usually factor 10 or higher. On the contrary, the flag -Xcomp
forces exactly the opposite behavior, that is, the JVM compiles all bytecode into native code on first use, thereby applying maximum optimization level. This sounds nice, because it completely avoids the slow interpreter. However, many applications will also suffer at least a bit from the use of -Xcomp
, even if the drop in performance is not comparable with the one resulting from -Xint
. The reason is that by setting -Xcomp
we prevent the JVM from making use of its JIT compiler to full effect. The JIT compiler creates method usage profiles at run time and then optimizes single methods (or parts of them) step by step, and sometimes speculatively, to the actual application behavior. Some of these optimization techniques, e.g., optimistic branch prediction, cannot be applied effectively without first profiling the application. Another aspect is that methods are only getting compiled at all when they prove themselves relevant, i.e., constitute some kind of hot spot in the application. Methods that are called rarely (or even only once) are continued to be executed in interpreted mode, thus saving the compilation and optimization cost.
2.什么是JIT即时编译
The input to the JVM is bytecode, and then there are several choices how it handles the bytecode during program execution. At times the JVM interprets bytecode only, without compiling it into native code first. In fact, every Java program you run will normally have some fraction of interpreted bytecode during its execution.Early JVMs only contained an interpreter, so your whole Java program bytecode was interpreted only. That’s the main reason why Java was (rightly) considered slow in its early years. Today, modern JVMs still allow you to use interpreted-only mode by specifying -Xint on the command line. Just add -XX:+PrintCompilation to the command line in addition to -Xint and you can see yourself that no compilation of bytecode into native code will happen. Compare the output with a run of the same Java program without -Xint.
When the JVM started to support bytecode-to-native compilation, people realized that it does not make sense to blindly compile each and every method into native code. Instead, the concepts/technologies nowadays known as “Just-in-time-compilation” and “HotSpot” were developed. In a nutshell, after startup the JVM first of all interprets the bytecode and then during program execution decides which methods to compile into native code. The idea is that only “hot” methods are worth the compiling/optimization effort required to produce efficient native code. On the contrary, “cold” methods will be handled in interpreted mode until they become “hot” – which might never happen for some methods.
By the way, when you dynamically reload classes or instrument methods at run time, the new bytecode will usually also be interpreted for a while even if the old version was already compiled. So, for every new piece of bytecode it sees, the JVM normally takes a while to decide whether it is “hot”.
This means that you will indeed find bytecode interpretation with every modern JVM execution. If you would like every method to be compiled into native code the first time it is called, you could specify -Xcomp on the command line, but I cannot really recommed this approach. JVMs are pretty clever nowadays!
JVM执行时,在comp模式下,立即解释为本地码;对于Xint,则永远不编译为本地码;对于Xmixed,则对访问频繁的方法进行优化,翻译成本地码,对于不常用的则不翻译
相关推荐
JVM与性能优化知识点整理.pdfJVM与性能优化知识点整理.pdfJVM与性能优化知识点整理.pdf
平时收集的与JVM相关的文章,现将整理在一起分享给大家,内容通俗易懂
JVM总结
JVM核心知识点梳理以及JVM面试题总结;JVM核心知识点梳理以及JVM面试题总结;JVM核心知识点梳理以及JVM面试题总结
JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的。 Java语言的一个非常重要的特点就是与平台的...
JVM详细的知识点总结,思维导图 1.类加载器子系统 2.Hotspot的内存详情 3.HotSpot虚拟机对象探秘 4.垃圾收集器
JVM知识点总结,最全思维导图,互联网大厂面试必备
准备秋招而做的JVM脑图,知识脉络清晰,总结详尽,还参考了大量大厂面经,易于理解和记忆,有一些基础的同学食用体验感更佳
作为有理想有追求的程序员,对于 JVM 的了解和掌握是有必要的。然而在我们工作中一般并不会直接和 JVM 打交道,因此这块...本文通过实例讲解的方式而不是泛泛的总结,将使你对 Java 类加载机制有相对深刻的理解和掌握
Java JVM知识点总结 248 equals()方法和hashCode()方法 270 数据结构 273 Array方法类汇总 304 Java数组与集合小结 305 递归 309 对象的序列化 310 Java两种线程类:Thread和Runnable 315 Java锁小结 321 java.util....
JAVA面试核心总结,包括jvm等知识点,覆盖面比较广
Java知识点总结,面试必备,java基础、java集合、JVM、Java并发、数据结构与算法、LeetCode、剑指offer、计算机网络、设计模式、MySQL、Redis
java知识点总结 包括: 1.jvm、基础知识、多线程 2.spring、springMVC、springBoot 3.sql优化、mybatis 4.SpringCloud、restful api、docker等
面试必问之JVM视频教程,百度云盘,总结了大部分面试中必问的jvm知识点,帮助各位面试顺利过关!
总结了学习jvm调优的知识点,便于大家随时查看,快速串联思维。主要包括:java内存结构、堆内存的构成、堆内存参数调整、垃圾收集算法、垃圾收集器选择、JVM参数、java对象的内存分配过程、Tomcat调优并使用Jmeter...
jvm笔记 1、jvm总体架构.pdf 2、堆内存内部结构.pdf 3、有关内存的常用配置参数.pdf 4、有关内存溢出和内存泄漏的...6、jvm优化知识点升级和配置总结.pdf 7、Tomcat调优实战.pdf 8、动态查看JVM内存的工具.pdf
互联网大厂开发高频面试及知识点总结 涉及JUC 包下的并发相关知识梳理 JVM及参数调优案例等
Java知识点总结,面试必备,java基础、java集合、JVM、Java并发、数据结构与算法、LeetCode、剑指offer、计算机网络、设计模式、MySQL、Redis.zip
Java知识点总结,面试必备,java基础、java集合、JVM、Java并发、数据结构与算法、LeetCode、剑指offer、计算机网络、设计模式、MySQL、Redis