<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Azul Systems - Medium]]></title>
        <description><![CDATA[Azul is exclusively focused on Java and the Java Virtual Machine (JVM). - Medium]]></description>
        <link>https://medium.com/azulsystems?source=rss----6649910540d3---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Azul Systems - Medium</title>
            <link>https://medium.com/azulsystems?source=rss----6649910540d3---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 09:02:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/azulsystems" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What’s next for JDK 12?]]></title>
            <link>https://medium.com/azulsystems/whats-next-for-jdk-12-c78f57ae316e?source=rss----6649910540d3---4</link>
            <guid isPermaLink="false">https://medium.com/p/c78f57ae316e</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Azul Systems]]></dc:creator>
            <pubDate>Thu, 25 Apr 2019 17:27:25 GMT</pubDate>
            <atom:updated>2019-04-25T17:27:25.688Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2C9V68IeW3SsT-cMieRSg.png" /></figure><p><a href="https://medium.com/u/ff649d6e025a">Simon Ritter</a>, Deputy CTO of Azul systems, has written several blog posts that list out all the changes for each of the most recent releases of Java (<a href="https://www.azul.com/109-new-features-in-jdk-10/">JDK 10</a>, <a href="https://www.azul.com/90-new-features-and-apis-in-jdk-11/">JDK 11</a>). With <a href="https://openjdk.java.net/projects/jdk/12/">JDK 12</a> just having been released, <a href="http://bit.ly/2uGqzQL"><strong>the following is an excerpt from his post “39 New Features (and APIs) in JDK12” which can be found here.</strong></a></p><h3>Overview</h3><p>As you may already know, we are now well into the new <a href="https://mreinhold.org/blog/forward-faster">six-monthly release cadence</a>. Simon represents Azul on the <a href="https://www.jcp.org/en/jsr/detail?id=386">Java SE JSR Expert Group</a>, and they decided to switch this version to <a href="https://www.jcp.org/en/procedures/jcp2_11">the revised JSR process</a>. This is not radically different, more of a streamlining of the process to fit into the available time more easily.</p><p>As you will see, JDK 12 clearly has the least new features of any Java release to date (I counted 109 in JDK 10 and 90 in JDK 11). This is most definitely not a negative; because of the time-driven delivery process, some versions will contain plenty of changes, some will provide less.</p><p>I’ll break things down into the obvious logical areas: Java language, libraries, JVM and other JDK features.</p><h3>Language Changes</h3><p>What I (and I assume many other people will) consider the most prominent new feature in JDK 12 is switch expressions (<a href="https://openjdk.java.net/jeps/325">JEP 325</a>). This is also the first language change to be included as a <em>preview language</em> <em>feature</em>. The idea of preview language features was introduced at the start of 2018, under <a href="https://openjdk.java.net/jeps/12">JEP 12</a>. Essentially, this is a way of including beta versions of new features. By doing this, it is still possible to make changes based on user feedback and, in an extreme case, remove the feature altogether if it is not well received. The key point about <em>preview</em> features is that they do not get included in the Java SE specification.</p><p>Prior to JDK 12, switch was a statement, which to give it a proper definition is a syntactic unit that expresses some action to be carried out. In JDK 12 it has become an expression, which evaluates the contents of the switch to produce a result. One thing to make clear straight away is that it does not impact backward compatibility, so you do not need to change any code you have that uses switch as a statement.</p><p>The reason for this change is that there is a widespread pattern in the use of switch. Frequently we use a switch to effectively map from the value being switched on to assigning the value of a variable. I’ll use the example from the JEP since that is both straightforward and easy to understand.</p><pre>int numLetters;<br>switch (day) {<br>   case MONDAY:<br>   case FRIDAY:<br>   case SUNDAY:<br>       numLetters = 6;<br>       break;<br>   case TUESDAY:<br>       numLetters = 7;<br>       break;<br>   case THURSDAY:<br>   case SATURDAY:<br>       numLetters = 8;<br>       break;<br>   case WEDNESDAY:<br>       numLetters = 9;<br>       break;<br>   default:<br>       throw new IllegalStateException(&quot;Huh? &quot; + day);<br>}</pre><p>As you can see, we’re mapping from the day of the week to the length of the name of that day, which is assigned to numLetters. Now that switch is a statement we can make the assignment once (reducing the potential for erroneous code greatly) using the result of the switch statement:</p><pre>int numLetters = switch (day) {<br>   case MONDAY, FRIDAY, SUNDAY -&gt; 6;<br>   case TUESDAY -&gt; 7;<br>   case THURSDAY, SATURDAY -&gt; 8;<br>   case WEDNESDAY -&gt; 9;<br>   default -&gt; throw new IllegalStateException(&quot;Huh? &quot; + day);<br>};</pre><p>Notice two important changes to the syntax we’re all used to.</p><p>First, we have finally moved away from each case needing to be separated. The OpenJDK developers have stumbled across a little know syntactic feature called a ‘comma separated list’.</p><p>Second, the Lambda expression operator, -&gt;, has been borrowed to simplify how we show what value to return from the switch. You can use break with a value if you really want to. There are a couple of other details about this feature which you can read about in the JEP.</p><h3>Changes to Java Libraries</h3><p>There is one change that I think is very useful. There are a number of minor ones as well.</p><p>The Streams API has a new Collector, as usual, provided by the Collectors utility class. The new collector can be obtained using the teeing() method. The teeing collector takes three arguments, two Collectors and a BiFunction. To understand what this does I’ve drawn a diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*5h5T_nH-yy_6xAX4.jpg" /></figure><p>All the values from the input stream are passed into each Collector. The result of each Collector is passed as arguments to the BiFunction to evaluate and generate a final result.</p><p>A simple example is one that calculates an average (yes, I know there are already Collectors for this like averagingInt(), but it’s an easy example to help understand the concept).</p><pre>/* Assume Collectors is statically imported */<br>double average = Stream.of(1, 4, 2, 7, 4, 6, 5)<br>    .collect(teeing(<br>        summingDouble(i -&gt; i), <br>        counting(),<br>        (sum, n) -&gt; sum / n));</pre><p>The first collector calculates the sum of the input stream while the second counts the number of elements. The BiFunction divides the sum by the element count to evaluate the average.</p><h4>java.io</h4><p>InputStream skipNBytes(long n): This skips over and discards exactly n bytes of data from this input stream. If n is zero or less, then no bytes are skipped.</p><h4>java.lang</h4><p>There is a new package, java.lang.constant, which is part of the <a href="https://openjdk.java.net/jeps/334">JVM Constants API, JEP 334</a>.</p><p>Every Java class file has a constant pool, which stores the operands for bytecode instructions in the class. For developers who want to manipulate class files (of which there won’t be that many), this is complicated because of issues around class loading. The JVM Constants API provides symbolic reference types to describe each form of constant (class, loadable constant, MethodHandle, MethodHandle constant and MethodType constant). There is also an enumeration for the kinds of MethodHandle that can be described and three classes for descriptions, one of which is the somewhat oxymoronic, DynamicConstantDesc (which is it, constant or dynamic? Surely it can’t be both).</p><p>This has also affected several other classes.</p><p>All the following classes now have a describeConstable() method:</p><ul><li>Class</li><li>Double</li><li>Enum</li><li>Float</li><li>Integer</li><li>Long</li><li>String</li><li>MethodHandle</li><li>MethodType</li><li>VarHandle</li></ul><p><em>Sidenote: As a Brit, I find this quite amusing. The term </em><a href="https://en.wikipedia.org/wiki/Constable"><em>Constable</em></a><em> has been used since the 11thCentury and is how we often refer to policemen. It is also the name of a famous 18thCentury artist, </em><a href="https://www.tate.org.uk/art/artists/john-constable-108"><em>John Constable</em></a><em>. It makes me wonder whether a future version will include a method, describeTurner().</em></p><p>Obviously, in this case, it is a contraction of Constant Table not referring to an officer of the law or a landscape artist.</p><p><strong>Update</strong>: It seems I am wrong in my assumption that Constable is a contraction of Constant Table. A poster on Reddit pointed out that it is something that can be represented in the constant pool, thus <em>const-able</em>. I’m happy to stand corrected, although it would be simpler if the API designers could avoid contractions of constant so that the confusion between whether it is <em>cons-table</em> or <em>const-able</em> is avoided.</p><p>The following classes now include a resolveConstantDesc() method</p><ul><li>Double</li><li>Enum.EnumDesc</li><li>Float</li><li>Integer</li><li>Long</li><li>String</li></ul><h4>java.lang.Character</h4><p>Inner classes have been updated to include new Unicode blocks. I always like to see what the Unicode people have found to add so here are some examples:</p><ul><li>Chess Symbols</li><li>Mayan numerals — An interesting base 20 numerical system</li><li>Sogdian — An Eastern Iranian language, which ceased to be used in the 11th Century.</li><li>Old Sogdian — An older (and, I suspect, of even more limited use) variation of Sogdian</li></ul><h4>java.lang.Class</h4><p>arrayType() returns a Class for an array type whose component type is described by this Class. Using jshell to test this shows:</p><pre>jshell&gt; (new String[2]).getClass().getName()<br>$11 ==&gt; &quot;[Ljava.lang.String;&quot;<br>jshell&gt; (new String[2]).getClass().arrayType()<br>$12 ==&gt; class [[Ljava.lang.String;<br>jshell&gt; &quot;foo&quot;.getClass().arrayType()<br>$15 ==&gt; class [Ljava.lang.String;</pre><p>I’m not totally sure what the point of this method is since all it does is prepend class [ to whatever type the Class represents.</p><p>componentType(), which is the same as getComponentType(), which begs the question, why add a redundant method?</p><p>descriptorString(). Again, this returns the same result as getName(). However, it is required as Class now implements the TypeDescriptor interface, which is related to the new JVM Constants API.</p><h4>java.lang.String</h4><p>indent(): adds a number of leading whitespace characters to the String. If the parameter is negative that number of leading whitespace characters will be removed (if possible).</p><p>transform(): Applies the provided function to the String. The result does not need to be a String.</p><h4>java.lang.invoke</h4><p>VarHandle now has a toString() method to return a compact description.</p><p>java.net.SecureCacheResponse and java.net.ssl.HttpsConnection both have a new method, getSSLSession(), which returns an Optional containing the SSLSession in use on the connection.</p><h4>java.nio.files</h4><p>The Files class has a new method, mismatch(), which finds and returns the position of the first mismatched byte in the content of two files, or -1L if there is no mismatch.</p><h4>java.text</h4><p>There is a new class, CompactNumberFormat. This is a subclass of NumberFormat that formats a decimal number in a compact form. An example of a compact form would be writing 1,000,000 as 1M, thus requiring two instead of nine characters. NumberFormat and java.text.spi.NumberFormatProvider have been extended to include a new method, getCompactNumberInstance(). There is also a related new enumeration, NumberFormatStyle, which has two values: LONG and SHORT.</p><h4>java.util.concurrent</h4><p>CompletionStage now include several overloaded forms of three methods:</p><ul><li>exceptionallyAsync</li><li>exceptionallyCompose</li><li>exceptionallyComposeAsync</li></ul><p>These methods extend how a new CompletionStage can be created from an existing CompletionStage if the current one completes exceptionally. Check the API documentation for the details.</p><h4>javax.crypto</h4><p>The Cipher class has a new toString() method, which returns a string containing the transformation, mode, and provider of the Cipher.</p><h4>javax.naming.ldap.spi</h4><p>This is a new package in JDK 12 and contains two classes, LdapDnsProvider, which is a service-provider class for DNS lookups when performing LDAP operations. LdapDnsProviderResults encapsulates the result of a DNS lookup for an LDAP URL.</p><h4>Swing</h4><p>Swing is still being updated! Yes, the filechooser.FileSystemView has a new catchy method, getChooserShortcutPanelFiles(). This returns an array of files representing the values to show by default in the file chooser shortcuts panel.</p><h3>Learn more about additional changes to JVM</h3><ol><li>JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector</li><li>JEP 344: Abortable Mixed Collections for G1JVM Changes</li><li>JEP 346: Promptly Return Unused Committed Memory from G1</li></ol><p>and other JDK features:</p><ol><li>JEP 230: Microbenchmarking Suite</li><li>JEP 340: One Aarch64 Port, Not Two</li></ol><p>By visiting the <a href="http://bit.ly/2uGqzQL">original post with additional perspective from Simon.</a></p><h3>Conclusions</h3><p>JDK 12 provides a small number of new features and APIs, with the switch expression being the most interesting to developers.</p><p>With the new release cadence, all users are advised to test their applications on this release. Keeping up with the gradual changes will avoid surprises if you decide to move to a subsequent long-term support release.</p><p>We have <a href="https://www.azul.com/downloads/zulu/">Zulu Community Edition builds of JDK 12 available completely free of charge</a> to help with your testing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c78f57ae316e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azulsystems/whats-next-for-jdk-12-c78f57ae316e">What’s next for JDK 12?</a> was originally published in <a href="https://medium.com/azulsystems">Azul Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using jlink to Build Java Runtimes for non-Modular Applications]]></title>
            <link>https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4?source=rss----6649910540d3---4</link>
            <guid isPermaLink="false">https://medium.com/p/9568c5e70ef4</guid>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Simon Ritter]]></dc:creator>
            <pubDate>Wed, 10 Oct 2018 10:55:41 GMT</pubDate>
            <atom:updated>2018-12-20T13:36:16.100Z</atom:updated>
            <content:encoded><![CDATA[<p>The most important new feature of <a href="http://openjdk.java.net/projects/jdk9/">JDK 9</a> was the <a href="https://jcp.org/en/jsr/detail?id=376">Java Platform Module System (JPMS)</a> that divided the monolithic rt.jar and tools.jar files into 75 distinct modules (at least in the <a href="http://openjdk.java.net/">OpenJDK</a>, the <a href="https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase9-3934878.html">Oracle JDK</a> contained a few more).</p><p>JDK 9 also eliminated the distinction between the Java Development Kit (JDK) and the Java Runtime Environment (JRE). In the past, there was a sub-directory in the JDK (unsurprisingly called jre) which only contained things that were required to run a Java application. On Linux, the full JDK 8 was 364 Mb, the JRE just 197 Mb. Users who were concerned about disk space could install the JRE and happily run their applications.</p><p>In JDK 9 and later, the idea is to build Java runtimes that are tailored to the requirements of a specific application. Rather than including all 75 modules, you need only include the <a href="https://docs.oracle.com/javase/9/docs/api/java.base-summary.html">java.base</a> module (which all runtimes must include by definition) as well as any other modules the application references. All transitive module dependencies must also be included. JDK 9 and later provides the <a href="https://docs.oracle.com/javase/9/tools/jlink.htm#JSWOR-GUID-CECAC52B-CFEE-46CB-8166-F17A8E9280E9">jlink</a> command to assemble and optimize a set of modules and their dependencies into a custom runtime image.</p><p>Many people, when moving an application from JDK 8 or earlier to JDK 11, do not want to have to take on the additional work of migrating application code to use modules. Fortunately, application code and external libraries can all be left on the classpath and treated as part of the unnamed module. For simple applications, you can use the same command to start the application as before.</p><p>However, the assumption is that, because jlink only works with modules that it can’t be used to generate a runtime image for non-module based applications.</p><p>This article will take you through the steps necessary to build significantly smaller Java runtimes for applications that have not been converted to use modules. In addition, since <a href="https://en.wikipedia.org/wiki/JavaFX">JavaFX</a> has been removed from the Oracle JDK (and was never part of OpenJDK binaries), we’ll include that in our application to demonstrate another part of using this tool.</p><p>The application we’ll be using is a simple data-entry application that presents a form to the user and then stores the fields into a MySQL database. How the application works is immaterial to this post so I won’t bother sharing the code.</p><p>The application was built using <a href="https://netbeans.org/">NetBeans</a>, which generates a <em>dist</em> directory that contains all the compiled code required to run the application. Since the application uses some libraries the layout looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUDE9y25LrOkz1Hi7fwGsw.jpeg" /></figure><h3>Using JavaFX with JDK 11</h3><p>To run the application on JDK 8, all that was required was</p><pre>java -jar FlightRecorder.jar</pre><p>If we run this application with JDK 9, we need to make no changes.</p><p>However, if we try this with JDK 11, we get the following error message:</p><pre>Error: Could not find or load main class flightrecorder.Main<br>Caused by: java.lang.NoClassDefFoundError: javafx/application/Application</pre><p>As I mentioned earlier, this is because neither the Oracle JDK nor OpenJDK binaries include JavaFX. Luckily, the nice people at <a href="https://gluonhq.com/products/javafx/">Gluon</a> provide free builds of the <a href="https://wiki.openjdk.java.net/display/OpenJFX/Main">OpenJFX</a> project, so it’s easy to resolve this issue.</p><p>To start, we need to download the <a href="https://gluonhq.com/products/javafx/">JavaFX SDK</a> and unzip it into a directory on our machine. For simplicity, we’ll put it in /opt. Next, we need a couple of extra command line flags:</p><pre>java --module-path /opt/javafx-sdk-11/lib --add-modules=javafx.controls -jar FlightRecorder.jar</pre><p>The two extra flags are:</p><ol><li>--module-path: Equivalent of the classpath, telling the JVM where to search for modules.</li><li>--add-modules: This specifies additional root modules to resolve. Because all the application code is on the classpath, we don’t have an initial module, so this option is required. We can specify this in two ways, either with an explicit list of modules as above, or we could indicate that everything on the module path is to be included by using the parameter ALL-MODULE-PATH.</li></ol><p>We now have an application that runs on JDK 11 using external JavaFX modules but with all application code still on the classpath.</p><h3>Building a Java Runtime</h3><p>In order to use jlink in this situation, we need to generate a list of the JDK modules that the application uses. To do this, we can use the <a href="https://docs.oracle.com/javase/9/tools/jdeps.htm#JSWOR690">jdeps</a> command that also comes with the JDK.</p><p>Interestingly, if we use the JDK 9 version of jdeps on the application we get this result:</p><pre>&gt; jdeps --list-deps FlightRecorder.jar<br>java.base<br>java.logging<br>java.sql<br>javafx.base<br>javafx.controls<br>javafx.graphics<br>not found<br>unnamed module: FlightRecorder.jar</pre><p>Most of this is fine but the ‘<em>not found</em>’ message is confusing and not very useful (what was not found?) Thankfully, jdeps was improved in JDK 10 so if we use the JDK 11 version we get the following:</p><pre>&gt; jdeps --list-deps FlightRecorder.jar<br>java.base<br>java.logging<br>java.sql</pre><p>Although this tells us which modules are used by the application, we’re missing some information. Remember, we’re providing the JavaFX modules separately so we need to analyse any JDK module dependencies they might have. The solution is to include the module details in the same way we did for the Java launcher:</p><pre>&gt; jdeps --module-path /opt/javafx-sdk-11/lib --add-modules=javafx.controls --list-deps FlightRecorder.jar<br>JDK removed internal API/com.sun.media.jfxmediaimpl.platform.ios<br>java.base<br>java.datatransfer<br>java.desktop/java.awt.dnd.peer<br>java.desktop/sun.awt<br>java.desktop/sun.awt.dnd<br>java.desktop/sun.swing<br>java.logging<br>java.scripting<br>java.sql<br>java.xml<br>jdk.jsobject<br>jdk.unsupported<br>jdk.unsupported.desktop<br>jdk.xml.dom</pre><p>I find this output a bit odd, as it includes more than just the module dependencies (which is what we asked for). In the case of (only) the java.desktop module we also get some extra information about the packages used. I also find the first message about the <em>JDK removed internal</em> somewhat confusing.</p><p>In theory, if we want an output that can be used directly in jlink, we can use the--print-module-deps flag instead of --list-dependencies. However, when I tried this on both MacOS X and Linux, I got a NullPointerException. Having posted a Tweet about this it has been <a href="https://bugs.openjdk.java.net/browse/JDK-8211887">submitted as a bug</a> and will hopefully be fixed soon (although it’s a P3 so it may be a while)</p><p>Now we are ready to use jlink to produce a runtime for the application.</p><pre>&gt; jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.datatransfer,java.desktop,java.logging,java.scripting,java.sql,java.xml,jdk.jsobject,jdk.unsupported,jdk.unsupported.desktop,jdk.xml.dom — output java-runtime</pre><p>To keep the size of the runtime as small as possible, we use command line flags to suppress the inclusion of header files and man pages as well as stripping the debug information and compressing to zip file format where relevant. The list of modules to include is the one generated by jdeps.</p><p>At this point, you would be forgiven for thinking that we can now run the application using our jlink generated runtime. However, if we try this here is the output:</p><pre>&gt; java-runtime/bin/java --module-path /opt/javafx-sdk-11/lib --add-modules=javafx.controls -jar FlightRecorder.jar<br>SEVERE: Error connecting to database<br>SEVERE: java.lang.NoClassDefFoundError: javax/naming/RefAddr</pre><p>This is because the application uses a MySQL JDBC driver packaged in the lib/mysql-connector-java-5.1.23-bin.jar file. Because this (and the two other jar files in the lib directory) are accessed via the classpath, they are not automatically analysed by jdeps. The jdeps command does allow you to specify a classpath via the -cp flag. Unfortunately, jdeps does not appear to use this to reference jar files that are required by the application. It is, therefore, necessary to make sure that all jar files used by the application are passed as arguments:</p><pre>&gt; jdeps --module-path /opt/javafx-sdk-11/lib --add-modules=javafx.controls --list-deps FlightRecorder.jar lib/*<br>JDK removed internal API/com.sun.media.jfxmediaimpl.platform.ios<br>java.base<br>java.datatransfer<br>java.desktop/java.awt.dnd.peer<br>java.desktop/sun.awt<br>java.desktop/sun.awt.dnd<br>java.desktop/sun.swing<br>java.logging<br>java.management<br>java.naming<br>java.rmi<br>java.scripting<br>java.sql<br>java.transaction.xa<br>java.xml<br>jdk.jsobject<br>jdk.unsupported<br>jdk.unsupported.desktop<br>jdk.xml.dom</pre><p>As you can see, we need to include a few more modules in our runtime. The command for jlink becomes:</p><pre>jlink --no-header-files --no-man-pages --add-modules java.datatransfer,java.desktop,java.logging,java.management,java.naming,java.rmi,java.scripting,java.sql,java.transaction.xa,java.xml,jdk.jsobject,jdk.unsupported,jdk.unsupported.desktop,jdk.xml.dom --output java-runtime</pre><p>The application now runs without any problems using the generated runtime. On my Mac, the java-runtime directory is a very respectable 39Mb, compared to 286Mb for the full JDK.</p><p>To simplify redistribution, we can copy the dist directory with the application jar files into the java-runtime directory, create a simple script to execute Java with all the appropriate command line flags and we are all good to go.</p><p>Why not try it with your applications?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9568c5e70ef4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4">Using jlink to Build Java Runtimes for non-Modular Applications</a> was originally published in <a href="https://medium.com/azulsystems">Azul Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Truly Final Optimization in Zing VM]]></title>
            <link>https://medium.com/azulsystems/truly-final-optimization-in-zing-vm-283d28418e55?source=rss----6649910540d3---4</link>
            <guid isPermaLink="false">https://medium.com/p/283d28418e55</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Anna Thomas]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 23:43:40 GMT</pubDate>
            <atom:updated>2018-09-19T23:43:39.930Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post is a condensed version of the talk presented at <a href="https://www.youtube.com/watch?v=2HfnaXND7-M&amp;frags=pl%2Cwn">JVM LS 2018</a>[1].</p><p>Zing is Azul’s <a href="https://www.azul.com/products/zing/">commercial flagship server-side JVM</a>. We have a couple of key features such as the C4 GC, an essentially pauseless <a href="https://www.azul.com/products/zing/readynow-technology-for-zing/">ReadyNow</a> technology that helps to eliminate warmup issues. And, as of early 2017, we productized <a href="https://www.youtube.com/watch?v=YsZ8ZfbCl30">Falcon</a>, which is our LLVM-based top-tier JIT. All of the truly final optimizations are implemented for the Falcon JIT compiler.</p><p>Let’s start with what the Java Language Spec (JLS) says about final fields. The JLS has a bunch of rules for final fields. The main one, is that a field that is declared final, is initialized once and it never changes under <em>normal</em> circumstances [<a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5">2</a>]. This lets the compiler do pretty aggressive optimizations such as moving the reads of final fields across synchronization barriers and across unknown calls. The final field can be cached in the register and not have to reload from memory.</p><p>Next, the JVM Spec (JVMS) also has couple of chapters on final fields. First, if a field is final it must be declared in the current class. Second, the putfield bytecode must occur in the init method of the class where the final field is declared, so this is within the lexical scope of the init method [3]. However, VMs tend to have a more relaxed rule around this, specifically the putfield bytecode can be in any method of that class, not just the init method. The reason VMs tend to have a relaxed rule is because they need to support real-world applications such as deserialization. Third, every field has got a <em>field-info</em> structure, and the ACC_FINAL flag in that struct is set to true for a final field.</p><p>There are two kinds of final fields. The first one is the static final. Here, the class variable itself is declared final, and it must be initialized in the static initializer (&lt;<em>clinit</em>&gt; method) of the defining class. The nice thing about static finals is that it does not need any sort of dependency tracking mechanism. They are trusted by default, except for certain fields in the java.lang.System class [2].</p><p>The trickier one is the instance final fields, and these are non-static variables that are declared final. The main thing is that a blank final must be assigned in every constructor of the class where it is declared [4]. The reasons instance final is tricky is because it’s not always final, even if it is declared so. Specifically, we can change the value of an instance final after construction through a couple of ways such as JNI, unsafe, reflection, deserialization and MethodHandles. Reflection and deserialization use unsafe as the underlying mechanism. MH’s default lookup mechanism does not allow to modify final fields, but the unreflectSetter API is specifically for modifying final fields.</p><p>As we can see for the most part, we can JIT compile code with the truly final optimizations turned on. However, if the field is changed through one of the ways stated above, we need to deoptimize the code that depended on the field being final and recompile code with truly final optimization turned OFF. In short, truly final optimization is a speculative or heroic optimization that needs its own dependency tracking mechanism.</p><h3>Implementing Dependency Tracking in Zing VM</h3><p>The first step is identifying finality, and we went ahead with the class-wide truly final tracking mechanism. This means that all final fields in a class are either trusted or untrusted together.</p><p>We have a truly final bit for a class, and this is set during verification. During verification we parse the byte codes of the method and we see that it satisfies the JLS rule, which is that all non-static final fields should be assigned in the constructor of the class, i.e. within the lexical scope of &lt;init&gt; method. If this rule is violated, the truly final bit of that class is set to false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dSHgnXxyx_u7OD1gCP9yA.png" /><figcaption><strong>Fig 1: Dependency Tracking Mechanism</strong></figcaption></figure><p>Dependency Tracking Mechanism (Fig 1) gives an idea of the process of dependency recording and invalidation. Let’s say that a method that uses a final field gets JIT compiled. The optimizer first checks whether the class that has this field has the truly final bit set and the field is actually final. Then, we need to record that dependency, because an optimization is true only as long as the dependency is true. Then we do the optimization. When we register the method, we need to install the dependencies along with the method, and then the method gets installed.</p><p>At the same time, or at a later time, let’s say that a final field gets modified. The first step is we need to set the truly final bit of that class, which contains the final field, to false, so that no later optimizations use this fact because it is no longer true. Next, we need to see if there were any other methods that depended on this field being final, and if there are other dependent methods we need to de-optimize these methods. This is the classic deoptimization as used for things like CHA. After we deoptimize these methods we will write the field. The deoptimization occurs on an installed method. Also, there can be a race between recording the dependencies and the dependency invalidation, so just before installing the dependencies we need to see if the truly final bit of that class is still true. If it is not true, then we need to throw away the compile and start re-compilation.</p><p>We added the deopt checks at relevant hooks such as unsafe, JNI, methodHandles. At those hooks, we need to traverse the dependent methods to check if that method had a truly final dependency. If we have even one method that has a truly final dependency, then we need to deoptimizate that method. The key thing to note here is that the writes must wait until we finish the deoptimization.</p><h3>Truly Final Optimizations</h3><p>The next part is the truly final optimizations we implemented for Falcon, our JIT LLVM based compiler. LLVM is a set of compiler libraries that operates on an intermediate representation called LLVM IR [5]. LLVM IR is SSA based typed IR.</p><p>In the Java VM, we have the C1 Compiler which acts as our lower-tier compiler and does profiling. Into this mix we add our bytecode front-end, which is essentially a parser. It converts the bytecode into LLVM IR. The LLVM optimizer is present outside of this VM, and here what we do is we pass this initial IR that’s generated by the bytecode front-end into the LLVM optimizer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBhHOkC2Ylmfnh8x3BFKdA.png" /><figcaption><strong>Fig 2: VM With LLVM Optimizer</strong></figcaption></figure><p>The LLVM Optimizer tries to optimize the initial IR provided. In the process, it asks the VM certain questions and VM responds with answers. The optimizer uses this information and optimizes the code better. It generates a final IR that is passed to the X86 backend and converted into assembly. The method is then installed.</p><p>The final field optimizations are constant folding of compile time constants, then redundant load elimination of final fields; this is across non-aliasing stores, across synchronization barriers, and across unknown calls.</p><p>Let us start with a constant folding example shown in Fig 3. This is pseudo-code with JMH notations. TrulyFinal class has a final primitive i that is assigned the value 10. The benchmark we are interested in is test which loads i from a static final object tf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Fll-xTjegc12OmqBjALSg.png" /><figcaption><strong>Fig 3: Constant Folding Example</strong></figcaption></figure><p>The (pseudo) LLVM IR test method gets lowered into is:</p><pre>%ref = load i8* , i8** @<strong>known_value<br></strong>%addr = getelementptr i8, i8* %ref, i32 <strong>16<br></strong>%i = load i32, i32* (cast&lt;i8* to i32*&gt; %addr)<br>ret i32 %i</pre><p>Since LLVM IR is type-based IR, we have types such as i32 which represent 32 byte integers. Our bytecode parser also tags compile time constants, i.e. static final variables as known_value. Then we are accessing 16 bytes off the known_value, and then we are loading i and returning the result.</p><p>The LLVM optimizer sees this known_value and the load following it, so it asks the VM: “<em>Can we get the result of this known value load?” </em>The VM answers “<em>yes, it is 10.” </em>So, the optimizer uses this result and simplifies the final IR to:</p><pre>ret i32 10</pre><p>The VM callback is a complete black box for the LLVM optimizer. The VM operates on the arguments passed in and does the recording of the truly final dependency we talked about earlier. In this case, the callback is GET RESULT OF KNOWN VALUE LOAD(KV ID, OFFSET, SIZE). In the callback, we retrieve the object corresponding to the KVID and get the field based on the OFFSET specified. After checking if the field is final (and recording that truly final dependency), we retrieve the constant value corresponding to that field.</p><p>The next example we look at is redundant loads of final fields within a constant region. In Fig 4, we have the pseudo-code where the benchmark of interest is the test function. We have the load of an instance final object utf and a load of a final primitive var within it. We again reload the same var but the loads are separated by a store to a volatile variable k. Since, volatiles introduce memory barriers, we have a strict ordering of loads and stores before and after the memory barrier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wPmnTILRPS7xUPZnaVaUXw.png" /><figcaption><strong>Fig 4: Truly Final loads in Constant Region</strong></figcaption></figure><p>This is the test LLVM IR:</p><pre>%<strong>ref</strong> = <strong>load</strong> i8*, i8** %<strong>addr<br></strong>%addr = getelementptr i8, i8* %<strong>ref</strong>, i32 <strong>16<br></strong>%var = <strong>load</strong> i32, i32* (cast&lt;i8* to i32*&gt; %addr)<br>%kref = load i8*, i8** %<strong>addr_k<br></strong>%addr = getelementptr i8, i8* %kref, i32 <strong>816<br>fence<br></strong>store i32 3, i32* (cast&lt;i8* to i32*&gt; %addr)<br>%<strong>refdup</strong> = <strong>load</strong> i8*, i8** %<strong>addr<br></strong>%addr1 = getelementptr i8, i8* %<strong>refdup</strong>, i32 <strong>16<br></strong>%tmp = <strong>load</strong> i32, i32* (cast&lt;i8* to i32*&gt; %addr1)<br>%res = <strong>sub</strong> i32 %var, %tmp<br>ret %res</pre><p>We have the load of the object utf, which is not a known_value. Then we load var at 16 bytes from that object. In LLVM IR, memory barriers are represented using fence instruction. We store to the volatile k and then we reload the object utf and var again and subtract both the loads of var. Since, both the object and the primitive loaded from that object are truly final, we know that the result should be zero. How does the optimizer figure this out?</p><p>First, the optimizer checks that the object has already been initialized, and then asks the VM about the caller property because the region that we are interested in here is the caller that is the test function. It asks the VM, “<em>Is the ref field modified in the test function?</em>” We parse in the type of the field, the offset, the size, and the caller. The VM responds, “<em>No, it is not modified</em>” which means that we are now allowed to get rid of the second load of that reference field refdup. The IR gets reduced to:</p><pre>%<strong>ref</strong> = <strong>load</strong> i8*, i8** %<strong>addr<br></strong>%addr = getelementptr i8, i8* %<strong>ref</strong>, i32 <strong>16<br></strong>%var = <strong>load</strong> i32, i32* (cast&lt;i8* to i32*&gt; %addr)<br>%kref = load i8*, i8** %<strong>addr_k<br></strong>%addr = getelementptr i8, i8* %kref, i32 <strong>816<br>fence<br></strong>store i32 3, i32* (cast&lt;i8* to i32*&gt; %addr)<br>%addr1 = getelementptr i8, i8* %<strong>ref</strong>, i32 <strong>16<br></strong>%tmp = <strong>load</strong> i32, i32* (cast&lt;i8* to i32*&gt; %addr1)<br>%res = <strong>sub</strong> i32 %var, %tmp<br>ret %res</pre><p>Then the optimizer <em>recursively</em> asks the VM about the second load of the primitive final var. “<em>Is var modified in the test function</em>”. VM again responds “<em>No, it is not modified</em>”. This identifies the second var load is redundant as well. We are finally left with the code, where all we have is a store to the volatile field and a return of zero, so we were able to get rid of four loads in the IR:</p><pre>%kref = load i8*, i8** %<strong>addr_k<br></strong>%addr = getelementptr i8, i8* %kref, i32 <strong>816<br>fence<br></strong>store i32 3, i32* (cast&lt;i8* to i32*&gt; %addr)<br>ret i32 0</pre><p>The VM callback for this optimization is IS MODIFIED IN REGION(TYPE, OFFSET, SIZE, REGION). The REGION here is test. In the callback implementation on the VM side, we check if REGION is the dynamic scope of the constructor that can modify the klass corresponding to TYPE. If it’s not then we go ahead and we extract the field from that offset and we check if that field is constant. Then, we record the dependency if that field is final and we say that, because it’s a final field and the region is not a constructor, it is not modified in that region.</p><p>The redundant load elimination across unknown calls follow along the same lines as the constant region optimization. It uses the same callback, but the region we are interested in, is the <em>unknown callee. </em>More details are available in the talk online.</p><h3>Performance</h3><p>Let us consider a real JMH microbenchmark example and how it performs with the Zing VM with truly final optimization. In Fig 5, we see a final array sumMeUpFinal, which is summed up in the benchmark sumFinal. Within the loop in sumFinal, we have a volatile load for mask in every iteration of the loop. We also have the null check on the final array and the invariant load of length of the sumMeUpFinal array. On a VM without truly final optimization, we will have to do the null check and the load of length on every iteration of the loop. Since Zing VM has support for truly final optimization, we are able to hoist the null check and the load of the length of that array out of the loop through loop invariant code-motion, and we are able to get rid of all these instructions within the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOKqj9ZGZAygQ1qYdIqWvw.png" /><figcaption><strong>Fig 5: JMH Truly Final Example</strong></figcaption></figure><p>When run on skylake Intel(R) Xeon(R) CPU E3–1220 v5 @ 3.00GHz, there is a <strong>2.5 X gain</strong> with Zing 18.04 when compared to Zing with the truly final optimizations turned off.</p><p>We also ran experiments to see how the truly final optimizations perform on real world applications. Fig 6 shows the results on skylake and broadwell machines over 90 benchmarks (the dots on the graph represent the benchmarks). The benchmarks are Specjvm, Dacapo, <a href="https://kafka.apache.org/">Kafka</a>, and certain application benchmarks. The baseline at 100% represents the truly final optimizations turned off. The green dot represents the gains that we see with truly final optimizations turned on. The blue and the green dots that’s close to the baseline are essentially variation. The key point here is that we have around 27% of the benchmarks that have gains between 2–11% with truly final optimizations turned on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KS8dyi9AQHgXN8VutpjyFw.png" /><figcaption><strong>Fig 6: Performance with Truly Final Optimizations</strong></figcaption></figure><p>In summary, final non-static fields are not always final and because of this we need dependency tracking and invalidation mechanism. We have optimizations for final fields that are implemented both for reference final and primitive finals. We see non-trivial gains across microbenchmarks and real world applications with truly final optimizations, and the gains that we see are usually from constant folding and better aliasing.</p><h3>References</h3><p>[1] <a href="https://www.youtube.com/watch?v=2HfnaXND7-M&amp;frags=pl%2Cwn">https://www.youtube.com/watch?v=2HfnaXND7-M&amp;frags=pl%2Cwn</a></p><p>[2] <a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.5">https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5</a></p><p>[3] <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.putfield">https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.putfield</a></p><p>[4] <a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.2">https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.2</a></p><p>[5] <a href="https://llvm.org/">https://llvm.org</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=283d28418e55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azulsystems/truly-final-optimization-in-zing-vm-283d28418e55">Truly Final Optimization in Zing VM</a> was originally published in <a href="https://medium.com/azulsystems">Azul Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azul Systems Launches a Tech Blog!]]></title>
            <link>https://medium.com/azulsystems/azul-systems-launches-a-tech-blog-e2f9a81f74f7?source=rss----6649910540d3---4</link>
            <guid isPermaLink="false">https://medium.com/p/e2f9a81f74f7</guid>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Azul Systems]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 00:23:31 GMT</pubDate>
            <atom:updated>2018-08-24T18:55:57.751Z</atom:updated>
            <content:encoded><![CDATA[<p>What do we know about <a href="https://www.azul.com/">Azul Systems</a>? We know that it’s <a href="https://www.azul.com/about-us/company-profile/">a company</a> that knows its stuff about <a href="https://vimeo.com/286260342">Java, JVM, and low latency garbage collection</a>.</p><p>Because our team is made up of Java experts, we thought it time to showcase their expertise and give the <em>developer ecosystem</em> a place to read and give feedback around topics of interest in the Java ecosystem.</p><h3>Meet the Team &amp; Engage</h3><p>Do you know any of our star developers (mind you, many are not listed here and are amazing, valuable members to the Azul Systems team!)? If not, here are some you may like to connect with or chat with at events:</p><p><strong>Sergey Grinev</strong>, Principal Software Engineer. Twitter: <a href="https://twitter.com/SergeyGrinev">@sergeygrinev</a></p><p><strong>Doug Hawkins</strong>, JVM Development Manager. Twitter: <a href="https://twitter.com/dougqh">@dougqh</a></p><p><strong>Ivan Krylov</strong>, Senior Software Engineer. Twitter: <a href="https://twitter.com/JohnWings">@JohnWings</a></p><p><a href="https://twitter.com/speakjava"><strong>Simon Ritter,</strong></a> Deputy CTO. Twitter: <a href="https://twitter.com/speakjava">@speakjava</a></p><p><a href="https://www.linkedin.com/in/giltene/"><strong>Gil Tene</strong></a>, CTO and Co-founder. Twitter: <a href="https://twitter.com/giltene">@giltene</a></p><p>We encourage you to give us a follow, let us know what topics you’d like us to write about if we don’t already cover them, and to please find us at the following events.</p><h3><strong>Let’s hang!</strong></h3><p>Here’s where we’ll be for the rest of 2018:</p><p><strong>[London, Sept. 6]</strong> <a href="https://www.eventbrite.co.uk/e/reactive-java-jdk9-10-11-and-beyond-delivering-new-features-to-the-jdk-tickets-48832978754">Reactive Java &amp; JDK9, 10, 11 and Beyond: Delivering New Features to the JDK</a>! This is a Meetup-stylie, with Simon and others, who will be sharing expertise about the JDK, OpenJDK, and Java.</p><p><strong>[Oslo, Norway. Sept. 12] </strong><a href="https://2018.javazone.no/program/c66bc3b6-77b2-48a5-8114-6a6a0527294f">JavaZone 2018</a>! <a href="https://twitter.com/speakjava">Simon</a> will be there as will Douglas, who will speak about “<a href="https://2018.javazone.no/program/0a068531-a857-4eb7-bd57-3c5b88c2cd86">ReadyNow, Azul System’s Unconventional AOT.</a>” Ping us on Twitter or email us at [community at azul dot com] to connect!</p><p><strong>[San Francisco, CA. Sept. 14] </strong><a href="http://distributeddatasummit.com/">Distributed Data Summit</a>! Several members of the team will be at this one, so let’s have a solid cup of coffee together, and chat about…Java. [We won’t go there with the coffee n’ Java joke, wait, we just went there.]</p><p><strong>[Washington, DC. Sept. 24] </strong><a href="https://www.azul.com/events/pivotal-springone-platform/">Pivotal SpringOne Platform</a>. It’s a big Pivotal party! Let’s hang.</p><p><strong>[London. Oct. 9]</strong> <a href="https://jaxlondon.com/program/">JAX London</a>: The Conference for Java and Software Innovation.</p><p><strong>[San Francisco, CA. Oct. 25–28] </strong><a href="https://www.oracle.com/code-one/agenda.html">Oracle Code One 2018</a>. We’ll be here: speaking, socializing, doing all that you’d expect at Oracle Code One! We’re excited to hang with the other Java Champions, users and contributors, so please let us know if you’ll also be there and want to raise a glass together!</p><p><strong>[Ludwigsburg, Germany. Oct. 22–25] </strong><a href="https://www.eclipsecon.org/europe2018">EclipseCon Europe 2018</a>.</p><p><strong>[San Francisco, CA. Nov. 5–9] </strong><a href="https://qconsf.com/">QCon San Francisco</a>.<strong> </strong>It’s great to wind down the year with other Java Rockstars at QCon. If you want to take a walk onthe Embarcadero, and share what projects you’re working on, how you’re contributing to <a href="https://www.azul.com/products/zulu-and-zulu-enterprise/">Zulu JDK</a> or OpenJDK or using Java, we’d love to spend time with you. Drop us a line: community at azul dot com.</p><p>Ok, folks! What you can expect from us in the near future, is output through this vehicle. That of <em>high quality technical posts about what we’re great at: creating world class Java and Java Virtual Machine (JVM) solutions</em>. If there are any particular topics in this scope you’d like us to write about, please let us know. Until then, follow us, ping to connect at the upcoming events we’ll both be at, and take good care!</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2f9a81f74f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azulsystems/azul-systems-launches-a-tech-blog-e2f9a81f74f7">Azul Systems Launches a Tech Blog!</a> was originally published in <a href="https://medium.com/azulsystems">Azul Systems</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>