Joseph D. Darcy's Sun Weblog

Joseph D. Darcy's Sun Weblog


20090602 Tuesday June 02, 2009

JavaOne 2009: Project Coin Slides Posted

I presented my technical session about Project Coin, titled more verbosely Small Language Changes in JDK™ Release 7, this afternoon at JavaOne. I've posted the slides. Besides discussing the proposals under further consideration, I also went over some of the experiences from JDK 5 and other considerations we take into account when evolving the language.

(2009-06-02 18:48:34.0) Permalink Comments [13]

20090527 Wednesday May 27, 2009

Project Coin: For further consideration, round 2

The first group of proposals selected for further consideration were:

After due deliberation, and next set of proposals meeting the Project Coin criteria for further consideration are:

All the selected proposals were reviewed and judged to have favorable effort to reward ratios and to preserve the essential character of the language.

Work should continue refining the selected proposals and producing prototypes. In particular, a unified proposal for integer literals should be produced.

Language change proposals not on the combined "for further consideration" list will not be included in JDK 7; there is no need for continued discussion about them on the Project Coin mailing list. Detailed rationales for why particular proposals were not selected will not be provided.

Final selection of the five or so proposals to be included in the platform will occur within the next few months.

(2009-05-27 20:43:57.0) Permalink Comments [9]

20090502 Saturday May 02, 2009

OpenJDK 6: Regression test results for b16, take 2

The corrected source bundle for b16 has slightly different regression test results than the original one. The langtools and hotspot results are the same, but the jdk area has a different difference from b14/b15:


0: b14-jdk/summary.txt   pass: 3,077; fail: 26; error: 3
1: b16a-jdk/summary.txt  pass: 3,085; fail: 29; error: 4

0      1      Test
pass   error  com/sun/jdi/DoubleAgentTest.java
---    pass   java/awt/FontClass/CreateFont/BigFont.java
---    pass   java/awt/FontClass/CreateFont/DeleteFont.sh
---    pass   java/awt/FontClass/CreateFont/fileaccess/FontFile.java
error  pass   java/awt/FullScreen/UninitializedDisplayModeChangeTest/
              UninitializedDisplayModeChangeTest.java
pass   fail   java/awt/print/PrinterJob/ExceptionTest.java
---    pass   java/beans/PropertyEditor/TestEnumSubclass.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassJava.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassNull.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassValue.java
---    pass   java/io/readBytes/MemoryLeak.java
pass   fail   java/rmi/transport/pinLastArguments/PinLastArguments.java
---    pass   java/util/concurrent/Semaphore/RacingReleases.java
---    pass   javax/print/attribute/MediaMappingsTest.java
---    pass   javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest.java
---    pass   javax/sound/midi/Gervill/SoftFilter/TestProcessAudio.java
---    pass   javax/sound/midi/Gervill/SoftLowFrequencyOscillator/TestProcessControlLogic.java
fail   pass   javax/swing/JColorChooser/Test6541987.java
pass   error  sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java
pass   fail   sun/tools/jhat/HatHeapDump1Test.java
pass   fail   sun/tools/native2ascii/NativeErrors.java
pass   ---    tools/pack200/MemoryAllocatorTest.java

22 differences

Comparing the initial and corrected builds of b16:


0: b16-jdk/summary.txt   pass: 3,079; fail: 27; error: 4
1: b16a-jdk/summary.txt  pass: 3,085; fail: 29; error: 4

0      1      Test
pass   fail   java/awt/Focus/FrameMinimizeTest/FrameMinimizeTest.java
---    pass   java/beans/PropertyEditor/TestEnumSubclass.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassJava.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassNull.java
---    pass   java/beans/PropertyEditor/TestEnumSubclassValue.java
pass   fail   java/rmi/transport/pinLastArguments/PinLastArguments.java
---    pass   java/util/concurrent/Semaphore/RacingReleases.java
---    pass   javax/sound/midi/Gervill/SoftChannel/NoteOverFlowTest.java
---    pass   javax/sound/midi/Gervill/SoftFilter/TestProcessAudio.java
---    pass   javax/sound/midi/Gervill/SoftLowFrequencyOscillator/TestProcessControlLogic.java

10 differences

(2009-05-02 13:18:00.0) Permalink Comments [1]

20090416 Thursday April 16, 2009

OpenJDK 6: Regression test results for b16

Update: Regression test results for the corrected b16 source bundle are now available.

Running with the usual jtreg flags, -a -ignore:quiet always and -s for the langtools area, the basic regression test results on Linux for OpenJDK 6 build 16 are:

  • HotSpot, 3 tests passed.

  • Langtools, 1,352 tests passed.

  • JDK, 3,077 tests pass, 26 tests fail, 3 tests have errors.

In this build, many of the bugs fixed were for security issues or ports of fixes already in JDK 7. The HotSpot test results were stable:

0: b14-hotspot/summary.txt  pass: 3
1: b16-hotspot/summary.txt  pass: 3

No differences

In langtools all the tests continue to pass and a new test was added:

0: b14-langtools/summary.txt  pass: 1,351
1: b16-langtools/summary.txt  pass: 1,352

0      1      Test
---    pass   tools/javac/processing/6512707/T6512707.java

1 differences

And in jdk, a few new tests were added in b16 and the existing tests have generally consistent results:

0: b14-jdk/summary.txt  pass: 3,077; fail: 26; error: 3
1: b16-jdk/summary.txt  pass: 3,079; fail: 27; error: 4

0      1      Test
pass   error  com/sun/jdi/DoubleAgentTest.java
fail   pass   java/awt/Focus/FrameMinimizeTest/FrameMinimizeTest.java
---    pass   java/awt/FontClass/CreateFont/BigFont.java
---    pass   java/awt/FontClass/CreateFont/DeleteFont.sh
---    pass   java/awt/FontClass/CreateFont/fileaccess/FontFile.java
error  pass   java/awt/FullScreen/UninitializedDisplayModeChangeTest
              UninitializedDisplayModeChangeTest.java
pass   fail   java/awt/print/PrinterJob/ExceptionTest.java
---    pass   java/io/readBytes/MemoryLeak.java
---    pass   javax/print/attribute/MediaMappingsTest.java
fail   pass   javax/swing/JColorChooser/Test6541987.java
pass   error  sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java
pass   fail   sun/tools/jhat/HatHeapDump1Test.java
pass   fail   sun/tools/native2ascii/NativeErrors.java
pass   ---    tools/pack200/MemoryAllocatorTest.java

14 differences

(2009-04-16 00:00:01.0) Permalink Comments [0]

20090415 Wednesday April 15, 2009

OpenJDK 6: b16 Source Bundle Published

Update: Due to a misunderstanding, some of the expected fixes were missing from the original b16 source bundle. The corrected bundle has subsequently been posted.

On April 15, the source bundle for OpenJDK 6 b16 was published.

The previous source bundle was for b14. There was no distinct b15 per se; b15 was used to mark the transition from teamware to Mercurial. The b16 build is the first to be done purely in Mercurial.

There were 45 bug fixes in this build ranging from security fixes to sound updates; OpenJDK 6 b16 has all relevant security fixes from the recent JDK synchronized security release. A few fixes of note, during a build importing the binary plugs now defaults to false (6781572) and several fixes were applied that should render a few IcedTea patches unnecessary:

  • 6736248 EnumEditor bug. Class check incorrect

  • 6733718 test /java/awt/FullScreen/UninitializedDisplayModeChangeTest/ fails

  • 6593946 (bf) X-Buffer.compact() does not discard mark as specified

  • 6778493 Fix (langtools) ant build to honor fcs MILESTONE setting

    The other non security bugs fixed in this build are:

    • 6761791 Crash in the FontManager code due to use of JNIEnv saved by another thread

    • 6512707 "incompatible types" after (unrelated) annotation processing

    • 6632696 Writing to closed output files (writeBytes) leaks native memory (unix)

    • 6788196 (porting) Bounds checks in io_util.c rely on undefined behaviour

    • 6791458 FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k

    • 6792066 src/share/native/java/io/io_util.c clean-ups

    • 6819886 System.getProperty("os.name") reports Vista on Windows 7

    • 6821031 Upgrade OpenJDK's LittleCMS version to 1.18

    • 6800572 Removing elements from views of NavigableMap implementations does not always work correctly.

    • 6801020 Concurrent Semaphore release may cause some require thread not signaled

    • 6806019 38 JCK api/javax_sound/midi/ tests fails starting from jdk7 b46

    • 6803402 Race condition in AbstractQueuedSynchronizer

    • 6793757 Fix formatting of copyright notices in Gervill

    • 6794201 remove unused sources

    • 6808724 UninitializedDisplayModeChangeTest/DisplayModeChanger.java has wrong legal notice

    • 6821030 Merge OpenJDK Gervill with upstream sources, Q1CY2009

    • 6823445 Gervill SoftChannel/ResetAllControllers jtreg test fails after portamento fix from last merge

    • 6823446 Gervill SoftLowFrequencyOscillator fails when freq is set to 0 cent or 8.1758 Hz.

    • 6824976 Fix NAWK assignment in shell script jdk/make/java/java/genlocales.gmk

    • 6828183 testcase from SSR09_01 into jdk6-open hangs

    (2009-04-15 19:24:26.0) Permalink Comments [1]

    JavaOne 2009: Small Language Changes in JDK™ Release 7

    My JavaOne 2009 proposal for a talk about Small Language Changes in JDK™ Release 7 was accepted and scheduled for the first day of the conference, 3:20 PM to 4:20 PM on June 2, 2009. Besides discussing experiences evaluating proposals submitted to Project Coin, I plan to include some broader thoughts on Java language evolution, including sharing some informative war stories from back in JDK 5.

    (2009-04-15 12:32:07.0) Permalink Comments [2]

  • 20090331 Tuesday March 31, 2009

    Project Coin: The Call for Proposals Phase is Over!

    Update: Added links to proposal for switch for all types and simple expressions and a link to a revised method chaining proposal.

    Project Coin's call for proposals phase is now over! Thirty four days long, the proposal period included nearly 70 proposals being sent to the mailing list, 19 coming in over the last two days, and over 1100 messages on the list discussing those proposals and related topics. With the flurry of pre-deadline activity over, the more deliberative task of finishing reviewing and evaluating the proposals awaits. Including several sent in a few hours after deadline, the proposals received since week four are:

    The figure below graphs when proposals were received; nothing like an impending deadline to focus the mind!

    Project Coin Proposal Submissions

    Sometime after the next for further consideration cut is made, I'll post some thoughts on and reaction to the call for proposals phase as a whole. This will not include a detailed analysis of why each proposal was or was not chosen; however, there will be discussion of common aspects of proposals that led them to be selected or not.

    (2009-03-31 17:26:42.0) Permalink Comments [2]

    20090327 Friday March 27, 2009

    Project Coin: Week 4 Update

    Update: Corrected to include Stephen Colebourne's enhanced enhanced for loop proposal.

    Further update: Added links to updated large arrays and compile time access proposals.

    Project Coin's fourth week saw continued lively traffic on the mailing list. As the submission deadline approaches, a flurry of new proposals were sent in:

    The field of over two dozen proposals previously sent in over the first three weeks of Project Coin was narrowed to six proposals still in consideration for inclusion in JDK 7. The proposals submitted this week and until the end of the call for proposals period will be similarly evaluated for their appropriateness to be added to the language. Finally, the combined list of candidate changes will be produced.

    (2009-03-27 17:36:11.0) Permalink Comments [6]

    20090324 Tuesday March 24, 2009

    A trail of coins

    For those interested in specifically following Project Coin related posts, my Project Coin entries are tagged with "projectcoin":
    http://blogs.sun.com/main/tags/projectcoin

    (2009-03-24 15:40:20.0) Permalink

    Project Coin: For further consideration...

    In the first three weeks of Project Coin over two dozen proposals have been sent to the mailing list for evaluation. The proposals have ranged the gamut from new kinds of expressions, to new statements forms, to improved generics support. Thanks to all Java community members who have sent in interesting, thoughtful proposals and contributed to informative discussions on the list!

    While there is a bit less than a week left in the call for proposals period, there has been enough discussion on the list to winnow the slate of proposals sent in so far to those that merit further consideration for possible inclusion in the platform.

    First, Bruce Chapman's proposal to extend the scope of imports to include package annotations will be implemented under JLS maintenance so further action is unnecessary on this matter as part of Project Coin. Second, since the JSR 294 expert group is discussing adding a module level of accessibility to the language, the decision of whether or not to include Adrian Kuhn's proposal of letting "package" explicitly name the default accessibility level will be deferred to that body. Working with Alex, I reviewed the remaining proposals. Sun believes that the following proposals are small enough, have favorable estimated reward to effort ratios, and advance the stated criteria of making things programmers do everyday easier or supporting platform changes in JDK 7:

    As this is just an initial cut and the proposals are not yet in a form suitable for direct inclusion in the JLS, work should continue to refine these proposed specifications and preferably also to produce prototype implementations to allow a more thorough evaluation of the utility and scope of the changes. The email list should focus on improving the selected proposals and on getting any remaining new proposals submitted; continued discussion of the other proposals is discouraged.

    The final list of small language changes will be determined after the call for proposals is over so proposals sent in this week are certainly still in the running! The final list will only have around five items so it is possible not all the changes above will be on the eventual final list.

    (2009-03-24 15:21:00.0) Permalink Comments [8]

    20090320 Friday March 20, 2009

    Project Coin: Week 3 Update

    Project Coin's third week was another week of lively traffic on the mailing list. New proposals were sent in:

    existing proposals were revised:

    and discussion continued on ARM and other proposals. The scoping and utility of a few pre-proposals was discussed on the list too.

    Ten days remain to get language change proposals in! (Purely libraries changes will be handled by other JDK 7 processes.)

    (2009-03-20 10:37:34.0) Permalink Comments [2]

    20090313 Friday March 13, 2009

    Project Coin: Week 2 Update

    After the vigorous start of week 1, the pace of new proposals being sent to the list slowed:

    However, brisk discussion continued on refining and exploring ARM blocks and their variations.

    (2009-03-13 09:30:00.0) Permalink Comments [1]

    20090312 Thursday March 12, 2009

    Language Model Changes as of JDK 7 Build 50

    To date, there have been a few API changes to javax.lang.model.* in JDK 7. Early in the release, SourceVersion.RELEASE_7 was added to correspond to any new source-level changes coming in JDK 7 (6458819). Eventually, there will be changes to support the modulue construct being added by JSR 294; changes may or may not be needed for language changes coming from Project Coin and JSR 308. Once modulues are added, the JSR 269 API elements meant to cope with the expression problem will be tested. In the mean time, some minor API cleanups have occurred, one to make handling exceptions easier (6794071), another to group common functionality in mixin interfaces (6460529), and some minor API clarifications (6501749). Along the way, there has been a little general bug fixing too (6478017, 6583626, 6498938).

    Small tweaks and bug fixing will continue to occur in the javax.lang.model.* and javax.annotation.processing packages throughout JDK 7 in addition to changes needed to support new language features.

    (2009-03-12 13:36:36.0) Permalink

    Design tips: Exception types

    Expanding on a few slides from my JavaOne talk last year, here are a few tips to keep in mind when designing exception types.

    First, all exceptions are serializable since Throwable implements Serializable; therefore, like all other serializable classes, exception types should declare a serialVersionUID field to ease evolving the type in the future. Using's javac's -Xlint:serial option will warn about missing serialVersionUID fields on serializable classes, amongst other possible issues.

    Second, when adding a new exception class, consider providing more information beyond just a distinct name, such as methods to return information about what specific situation triggered the exception and possibly how to recover from it. Providing this additional information can interact with being serializable; when the additional information is not logically serializable, the specification may need to allow the information to be unavailable after deserialization.

    Third, when multiple related exceptions types are added, a common direct superclass allows a single catch block to handle the related exceptions uniformly. (Having a common super-exception would still be useful even if multi-catch is added to the language in JDK 7.)

    Looking at the exceptions in the JSR 269 API, various methods note the possible impact of serialization-deserialization on the returned values. JSR 269 provided a trio of similar exceptions for the situation of encountering a kind of object unknown in an earlier version of the language, such as a JDK 6 era annotation processor coming across a module from JDK 7:

    However, the original JSR 269 API does not have a common direct superclass to group these related conditions. That deficiency was addressed in JDK 7 build 48 with the addition of javax.lang.model.UnknownEntityException as the direct superclass of these three exceptions (6794071). Retrofitting this change is binary compatible because UnknownEntityException directly extends RuntimeException as did the old exceptions and serialization compatibility is preserved by the existing serialVersionUID fields in the old exceptions.

    (2009-03-12 12:00:07.0) Permalink

    20090310 Tuesday March 10, 2009

    All about JDK 7

    Those interested in following JDK 7 happenings from Sun engineers can track "jdk7" tagged entries on http://blogs.sun.com/main/tags/jdk7.

    (2009-03-10 11:27:20.0) Permalink Comments [1]

    20090308 Sunday March 08, 2009

    The crested butte of Crested Butte

    Last week I was off attending my first Java Posse Roundup in scenic Crested Butte Colorado, pictured below. There were many good discussions related to JDK 7 and other programming, and non-programming, topics.

    Unfortunately, there were some difficulties with my flight back. Once again, the plane I was flying on had to be rebooted, but at least this time the passengers didn't need to be reinstalled! I missed my scheduled connection in Denver and caught the next flight to the bay area a few hours later. The wait in Denver was made more pleasant by the airport's free-after-a-short-ad wi-fi and recharging stations for electronic gear. More airports should have those amenities!

    (2009-03-08 22:15:09.0) Permalink

    20090306 Friday March 06, 2009

    Project Coin: Week 1 Update

    In its first week, Project Coin enjoyed a vigorous start with well over a dozen proposals submitted:

    Traffic on the the list has been high, with lots of feedback and analysis leading to some revised proposals.

    A few general comments on the proposals that have been sent in so far to help refine those proposals and improve future proposals before they are sent in.

    The proposals submitted to Project Coin should already be well thought-through. The goal is to have in short order specifications approaching JLS quality, preferably with a prototype to help validate the design. The feedback on the list should be much closer to finding and illuminating any remaining dark corners of a proposal rather than fleshing out its basic structure. If a proposal does not cite chapter and verse of the JLS for parts of its specification, that is a good indication the proposal is too vague. All affected sections of the JLS should be listed, including binary compatibility and the flow analysis in definite assignment.

    It is fine if someone posts to the list to solicit help writing a proposal for a given change.

    Proposal writers should be aware of the size and scope parameters established for the project; for background see:

    Also, proposal writers should search Sun's bug database for bugs related to the change. The URL for the database is http://bugs.sun.com; Java specification issues are in category Java SE and subcategory specification. Of course the database is also searchable with your favorite search engine restricted to that site. Besides the evaluation field from the bug database, the external comment can often also have valuable insight into and discussion of alternatives to solving the problem or reasons why the problem shouldn't be solved.

    As has already been happening on the list, authors and advocates of a proposal are responsible for responding to feedback and incorporating changes into any subsequent iterations of the proposal. For now, I think it is adequate to just send the revised proposals to the list. Only if there turns out to be frequent change would a more formal tracking system be warranted. Keeping such discussions on the list is important both to allow easy, centralized tracking of the proposal drafts and also for future language archaeologists who are curious about why a particular decision was made.

    After a few iterations of feedback and refinements, the specification and compilation strategy should be sufficiently detailed to provide high-confidence that the proposal is practical and can be reduced to practice. For example, I think the initial proposal for the admittedly simple strings in switch change provides adequate detail on these fronts.

    (2009-03-06 09:00:00.0) Permalink Comments [15]

    20090301 Sunday March 01, 2009

    Project Coin: Proposal for Strings in switch

    Below is a Project Coin language proposal form I wrote for Strings in switch; send any comment to the Project Coin mailing list.


    PROJECT COIN SMALL LANGUAGE CHANGE PROPOSAL FORM v1.0

    AUTHOR(S): Joseph D. Darcy

    OVERVIEW
    Provide a two sentence or shorter description of these five aspects of the feature:
    FEATURE SUMMARY: Should be suitable as a summary in a language tutorial.

    Add the ability to switch on string values analogous to the existing ability to switch on values of the primitive types.

    MAJOR ADVANTAGE: What makes the proposal a favorable change?

    More regular coding patterns can be used for operations selected on the basis of a set of constant string values; the meaning of the new construct should be obvious to Java developers.

    MAJOR BENEFIT: Why is the platform better if the proposal is adopted?

    Potentially better performance for string-based dispatch code.

    MAJOR DISADVANTAGE: There is always a cost.

    Some increased implementation and testing complexity for the compiler.

    ALTERNATIVES: Can the benefits and advantages be had some way without a language change?

    No; chained if-then-else tests for string equality are potentially expensive and introducing an enum for its switchable constants, one per string value of interest, would add another type to a program without good cause.

    EXAMPLES
    Show us the code!
    SIMPLE EXAMPLE: Show the simplest possible program utilizing the new feature.

    String s = ...
    switch(s) {
     case "foo":
       processFoo(s);
       break;
    }
    

    ADVANCED EXAMPLE: Show advanced usage(s) of the feature.

    String s = ...
    switch(s) {
    case "quux":
       processQuux(s);
       // fall-through
    
     case "foo":
     case "bar":
       processFooOrBar(s);
       break;
    
     case "baz":
        processBaz(s);
       // fall-through
    
     default:
       processDefault(s);
       break;
    }
    

    DETAILS
    SPECIFICATION: Describe how the proposal affects the grammar, type system, and meaning of expressions and statements in the Java Programming Language as well as any other known impacts.

    The lexical grammar is unchanged. String is added to the set of types valid for a switch statement in JLSv3 section 14.11. Since Strings are already included in the definition of constant expressions, JLSv3 section 15.28, the SwitchLabel production does not need to be augmented. The existing restrictions in 14.11 on no duplicate labels, at most one default, no null labels, etc. all apply to Strings as well. The type system is unchanged. The definite assignment analysis of switch statement, JLSv3 section 16.2.9, is unchanged as well.

    COMPILATION: How would the feature be compiled to class files? Show how the simple and advanced examples would be compiled. Compilation can be expressed as at least one of a desugaring to existing source constructs and a translation down to bytecode. If a new bytecode is used or the semantics of an existing bytecode are changed, describe those changes, including how they impact verification. Also discuss any new class file attributes that are introduced. Note that there are many downstream tools that consume class files and that they may to be updated to support the proposal!

    One way to support this change would be to augment the JVM's lookupswitch instruction to operate on String values; however, that approach is not recommended or necessary. It would be possible to translate the switches to equivalent if-then-else code, but that would require unnecessary equality comparisons which are potentially expensive. Instead, a switch should occur on a predictable and fast integer (or long) function value computed from the string. The most natural choice for this function is String.hashCode, but other functions could also be used either alone or in conjunction with hashCode. (The specification of String.hashCode is assumed to be stable at this point.) If all the string labels have different lengths, String.length() could be used instead of hashCode. Generally a String.equals() check will be needed to verify the candidate string's identity in addition to the evaluation of the screening function because multiple string inputs could evaluate to the same result.

    A single case label, a single case label with a default, and two case labels can be special-cased to just equality checks without function evaluations. If there are collisions in String.hashCode on the set of case labels in a switch block, a different function without collisions on that set of inputs should be used; for example ((long)s.hashCode<<32 ) + s.length()) is another candidate function.

    Here are desugarings to currently legal Java source for the two examples above where the default hash code do not collide:

    // Simple Example
    if (s.equals("foo")) { // cause NPE if s is null
     processFoo(s);
    }
    
    
    // Advanced example
    {  // new scope for synthetic variables
     boolean $take_default = false;
     boolean $fallthrough = false;
     $default_label: {
         switch(s.hashCode()) { // cause NPE if s is null
         case 3482567: // "quux".hashCode()
             if (!s.equals("quux")) {
                 $take_default = true;
                 break $default_label;
             }
             processQuux(s);
             $fallthrough = true;
                   case 101574: // "foo".hashCode()
             if (!$fallthrough && !s.equals("foo")) {
                 $take_default = true;
                 break $default_label;
             }
             $fallthrough = true;
         case 97299:  // "bar".hashCode()
             if (!$fallthrough && !s.equals("bar")) {
                 $take_default = true;
                 break $default_label;
             }
             processFooOrBar(s);
             break;
    
         case 97307: // "baz".hashCode()
             if (!s.equals("baz")) {
                 $take_default = true;
                 break $default_label;
             }
             processBaz(s);
             $fallthrough = true;
    
         default:
             $take_default = true;
             break $default_label;
         }
     }
     if($take_default)
         processDefault(s);
    } 
    

    In the advanced example, the boolean "fallthrough" variable is needed to track whether a fall-through has occurred so the string equality checks can be skipped. If there are no fall-throughs, this variable can be removed. Likewise, if there is no default label in the original code, the $take_default variable is not needed and a simple break can be used instead.

    In a translation directly to bytecode, the synthetic state variables can be replaced with goto's; expressing this in pseudo Java source with goto:

    // Advanced example in pseudo Java with goto
    switch(s.hashCode()) { // cause NPE if s is null
    case 3482567: // "quux".hashCode()
       if (!s.equals("quux"))
           goto $default_label;
       goto $fooOrBarCode_label;
      case 101574: // "foo".hashCode()
       if (!s.equals("foo"))
           goto $default_label;
       goto $fooOrBarCode_label;
    
    case 97299:  // "bar".hashCode()
       if (!s.equals("bar"))
           goto $default_label;
    
       $fooOrBarCode_label:
       processFooOrBar(s);
       break;
    
    case 97307: // "baz".hashCode()
       if (!s.equals("baz"))
           goto $default_label;
       processBaz(s);
    
    default:
    $default_label:
       processDefault(s);
       break;
    } 
    

    Related to compilation, a compiler's existing diagnostics around falling through switches, such as javac's -Xlint:fallthrough option and @SuppressWarnings("fallthrough"), should work identically on switch statements based on Strings.

    TESTING: How can the feature be tested?

    Generating various simple and complex uses of the new structure and verifying the proper execution paths occur; combinations to test include switch statements with and without fall-throughs, with and without collisions in the hash codes, and with and without default labels.

    LIBRARY SUPPORT: Are any supporting libraries needed for the feature?

    No.

    REFLECTIVE APIS: Do any of the various and sundry reflection APIs need to be updated? This list of reflective APIs includes but is not limited to core reflection (java.lang.Class and java.lang.reflect.*), javax.lang.model.*, the doclet API, and JPDA.

    Only reflective APIs that model statements in the source language might be affected. None of core reflection, javax.lang.model.*, the doclet API, and JDPA model statements; therefore, they are unaffected. The tree API in javac, does model statements, but the existing API for switch statements is general enough to model the revised language without any API changes.

    OTHER CHANGES: Do any other parts of the platform need be updated too? Possibilities include but are not limited to JNI, serialization, and output of the javadoc tool.

    No.

    MIGRATION: Sketch how a code base could be converted, manually or automatically, to use the new feature.

    Look for sequences of if ("constant string".equals(foo)) or if (foo.equals("constant string")) and replace accordingly.

    COMPATIBILITY
    BREAKING CHANGES: Are any previously valid programs now invalid? If so, list one.

    All existing programs remain valid.

    EXISTING PROGRAMS: How do source and class files of earlier platform versions interact with the feature? Can any new overloadings occur? Can any new overriding occur?

    The semantics of existing class files and legal source files and are unchanged by this feature.

    REFERENCES
    EXISTING BUGS: Please include a list of any existing Sun bug ids related to this proposal.

    5012262 Using Strings and Objects in Switch case statements.

    URL FOR PROTOTYPE (optional):

    No prototype at this time.

    (2009-03-01 10:00:00.0) Permalink Comments [7]

    20090227 Friday February 27, 2009

    Project Coin Now Live

    The Project Coin OpenJDK page and mailing list are now live. The call for proposal period will run until March 30, 2009. Let the proposing begin!

    (2009-02-27 15:17:18.0) Permalink Comments [2]

    20090213 Friday February 13, 2009

    FOSDEM 2009: OpenJDK 6 and Project Coin

    I was pleased to attend and speak at my first FOSDEM conference this year. The classroom setting of the Free Java Developer Room was certainly different than the cavernous session halls of JavaOne! My talks were on OpenJDK 6 and Project Coin:

    Mark spoke on modularity and overall plans for JDK 7 and Alex spoke on progress towards a universal VM.

    Another enjoyable aspect of FOSDEM for me was meeting in person a number of people I'd corresponded with over email who had contributed to OpenJDK 6, including Karl Helgason of Gervill fame and Andrew Haley and other IcedTea engineers from Red Hat.

    (2009-02-13 10:00:00.0) Permalink Comments [5]

    Calendar

    « June 2009
    SunMonTueWedThuFriSat
     
    1
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
        
           
    Today

    RSS Feeds

    XML
    All
    /Annotation Processing
    /General
    /Java
    /JavaOne
    /Numerics
    /OpenJDK

    Search

    Links

      Blogroll
    • Download the JRE

      News

    Navigation



    Referers

    Today's Page Hits: 113