Polyglot language interoperation

From WikiEducator
Jump to: navigation, search


Performance Anti-Patterns
Convenor: Ben Evans
Participants:
  • Ben Evans
  • Sven Reimers
  • Michael Hunger
  • Elisabeth Kasimir
  • Alexander Kasimir
  • Kon Soulianidis
  • Mike Nielson
  • John Kostaras
  • Marc Hoffmann
  • Andriy
  • Phil
Summary:

Fact: Interopability is hard

Why? Source is compiled to class (bytecode)

clojure one class per method fn: -> fn$1134

What is hard?

  • Everything is an object
  • String(s) -> Ruby Strings are mutable
  • Primitive Types
  • Method Dispatch Semantics
  • Scopes + Scoping
  • Lambdas + Closures
  • Multi-Return
  • Annotations, (Generics,) Metadata
  • Pass by reference / pass by value
  • Inheritance Semantics

Just looking at method dispatch Java Dispatch...

  • Static
  • Special
  • Interface
  • Virtual

Virtual Method Call:

1. Mark 2. Pointer to class having list of pointers to methods (v-table), get the offset walk the inheritance

Other language:

$obj->$method();

Starting with reflection you end up with not typesafe method description.

Java 7 introduces a type safe way:

MethodType.methodType(retType, paramTypes)

MethodHandles: Lookup -findVirtual(MethodType...) -getStatic -...

results in MethodHandle mh

mh.invoke(...);

=> unreflection is possible...

Using MethodHandles can improve the performance:


MH1->MH2->MH3 V1 -> V2 -> V3 -> (makes inling by hotspot possible)


Covariant and Contravariant Disptach -> List<Pet> lp; List<Cats> lc; : is lc a lp ???

Inheritance: Ruby: Everything is an IRubyObject (The IRubyObject Approach)

myObj = (IRubyObject) registry.get(...)

Scala: has Any and AnyRef, no common super type to cast to

What you really need:

  • Registry
    • foreign objects
    • method linkages
  • Type Biconversion

Biconversion: java.lang.interop

  • Primitives
  • Strings
  • Function types (i.e. lambda)

Project DYNALINK (Attila Szegedi)

Recommendations:

(as above)