Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java 7: Fork/Join, Invokedynamic and the future

4,374 views

Published on

Presented at the NLJUG Java 7 launch event 7/7/2011

Published in: Technology, News & Politics
  • Be the first to comment

Java 7: Fork/Join, Invokedynamic and the future

  1. 1. Java
7
LaunchFork/Join
concurrency @Sander_Mak
  2. 2. What?Fork:Recursively
decomposelarge
task
into
subtasksJoin:Combine
results
ofrecursive
tasks 7/7/2011 Java
7
Launch
Event
  3. 3. Why? Mul3core
challenge 7/7/2011 Java
7
Launch
Event
  4. 4. How?Introducing:

java.uLl.concurrent.ForkJoinPool Worker 1• ‘ExecutorService
with
 Worker 2 runLme
tuning’• Recursive
algorithms Worker 3• Workstealing 7/7/2011 Java
7
Launch
Event
  5. 5. ...
MapReduce?Environment Single
JVM ClusterModel Recursive
forking Single
fork
stepScales
with Cores/CPUs NodesOpera3on Workstealing No
inter‐node
 communicaLon 7/7/2011 Java
7
Launch
Event
  6. 6. ExampleSony’s
been
hacked... Are
we
compromised...? 7/7/2011 Java
7
Launch
Event
  7. 7. Java
7
LaunchJSR‐292:
Invokedynamic @Sander_Mak
  8. 8. JVM
Languages Java 7/7/2011 Java
7
Launch
Event
  9. 9. JVM
Languages Groovy Clojure JRuby Java JavaFX Scala 7/7/2011 Java
7
Launch
Event
  10. 10. JVM
LanguagesjProlog Pizza MultiJava Fantom JLog Groovy Clojure MetaJ JRuby Java JavaFX Jaskell Rhino Scala JBasicAardappel Funnel Jacl Drools Jython 7/7/2011 Java
7
Launch
Event
  11. 11. JVM
Languages Hundreds of Languages 7/7/2011 Java
7
Launch
Event
  12. 12. JVM
Languages‘Language
ficLons’ JVM Exceptions Primitive types Objects Access control Garbage coll. Threading Memory model 7/7/2011 Java
7
Launch
Event
  13. 13. JVM
Languages‘Language
ficLons’ Java Enums Checked exc. JVM Generics Exceptions Exceptions Primitive types Primitive types Objects Objects Access control Access control Garbage coll. Garbage coll. Threading Threading. Memory model Memory model 7/7/2011 Java
7
Launch
Event
  14. 14. JVM
Languages JRuby‘Language
ficLons’ Open classes Dynamic typing Java Closures Enums Enums Checked exc. Checked exc. JVM Generics Generics Exceptions Exceptions Exceptions Primitive types Primitive types Primitive types Objects Objects Objects Access control Access control Access control Garbage coll. Garbage coll. Garbage coll. Threading Threading. Threading Memory model Memory model Memory model 7/7/2011 Java
7
Launch
Event
  15. 15. JVM
Languages JRuby‘Language
ficLons’ Open classes Dynamic typing Java Closures Enums Enums Checked exc. Checked exc. JVM Generics Generics Exceptions Exceptions Exceptions Primitive types Primitive types Primitive types Objects Objects Objects Access control Access control Access control Garbage coll. Garbage coll. Garbage coll. Threading Threading. Threading Memory model Memory model Memory model 7/7/2011 Java
7
Launch
Event
  16. 16. JVM
Languages Obviously
JVM
is
viable,
however:• Language
implementors
need
to
invent
 ‘creaLve’
compilaLon
schemes
for
every
 language• Performance
suffers
when
abstracLng
beyond
 Java
idioms How
to
improve? 7/7/2011 Java
7
Launch
Event
  17. 17. JSR‐292 Mission: “We are extending the JVM with first-class architectural support for languages other than Java, especially dynamic languages. This project will prototype a number of extensions to the JVM, so that it can run non-Java languages efficiently, with a performance level comparable to that of Java itself.” http://openjdk.java.net/projects/mlvm/ 7/7/2011 Java
7
Launch
Event
  18. 18. Compiling
dynamic
languages • JVM
pre]y
language‐friendly • ExcepLon:
method
calls – Signature
at
callsite
must
match
exactly TargetClass Name Method descriptor18: invokevirtual #5; //Method java/util/ArrayList.add:(Ljava/lang/Object;)Z – Dispatch
on
staLc
type
of
parameters
and
dynamic
 type
of
receiver – Method
must
exist
at
compile
Lme – Link
to
target
is
fixed,
no
relinking 7/7/2011 Java
7
Launch
Event
  19. 19. Compiling
dynamic
languages• Common
soluLons: - Don’t
compile,
interpret
(someLmes
unavoidable) - Introduce
generic
CallSite
abstracLon
which
dispatches
 method
calls - AOT
compilaLon
into
specialized
invoker
classes
 (suitable
for
core
methods) - JIT
bytecode
generaLon
of
small
stub
methods Either
way:
abundance
of
syntheLc
types
and
 bytecode
hard
to
opLmize
for
JVM 7/7/2011 Java
7
Launch
Event
  20. 20. Invokedynamic New
bytecode,
last
piece
of
JSR‐292
puzzle: Name Method descriptor18: invokedynamic #5; //NameAndType addInts:(II)I • InvocaLon
without
reference
to
actual
method
 descriptor • Instead,
