`
bit1129
  • 浏览: 1069637 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

【JVM七】JVM知识点总结

    博客分类:
  • JVM
 
阅读更多

 

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知识点汇总

    本文根据《深入理解Java虚拟机》书籍内容及作者理解,总结了JVM相关的知识点,分享如下: 一、JVM内存区域 JVM在运行时,将内存空间分为若干个区域,主要包括方法区、堆内存、虚拟机栈、本地方法栈、程序计数器五...

    JVM知识点总结的思维导图

    JVM总结

    jvm的基础知识总结

    总结以上知识点,JVM作为Java程序的运行环境,拥有复杂的内存管理机制和高效的垃圾回收策略。理解JVM的内存模型、垃圾回收算法、类加载机制以及线程模型对编写高效稳定Java应用至关重要。同时,直接内存的使用也是...

    JVM与性能优化知识点整理.pdf

    **JVM(Java Virtual Machine)是Java程序运行的基础,它为Java代码提供了跨平台的运行环境。JVM的性能优化是提升Java应用效率的关键环节,涉及到内存管理、垃圾收集、线程调度等多个方面。** 一、JVM内存结构 1. *...

    JVM核心知识点总结(高质量)

    JVM核心知识点总结(高质量)

    JVM 精华知识点汇总1

    总结来说,理解和掌握JVM内存区域的划分以及如何避免内存溢出是Java开发中至关重要的知识点,这有助于优化程序性能和解决运行时的内存问题。通过深入学习JVM的内存管理机制,开发者可以更好地控制和调优Java应用程序...

    JVM调优文档知识点总结

    JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的。 Java语言的一个非常重要的特点就是与平台的...

    JVM核心知识点梳理以及JVM面试题总结

    以下是对JVM核心知识点的详细梳理和面试题的总结: 1. **内存结构** - **堆(Heap)**:所有线程共享的内存区域,用于存储对象实例。堆分为新生代和老年代。 - **新生代** 包括Eden区、Survivor区(from和to)。...

    JVM学习笔记核心知识点整理

    ### JVM学习笔记核心知识点整理 #### 一、引言与背景 随着软件开发技术的不断发展,Java作为一种广泛应用的编程语言,其背后的核心技术——Java虚拟机(JVM)的重要性日益凸显。掌握JVM不仅可以帮助开发者更好地理解...

    JVM知识点思维导图版

    JVM详细的知识点总结,思维导图 1.类加载器子系统 2.Hotspot的内存详情 3.HotSpot虚拟机对象探秘 4.垃圾收集器

    JVM知识点总结,最全思维导图,互联网大厂面试必备

    JVM知识点总结,最全思维导图,互联网大厂面试必备

    JVM.xmind(JVM必会知识脑图)

    准备秋招而做的JVM脑图,知识脉络清晰,总结详尽,还参考了大量大厂面经,易于理解和记忆,有一些基础的同学食用体验感更佳

    JVM与性能优化知识点整理.rar

    在面试和技术学习中,JVM及其性能优化是不可或缺的知识点。下面,我们将深入探讨JVM的主要组成部分、工作原理以及性能优化策略。 一、JVM的结构与工作流程 1. 类加载子系统:负责加载类文件,包括类的加载、验证、...

    深入JVM内核—原理、诊断与优化视频教程-3.常用JVM配置参数

    本教程——“深入JVM内核—原理、诊断与优化视频教程”,将重点讲解这些关键点,帮助开发者提升技术水平,更好地解决实际问题。 首先,我们来探讨JVM的内核原理。JVM主要由类加载子系统、运行时数据区、执行引擎、...

    个人总结之—JVM性能调优实战

    #### 关键知识点 ##### 1. JVM基础知识 - **JVM结构与工作原理**:了解JVM的基本组成及其工作流程对于进行有效的性能调优至关重要。 - **内存区域划分**:JVM的内存被划分为不同的区域,如堆区、方法区、栈区等,...

    Java基础知识点总结.docx

    以下是对这些知识点的详细说明: 一、Java概述: Java是由Sun Microsystems开发的一种跨平台的编程语言,它具有“一次编写,到处运行”的特性,通过Java虚拟机(JVM)实现平台无关性。Java有丰富的类库支持,适用于...

    2021面试题总结JVM篇.pdf

    根据提供的文档内容,我们可以深入探讨以下几个关键的JVM知识点: ### 1. 栈内存溢出 在Java虚拟机(JVM)中,每个线程都有一个独立的栈,即虚拟机栈,它用于存储线程运行时的数据。当线程执行方法时,会在栈上创建...

    R大(国内JVM权威)资料合集

    ### 知识点总结 #### 1. 高级语言虚拟机 (JVM) 概念及重要性 - **概念**: JVM(Java Virtual Machine),即Java虚拟机,是一种能够执行字节码(Bytecode)的虚拟机实例。它是运行Java程序的核心组件,负责将Java...

    马士兵jvm调优笔记.docx

    ### 马士兵JVM调优笔记知识点梳理 ...以上是基于《马士兵JVM调优笔记》文档内容整理的关键知识点总结。通过理解和掌握这些概念与技巧,可以帮助开发者更高效地管理和优化Java应用程序的内存使用情况。

    jvm

    ### JVM核心知识点解析 #### JVM概述 JVM(Java Virtual Machine)是运行Java字节码的虚拟机,它为Java程序提供了平台独立性,使得Java程序可以在任何支持JVM的平台上运行而无需重新编译。JVM的主要组成部分包括类...

Global site tag (gtag.js) - Google Analytics