Virtual Machines
JITs
GCs
I’m not an expert, I’m just a JS developer who loves to know about the technology that runs his favorite language
And so should you!
I’m trying to give links/citations where possible
Is the worlds most compiled language
(even though you don’t compile it yourself)
The browser compiles it over and over again,
every single time you load a web site.
Compilation needs to be insanely fast!
Stage 1: full-codegen
↓
Stage 2: Crankshaft
http://wingolog.org/archives/2013/04/18/inside-full-codegen-v8s-baseline-compiler
Stage 0: Interpreter
↓
Stage 2: TraceMonkey
Stage 0: Interpreter
↓
Stage 1: JägerMonkey
↓
Stage 2: TraceMonkey
Stage 0: Interpreter
↓
Stage 1: JägerMonkey + Type Inference
↓
Stage 2: TraceMonkey
Stage 0: Interpreter
↓
Stage 1: JägerMonkey + Type Inference
↓
Stage 2: IonMonkey
Stage 0: Interpreter
↓
Stage 1: Baseline
↓
Stage 2: IonMonkey
Stage 1 generates native code, but most operations still fall back to generic C++ methods
ICs are type specialized snippets that are chained in front of the generic fallback
bool
ICUnaryArith_Double::Compiler::generateStubCode(MacroAssembler &masm)
{
Label failure;
masm.ensureDouble(R0, FloatReg0, &failure);
JS_ASSERT(op == JSOP_NEG);
masm.negateDouble(FloatReg0);
masm.boxDouble(FloatReg0, R0);
EmitReturnFromIC(masm);
// Failure case - jump to next stub
masm.bind(&failure);
EmitStubGuardFailure(masm);
return true;
}
http://mxr.mozilla.org/mozilla-central/source/js/src/jit/BaselineIC.cpp#3087
Something is rotten in the state of Denmark
and Hamlet is taking out the trash!
You allocate *a lot* of objects and produce a lot of trash
“new”, object literals, …
The optimizing (stage 2) JITs can optimize most of it away
Stage 1 JITs will sometimes allocate for every single arithmatic
expression.
Taking out the trash costs, a lot.