symbolic
name
and
type • No
receiver:
all
arguments
are
equal What
is
the
target? 7/7/2011 Java
7
Launch
Event
  21. 21. Method
handles• Lightweight,
safe
method
pointers• Like
java.lang.reflect.Method,
but: – No
argument
boxing/unboxing – Access
checks
only
at
creaLon
Lme – Leaner,
can
be
as
fast
as
direct
call – No
wrapping
of
excepLons 7/7/2011 Java
7
Launch
Event
  22. 22. Method
handles• Lightweight,
safe
method
pointers• Like
java.lang.reflect.Method,
but: – No
argument
boxing/unboxing – Access
checks
only
at
creaLon
Lme – Leaner,
can
be
as
fast
as
direct
call – No
wrapping
of
excepLons Java
7 MethodHandle mh = MethodHandles.lookup().findVirtual(String.class, “substring”, typeDescriptor); String java = (String) mh.invokeExact(“jjava”, 1); 7/7/2011 Java
7
Launch
Event
  23. 23. Invokedynamic
‐
bootstrap• Invokedynamic
triggers
bootstrap• Ader
installing
target,
invokedynamic
invokes
 MH
directly DynamicInvokerClass ImplementationClassaload_1;invokedyn. meth:Type; implementation(Type) {return; result = .. return result }bootstrap( .. ) { ..lookup.. return CallSite} 7/7/2011 Java
7
Launch
Event
  24. 24. Invokedynamic
‐
bootstrap• Invokedynamic
triggers
bootstrap• Ader
installing
target,
invokedynamic
invokes
 MH
directly DynamicInvokerClass ImplementationClassaload_1;invokedyn. meth:Type; implementation(Type) {return; result = .. return result }bootstrap( .. ) { ..lookup.. return CallSite} 7/7/2011 Java
7
Launch
Event
  25. 25. Invokedynamic
‐
bootstrap• Invokedynamic
triggers
bootstrap• Ader
installing
target,
invokedynamic
invokes
 MH
directly DynamicInvokerClass ImplementationClassaload_1;invokedyn. meth:Type; implementation(Type) {return; result = .. return result }bootstrap( .. ) { ..lookup.. return CallSite} 7/7/2011 Java
7
Launch
Event
  26. 26. Invokedynamic
‐
bootstrap• Invokedynamic
triggers
bootstrap• Ader
installing
target,
invokedynamic
invokes
 MH
directly DynamicInvokerClass ImplementationClassaload_1;invokedyn. meth:Type; implementation(Type) {return; result = .. return result }bootstrap( .. ) { ..lookup.. MH
can
be
guarded
 return CallSite with
test,
adapt
types,
} etc. 7/7/2011 Java
7
Launch
Event
  27. 27. Invokedynamic
‐
bootstrap• Invokedynamic
triggers
bootstrap• Ader
installing
target,
invokedynamic
invokes
 MH
directly DynamicInvokerClass ImplementationClassaload_1;invokedyn. meth:Type; Method implementation(Type) {return; Handle(s) result = .. return result }bootstrap( .. ) { ..lookup.. return CallSite} 7/7/2011 Java
7
Launch
Event
  28. 28. Invokedynamic• Invokedynamic
+
bootstrap
method
allow
 language
to
up‐call
from
VM
for
linking/ dispatching.Not
impossible
before,
but
hard
and
slow.
JVM
now
 fully
opLmizes
dynamic
calls. 7/7/2011 Java
7
Launch
Event
  29. 29. Wrap‐up• JSR‐292
invokedynamic
features: – Let’s
language
implementors
avoid
tricks – Level
the
playing
ground,
speedwise – Allow
exisLng
VM
opLmizaLons
to
be
applied
to
 new
paradigms• JRuby,
Groovy
acLvely
working
on
JSR‐292
 support• For
example,
JRuby
can
cut
80%
of
linking/ calling
code
in
runLme 7/7/2011 Java
7
Launch
Event
  30. 30. Java
7
Launch Beyond
Java
7 @Sander_Mak
  31. 31. Ader
JDK7
 7/7/2011 Java
7
Launch
Event
  32. 32. JDK8:
Coin
conLnued Java
7List<Integer> piDigits = Collections.unmodifiableList(Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9 )); Java
8// List literal:List<Integer> piDigits = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9];Integer first = piDigits[0];// Map literal:Map<Integer, String> platonicSolids = { 4 : "tetrahedron", 6 : "cube", 8 : "octahedron", 12 : "dodecahedron", 20 : "icosahedron"}; 7/7/2011 Java
7
Launch
Event
  33. 33. JDK8:
Project
Lambda• Add
first‐class
funcLons• Single
Abstract
Method
types• Solve
interface
evoluLon
with

‘defender
 methods’• Paves
way
for
parallel
collecLons Java
8// Lambda expressionList<Integer> list = [1,2,3];list.forEach(#{ e -> e * 2; });// Reference existing methodsPerson[] people = ...Arrays.sort(people, #Person.compareByAge); 7/7/2011 Java
7
Launch
Event
  34. 34. JDK8:
ModularityJSR‐294
‘Project
Jigsaw’,
goals:• Modular
JDK - SE
Core - Packages:
Swing,
CORBA,
XML,
etc.• Modular
and
versioned
applicaLons• Integrate
with
plamorm
dependency
 management 7/7/2011 Java
7
Launch
Event
  35. 35. JDK8 Available
Fall/Winter
of See
you
@
next
launch
event? 7/7/2011 Java
7
Launch
Event

×