Ananth
Ananth

Reputation: 10730

Is JIT compiler a Compiler or Interpreter?

My question is whether JIT compiler which converts the IL to Machine language is exactly a compiler or an interpreter.

One more question : Is HTML, JavaScript a compiled language or interpreted language?

Thanks in Advance

Upvotes: 17

Views: 8969

Answers (7)

Anands23
Anands23

Reputation: 790

JIT (Just In Time) Compiler is a compiler only and not an interpreter,because JIT compiler compiles or converts certain pieces of bytecodes to native machine code at run-time for high performance,but it does'nt execute the instructions.

Whereas,an Interpreter reads and executes the instructions at runtime.

HTML and Javascript are interpreted,it is directly executed by browser without compilation.

Upvotes: 0

Yochai Timmer
Yochai Timmer

Reputation: 49271

JIT (just in time) compiler is a compiler. It does optimizations as well as compiling to machine code. (and even called a compiler)

HTML, Javascript are interpreted, they are read as-is by the web browser, and run with minimal bug fixes and optimizations.

Upvotes: 13

Alexei Levenkov
Alexei Levenkov

Reputation: 100620

HTML is not programing language, so it is hard to say if it is compiled or interpreted... In sence of "if result of compilation is reused" HTML is not compiled by any browsers (it is parsed any time page is renderd).

JavaScript in older browsers is interpreted (preprocessed into intermediate representation, but not to machine code). Latest versions of browsers have JavaScript JIT compilers - so it is much harder to define if it is interpreted or compiled language now.

Upvotes: 1

Oak
Oak

Reputation: 26898

Technically, a compiler translates from one language to another language. Since a JIT compiler receives an IL as its input and outputs native machine binary, it easily fits this criteria and should be called a compiler.

Regarding Javascript, making a distinction here is more difficult. If you want to be pedantic, there's no such thing as a "compiled language" or "interpreted language". I mean, it's true that in practice most languages have one common way of running them and if that is an interpreter they are usually called interpreted languages, but interpretation or compilation are (usually) not traits of the language itself. Python is almost universally considered interpreted, but it's possible to write a compiler which compiles it to native binary code; does it still deserve the "interpreted" adjective?

Now to get to the actual answer: Javascript is typically ran by an interpreter which, among other things, uses a JIT compiler itself. Is that interpreted or compiled, then? Your call.

Upvotes: 8

Tedd Hansen
Tedd Hansen

Reputation: 12326

CLI (.Net bytecode) has features not found in native CPU's, so JIT is most definitively a compiler. Contrary to what some write here most of the optimizations has already been done however.

Upvotes: 1

Euro Micelli
Euro Micelli

Reputation: 34056

JIT processors like IL are compilers, mostly. JavaScript processors are interpreters, mostly. I understand your curiosity for this question, but personally I've come to think that there really isn't any 'right' anwser.

There are JavaScript interpreters that compiler parts or all of the code for efficiency reasons. Are those really interpreters?

JIT acts at runtime, so it can be understood as a clever, highly optimized interpreter. Which is it?

It's like "it's a plant" or "it's an animal" questions. There are live things that don't quite fit either mold very well: nature is what nature is, and 'classification' of things is a purely human intellectual effort that has its limitations. Even man-made things like 'code' are subject to the same considerations.

Ok; so maybe there is one right answer:

The way JavaScript is processed (say, as of 5 years ago) is called an 'Interpreter'. The way C++ is processed is considered a 'compiler'.

The way IL is processed is simply... a 'JIT'.

Upvotes: 2

Saurabh Gokhale
Saurabh Gokhale

Reputation: 46425

From Wiki's , just-in-time compiler(JIT), also known as dynamic translator, is used to improve the runtime performance of computer programs.

Just-in-time compilation is the conversion of non-native code, for example bytecode, into native code just before it is executed.JIT compiler is the one who compiles the IL code and output the native code which is cached, where as an interpreter will execute line by line code,
i.e in the case of java the class files are the input to the interpreter.

More on JIT here :

Yes, HTML, JavaScript are interpreted languages since they aren't compiled to any code. It means that scripts execute without preliminary compilation.

Also a good read here on JavaScript/HTML not being the compiled languages.

Upvotes: 5

Related Questions