2013/11/13

Devoxx 2013 - Lambda: A Peek Under the Hood

Brian Goetz
lambda expression
  • "anonymous method"
  • type inference compiler
  • capture values from context
why lambdas for java
  • path to multicore support in libraries
  • library developers
  • competition other languages
  • inner classes: clunky
  • @runtime support
typing of lambda expressions
  • function types? -> VM / bytecode issues -> too complex
  • functional interfaces:
    • single method interfaces (cfr Runnable, Comparator)
    • compiler identifies functional interface
    • compiler infers lambda
      representation
  • inner classes? -> performance issues, error-prone, -> "obvious but wrong"
  • MethodHandle in Java7 (tool for compiler writers) -> performance issues, conflates binary representation with impl. -> wrong
  • invokedynamic
    • lets some language logic determine call logic
    • performant impl. in jvm
lambda & invokedynamic
  • code generation strategy (metafactory)
    • dynamic inner classes (=current Java 8 startegy)
    • wrapper class per interface
    • dynamic proxies (or MethodHandleProxy
  • vm-private APIs
    • build object from scratch
  • lazy evaluation
    • non-capturing lambda's: create single instance
    • defer initialization cost to first use
    • VM optimizes call
  • faster than inner classes
  • usable by other languages
  • serialization support: SerializeLambda
  • future VM optimizations
    • escape analysis

No comments: