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

java as a platform
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Ola ¡Bini

computational ¡metalinguist ¡

  • la.bini@gmail.com

http://olabini.com/blog

Java ¡as ¡a ¡Platform

torsdag den 12 maj 2011

slide-2
SLIDE 2

From ¡Sweden ¡to ¡Chicago ¡through ¡ThoughtWorks Language ¡geek ¡at ¡ThoughtWorks JRuby ¡core ¡developer, ¡Ioke ¡and ¡Seph ¡creator Member ¡of ¡the ¡JSR ¡292 ¡EG

Your ¡host

torsdag den 12 maj 2011

slide-3
SLIDE 3

Platform

torsdag den 12 maj 2011

slide-4
SLIDE 4

What ¡you ¡get

torsdag den 12 maj 2011

slide-5
SLIDE 5

torsdag den 12 maj 2011

slide-6
SLIDE 6

torsdag den 12 maj 2011

slide-7
SLIDE 7

Code ¡loading

torsdag den 12 maj 2011

slide-8
SLIDE 8

Platform ¡ independence

torsdag den 12 maj 2011

slide-9
SLIDE 9

torsdag den 12 maj 2011

slide-10
SLIDE 10

JIT

torsdag den 12 maj 2011

slide-11
SLIDE 11

torsdag den 12 maj 2011

slide-12
SLIDE 12

Languages

torsdag den 12 maj 2011

slide-13
SLIDE 13

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

torsdag den 12 maj 2011

slide-14
SLIDE 14

Paradigms

torsdag den 12 maj 2011

slide-15
SLIDE 15

Object ¡Oriented

torsdag den 12 maj 2011

slide-16
SLIDE 16

Statically ¡typed

torsdag den 12 maj 2011

slide-17
SLIDE 17

Dynamically ¡typed

torsdag den 12 maj 2011

slide-18
SLIDE 18

Concatenative

torsdag den 12 maj 2011

slide-19
SLIDE 19

And ¡many ¡more...

torsdag den 12 maj 2011

slide-20
SLIDE 20

What’s ¡missing?

torsdag den 12 maj 2011

slide-21
SLIDE 21

torsdag den 12 maj 2011

slide-22
SLIDE 22

Light ¡code ¡loading

torsdag den 12 maj 2011

slide-23
SLIDE 23

Variable static ¡typing

torsdag den 12 maj 2011

slide-24
SLIDE 24

torsdag den 12 maj 2011

slide-25
SLIDE 25

torsdag den 12 maj 2011

slide-26
SLIDE 26

Value ¡objects

torsdag den 12 maj 2011

slide-27
SLIDE 27

JVM ¡Safepoint

torsdag den 12 maj 2011

slide-28
SLIDE 28

JVM ¡Library ¡Help

torsdag den 12 maj 2011

slide-29
SLIDE 29

Symbolic ¡freedom

torsdag den 12 maj 2011

slide-30
SLIDE 30

Interface ¡Injection

torsdag den 12 maj 2011

slide-31
SLIDE 31

Language ¡Specific ¡ Invocation

torsdag den 12 maj 2011

slide-32
SLIDE 32

The ¡DaVinci ¡ Machine

torsdag den 12 maj 2011

slide-33
SLIDE 33

JSR292

torsdag den 12 maj 2011

slide-34
SLIDE 34

Dynamic ¡ dispatch ¡today

torsdag den 12 maj 2011

slide-35
SLIDE 35

Some ¡machinery

torsdag den 12 maj 2011

slide-36
SLIDE 36

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

Class ¡Values

torsdag den 12 maj 2011

slide-37
SLIDE 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

slide-38
SLIDE 38

Method ¡Handles

torsdag den 12 maj 2011

slide-39
SLIDE 39

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

Combinators

torsdag den 12 maj 2011

slide-40
SLIDE 40

static ¡MethodHandle ¡guardWithTest(MethodHandle ¡test, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡MethodHandle ¡target, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡MethodHandle ¡fallback) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Easy ¡way ¡to ¡implement ¡Monomorphic ¡Inline ¡Cache Most ¡likely ¡thing ¡to ¡be ¡returned ¡from ¡InvokeDynamic

Guard ¡with ¡test

torsdag den 12 maj 2011

slide-41
SLIDE 41

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

SwitchPoint

torsdag den 12 maj 2011

slide-42
SLIDE 42

InvokeDynamic

torsdag den 12 maj 2011

slide-43
SLIDE 43

Call ¡site

torsdag den 12 maj 2011

slide-44
SLIDE 44

Bootstrap ¡Method

torsdag den 12 maj 2011

slide-45
SLIDE 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

slide-46
SLIDE 46

InvokeDynamic

torsdag den 12 maj 2011

slide-47
SLIDE 47

An ¡Example

torsdag den 12 maj 2011

slide-48
SLIDE 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

slide-49
SLIDE 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

slide-50
SLIDE 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

slide-51
SLIDE 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

slide-52
SLIDE 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

slide-53
SLIDE 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

slide-54
SLIDE 54

JSR292.next?

torsdag den 12 maj 2011

slide-55
SLIDE 55

Questions?

OLA BINI

http://olabini.com

  • bini@thoughtworks.com

@olabini

torsdag den 12 maj 2011