Questions tagged [jit]

Just-In-Time compilation (JIT) is a technique used to improve the performance of interpreted code by translating it to machine code.

Introduction

From Wikipedia:

In computing, just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance of computer programs based on bytecode.

JIT compilers represent a hybrid approach, with translation occurring continuously, as with interpreters, but with caching of translated code to minimize performance degradation. They also offer handling of late-bound data types and the ability to enforce security guarantees.

In a bytecode-compiled system, source code is translated to an intermediate representation known as bytecode. The JIT compiler reads the bytecode and compiles it dynamically into machine language so the program can run faster.

Tag usage

Use the tag for questions about JIT compilers. Be sure to include other relevant tags as well. For example, if your JIT question is Java-specific, include the tag.

Further reading

1936 questions
54
votes
10 answers

Why is Java faster when using a JIT vs. compiling to machine code?

I have heard that Java must use a JIT to be fast. This makes perfect sense when comparing to interpretation, but why can't someone make an ahead-of-time compiler that generates fast Java code? I know about gcj, but I don't think its output is…
Adam Goode
  • 7,380
  • 3
  • 29
  • 33
50
votes
5 answers

Is there a runtime benefit to using const local variables?

Outside of the ensuring that they cannot be changed (to the tune of a compiler error), does the JIT make any optimisations for const locals? Eg. public static int Main(string[] args) { const int timesToLoop = 50; for (int i=0;…
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
49
votes
6 answers

Where is the .NET JIT-compiled code cached?

A .NET program is first compiled into MSIL code. When it is executed, the JIT compiler will compile it into native machine code. I am wondering: Where is these JIT-compiled machine code stored? Is it only stored in address space of the process?…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
49
votes
1 answer

JIT not optimizing loop that involves Integer.MAX_VALUE

While writing an answer to another question, I noticed a strange border case for JIT optimization. The following program is not a "Microbenchmark" and not intended to reliably measure an execution time (as pointed out in the answers to the other…
Marco13
  • 53,703
  • 9
  • 80
  • 159
47
votes
8 answers

What are the differences between a Just-in-Time-Compiler and an Interpreter?

What are the differences between a Just-in-Time-Compiler and an Interpreter, and are there differences between the .NET and the Java JIT compiler?
Rookian
  • 19,841
  • 28
  • 110
  • 180
45
votes
4 answers

Do redundant casts get optimized?

I am updating some old code, and have found several instances where the same object is being cast repeatedly each time one of its properties or methods needs to be called. Example: if (recDate != null && recDate >…
allonym
  • 1,408
  • 10
  • 18
45
votes
4 answers

java PrintCompilation output: what's the meaning of "made not entrant" and "made zombie"

When running a Java 1.6 (1.6.0_03-b05) app I've added the -XX:+PrintCompilation flag. On the output for some methods, in particular some of those that I know are getting called a lot, I see the text made not entrant and made zombie. What do these…
Joe Kearney
  • 7,397
  • 6
  • 34
  • 45
45
votes
7 answers

Does the .NET CLR Really Optimize for the Current Processor

When I read about the performance of JITted languages like C# or Java, authors usually say that they should/could theoretically outperform many native-compiled applications. The theory being that native applications are usually just compiled for a…
dewald
  • 5,133
  • 7
  • 38
  • 42
44
votes
2 answers

Why is it hard to beat AOT compiler with a JIT compiler (in terms of app. performance)?

I was thinking that JIT compilers will eventually beat AOT compilers in terms of the performance of the compiled code, due to the inherent advantage of JIT (can use information available only at runtime). One argument is that AOT compilers can spend…
Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
44
votes
4 answers

Is it true that having lots of small methods helps the JIT compiler optimize?

In a recent discussion about how to optimize some code, I was told that breaking code up into lots of small methods can significantly increase performance, because the JIT compiler doesn't like to optimize large methods. I wasn't sure about this…
sanity
  • 35,347
  • 40
  • 135
  • 226
44
votes
5 answers

Why does adding local variables make .NET code slower

Why does commenting out the first two lines of this for loop and uncommenting the third result in a 42% speedup? int count = 0; for (uint i = 0; i < 1000000000; ++i) { var isMultipleOf16 = i % 16 == 0; count += isMultipleOf16 ? 1 : 0; …
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
43
votes
2 answers

How does the JVM decided to JIT-compile a method (categorize a method as "hot")?

I already worked with -XX:+PrintCompilation, and I know the basic techniques of the JIT-compiler and why JIT-compilation is used. Yet I still have not found out how the JVM decides to JIT-compile a method, i.e. "when the right time has come to…
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
42
votes
11 answers

JIT compiler vs offline compilers

Are there scenarios where JIT compiler is faster than other compilers like C++? Do you think in the future JIT compiler will just see minor optimizations, features but follow a similar performance, or will there be breakthroughs that will make it…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
41
votes
5 answers

When is a method eligible to be inlined by the CLR?

I've observed a lot of "stack-introspective" code in applications, which often implicitly rely on their containing methods not being inlined for their correctness. Such methods commonly involve calls…
Ani
  • 111,048
  • 26
  • 262
  • 307
39
votes
5 answers

Can only 'perl6' parse Perl 6?

There's that (relatively) well known Perl axiom, "Only perl can parse Perl." I'm wondering, will that remain true for Perl 6? Expanding the discussion... I thought of this question given the recent update of PyPy. Does Perl's unique parsability…
Mark Canlas
  • 9,385
  • 5
  • 41
  • 63