days
1
3
hours
1
1
minutes
1
0
seconds
0
6
search
Take a look at 26 key Java 9 features

What’s brewing in Java 9?

Richard Gall
Java 9
© Shutterstock / Alpha_7D

Big changes are going on with the Java platform. In this excerpt from Mastering Java 9, Dr. Edward Lavieri and Peter Verhas go over 26 key changes to Java 9 features you need to know.

This is an excerpt from the book, Mastering Java 9 written by By Dr. Edward Lavieri and Peter Verhas, and published by Packt Publishing.

Java 9 represents a major release and consists of a large number of internal changes to the Java platform. Collectively, these internal changes represent a tremendous set of new possibilities for Java developers, some stemming from developer requests, others from Oracle-inspired enhancements. In this chapter, we will review 26 of the most important changes. Each change is related to a JDK Enhancement Proposal (JEP). JEPs are indexed and housed here. You can visit this site for additional information on each JEP.

Note: The JEP program is part of Oracle’s support for open source, open innovation, and open standards. While other open source Java projects can be found, OpenJDK is the only one supported by Oracle.

In this post, we will cover changes to the Java platform. These changes have several impressive implications, including:

  • Heap space efficiencies
  • Memory allocation
  • Compilation process improvements
  • Type testing
  • Annotations
  • Automated runtime compiler tests
  • Improved garbage collection

Key Java 9 changes

1. Improved Contended Locking [JEP 143]

The general goal of JEP 143 was to increase the overall performance of how the JVM manages contention over locked Java object monitors. The improvements to contended locking were all internal to the JVM and do not require any developer actions to benefit from them. The overall improvement goals were related to faster operations. These include faster monitor enter, faster monitor exit and faster notifications.

2. Segmented code cache [JEP 197]

The segmented code cache JEP (197) upgrade was completed and results in faster, more efficient execution time. At the core of this change was the segmentation of the code cache into three distinct segments–non-method, profiled, and non-profiled code.

3. Smart Java compilation, phase two [JEP 199]

The JDK Enhancement Proposal 199 is aimed at improving the code compilation process. All Java developers will be familiar with the javac tool for compiling source code to bytecode, which is used by the JVM to run Java programs. Smart Java Compilation, also referred to as Smart Javac and sjavac, adds a smart wrapper around the javac process. Perhaps the core improvement sjavac adds is that only the necessary code is recompiled.

4. Resolving Lint and Doclint warnings [JEP 212]

Both Lint and Doclint report errors and warnings during the compile process. Resolution of these warnings was the focus of JEP 212. When using core libraries, there should not be any warnings. This mindset led to JEP 212, which has been resolved and implemented in Java 9.

SEE MORE: How Java 9 will change your life

5. Tiered attribution for javac [JEP 215]

JEP 215 represents an impressive undertaking to streamline javac’s type checking schema. In Java 8, type checking of poly expressions is handled by a speculative attribution tool. The goal with JEP 215 was to change the type checking schema to create faster results. The new approach, released with Java 9, uses a tiered attribution tool. This tool implements a tiered approach for type checking argument expressions for all method calls. Permissions are also made for method overriding. In order for this new schema to work, new structural types are created for each of the following listed types of method arguments:

  • Lambda expressions
  • Poly expressions
  • Regular method calls
  • Method references
  • Diamond instance creation expressions

6. Annotations pipeline 2.0 [JEP 217]

Java 8 related changes impacted Java annotations, but did not usher in a change to how javac processed them. There were some hardcoded solutions that allowed javac to handle the new annotations, but they were not efficient. Moreover, this type of coding (hardcoding workarounds) is difficult to maintain.

So, JEP 217 focused on refactoring the javac annotation pipeline. This refactoring was all internal to javac, so it should not be evident to developers.

7. New version-string scheme [JEP 223]

Prior to Java 9, the release numbers did not follow industry standard versioning–semantic versioning. Oracle has embraced semantic versioning for Java 9 and beyond. For Java, a major-minor-security schema will be used for the first three elements of Java version numbers:

  • Major: A major release consisting of a significant new set of features
  • Minor: Revisions and bug fixes that are backwards compatible
  • Security: Fixes deemed critical to improve security

SEE MORE: “Java 9 can do for modularity what Java 8 did for functional programming”

8. Generating run-time compiler tests automatically [JEP 233]

The purpose of JEP 233 was to create a tool that could automate the runtime compiler tests.

The tool that was created starts by generating a random set of Java source code and/or byte code. The generated code will have three key characteristics:

  • Be syntactically correct
  • Be semantically correct
  • Use a random seed that permits reusing the same randomly-generated code

The source code that is randomly generated will be saved in the following directory:

hotspot/test/testlibrary/jit-tester

These test cases will be stored for later re-use. They can be run from the j-treg directory or from the tool’s makefile. One of the benefits of re-running saved tests is to test the stability of your system.

9. Testing class-file attributes generated by Javac [JEP 235]

Prior to Java 9, there was no method of testing a class-file’s attributes. Running a class and testing the code for anticipated or expected results was the most commonly used method of testing javac generated class-files. This technique falls short of testing to validate the file’s attributes.

The lack of, or insufficient, capability to create tests for class-file attributes was the impetus behind JEP 235. The goal is to ensure javac creates a class-file’s attributes completely and correctly.

10. Storing interned strings in CDS archives [JEP 250]

CDS archives now allocate specific space on the heap for strings:

Java 9

The string space is mapped using a shared-string table, hash tables, and deduplication.

SEE MORE: New Java 9 features at a glance

Other features/enhancements in Java 9 are:

We explored 10 of the 26 main Java 9 changes in this post. To learn more about the other 16 Java 9 features/enhancements, check out the detailed article on Packt Hub. (Use the code ORJEB10 at checkout to get recommended eBook retail price for$10 only until June 15, 2018.)

11. Preparing JavaFX UI controls and CSS APIs for modularization [JEP 253]

12. Compact strings [JEP 254]

13. Merging selected Xerces 2.11.0 updates into JAXP [JEP 255]

14. Updating JavaFX/Media to newer version of GStreamer [JEP 257]

15. HarfBuzz Font-Layout Engine [JEP 258]

16. HiDPI graphics on Windows and Linux [JEP 263]

17. Marlin graphics renderer [JEP 265]

18. Unicode 8.0.0 [JEP 267]

19. Reserved stack areas for critical sections [JEP 270]

20. Dynamic linking of language-defined object models [JEP 276]

21. Additional tests for humongous objects in G1 [JEP 278]

22. Improving test-failure troubleshooting [JEP 279]

23. Optimizing string concatenation [JEP 280]

24. HotSpot C++ unit-test framework [JEP 281]

25. Enabling GTK 3 on Linux [JEP 283]

26. New HotSpot build system [JEP 284]

These were some impressive new features of the Java platform, with specific focus on javac, JDK libraries, and various test suites. Memory management improvements, including heap space efficiencies, memory allocation, and improved garbage collection represent a powerful new set of Java platform enhancements. Changes regarding the compilation process resulting in greater efficiencies were part of this discussion We also covered important improvements, such as with the compilation process, type testing, annotations, and automated runtime compiler tests.

 

You just enjoyed an excerpt from the book Mastering Java 9 written by By Dr. Edward Lavieri and Peter Verhas.

Use the code ORJEB10 at checkout to get recommended eBook retail price for$10 only until June 15, 2018.

Author

Richard Gall

Richard Gall is Communications Manager at Packt, utilising his background in writing and publishing to help Packt in their mission to help the world put software to work in new ways. Packt, one of the biggest tech publishers in the world, deliver effective learning and information services to IT professionals.


Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of