mtumilowicz/jit-notes is a public repo on GitHub by mtumilowicz. JIT in details. It declares the GPL-3.0 license on GitHub. It has 8 stars and last changed on 2021-02-14. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
-Xint - flag forces the JVM to execute all bytecode in the interpreted mode, which comes along with a
considerable slowdown, usually factor 10 or higher
-XX:+PrintCompilation - show basic information on when Hotspot compiles methods
shows timespan from start-up to compilation
shows compilation identifier (each compilation bumps identifier by 1)
C1 and C2 have separate identifiers
hot spots - programming parts that are executed a lot
spring configuration classes - only once during bootstrap
rest controller methods - many times
jit compilers consume transient resources (CPU cycles and memory)
from under a millisecond to seconds of compile time
can allocate 100s MBs
takes time to get to "full speed" because there may be 1000s of methods to compile
possible stop-the-world events, especially during deoptimization
collecting profile data is an overhead
cost usually paid while code is interpreted: slows start-up and ramp-up
mechanics
tiered
C2 compilation time is nearly 4 times slower than C1, but the code is 2-10x faster than C1
counters
hot method: invocation counter > invocation threshold
hot loops: backedge (loop) counter > backedge threshold
backedge (loop) counter - number of already happened iterations
invocation + backedge counter > compile threshold
medium hot methods with medium hot loops
if counter > threshold -> compile loop
C1: 2000 invocations
C2: 10000 invocations
Compiler Task Queue
JIT compilation is an asynchronous process
when the JVM decides that a certain block of code should be compiled, that block of code is put in a queue
not strictly first in, first out
methods whose invocation counters are higher have priority
the JVM will continue interpreting the method, and the next time
the method is called, the JVM will execute the compiled version of the method
if method stays in a queue for too long - it will be removed from the queue
maybe we don't need optimization for that method anymore
on-stack replacement (OSR) context
consider a long-running loop
JVM needs the ability to start executing the compiled version of the loop while
the loop is still running
when the code for the loop has finished compiling, the JVM replaces the code (on the stack), and the
next iteration of the loop will execute the much faster-compiled version of the code
deprecating old optimizations
made not entrant
there could exist many compilations of a single method simultaneously
if methodA calls methodB, it wants to have the best compilation
first time - it asks Call Dispatcher for the best compilation
methodA caches that information
subsequent calls
if the methodB is made not entrant - methodA calls dispatcher and gets the best compilation
if the methodB is not yet made not entrant - we have two compilations in the memory
we have to accept the slower compilation
somewhere in the meantime dispatcher will mark our compilation as made not entrant and
redirect calls to the faster one
made zombie - method was made not entrant and no thread has it on its stack
could be removed
c1
fast
trivial methods, up to 6 bytes (MaxTrivialSize) are inlined by default
up to 35 bytes (in bytecode) (MaxInlineSize)
inlining depth limit: 9 methods deep
c2
slow but generates faster code (compared to C1)
very complex
learning curve way too steep
the last few years no new major optimization
reached its end-of-life already years ago
by default limited by bytecode size of 325 (FreqInlineSize)
if > 8000 bytecode - always interpreted
optimizations
golden rule of optimization: don't do unnecessary work
it is almost never a single optimization but a sequence of optimizations
public static void x(Object object) {
if (object == null) {
System.out.println("a");
}
}
public void y() {
x(this);
}
inlining:
public void y() {
if (this == null) {
System.out.println("a");
}
}
null-check folding:
public void y() {
if (false) {
System.out.println("a");
}
}
resulting optimized code assumes that the rarely-taken branch or dispatch will
never execute, and the missing code is replaced by a trap that is triggered if
the rare case should occur
known as an uncommon trap
method inlining
expanding optimizations horizon
mother of all optimizations
"if you remove every other optimization java will be very fast anyway" - Joshua Bloch
tuning
-XX:+MaxTrivialSize=6 // trivial methods are inlined by default
-XX:+MaxInlineSize=35
-XX:+MaxInlineLevel=9
-XX:+MaxRecursiveInlineLevel=#
class hierarchy analysis
when dispatching a method call, the JVM checks how many implementations of that method is
1: it’s called monomorphic dispatch
2: it’s called bimorphic dispatch
more: it’s called megamorphic dispatch
monomorphic and bimorphic method calls can be inlined, while megamorphic calls can not
public void elide() {
var l = new ArrayList();
synchronized(l) { // lock on local variable
loop {
l.add(...) // l never escapes this thread
}
}
}
compiled into
public void elide() {
var l = new ArrayList();
loop {
l.add(...)
}
}
dead code elimination
duplicate code elimination
escape analysis
public void x() {
var f = new Foo("X", "Y");
baz(f)
}
public void baz(Foo f) {
sout(f.a)
sout(",")
quux(f)
}
public void quux(Foo f) {
sout(f.b)
sout("!")
}
JVM knows the implementation of an intrinsic method and can substitute the original java-code with
machine-dependent well-optimized instructions (sometimes even with a single processor instruction)
known to the jit
don't inline bytecode, do insert "best" native code
e.g. kernel-level memory operation
e.g. optimized sqrt in machine code
common intrinsics
String#equals
most Math methods
@HotSpotIntrinsticCandidate - extremely popular in that package
System.arraycopy - 4 assembler instructions without a loop
Unsafe.storeFence - calls directly CPU instruction
JVM implement the null check using virtual memory hardware
JVM arranges that page zero in its virtual address space is mapped to a page that
is unreadable + unwritable
since null is represented as zero, when Java code tries to dereference null this will try
to access a non-addressible page and will lead to the OS delivering a "segfault" signal to the JVM
JVM's segfault signal (SEGV) handler could trap this, figure out where the code was executing,
and create and throw an NPE on the stack of the appropriate thread
without this, every deref should be guarded
public static int getSize(Collection collection) {
if (collection == null) { // othervise checks like that should be added during compilation
throw new NullPointerException();
}
return collection.size(); // assembler: segmentation violation
// will crush JVM
}
deoptimizations
Questions
What is jit-notes?
mtumilowicz/jit-notes is a public repo on GitHub by mtumilowicz. JIT in details.
Is jit-notes open source?
It declares the GPL-3.0 license on GitHub.
Does jit-notes run on macOS, Windows or Linux?
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
How do I install jit-notes?
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Is jit-notes still maintained?
Its last change on GitHub was on 2021-02-14. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Is jit-notes safe to install?
Take My Repo cannot say: it does not audit code and has not run jit-notes. What is known comes from GitHub. It declares the GPL-3.0 license on GitHub. Its last change was on 2021-02-14. It has 8 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.