Join the DZone community and get the full member experience.Join For Free
Compilation and Interpretation
Compilation and interpretation are few approaches that are used generally for the implementation of the code by programming languages.
A compiler can be defined as a program that helps in transforming a code. This transformation is done for the code that has been written in any programming language (source language) into another programming language that was targeted by you. They perform this task by translating the source code from a much high-level programming language to a low-level programming language i.e. machine language.
An interpreter analyses your source code line by line and instruction by instruction and then performs the execution of the corresponding machine code on the targeted machine directly without any involvement of a third party.
Although compilation and interpretation are the two principles with the help of which the implementation of the programming languages is done, they are also related to each other in some cases. This relation comes out as most of the systems that use interpretation do perform some works of translation. The translation work is done by compilers also.
How Does it Work?
Further, the interpreter takes this byte code, and then make the conversion into machine code. This machine code will further run this code on the hardware of the machine.
"It is very similar to the working of Java but the generation of byte code is done by the programmer and byte code has been shared universally not the source code."
The job of a baseline compiler is to perform the compilation of the code as fast as possible. It also generates a less-optimized byte code. As in the interpreter, it doesn’t have an optimized byte code for working with, then the speed of the application will be very slow. On the other hand, the time of the application will be very less.
Thinking about these things and other problems as well that were caused by full-codegen and crankshaft, the team of V8 performs the creation of a new version of the V8 engine from the ground up. The new version that was created was launched in 2017.
We have looked upon the working of V8, we will discuss in detail also later in this article. Very similar to this one, another model is being followed by a few of the other browsers vendors such as Spider Monkey engine which is used in Firefox, and Chakra engine which is used in internet explorers.
The objects in it are observed by garbage collectors including data that is no longer referenced. The collection of this kind of data is done by this collector. While performing a garbage collection cycle, the V8 engine automatically stops the execution of the program.
Spider Monkey consists of an interpreter, few JIT compilers, a de-compiler, and a garbage collector.
The concept of inline caching is based on empirical observation. It means that the objects that occur at a particular call site are often of the same type. In those cases, performance can be increased greatly by storing the result of a method lookup "inline", i.e. directly at the call site. To facilitate this process, call sites are assigned different states. Initially, a call site is considered to be "uninitialized".
Once the language runtime reaches a particular uninitialized call site, it performs the dynamic lookup, stores the result at the call site, and changes its state to "monomorphic". If the language runtime reaches the same call site again. It retrieves the call from it and invokes it directly without performing any more lookups. To account for the possibility that objects of different types may occur at the same call site, the language runtime also has to insert guard conditions into the code.
Opinions expressed by DZone contributors are their own.