本文介绍了Java解释器或任何解释器如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我一直在弄清楚口译员的确切工作方式,搜寻了一下并得出了一些结论,只是希望有人可以纠正它,以便让我对口译员的工作有更好的了解.

I have been figuring out the exact working of an interpreter, have googled around and have come up with some conclusion, just wanted it to be rectified by someone who can give me a better understanding of the working of interpreter.

所以我了解的是:

  1. 解释器是将高级代码转换为软件的软件程序语言转换成机器格式.
  2. 专门讲Java解释器,它以二进制格式获取代码(之前由Java编译器将其从源代码转换为字节码).
  3. 现在,用于Java解释器的平台是运行它的JVM,因此基本上它将产生可以由JVM运行的代码.
  4. 因此它需要字节码产生中间代码,然后目标机器代码并将其提供给JVM.
  5. JVM依次在JVM所在的OS平台上执行该代码.已实施或正在运行.
  1. An interpreter is a software program that converts code from high levellanguage to machine format.
  2. speaking specifically about java interpreter, it gets code in binary format(which is earlier translated by java compiler from source code to bytecode).
  3. now platform for a java interpreter is the JVM, in which it runs, sobasically it is going to produce code which can be run by JVM.
  4. so it takes the bytecode produces intermediate code and the target machinecode and gives it to JVM.
  5. JVM in turns executes that code on the OS platform in which JVM isimplemented or being run.

现在我仍然不清楚在这之间发生的子过程.

Now i am still not clear with the sub process that happens in between i.e.

  1. 解释器生成中间代码.
  2. 然后优化解释的代码.
  3. 然后生成目标代码
  4. 最后执行.

更多问题:

  • 那么解释器独自负责生成目标代码吗?和执行它?
  • 执行是否表示它已在JVM或底层操作系统中执行?
  • so is the interpreter alone responsible for generating target code ? andexecuting it ?
  • and does executing means it gets executed in JVM or in the underlying OS ?

推荐答案

不.那是一个编译器. 解释器执行指令的计算机程序直接用一种语言编写.这与将高级语言转换为低级语言的编译器不同. C编译器通过汇编程序(另一种编译器)将C语言转换为汇编代码,从而将汇编语言转换为机器代码-现代C编译器完成了从C语言转换为机器代码的两个步骤.

No. That's a compiler. An interpreter is a computer program that executes the instructions written in a language directly. This is different from a compiler that converts a higher level language into a lower language. The C compiler goes from C to assembly code with the assembler (another type of compiler) translates from assembly to machine code -- modern C compilers do both steps to go from C to machine code.

在Java中,java编译器进行代码验证,并将Java源代码转换为字节码类文件.它还执行许多小的处理任务,例如常量的预先计算(如果可能),字符串的缓存等.

In Java, the java compiler does code verification and converts from Java source to byte-code class files. It also does a number of small processing tasks such as pre-calculation of constants (if possible), caching of strings, etc..

JVM直接在字节码上运行. Java解释器与JVM紧密集成在一起,因此不应真正将它们视为单独的实体.还发生了一些优化问题,其中字节码基本上是动态优化的.这使得仅将其称为解释器是不够的.见下文.

The JVM operates on the bytecode directly. The java interpreter is integrated so closely with the JVM that they shouldn't really be thought of as separate entities. What also is happening is a crap-ton of optimization where bytecode is basically optimized on the fly. This makes calling it just an interpreter inadequate. See below.

JVM正在执行这些翻译.

The JVM is doing these translations.

我宁愿说JVM结合使用字节码,优化的用户代码,包括Java和本机代码的Java库以及OS调用来执行Java应用程序.

I'd rather say that the JVM uses the bytecode, optimized user code, the java libraries which include java and native code, in conjunction with OS calls to execute java applications.

Java编译器生成字节码.当JVM执行代码时,步骤2-4在JVM内部的运行时发生.例如,它与C截然不同,后者具有由不同的实用程序运行的这些独立步骤.不要将其视为子进程",而应将其视为JVM内部的模块.

The Java compiler generates bytecode. When the JVM executes the code, steps 2-4 happen at runtime inside of the JVM. It is very different than C (for example) which has these separate steps being run by different utilities. Don't think about this as "subprocesses", think about it as modules inside of the JVM.

排序. JVM的解释器根据定义读取字节码并直接执行.但是,在现代JVM中,解释器与即时编译器(JIT)协同工作,以即时生成本地代码,以便JVM可以使您的代码更有效地执行.

Sort of. The JVM's interpreter by definition reads the bytecode and executes it directly. However, in modern JVMs, the interpreter works in tandem with the Just-In-Time compiler (JIT) to generate native code on the fly so that the JVM can have your code execute more efficiently.

此外,还有后期处理编译"阶段,这些阶段在运行时分析生成的代码,以便可以通过内联常用代码块或通过其他机制来优化本机代码.这就是启动时JVM负载如此之高的原因.它不仅会加载到jar和类文件中,而且实际上是在运行中执行cc -O3.

In addition, there are post-processing "compilation" stages which analyze the generated code at runtime so that native code can be optimized by inlining often-used code blocks and through other mechanisms. This is the reason why the JVM load spikes so high on startup. Not only is it loading in the jars and class files, but it is in effect doing a cc -O3 on the fly.

尽管我们谈论的是JVM执行代码,但这在技术上并不正确.一旦将字节代码转换为本地代码,JVM和Java应用程序的执行就由CPU和其余硬件体系结构完成.

Although we talk about the JVM executing the code, this is not technically correct. As soon as the byte-code is translated into native code, the execution of the JVM and your java application is done by the CPU and the rest of the hardware architecture.

操作系统是执行所有过程和资源管理的基础,因此程序可以有效地共享硬件并有效地执行.该操作系统还为应用程序提供了API,使应用程序可以轻松访问磁盘,网络,内存以及其他硬件和资源.

The Operating System is the substrate that that does all of the process and resource management so the programs can efficiently share the hardware and execute efficiently. The OS also provides the APIs for applications to easily access the disk, network, memory, and other hardware and resources.

这篇关于Java解释器或任何解释器如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:05