Invoke Dynamic
Upcoming SlideShare
Loading in...5
×
 

Invoke Dynamic

on

  • 3,051 Views

 

Statistics

Views

Total Views
3,051
Views on SlideShare
2,915
Embed Views
136

Actions

Likes
2
Downloads
35
Comments
0

5 Einbettungen 136

http://jujo00obo2o234ungd3t8qjfcjrs3o6k-a-sites-opensocial.googleusercontent.com 119
https://jujo00obo2o234ungd3t8qjfcjrs3o6k-a-sites-opensocial.googleusercontent.com 10
http://jug.lv 3
http://jugpreview.tumblr.com 2
http://www.jug.lv 2

Zugänglichkeit

Kategorien

Details hochladen

Uploaded via as Adobe PDF

Benutzerrechte

© Alle Rechte vorbehalten

Report content

Als unangemessen gemeldet Als unangemessen melden
Als unangemessen melden

Wählen Sie Ihren Grund, warum Sie diese Präsentation als unangemessen melden.

Löschen
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Ihre Nachricht erscheint hier
    Processing...
Kommentar posten
Kommentar bearbeiten

Invoke Dynamic Invoke Dynamic Presentation Transcript

  • InvokeDynamicJava 7 dynamically typed language support arkadi.shishlov@gmail.com
  • Statically typed languages Java Scala C# C C++ F# Haskel
  • Dynamic languagesGroovyClojureJavaScriptPerlPythonRubyPHP
  • Dynamic languageobject runtime alteration (open program code)metaobject protocolevalfunctional programming, closures, macros
  • Dynamically typed languagetype checking performed at runtimevariable does not have a typevalue is associated with a typeduck typing
  • The program must be compiledto bytecode to achieve Javalevel performance
  • Use casegroovy:000> f = { it + it }===> groovysh_evaluate$_run_closure1@dc737begroovy:000> f(1)===> 2groovy:000> f("qw")===> qwqwgroovy:000> [2, "qwe"].collect(f)===> [4, qweqwe]groovy:000>
  • collect (list, func) { foreach (list) push (result, func (it))}
  • The probleminvokevirtual some/class/Name.func(Ljava/lang/String)Z, objectref, arg1, arg2, ...invokespecialinvokestatic has similar calling conventioninvokeinterface
  • The solution Reflection is (relatively) slow There are others possibilities
  • Java 7 approach - JSR292invokedynamic (indy) boostrapFuncRef, NameLiteral(Lorg/jruby/runtime/builtin/IRubyObject) Lorg/jruby/runtime/builtin/IRubyObject, arg1, arg2, ...
  • java.lang.invoke.* MethodHandle CallSite ConstantCallSite MutableCallSite VolatileCallSite MethodType
  • public static CallSite bootstrap ( MethodHandles.Lookup lookup, String dynMethodName, MethodType dynMethodType) throws Throwable { MethodHandle handle = lookup.findStatic( SomeClosure.class, "func", MethodType.methodType( Integer.class, Object.class, Object.class)); if (!dynMethodType.equals(handle.type())) handle = handle.asType(dynMethodType); return new ConstantCallSite(handle);}
  • MutableCallSite.setTarget(MethodHandle newTarget)
  • AdvantagesfastJIT-tedinlinedsignature polymorphism, arguments adaptation
  • Work in ProgressJRuby - works, sort of; MirahRhino (JavaScript) - J.Rose experiment, V8 forperformance freaksGroovy - proposed for 1.9, no implJython (Python) - different priorities: PyPy, Cython,language features upgradeClojure - many features not applicable to IndyPHP.reboot
  • Learn morehttp://download.java.net/jdk7/docs/technotes/guides/vm/multiple-language-support.htmlJDK 7 JSR-292 java.lang.invoke.* APIJRuby source: src/org/jruby/compiler/impl/*.javahttp://code.google.com/p/jsr292-cookbook/http://mail.openjdk.java.net/pipermail/mlvm-dev/http://www.oracle.com/technetwork/issue-archive/2010/10-may/o30java-099612.htmlhttp://blog.headius.com/2008/09/first-taste-of-invokedynamic.html