13

Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute
Page 2: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Where*far*art*thou…()*L>*Lambda*Coherence(SIG,(London(

Harvey*Raja*Consul@ng*Member*Technical*Staff*Coherence*July,*2015*

Page 3: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Safe*Harbor*Statement*The*following*is*intended*to*outline*our*general*product*direc@on.*It*is*intended*for*informa@on*purposes*only,*and*may*not*be*incorporated*into*any*contract.*It*is*not*a*commitment*to*deliver*any*material,*code,*or*func@onality,*and*should*not*be*relied*upon*in*making*purchasing*decisions.*The*development,*release,*and*@ming*of*any*features*or*func@onality*described*for*Oracle’s*products*remains*at*the*sole*discre@on*of*Oracle.*

3*

Page 4: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Persistence*

Java*8*

Lambdas*

Infiltra@ng*Lambdas*

Streams*

Con@nuous*Demo…*

1(

2(

3(

4(

5(

Page 5: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Java*8*

• Released*03/2014!**•  Lambdas*•  Streams*•  Improvements*to*G1*• Default*methods*• Date*/*Time*improvements*• Nashorn*

Page 6: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*

•  Introduce*func@ons*as*a*first*class*ci@zen*to*the*language*•  Facilitates*func@onal*programming*constructs*• Any*interface*or*class*with*a*Single*Abstract*Method*can*be*defined*as*a*Lambda*•  Last*expression*is*the*return*argument*(nonLvoid*methods)*•  Surrounding*arguments*can*be*captured*• A*reference*to*a*method*(including*constructors)*can*be*captured*as*a*Lambda*

Page 7: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*

Page 8: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*

Page 9: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*–*under*the*hood*

• Compiler*converts*lambda*expression*into*a*number*of*parts:**

Capturing*Class*

lambda$methodWithLambda$0xFAE

methodWithLambda:

invokedynamic 0

COMPILE*TIME* RUN*TIME*

LambdaMetaFactory.altMetaFactory

BootstrapMethod: 0 - LambdaMetaFactory

Generated*Lambda*Class*

*Implements*Interface*

Page 10: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*–*under*the*hood*

•  InvokeDynamic*is*beau@ful*– Introduces*the*no@on*of*linkage*@me*– Allows*for*different*types*of*call*sites*to*be*returned*allowing*the*JVM*to*op@mize*for*ConstantCallSites*

•  LambdaMetaFactory*dynamically*generates*a*class*implemen@ng*the*SAM*•  SAM*implementa@on*will*call*generated*synthe@c*method*on*capturing*class*•  The*class*is*defined*‘anonymously’*

*

Page 11: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Lambdas*–*under*the*hood*

•  Lambdas*can*be*serialized*but*must*implement*Serializable*• A*Serializable*lambda*adds*behaviour*to*the*class:*– writeReplace/readResolve*– SerializedLambda*

• Metadata*for*the*lambda*and*captured*arguments*are*serialized*•  Type*conversion*as*interface*types*can*be*narrowed*at*the*call*site*/*captured*class*– Slightly*more*involved*for*primi@ves*–*boxed*&*unboxed*

Page 12: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute

Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute*

Page 13: Where*far*art*thou…()*L>*Lambda* · Copyright*©*2015,*Oracle*and/or*its*affiliates.*All*rights*reserved.**|*Oracle*Confiden@al*–*Distributed*under*Non*Disclosure*Agreement**–*Do*Not*Distribute