Skip to content

Instantly share code, notes, and snippets.

@xushijie
Created December 30, 2013 16:34
Show Gist options
  • Save xushijie/8184377 to your computer and use it in GitHub Desktop.
Save xushijie/8184377 to your computer and use it in GitHub Desktop.
Bytecodes meet Combinators: invokedynamic on the JVM(VMIL 09)
The author from SUN provides a general introduction of JSR292(invokedynamic introduction):
A dynamic compiler can traverse both representations simultaneously, producing optimized machine code which is the seamless union of both kinds of input. As a final twist, the user-defined linkage of a call site may change, allowing the code to adapt as the application evolves over time.
Some of hints are:
1, Operand types are collected at message sends and other opportune points, and are captured in inline caches or summarized
in a type profile. This information is local to each instruction.
2. Instructions are split by trace splitting or inlining, producing refined caches or profiles. The splits can be chosen so that the increased locality across different traces of the same original code is likely to exhibit distinct type statistics.
3. Operand types are predicted, based on statistics, a prioriex pectations, local inference, global analysis, or all of the above.
4. Speculative optimizations are placed on a fast path protected by aguard predicate testing a speculated condition. Each fast
path is joined by a slow path which handles guard failures.
5.Slow paths may execute more general code or branch to another execution mode, such as an interpreter. They may also trigger a discard of the current optimized code, queue it for future re-optimization, or patch the code of the fast path.
6. If the slow path does not merge with the fast path’s successors, the fast path guard dominates them, allowing speculative type
predictions to flow forward in the control flow graph.
7. A runtime dispatch can be speculatively resolved to a method,which then may be called directly, after a simple type guard.
The guard is usually a pointer comparison with a predictable branch. This tactic strength-reduces complex dispatch logic
such as a virtual table lookup or method table search.
8. Speculatively dispatched methods can be inlined, and the inlined code can be customized to all relevant locally predicted
operand types. Sometimes an out-of-line call is preferable.
9. If a dynamic compiler runs after type information is collected,it uses this type information to guide the previous steps.
@xushijie
Copy link
Author

inline target method(monmorphic) VS inline method handle graph (megamutable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment