coin launch

Upload: venkat-bharadwaj-j

Post on 07-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Coin Launch

    1/29

    1 | 2011 Oracle Corporation

  • 8/6/2019 Coin Launch

    2/29

    2 | 2011 Oracle Corporation

    Making heads and tails of Project Coin,Small language changes in JDK 7

    Joseph D. Darcy

  • 8/6/2019 Coin Launch

    3/29

    3 | 2011 Oracle Corporation

    Project Coin is a suite oflanguage and library chang

    to make things programmereveryday easier.

  • 8/6/2019 Coin Launch

    4/29

    4 | 2011 Oracle Corporation

    coin, n. A piece of small chcoin, v. To create new lang

  • 8/6/2019 Coin Launch

    5/29

    5 | 2011 Oracle Corporation

    Project Coin ready to use today!

    Remove extra text to make programs more rea

    Encourage writing programs that are more relia

    Integrate well with past and future changes

  • 8/6/2019 Coin Launch

    6/29

    6 | 2011 Oracle Corporation

    Coin Constraints

    Smalllanguage changes Specification

    Implementation

    Testing

    Coordinate with larger language changes,

    past and future, such as Project Lambda Complex language interactions; need to be wa

    Specification

    Implementation

  • 8/6/2019 Coin Launch

    7/29

    7 | 2011 Oracle Corporation

    Coin Details

    Easier to use generics Diamond

    Varargs warnings

    More concise error handling Multi-catch

    try-with-resources

    Consistency and clarity Strings in switch

    Literal improvements

  • 8/6/2019 Coin Launch

    8/29

    8 | 2011 Oracle Corporation

    Project Coin History

    Project Coin in OpenJDK:

    http://openjdk.java.net/projects/coin/

    Initial call for proposals to the community

    Implementation done as part of overall JDK 7 p

    Specification and implementation

  • 8/6/2019 Coin Launch

    9/29

    9 | 2011 Oracle Corporation

    Project Coin Proposals

    0

    1

    2

    3

    4

    5

    6

    7

    0

    2

    4

    6

    8

    10

    SubmittedProposalsPerD

    ay

    Days after Opening

  • 8/6/2019 Coin Launch

    10/29

    10 | 2011 Oracle Corporation

    coin-devtraffic

    1

    4

    16

    64

    256

    1024

    4096

    Mont

    Total

    Note:Log scale

  • 8/6/2019 Coin Launch

    11/29

    11 | 2011 Oracle Corporation

    Project Coin Specification

    Specification in the JCP:

    JSR 334: Small Enhancements to theJava Programming Language

    http://www.jcp.org/en/jsr/detail?id=334

    Stages

    Early draft review Public Review

    Proposed Final Draft

    Final approval ballot underway!

  • 8/6/2019 Coin Launch

    12/29

    12 | 2011 Oracle Corporation

    IDE Support

    Beta support in Eclipsehttp://thecoderlounge.blogspot.com/2011/06/java-7-support-in-eclipse-

    IntelliJ IDEA 10.5

    NetBeans 7.0http://netbeans.org/kb/docs/java/javase-jdk7.ht

    Here today and more on the way!

    DEMO

  • 8/6/2019 Coin Launch

    13/29

    13 | 2011 Oracle Corporation

    Project Coin Features

    Binary literals and underscores in literals

    Strings in switch

    Diamond

    Multi-catch and more precise rethrow

    try-with-resources Varargs warnings

  • 8/6/2019 Coin Launch

    14/29

    14 | 2011 Oracle Corporation

    Varargs warnings

    Summary: no longer receive uninformative unc

    compiler warnings from calling platform library List Arrays.asList(T... a)

    boolean Collections.addAll(Collection

  • 8/6/2019 Coin Launch

    15/29

    15 | 2011 Oracle Corporation

    Coin features easy to use

    Type inference in diamond

    Internal compiler desugaring multi-catch

    strings in switch

    try-with-resources

    More work for the compiler!

  • 8/6/2019 Coin Launch

    16/29

    16 | 2011 Oracle Corporation

    // Sugared

    switch(s) {

    case "a":

    case "b":

    case "c":

    return 10;

    case "d":

    case "e":

    case "f":

    return 20;

    ...

    }

    // Desugared

    int $t = -1;

    switch(s.hashCode()) {

    case 0x61: // "a".hashCode()

    if(s.equals("a")) $t = 1; br

    case 0x62:

    if(s.equals("b")) $t = 2; br

    ... }

    switch($t) {

    case 1:

    case 2:

    case 3:

    return 10;

    case 4:

    case 5:

    case 6:

    return 20;

    ...

    }

  • 8/6/2019 Coin Launch

    17/29

    17 | 2011 Oracle Corporation

    // Sugared

    switch(s) {

    case "a":

    case "b":

    case "c":

    return 10;

    case "d":

    case "e":

    case "f":

    return 20;

    ...

    }

    // Desugared

    int $t = -1;

    switch(s.hashCode()) {

    case 0x61: // "a".hashCode()

    if(s.equals("a")) $t = 1; br

    case 0x62:

    if(s.equals("b")) $t = 2; br

    ... }

    switch($t) {

    case 1:

    case 2:

    case 3:

    return 10;

    case 4:

    case 5:

    case 6:

    return 20;

    ...

    }

  • 8/6/2019 Coin Launch

    18/29

    18 | 2011 Oracle Corporation

    try-with-resources desugaringtry ResourceSpecification

    Block

    {

    final VariableModifiers_minus_final R #resource

    Throwable #primaryException = null;

    try ResourceSpecificationtail

    Blockcatch (Throwable #t) {

    #primaryException = t;

    throw #t;

    } finally {

    if (#resource != null) {

    if (#primaryException != null) {

    try {

    #resource.close();

    } catch(Throwable #suppressedException#primaryException.addSuppressed(#supp

    }

    } else {

    #resource.close();

    }

    }

    }

    }

  • 8/6/2019 Coin Launch

    19/29

    19 | 2011 Oracle Corporation

    Library support

    New superinterface java.lang.AutoClosea

    AllAutoCloseable and by extension java.io.Clotypes usable with try-with-resources

    Retrofit Closeable/AutoCloseable to Java SE A JDBC 4.1 retrofitted asAutoCloseable too

    Suppressed exceptionsare recorded for postea new facility Throwable.addSuppressed

    Suppressed exception info included in stack trace, etc

    try-with-resources isnt just a language feature

  • 8/6/2019 Coin Launch

    20/29

    20 | 2011 Oracle Corporation

    Minty fresh libraries in JDK 7

    Retrofit Project Coin features in the JDK code b

    Improve the existing code base

    Validate the design of features through use

    Detectors / converters applied for Diamond, try-with-resources

    JDK7, Coin, and Making Libraries Fresh and Minty,http://stuartmarks.wordpress.com/2010/12/23/jdk7-coin-and-making-libraries-fresh

    Also used in new library and test code try-with-resources in JSR 203/NIO2 utility methods

    Better JDK coding through coinification

  • 8/6/2019 Coin Launch

    21/29

    21 | 2011 Oracle Corporation

    A Systematic Update

    Automated code conversion for coinification

    Ran annotation processorsover the JDK Types to be retrofitted as Closeable/AutoCloseab

    Project Coin: Bringing it to a Close(able),http://blogs.sun.com/darcy/entry/project_coin_bring_close/

    Methods and constructors to be annotated with @SafeProject Coin: Safe Varargs in JDK Libraries,http://blogs.sun.com/darcy/entry/project_coin_safe_vararg_librarie

    Quantitativelanguage design

  • 8/6/2019 Coin Launch

    22/29

    22 | 2011 Oracle Corporation

    Language design for the real world: Di

    Two inference algorithms were considered for d

    Differed in how constraints were gathered

    Sometimes the 1st algorithm was more useful,other times the 2nd algorithm was more useful

    What to do?

    Is either one any good?

    How to choose between them?

    Look at relative performance on a body of code

  • 8/6/2019 Coin Launch

    23/29

    23 | 2011 Oracle Corporation

    Diamond outcome

    Both algorithms were equally effective

    Type arguments eliminated in 90% of constructor calls A slightly different 90% for each algorithm

    Choose the algorithm with better future evolutioproperties

    On a body of millions of lines of code

  • 8/6/2019 Coin Launch

    24/29

    24 | 2011 Oracle Corporation

    The importance of source compatibilityA migration issue with more precise rethrow?

    try {

    throw new DaughterOfFoo();} catch (Foo e) {

    try {

    throw e; // Used to be treated as throwing

    // would now throw DaughterOfFoo

    } catch (SonOfFoo anotherException) {; // Reachable?

    }

    }

    Sh ld h f b li i l

  • 8/6/2019 Coin Launch

    25/29

    25 | 2011 Oracle Corporation

    Should the feature be explicitly reques

    try {

    throw new DaughterOfFoo();} catch (final Foo e) {

    try {

    throw e; // Used to be treated as throwing

    // would now throw DaughterOfFoo

    } catch (SonOfFoo anotherException) {; // Reachable?

    }

    }

    N bl d t i ti

  • 8/6/2019 Coin Launch

    26/29

    26 | 2011 Oracle Corporation

    No; problem doesnt occur in practice

    More precise analysis by default, easy path to m

    try {

    throw new DaughterOfFoo();} catch (Foo e) {

    try {

    throw e; // Used to be treated as throwing

    // would now throw DaughterOfFoo

    } catch (SonOfFoo anotherException) {; // Reachable?

    }

    }

    C l i

  • 8/6/2019 Coin Launch

    27/29

    27 | 2011 Oracle Corporation

    Conclusion

    Project Coin features are easy to use today!

    Ease writing readable and reliable code Tooling support in IDEs

    Systematic platform upgrade

  • 8/6/2019 Coin Launch

    28/29

    28 | 2011 Oracle Corporation

    Q&A

    blogs.oracle.com/darcy

  • 8/6/2019 Coin Launch

    29/29

    29 | 2011 Oracle Corporation