Your SlideShare is downloading. ×
Invoke Dynamic
Nächste SlideShare
Wird geladen in ...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Invoke Dynamic

2,776
views

Published on

Published in: Technologie, Bildung

0 Kommentare
2 Gefällt mir
Statistiken
Notizen
  • Hinterlassen Sie den ersten Kommentar

Keine Downloads
Views
Gesamtviews
2,776
Bei Slideshare
0
Aus Einbettungen
0
Anzahl an Einbettungen
1
Aktionen
Geteilt
0
Downloads
35
Kommentare
0
Gefällt mir
2
Einbettungen 0
No embeds

Inhalte melden
Als unangemessen gemeldet Als unangemessen melden
Als unangemessen melden

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

Löschen
No notes for slide

Transcript

  • 1. InvokeDynamicJava 7 dynamically typed language support arkadi.shishlov@gmail.com
  • 2. Statically typed languages Java Scala C# C C++ F# Haskel
  • 3. Dynamic languagesGroovyClojureJavaScriptPerlPythonRubyPHP
  • 4. Dynamic languageobject runtime alteration (open program code)metaobject protocolevalfunctional programming, closures, macros
  • 5. Dynamically typed languagetype checking performed at runtimevariable does not have a typevalue is associated with a typeduck typing
  • 6. The program must be compiledto bytecode to achieve Javalevel performance
  • 7. 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>
  • 8. collect (list, func) { foreach (list) push (result, func (it))}
  • 9. The probleminvokevirtual some/class/Name.func(Ljava/lang/String)Z, objectref, arg1, arg2, ...invokespecialinvokestatic has similar calling conventioninvokeinterface
  • 10. The solution Reflection is (relatively) slow There are others possibilities
  • 11. Java 7 approach - JSR292invokedynamic (indy) boostrapFuncRef, NameLiteral(Lorg/jruby/runtime/builtin/IRubyObject) Lorg/jruby/runtime/builtin/IRubyObject, arg1, arg2, ...
  • 12. java.lang.invoke.* MethodHandle CallSite ConstantCallSite MutableCallSite VolatileCallSite MethodType
  • 13. 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);}
  • 14. MutableCallSite.setTarget(MethodHandle newTarget)
  • 15. AdvantagesfastJIT-tedinlinedsignature polymorphism, arguments adaptation
  • 16. 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
  • 17. 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

×