JVM 是编译器还是解释器?

2022-01-16 00:00:00 jvm java

我有一个关于 JVM 的非常基本的问题:它是编译器还是解释器?

I have a very basic question about JVM: is it a compiler or an interpreter?

如果是解释器,那么JVM内部存在的JIT编译器呢?
如果两者都不是,那么 JVM 到底是什么?(我不想要将字节码转换为机器特定代码等的JVM的基本定义.)

If it is an interpreter, then what about JIT compiler that exist inside the JVM?
If neither, then what exactly is the JVM? (I dont want the basic definition of jVM of converting byte code to machine specific code etc.)

推荐答案

首先,让我们对以下术语有一个清晰的认识

First, let's have a clear idea of the following terms

Javac 是 Java Compiler -- 将你的 Java 代码编译成 Bytecode

Javac is Java Compiler -- Compiles your Java code into Bytecode

JVM 是 Java 虚拟机 -- 运行/解释/翻译字节码为 本机机器码

JVM is Java Virtual Machine -- Runs/ Interprets/ translates Bytecode into Native Machine Code

JIT 是即时编译器——在本地执行之前将给定的字节码指令序列编译为 runtime 的机器码.它的主要目的是对性能进行大量优化.

JIT is Just In Time Compiler -- Compiles the given bytecode instruction sequence to machine code at runtime before executing it natively. It's main purpose is to do heavy optimizations in performance.

现在,让我们为您的问题寻找答案.

1)JVM:它是编译器还是解释器? -- Ans:解释器

2)JVM中存在的JIT编译器呢? -- Ans:如果你完整阅读了这个回复,你可能现在就知道了

2)what about JIT compiler that exist inside the JVM? -- Ans: If you read this reply completly, you probably know it now

3)JVM到底是什么? -- Ans:

  • JVM 是驻留在 RAM 上的虚拟平台
  • 其组件类加载器将.class文件加载到RAM中
  • JVM 中的字节码验证器 组件检查您的代码中是否存在任何访问限制违规.(这是 java 安全的主要原因之一)
  • 接下来,执行引擎组件将字节码转换成可执行的机器码
  • JVM is a virtual platform that resides on your RAM
  • Its component, Class loader loads the .class file into the RAM
  • The Byte code Verifier component in JVM checks if there are any access restriction violations in your code. (This is one of the principle reasons why java is secure)
  • Next, the Execution Engine component converts the Bytecode into executable machine code

希望这对您有所帮助..

Hope this helped you..

相关文章