Java SE 8 Beyond Lambdas: The Big Picture
The JVM internals received a lot of attention in this release as well, including the removal of what's called the "Permanent Generation" (PermGen) within the Java heap. In previous versions of Java, this area was used to store class metadata, the VM's internal representation of classes themselves (from which Java objects are created), constants, and all sorts of other information the JVM needs to keep about classes and methods. The issue is, not only is this area subject to garbage collection and related pauses, it's fixed in size at startup meaning once it fills up, you'll receive
OutOfMemory exceptions with very little you can do about it.
Java SE 8 replaces all this with a new "Metaspace," including a new classloader storage model where the lifetime of the classes and metadata match the lifetime of the classloader, a linear allocation of native memory for class data to avoid fragmentation and aid in cleanup, and the removal of individual class metadata reclamation and GC scanning within. This means that once there's no need for class metadata, the entire area is reclaimed in one operation as soon as the classloader is removed. Not only does this remove the size limitations associated with the PermGen model, the metadata space can grow as needed, and it's free from GC-related pauses.
Speaking of garbage collection, the removal of PermGen is only one part of GC enhancements in this release of Java. Also included is a cleanup of rarely used and contradictory GC-related command-line parameters, as well as further enhancements to the G1 collector.
In addition to the client and server JVMs, Java SE 8 adds a newer, smaller VM called appropriately, the "Small VM." It's only 3MB in size (compared to 6MB and 9MB for the client and server VMs, respectively).
Not to be left out, the javac Java compiler has been enhanced to provide much improved build times via an incremental build process, as well as added support for concurrency to take advantage of multi-cpu/multicore build machines. Other enhancements include the addition of persistence of metadata across builds, and the automatic generation of headers for JNI.
Java SE 8 Compact Profiles
Oracle did a lot of work to merge its two teams and two implementations of Java (HotSpot and JRockit). The fruit of this effort has been seen starting with Java SE 7 and the many updates that followed. However, Java SE 8 completes the effort. One of the biggest areas of convergence is the merging of Java ME CDC into Java SE via the new Java SE compact profiles.
Java SE 8 compact profiles provide Java SE-compatible subsets of the JVM and libraries to target smaller or constrained environments or embedded systems. The smallest profile is about 12MB in static size, and has a reduced dynamic footprint compared to Java SE 7 (around 16MB for headless embedded versions, or 32MB for headful embedded version). Overall, there are four profiles defined:
- Compact Profile 1: The smallest, base set of API packages including security, meant as a migration point for Java ME CDC developers and applications. It's about 11-12MB in footprint.
- Compact Profile 2: Built on compact profile 1, it adds XML, JDBC, and RMI. It's about 15MB in footprint.
- Compact Profile 3: Built on both compact profile 1 and compact profile 2, it adds support for management, naming (JNDI), additional security, and the compiler API most of Java SE. It's about 20MB in footprint
- Full JRE: Built on the three compact profiles inclusive, it adds the desktop APIs (Swing and so on), support for Web services, and CORBA APIs. It includes all of Java SE and has a footprint of about 48MB.
Additionally, there are sets of optional APIs and libraries that can be added to each compact profile. Using a new tool called "jrecreate," developers can build their own custom JRE by choosing a base profile, the JVM to use (small, client, or server), and any optional APIs that are to be added to the profile. This gives you control over custom sizing and tuning the JRE to more specifically meet your application needs. Overall, using the compact profiles results in shorter download and startup times, with reduced static and dynamic demands on the underlying system.
NetBeans 8.0 also includes built-in support for Java SE 8's compact profiles, where you can select the profile through your project's settings, see Figure 1.
The source editor also provides support and hints when you write code to show you only the available methods within your selected profile.
Choosing the appropriate compact profile based on a cross-section of your application's needs and target device capabilities, Java SE 8 allows embedded developers to share the same tools as server-side Java developers, including the Java Flight Recorder, the Java Serviceability Agent, and NetBeans.
JavaFX 8 and JavaFX for Embedded
Continuing on the embedded theme, Oracle has provided options for a scaled-down version of JavaFX with Java SE 8, called "JavaFX for Embedded." This graphics stack is built on top of Java SE 8 compact profile 1 with the small minimal VM, removes the need for an X Server or X11 library, and is about 18MB in size with the VM and libraries. It supports OpenGLES2, GPU-based hardware acceleration, and software-based acceleration if no GPU is present.
Beyond the embedded stack, the full-sized JavaFX 8 includes additional support for 3D rendering, rich text, a new Modena Theme for unification across platforms (Windows, Mac OS X, and Linux) that looks great out of the box on hi-res (retina) screens; improvements for HTML5 integration; a bunch of new UI controls such as
DatePicker; and multi-touch support for tablets and laptops that support it. Remember that although JavaFX doesn't officially run on an iPad yet ( there are ways to do it unofficially), it is supported and runs very well on Microsoft Surface Pro tablets and Windows 8 laptops with touch screen support, where the multi-touch capabilities come into play.
Take a deep breath as we complete our dive into the bevy of new features beyond Lambdas that are included with Java SE 8. Whereas we need to wait until JDK 9 for Java modularity to be completed, additions and improvements such as compact profiles and the new Metaspace in Java SE 8 should bring much needed customization and enhancement help for developers in the age of the Internet of Things (IoT).