解释字节码与编译字节码? [英] Interpreting bytecode vs compiling bytecode?

查看:115
本文介绍了解释字节码与编译字节码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些关于JVM / JIT活动的参考文献,其中似乎在编译字节码和解释字节码之间存在差异。特定注释声明字节码被解释为前10000次运行并在之后编译。

I have come across a few references regarding the JVM/JIT activity where there appears to be a distinction made between compiling bytecode and interpreting bytecode. The particular comment stated bytecode is interpreted for the first 10000 runs and compiled thereafter.

编译和解释字节码有什么区别?

What is the difference between "compiling" and "interpreting" bytecode?

推荐答案

解释字节代码基本上逐行读取字节码,不做任何优化或任何事情,解析并实时执行。由于多种原因,这显然是低效的,包括Java字节码不能快速解释的问题。

Interpreting byte code basically reads the bytecode line by line, doing no optimization or anything, and parsing it and executing it in realtime. This is notably inefficient for a number of reasons, including the issue that Java bytecode isn't designed to be interpreted quickly.

编译方法时,JIT加载整个方法并生成直接在CPU上运行的本机代码,而不是逐行读取和解释字节代码。编译该方法一次后,每次调用该方法时都会直接使用生成的本机代码。这在天文学上更快,但在编译方法时会产生一些开销;除此之外,JVM还负责仅编译经常调用的方法,以最大限度地减少开销,同时最大限度地提高经常被调用的紧密内循环代码的性能。

When a method is compiled, the JIT loads the whole method and generates native code to run directly on the CPU, rather than reading and interpreting the byte code line by line. After the method is compiled once, the generated native code gets used directly every time the method is called. This is astronomically faster, but incurs some overhead when the method gets compiled; among other things, the JVM is responsible for only compiling frequently called methods, to minimize the overhead while maximizing the performance of "tight inner loop" code that gets called extremely often.

这篇关于解释字节码与编译字节码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