15

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

Ananth
  • 10,330
  • 24
  • 82
  • 109
  • 4
    There is no hard line between a "compiled" language and an "interpreted" language. At some point, all source code must be translated to machine code (unless you're writing assembly). – Matt Ball Feb 22 '11 at 05:03
  • 1
    it runs in mixed mode for most of the part (like most JITs), compiling everything is unnecessary (your main method for instance is run once one, no point to compile it). Inner loops are prime candidate for compilation. Javascript can be both but nowadays is mostly compiled. – bestsss Feb 22 '11 at 06:17
  • Sorry for the nitpick, but in English.. a "doubt" means that you do not believe something is true, or you are not sure if it's true. What you are asking is a "question". It's proper to say that if you doubt something, you question it, but that doesn't mean that all questions are doubts. – Erik Funkenbusch Feb 22 '11 at 07:09
  • @bestsss The .NET CLR does JIT every method. So does Mono. Also why do you assume Main is run once? Programs are allowed to call Main as many times as they please. – Michael Graczyk Jul 09 '12 at 17:11
  • @MichaelGraczyk, JIT every method is waste and the code has to be put somewhere, the generated code needs memory [not the regular heap even as it needs the execution bit]. JIT w/o profiling creates crappy/non-optimal code and letting the interpreter grok the code will be faster too. While 'main' can be run as you'd like, it's just not the norm at any rate. Microbenchmarks w/ loops in the main method result in OCRs too. Even TieredCompilation in Java that JITs a lot more via C1 produces TONS of unnecessary compiled code easily increasing the footprint of a server by 100ish MBs. – bestsss Jul 09 '12 at 19:09
  • @bestsss All the same, the .NET CLR does not do any interpreting (DLR aside.) It uses now and always has used JITed code for all methods. – Michael Graczyk Jul 09 '12 at 21:23

7 Answers7

13

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.

Tarik
  • 79,711
  • 83
  • 236
  • 349
Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
  • 9
    Modern web browsers can JIT-compile Javascript. Also, they store rendered HTML in an in-memory cache, which is analogous to JIT for programs. – Mechanical snail Sep 29 '11 at 02:05
  • Interestingly, Chrome's V8 engine used to not be able to interpret javascript, and [needed to compile it to machine code first (JIT)](https://stackoverflow.com/a/59812253/7365866). `In recent years, V8 has had an interpreter as its first execution tier.` – Ben Butterworth Sep 13 '21 at 19:22
8

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.

Oak
  • 26,231
  • 8
  • 93
  • 152
5

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.

Community
  • 1
  • 1
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164
2

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'.

Euro Micelli
  • 33,285
  • 8
  • 51
  • 70
  • if the JIT does on the stack replacement I do consider it compilation, the code is not needed to be compiled 100% just the hot parts. – bestsss Feb 23 '11 at 14:28
  • -1 "I've come to think that there really isn't any 'right' anwser". Compilers do partial specialization is the right answer. – J D Mar 04 '12 at 17:25
1

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.

Tedd Hansen
  • 12,074
  • 14
  • 61
  • 97
1

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.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
0

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.

Anands23
  • 758
  • 9
  • 19