Open Source Java & Da Vinci VM Dalibor Topi Java F/OSS Ambassador Sun Microsystems http://robilad.livejournal.com Dalibor.Topic@Sun.com 2 Java SE 6 : Top Features · · · · · · · · · Web Service & Compiler APIs Scripting language support Updated database APIs Swing enhancements Monitoring and Management Pluggable Annotations Desktop deployment Integration with native security services Quality, compatibility and stability 3 Java SE 6u10 · Major update runtime and deployment features · Pre-FCS builds available for 12 months · Lighterweight, more nimble, better looking · Underpinning of upcoming Java FX 1.0 release 4 Java SE 6u10: Top Features · New Plug-In · Deployment Toolkit · Java Kernel · Nimbus Look and Feel · Java Quick Starter · Performance & Usability 5 Language Usage For Java is Up Evans Data Survey: Fall 2007 P e rc e n t o f T im e D e v e lo p in g in J a v a 65 60 55 50 45 40 35 30 25 20 15 10 5 0 Spring 2005 Fall 2005 Spring 2006 Fall 2006 Spring 2007 2008 (est'd) North America EMEA APAC 2008 JavaOneConference | java.sun.com/javaone 13 | SM Java is doing well · More than 6 million developers · On 90+% of Internet connected PCs · But there is a large, open-source affine ecosystem out there that Java isn't really part of ... · ... scripting languages 7 Scripting Languages Usage 2007-2008 North America 70 60 50 40 30 20 10 0 Java Script Perl PHP 2007 Python 2008 ActionScript Ruby Other Europe, Middle East and Africa 70 60 50 40 30 20 10 0 Java Script Perl PHP Python ActionScript Ruby Other 2007 2008 Asia and Pacific Rim 80 70 60 50 40 30 20 10 0 -10 Java Script Perl PHP Python ActionRuby Other 2007 2008 2008 JavaOneConference | java.sun.com/javaone 15 | SM Scripting on Java SE 6 Platform // create a ScriptEngineManager & grab an engine ScriptEngineManager m = new ScriptEngineManager(); ScriptEngine engine = m.getEngineByName("js"); // evaluate javascript directly.... jsEngine.eval("print('Hello, world!')"); // ...or from a script InputStream is = this.getClass().getResourceAsStream("/scripts/hello.js"); Reader reader = new InputStreamReader(is); engine.eval(reader); // ...even call functions and methods in a script engine.eval("function sayHello() {" + " println('Hello, world!');" + "}"); Invocable invocableEngine = (Invocable) jsEngine; invocableEngine.invokeFunction("sayHello"); 2008 JavaOneConference | java.sun.com/javaone 17 | SM Sleep Languages on the JVMTM: Present Bex Script Zigzag WebL JESS Simkin Nice Funnel Tea Jickle Lisp iScript Modula-2 Correlate CAL Drools JavaScript Luck Pascal Hojo Icon Groovy Tcl Simkin Prolog Basic JudoScript Eiffel Mini v-language PLAN Scala Rexx Tiger E Logo Ada Processing JavaFX Script Anvil Yassl Smalltalk Tiger G Dawn LLP TermWare Forth Yoix Clojure JHCR Scheme foo FScript Oberon JRuby Phobos Sather BeanShell Jython C# PHP Pnuts SALSA ObjectScript Piccola 2008 JavaOneConference | SM java.sun.com/javaone 16 | Java SE, JavaFX Roadmap Rich Clients Multiple Languages rity Modula i rm Perfo ance and Scalabil ty JavaFX SDK Preview JavaFX Desktop 2008 2009 JavaFX Mobile 2010 JDK 6 Update 10 'Consumer JRE' JDK 6 Update 5p 'Performance JRE' JDK 6 Update 7 JDK 7 Preview JDK 7 Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 12 Why Now? Maturity ·Java is everywhere ·F/OSS spreading worldwide ·Participation drives progress 13 Adoption Innovation Why GNU/Linux? Values Freedom as a core value Free Software above and below the JVM Increasing demand for Java integration 14 Stack Demand Who Wins? Developers ·New markets, freedoms ·More innovation, less risk ·More opportunity, mindshare 15 Customers Sun License · GPL v2 · No proprietary forks · Popular & trusted license · Compatible with GNU/Linux · Fostering adoption · + Classpath Exception · Programs can have any license · Improvements remain in the community · FSFs license for GNU Classpath 16 17 18 Activity ­ Groups and Projects · New Groups > Porters > Conformance · Some of the new Projects Multi-language VM JDK 6 Annotations on types Modules Zero assembler interpreter backend for Hotspot > BSD port to FreeBSD, OpenBSD, Darwin > > > > > 19 Multi-language VM: Opportunities · VM-based systems have become normal · CPU cycles are cheap enough for JIT, GC, RTT, ... · many Java programmers, tools, systems · much of the ecosystem is now opensource 20 Multi-language VM: The JVM Rocks · flexible online code loading · fast garbage collection · reflective access to classes & objects · lots of ancillary tools (JMX, JVMTI, dtrace) · lots of good libraries & a nice language · optimizing JIT, object- and library-aware · clever performance techniques: > type inference, customization, profiling, deoptimization, fast/slow paths, etc., etc. 21 Dynamic Language Runtime Needs · Dynamic invocation according to own invocation rules · Very late binding (runtime linking) · Automatic storage management (GC) · Environmental queries (reflection, ...) · Exotic primitives (tailcall, bignums, ...) · Code management integrated with execution · Helpful runtime support libraries (RE, ...) · JIT/AOT compiler that understands it all 22 Multi-language VM: Issues · VMs can do much more than C/C++, > but not quite enough for emerging languages > historically, the JVM was for Java only... > (historically the x86 was for C and Pascal...) · Language implementors are trying to reuse VMs > Near-misses are experienced as "pain points" 23 Multi-language VM: Requirements · Dynamic invocation according to own invocation rules · Very late binding (runtime linking) · Automatic storage management (GC) · Environmental queries (reflection, ...) · Exotic primitives (tailcall, bignums, ...) · Code management integrated with execution · Helpful runtime support libraries (RE, ...) · A compiler that understands it all 24 Multi-language VM: What's missing · Dynamic invocation · And always, higher performance 25 Multi-language VM: What's missing · Dynamic invocation · Lightweight method objects · Lightweight bytecode loading · Continuations and stack introspection · Tail calls and tail recursion · Tuples and value-oriented types · Immediate wrapper types · Symbolic freedom (non-Java names) · And always, higher performance 26 Da Vinci VM To The Rescue · Evolutionary adaptation of the JVM · Open-ended experimentation on Hotspot > wild ideas are considered, but must prove useful > while incubating, features are disabled by default · Eventual convergence on standards · Extension of the standard JVM architecture > deliberate, measured, careful extension 27 Da Vinci VM Mission Statement · Prototype JVM extensions to run non-Java languages efficiently · First-class architectural support (not hacks) · Complete the existing architecture with general purpose extensions · New languages to co-exist gracefully with Java in the JVM 28 Dynamic Invocation JVM already has invoke* bytecodes Invokespecial/static/virtual/interface But their semantics are tied to Java Dynamic languages usually have wildly different invocation semantics · Different type systems, binding rules, ... · Can't add a new dynamic invocation bytecode without breaking verification · The feature needs to be minimally invasive · · · · 29 Dynamic Invocation · · · · JSR 292 Invokedynamic specification early draft Non-Java call site in bytecode Language specific handler > Installs direct (non-reflective) methods > Determines call linkage at runtime > Works in a reflective style · Type-sensitive target method selection · Stateful: updated or revoked over time 30 Invokedynamic Pseudo Code // Running example of invokedynamic call site class MyCaller { private static final CallSite site1 = (...); // Managed by JVM private static final MethodHandle bootstrapMethod = (...); Object myMethod(Object x, Object y, int z) { // x . invokedynamic["alpha",(Object,int)Object] (y, z) MethodHandle method1 = site1.target; if (method1 == null) return bootstrapMethod.invoke(site1, x, y, z); return method1.invoke(x, y, z); } } 31 Method Handles · Method Handle = lightweight reference to a method · Caller invokes without knowing method's name, etc. · Call runs nearly at the speed of a Java call · Required to glue together dynamic call sites 32 Method Handle In Practice · A call to a method handle directly calls the wrapped method · Method handles can invoke both static and non-static methods · API for binding method handle to a receiver, creating a bound handle · API to adapt a method handle to include changes in argument and return types · Interface java.dyn.MethodHandle · Class java.dyn.MethodType 33 Invokedynamic at bytecode lovel · Marker interface java.dyn.Dynamic · Invokeinterface semantics changed to recognize invokeinterface calls on Dynamic interface as triggerring special processing · Each call is associated with hidden variable for the call site: target method · It encodes the linkage state · Managed by JVM, not visible to code · Starts out as unlnked, changes as we run 34 Invokedynamic at bytecode lovel · So, invokedynamic works much like a normal method handle invocation site · Three differences: > Called method comes form the linkage state of the call site (target method) > Symbolic name can be any constant string > There is an unlinked state which causes special processing of call state > The JVM may have more opportunities to optimize a stable linkage state 35 Invokedynamic at bytecode lovel · Target method managed by the JVM · If no target method is set, the bootstrap method of the class containing the invokedynamic call is called · The bootstrap method receives the arguments to the function, the StaticContext of the execution, and the CallSite's wrapper object · The bootstrap method deals with the call · It can handle linkage, type reification, errors and (re)set method handle 36 Participation · DaVinci VM is developed as Open Source software within OpenJDK · http://openjdk.java.net/projects/mlvm/ · Read the JSR 292 early draft · Research/Hack on the subprojects · http://openjdk.java.net/projects/mlvm/subprojects.html · Language Implementors mailing list · http://groups.google.com/group/jvm-languages 37 Future Ideas · Anonymous classes > Allow classes without explicit, static names > Allow the VM to patch classes in place > Faster class (un)loading · Performance work > Faster reflection > Escape analysis · Interface injection > Ability to add interfaces to class at runtime · Meta-Object Protocol > Allow one language to call another one 38 Dynamic Languages On JVM Summit · · · · · · · · · Summit in October 2008 in California http://wiki.jvmlangsummit.com/ All popular JVMs present Many JVM language authors And academics, too Lots of potential, will for collaboration Great feedback on existing work Lots of ideas for improvements May do it again next year 39 Thank you for coming! http://OpenJDK.java.net dalibor.topic@sun.com irc://irc.oftc.net/#openjdk