java as a platform
play

Java as a Platform Ola Bini computational metalinguist - PowerPoint PPT Presentation

Java as a Platform Ola Bini computational metalinguist ola.bini@gmail.com http://olabini.com/blog torsdag den 12 maj 2011 Your host From Sweden to Chicago through ThoughtWorks Language


  1. Java ¡as ¡a ¡Platform Ola ¡Bini computational ¡metalinguist ¡ ola.bini@gmail.com http://olabini.com/blog torsdag den 12 maj 2011

  2. Your ¡host From ¡Sweden ¡to ¡Chicago ¡through ¡ThoughtWorks Language ¡geek ¡at ¡ThoughtWorks JRuby ¡core ¡developer, ¡Ioke ¡and ¡Seph ¡creator Member ¡of ¡the ¡JSR ¡292 ¡EG torsdag den 12 maj 2011

  3. Platform torsdag den 12 maj 2011

  4. What ¡you ¡get torsdag den 12 maj 2011

  5. torsdag den 12 maj 2011

  6. torsdag den 12 maj 2011

  7. Code ¡loading torsdag den 12 maj 2011

  8. Platform ¡ independence torsdag den 12 maj 2011

  9. torsdag den 12 maj 2011

  10. JIT torsdag den 12 maj 2011

  11. torsdag den 12 maj 2011

  12. Languages torsdag den 12 maj 2011

  13. Aardappel Gosu JudoScript Scala ABCL Groovy Jython SISC AJLogo Hecl Kawa Sixx Anvil Hojo Lili Skij BDC Scheme HotScheme Lisp Sleep BeanShell HotTEA LL SmallWorld Bex Script Ioke Mapyrus StarLogo Bigloo iScript MetaJ Talks2 Bistro Jacl Mini TermWare CAL Jaja NetLogo Thorn Ceylon Janino Nice tuProlog CKI Prolog Jatha Obol Turtle Tracks Clojure javalog PERCobol uts COCOA JBasic PLAN v-language CONVERT Jickle Pnuts W4F Correlate JLog PS3i webLISP Demeter/Java JMatch Quercus WLShell dSelf Join Java Resin XProlog Fan JoyJ Rhino Yassl FScript JRuby rLogo Ync/Javascript Funnel JScheme Sather Yoix torsdag den 12 maj 2011

  14. Paradigms torsdag den 12 maj 2011

  15. Object ¡Oriented torsdag den 12 maj 2011

  16. Statically ¡typed torsdag den 12 maj 2011

  17. Dynamically ¡typed torsdag den 12 maj 2011

  18. Concatenative torsdag den 12 maj 2011

  19. And ¡many ¡more... torsdag den 12 maj 2011

  20. What’s ¡missing? torsdag den 12 maj 2011

  21. torsdag den 12 maj 2011

  22. Light ¡code ¡loading torsdag den 12 maj 2011

  23. Variable static ¡typing torsdag den 12 maj 2011

  24. torsdag den 12 maj 2011

  25. torsdag den 12 maj 2011

  26. Value ¡objects torsdag den 12 maj 2011

  27. JVM ¡Safepoint torsdag den 12 maj 2011

  28. JVM ¡Library ¡Help torsdag den 12 maj 2011

  29. Symbolic ¡freedom torsdag den 12 maj 2011

  30. Interface ¡Injection torsdag den 12 maj 2011

  31. Language ¡Specific ¡ Invocation torsdag den 12 maj 2011

  32. The ¡DaVinci ¡ Machine torsdag den 12 maj 2011

  33. JSR292 torsdag den 12 maj 2011

  34. Dynamic ¡ dispatch ¡today torsdag den 12 maj 2011

  35. Some ¡machinery torsdag den 12 maj 2011

  36. Class ¡Values Analog ¡to ¡ThreadLocal Allows ¡association ¡of ¡classes ¡to ¡values Values ¡are ¡computed ¡lazily Installation ¡of ¡new ¡values ¡happen ¡atomically It ¡works ¡on ¡any ¡type, ¡including ¡int.class ¡or ¡void.class You ¡can ¡remove ¡Class ¡Values ¡for ¡a ¡specific ¡type ¡too torsdag den 12 maj 2011

  37. import java.lang.ClassValue; public class ClassValueTest { private final static ClassValue<MethodTable> methods = new ClassValue<MethodTable>() { public MethodTable computeValue(Class<?> type) { return MethodTable.newTableFor(type); } }; public static void main(String[] args) { MethodTable intMethods = methods.get(int.class); MethodTable stringMethods = methods.get(String.class); // Do something extremely cool here } } torsdag den 12 maj 2011

  38. Method ¡Handles torsdag den 12 maj 2011

  39. Combinators Collect ¡arguments Spread ¡arguments Binding ¡to ¡a ¡specific ¡object Convert ¡a ¡MethodHandle ¡to ¡an ¡instance ¡of ¡a ¡SAM Convert ¡arguments Filter ¡arguments ¡and ¡return ¡values Fold ¡arguments Catch ¡exceptions Permute ¡arguments torsdag den 12 maj 2011

  40. Guard ¡with ¡test static ¡MethodHandle ¡guardWithTest(MethodHandle ¡test, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡MethodHandle ¡target, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡MethodHandle ¡fallback) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Easy ¡way ¡to ¡implement ¡Monomorphic ¡Inline ¡Cache Most ¡likely ¡thing ¡to ¡be ¡returned ¡from ¡InvokeDynamic torsdag den 12 maj 2011

  41. SwitchPoint MethodHandle ¡guardWithTest(MH ¡target, ¡MH ¡fallback) static ¡void ¡invalidateAll(SwitchPoint[] ¡switchPoints) Makes ¡it ¡possible ¡to ¡publish ¡a ¡one ¡time ¡state ¡transition It ¡begins ¡in ¡a ¡valid ¡state Can ¡at ¡any ¡point ¡become ¡invalid Invalidation ¡is ¡global, ¡immediate ¡and ¡permanent torsdag den 12 maj 2011

  42. InvokeDynamic torsdag den 12 maj 2011

  43. Call ¡site torsdag den 12 maj 2011

  44. Bootstrap ¡Method torsdag den 12 maj 2011

  45. public static CallSite bootstrapOne( MethodHandles.Lookup callerClassLookup, String methodName, MethodType typeDescriptor, String staticArg1, String staticArg2) { return new ConstantCallSite(someMethodHandle); } torsdag den 12 maj 2011

  46. InvokeDynamic torsdag den 12 maj 2011

  47. An ¡Example torsdag den 12 maj 2011

  48. SephCallSite.java public class SephCallSite extends MutableCallSite { private enum Morphicity { NILADIC, MONOMORPHIC, POLYMORPHIC, MEGAMORPHIC } int numberOfGuards = 0; Morphicity morphicity = Morphicity.NILADIC; public SephCallSite(MethodType type) { super(type); } } torsdag den 12 maj 2011

  49. AbstractionCompiler.java String bootstrapName = "basicSephBootstrap"; boolean fullPumping = false; if(first) { if(current == last) { bootstrapName = "noReceiverTailCallSephBootstrap"; fullPumping = true; } else { bootstrapName = "noReceiverSephBootstrap"; fullPumping = false; } } else if(current == last) { bootstrapName = "tailCallSephBootstrap"; fullPumping = true; } ma.dynamicCall(encode(current.name()), sigFor(arity), bootstrapNamed(bootstrapName + possibleIntrinsic)); torsdag den 12 maj 2011

  50. Bootstrap.java private static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type, String bootstrapType) { SephCallSite site = new SephCallSite(type); MethodType fallbackType = type.insertParameterTypes(0, SephCallSite.class, String.class); MethodHandle fallback = MethodHandles.insertArguments( findStatic(Bootstrap.class, bootstrapType, fallbackType), 0, site, decode(name)); site.setTarget(fallback); return site; } public static CallSite basicSephBootstrap(MethodHandles.Lookup lookup, String name, MethodType type) { return bootstrap(lookup, name, type, "fallback"); } torsdag den 12 maj 2011

  51. Bootstrap.java ¡(continued) public static SephObject fallback(SephCallSite site, String name, SephObject receiver, SThread thread, LexicalScope scope, IPersistentList args) { SephObject value = receiver.get(name); if(null == value) { throw new RuntimeException(" *** couldn't find: " + name + " on " + receiver); } if(value.isActivatable()) { site.installActivatableEntry(receiver, null, value, -1); return value.activateWith(receiver, thread, scope, args); } else { site.installConstantEntry(receiver, null, value, -1); } return value; } torsdag den 12 maj 2011

  52. Bootstrap.java ¡(continued) public static SephObject initialSetup_intrinsic_if(SephCallSite site, MethodHandle slow, SephObject receiver, SThread thread, LexicalScope scope, MethodHandle test, MethodHandle then, MethodHandle _else) throws Throwable { MethodHandle guarded = thread.runtime.INTRINSIC_IF_SP.guardWithTest( INTRINSIC_IF_MH, replaceCompletely3(slow, site)); site.setTarget(guarded); return (SephObject)guarded.invokeExact(receiver, thread, scope, test, then, _else); } torsdag den 12 maj 2011

  53. Runtime.java public final SwitchPoint INTRINSIC_IF_SP = new SwitchPoint(); public static void empty() {} public static void invalidate(SwitchPoint sp) { SwitchPoint.invalidateAll(new SwitchPoint[] {sp}); } public final MethodHandle INVALIDATE_IF = INTRINSIC_IF_SP.guardWithTest( INVALIDATE_MH.bindTo(INTRINSIC_IF_SP), EMPTY_MH); public void checkIntrinsicAssignment(String name) { name = name.intern(); try { if(name == "true") { INVALIDATE_TRUE.invokeExact(); } else if(name == "if") { INVALIDATE_IF.invokeExact(); } } catch(Throwable e) {} } torsdag den 12 maj 2011

  54. JSR292.next? torsdag den 12 maj 2011

  55. Questions? O LA B INI @olabini http://olabini.com obini@thoughtworks.com torsdag den 12 maj 2011

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend