Skip to content

Commit

Permalink
Flip all literals to use indy.
Browse files Browse the repository at this point in the history
This commit modifies the JIT to use invokedynamic for lazy init
and caching of most literal values. This includes things like:

* Immediate values like numbers, symbols, true/false/nil
* Frozen strings
* Symbol procs
* Basically anything initialized once and cached in IR

The original logic for "non-indy" literals followed this pattern:

* Emit a small method body
* In that method body, check a static field
* If null, initialize the value and set the field
* Return the value

This mechanism has many down sides:

* Extra method body emitted for every literal
* Bytecode for initializing the value, only ever run once (and
  therefore never jitted by JVM)
* Field access plus null check every time, preventing folding of
  what should be a constant value
* Accompanying metaspace overhead and emitted code size from all
  of the above

By moving this logic to indy, we should see no worse init costs
for these values but get truly foldable constants. In addition,
because all literals of a given type will use the same indy call
site logic, that logic will JIT at the JVM level much sooner. We
should also see a reduction in metaspace by making the generated
class structure smaller and simpler.
  • Loading branch information
headius committed Sep 12, 2019
1 parent 31b50d7 commit a7484ba
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 385 deletions.
Expand Up @@ -364,9 +364,9 @@ public org.objectweb.asm.Label newLabel() {
*
* Stack required: none
*
* @param id raw id string for the symbol.
* @param bytes the ByteList for the symbol
*/
public abstract void pushSymbolProc(String id);
public abstract void pushSymbolProc(ByteList bytes);

/**
* Push the JRuby runtime on the stack.
Expand Down

0 comments on commit a7484ba

Please sign in to comment.