当前位置:网站首页>JVM学习笔记:三 本地方法接口、执行引擎
JVM学习笔记:三 本地方法接口、执行引擎
2022-06-12 08:21:00 【lanleihhh】
JVM学习笔记:三 本地方法接口、执行引擎
本地方法接口

本地方法
- Java中的native修饰的方法
- native method 就是java调用非java代码的接口
- 本地方法都是操作系统提供的(由C或C++编写)
- 定义native方法,不提供实现,调用的是非Java代码实现
- native可以与除abstract之外的标识符连用
使用本地方法的好处
- Java可以与底层操作系统交互
有些任务使用Java不容易实现
不必关心实现细节,只要调用即可 - Java与硬件进行数据交互(
start(),read(),hashCode())
JVM的解释器用C实现,可以更好地与外部交互
jre大部分是Java实现,通过一些本地方法来和外界交互
例如java.lang.Thread的setPriority()方法是用 Java 实现的,但是它实现调用的事 该类里的本地方法setPriority0()

执行引擎
概述
执行引擎是JVM的核心组成部分之一

JVM将字节码装载到内存,字节码不是可执行的机器码,需要经过执行引擎将字节码解释/编译为对应平台上的机器指令。
执行引擎在JVM中扮演一个将高级语言翻译为机器语言的角色
- 前端编译:.java --> .class
- 后端编译:.class 解释/编译为机器码
执行引擎的机制
- 解释器
JVM启动时,根据预定义的规范对字节码逐行地解释执行,将字节码内容翻译为对应平台的机器码执行。 - JIT编译器
将字节码整体编译为机器码,但不立即执行
为什么Java是半解释半编译型语言?
JIT即时编译器是Java后来有的,原先就是解释执行
- 原来单纯的逐行解释字节码执行的效率低
- JIT将字节码翻译为机器码后,缓存到方法区的JIT代码缓存中,提升了执行效率
- 根据代码被执行的频率来决定是否启动JIT编译器将字节码直接编译为对应平台的机器码
JVM会针对使用频率较高的热点代码进行编译,缓存到方法区,执行效率高
JIT 编译器执行效率高为什么还需要解释器?
JIT编译器编译过程需要时间,但是执行效率高。
程序一启动,解释器马上响应,去解释执行。
将两者结合,JVM启动后,先通过解释器解释执行代码,之后使用编译器编译执行。采用解释器和即时编译器并存的架构来平衡。
边栏推荐
- Vision Transformer | Arxiv 2205 - LiTv2: Fast Vision Transformers with HiLo Attention
- 企业上线MES软件的费用真的很贵?
- (p25-p26) three details of non range based for loop and range based for loop
- MATLAB image processing - Otsu threshold segmentation (with code)
- The residual pressure monitoring system ensures the smoothness of the fire evacuation passage in case of fire, and protects the safe operation of large high-rise buildings and the safety of people's l
- Vscode 调试TS
- 计组第一章
- 制造企业生产排产现状和APS系统的解决方案
- MES帮助企业智能化改造,提高企业生产透明度
- C # push box
猜你喜欢

超全MES系统知识普及,必读此文

Model Trick | CVPR 2022 Oral - Stochastic Backpropagation A Memory Efficient Strategy

What is an extension method- What are Extension Methods?

Database foundation -- normalization and relational schema

计组第一章

如何理解APS系统的生产排程?

Model Trick | CVPR 2022 Oral - Stochastic Backpropagation A Memory Efficient Strategy

Ankerui motor protector has the functions of overload inverse time limit, overload definite time limit, grounding, starting timeout, leakage, underload, phase failure, locked rotor, etc

安科瑞电动机保护器具有过载反时限、过载定时限、接地、起动超时、漏电、欠载、断相、堵转等功能

x64dbg 调试 EXCEPTION_ACCESS_VIOLATION C0000005
随机推荐
Learning notes (1): live broadcast by Dr. Lu Qi - face up to challenges and grasp entrepreneurial innovation opportunities - face up to challenges and grasp entrepreneurial innovation opportunities -1
EasyExcel导出Excel表格到浏览器,并通过Postman测试导出Excel【入门案例】
MYSQL中的锁的机制
Bean的作用域
(P21-P24)统一的数据初始化方式:列表初始化、使用初始化列表初始化非聚合类型的对象、initializer_lisy模板类的使用
Arrays in JS
Webrtc adding third-party libraries
Lock mechanism in MySQL
ctfshow web3
In depth interpretation of 5g key technologies
Database foundation -- normalization and relational schema
You get download the installation and use of artifact
C语言printf输出整型格式符简单总结
Calling stored procedures in mysql, definition of variables,
Derivation of Poisson distribution
Hands on deep learning -- implementation of multi-layer perceptron from scratch and its concise implementation
Vscade debug TS
智能制造的时代,企业如何进行数字化转型
Cmake can't find the solution of sophus
Vision transformer | arXiv 2205 - TRT vit vision transformer for tensorrt