{"id":1215,"date":"2021-01-29T11:31:02","date_gmt":"2021-01-29T10:31:02","guid":{"rendered":"https:\/\/www.loicmathieu.fr\/wordpress\/?p=1215"},"modified":"2021-02-23T13:09:21","modified_gmt":"2021-02-23T12:09:21","slug":"java-16-quoi-de-neuf","status":"publish","type":"post","link":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-16-quoi-de-neuf\/","title":{"rendered":"Java 16 : what&#8217;s new ?"},"content":{"rendered":"<p>Now that Java 16 is features complete (Rampdown Phase Two at the day of writing), it\u2019s time to walk throught all the functionalities that brings to us, developers, this new version.<\/p>\n<p>This article is part of a series on <a href=\"https:\/\/www.loicmathieu.fr\/wordpress\/tag\/whatsnew\/\">what\u2019s new on the last versions of Java<\/a>, for those who wants to read the others, here are the links : <a href=\"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-15-quoi-de-neuf\/\">Java 15<\/a>,, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-14-quoi-de-neuf\/\">Java 14<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-13-quoi-de-neuf\/\">Java 13<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-12-quoi-de-neuf\/\">Java 12<\/a>, <a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-11-quoi-de-neuf\/\">Java 11<\/a>,\u00a0<a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-10-quoi-de-neuf\/\">Java 10,<\/a>\u00a0and\u00a0<a href=\"http:\/\/www.loicmathieu.fr\/wordpress\/informatique\/les-nouveautes-de-java-9-pour-les-developeurs\/\">Java 9<\/a>.<\/p>\n<p>This new version counts no less than 17 JEPs, but above all, sees the <strong>Records<\/strong> and the pattern matching for <strong>instanceof<\/strong> going out of preview and that&#8217;s good news!<\/p>\n<h2>JEP 380: Unix-Domain Socket Channels<\/h2>\n<p>First of all, a small description of what a Unix-Domain socket is:<\/p>\n<blockquote>Unix-Domain sockets are used for inter-process communication (IPC) on the same host. They are similar to TCP\/IP sockets in many ways, except that they are addressed by filesystem path rather than by IP addresses and port numbers.<\/blockquote>\n<p>The <code>SocketChannel<\/code> and <code>ServerSocketChannel<\/code> classes can now be created from a Unix-Domain socket.<\/p>\n<p>Example (non tested):<\/p>\n<pre>\nServerSocketChannel serverSocketChannel = ServerSocketChannel.open();\nserverSocketChannel.socket().bind(UnixDomainSocketAddress.of(\"path\/to\/socket\/file\");\nwhile(true){\n    SocketChannel socketChannel = serverSocketChannel.accept();\n    \/\/do something with socketChannel...\n}\n<\/pre>\n<p>More info : <a href=\"https:\/\/openjdk.java.net\/jeps\/380\" rel=\"noopener\" target=\"_blank\">JEP-380<\/a>.<\/p>\n<h2>JEP 338: Vector API (Incubator)<\/h2>\n<p>Vector API is a new API which allows to express vector calculations (matrix calculation among others), which will be executed via optimal machine instructions depending on the execution platform.\nThese optimizations include changes within the Just In Time compiler, intrinsics, and use of AVX\/SSE instructions of CPUs which allow vectorization of calculations (SIMD type instructions &#8211; Single Instruction Multiple Data).<\/p>\n<p>The JEP contains the following example, implemented before the Vector API by:<\/p>\n<pre>\nvoid scalarComputation(float[] a, float[] b, float[] c) {\n   for (int i = 0; i <\/pre>\n<p>And with the Vector API by:<\/p>\n<pre>\nstatic final VectorSpecies SPECIES = FloatVector.SPECIES_256;\n\nvoid vectorComputation(float[] a, float[] b, float[] c) {\n\n    for (int i = 0; i <\/pre>\n<p>We use here a <code>FloatVector.SPECIES_256<\/code> which allows to manage float vectors on 256 bits. The <code>mul<\/code>, <code>add<\/code>and<code> neg <\/code> operations will therefore be done via SIMD instructions on 256 bits instead of being done individually on each float.<\/p>\n<p>More info : <a href=\"https:\/\/openjdk.java.net\/jeps\/338\" rel=\"noopener\" target=\"_blank\">JEP-338<\/a>.<\/p>\n<h2>JEP 389: Foreign Linker API (Incubator)<\/h2>\n<p>With the JEP-393 Foreign-Memory API, which allows you to manage memory segments (on heap or off heap), this new functionality lays the foundations for the project <a href=\"https:\/\/openjdk.java.net\/projects\/panama\">Panama<\/a> by allowing the interconnection of the JVM with native code.<\/p>\n<p>The Foreign Linker API makes it possible to call native code (in C for example) in an easy and performant way.<\/p>\n<p>Here is an example of calling the <code>strlen<\/code> function of the standard C library:<\/p>\n<pre>\nMethodHandle strlen = CLinker.getInstance().downcallHandle(\n        LibraryLookup.ofDefault().lookup(\"strlen\").get(),\n        MethodType.methodType(long.class, MemoryAddress.class),\n        FunctionDescriptor.of(C_LONG, C_POINTER)\n);\n\nlong len = strlen.invokeExact(CLinker.toCString(\"Hello\").address())\n<\/pre>\n<p>More information on native function calls in this article by Maurizio Cimadamore: <a href=\"https:\/\/cr.openjdk.java.net\/~mcimadamore\/panama\/ffi.html\" rel=\"noopener\" target=\"_blank\">State of foreign function support<\/a>.<\/p>\n<p>This code may seem a bit complex, that&#8217;s why <strong>jextract<\/strong> was created, which allows you to extract the code necessary to call a C library automatically from a C header file .<\/p>\n<p>Example for calling the <code>getpid<\/code> method of the C standard library:<\/p>\n<pre>\necho \"int getpid();\" &gt; getpid.h\njextract -t com.unix getpid.h\n<\/pre>\n<pre>\nimport static com.unix.getpid_h.*;\n\nclass Main2 {\n   public static void main(String[] args) {\n      System.out.println(getpid());\n  }\n}\n<\/pre>\n<p>More information on <strong>jextract<\/strong> in this article, by Sundar Athijegannathan: <a href=\"https:\/\/inside.java\/2020\/10\/06\/jextract\/\" rel=\"noopener\" target=\"_blank\">Project Panama and jextract<\/a>.<\/p>\n<h2>Two new ports of the JVM<\/h2>\n<p>OpenJDK 16 adds Alpine Linux support and thus <a href=\"https:\/\/musl.libc.org\/\" rel=\"noopener\" target=\"_blank\">Musl<\/a> as implementation of the C standard library for x64 and AArch64 architectures. More information in the <a href=\"https:\/\/openjdk.java.net\/jeps\/386\" rel=\"noopener\" target=\"_blank\">JEP-386<\/a>.<\/p>\n<p>OpenJDK 16 also adds support for the AArch64 architecture on Windows (previously only supported on Linux) via the <a href=\"https:\/\/openjdk.java.net\/jeps\/388\" rel=\"noopener\" target=\"_blank\">JEP 388<\/a>. MacOS support on this architecture is in progress and will certainly be delivered in a future version of Java, see <a href=\"https:\/\/openjdk.java.net\/jeps\/391\" rel=\"noopener\" target=\"_blank\">JEP 391<\/a>.<\/p>\n<h2>Functionalities that go from preview to standard<\/h2>\n<p>The following functionalities, which were in preview (or incubator module), are now standard.\nFor details about them you can refer to my previous articles.<\/p>\n<ul><li><a href=\"https:\/\/openjdk.java.net\/jeps\/392\" rel=\"noopener\" target=\"_blank\">JEP 392<\/a> : Packaging Tool.<\/li>\n\n<li><a href=\"https:\/\/openjdk.java.net\/jeps\/394\" rel=\"noopener\" target=\"_blank\">JEP 394<\/a> : Pattern Matching for instanceof.<\/li>\n\n<li><a href=\"https:\/\/openjdk.java.net\/jeps\/395\" rel=\"noopener\" target=\"_blank\">JEP 395<\/a>: Records.<\/li>\n<\/ul>\n<h2>Functionalities that stay in preview<\/h2>\n<p>The following functionalities remain in preview (or incubator module).\nFor details about them you can refer to my previous articles.<\/p>\n<ul><li><a href=\"https:\/\/openjdk.java.net\/jeps\/393\" rel=\"noopener\" target=\"_blank\">JEP 393<\/a> : Foreign-Memory Access API (Third Incubator)<\/li>\n\n<li><a href=\"https:\/\/openjdk.java.net\/jeps\/397\" rel=\"noopener\" target=\"_blank\">JEP 397<\/a> : Sealed Classes (Second Preview)<\/li>\n<\/ul>\n<h2>Miscellaneous<\/h2>\n<p>Various additions to the JDK :<\/p>\n<ul><li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8238286\" rel=\"noopener\" target=\"_blank\">JDK-8238286<\/a> : Stream.mapMulti() : allows to map an element <code>T<\/code> into n elements <code>R<\/code> via a <code>Consumer&lt;R&gt;<\/code><\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8180352\" rel=\"noopener\" target=\"_blank\">JDK-8180352<\/a> : Stream.toList() : accumulates the elements of the Stream in an immutable list.<\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8255150\" rel=\"noopener\" target=\"_blank\">JDK-8255150<\/a> : Adds utility methods to check the range of a long index : <code>Objects.checkIndex(long index, long length)<\/code>, <code>Objects.checkFromToIndex(long fromIndex, long toIndex, long length)<\/code>, <code>Objects.checkFromIndexSize(long fromIndex, long size, long length)<\/code>. These new methods are optimized through the addition of intrinsics.<\/li>\n<\/ul>\n<p>During the modularization of the JDK via the Jigsaw project, some internal APIs of the JDK that should not be usable outside of it were nevertheless made usable (for lack of alternatives, or to give applications using them a migration time). This has been called <a href=\"https:\/\/openjdk.java.net\/jeps\/261#Relaxed-strong-encapsulation\" rel=\"noopener\" target=\"_blank\">Relaxed Strong Encapsulation<\/a>. A simple WARNING was displayed in the JVM logs the first time these APIs were used (behaviour that can be modified via <code>--illegal-access<\/code>). With the <a href=\"https:\/\/openjdk.java.net\/jeps\/396\" rel=\"noopener\" target=\"_blank\">JEP 396<\/a> : Strongly Encapsulate JDK Internals by Default, access to these APIs (which almost all have an official replacement in the JDK), is now forbidden by default. The default value of the flag <code>--illegal-access<\/code> therefore changes from <code>permit<\/code> to <code>deny<\/code>. The flag is always present and can be modified to return to the previous behavior if necessary.<\/p>\n<p>A change in preparation for inline classes of project Valhalla: <a href=\"https:\/\/openjdk.java.net\/jeps\/390\" rel=\"noopener\" target=\"_blank\">JEP 390<\/a> : Warnings for Value-Based Classes. Some JDK classes are called <strong>Value-Based Classes<\/strong>, these classes are only vehicles for data (data carier), and are therefore likely to be transformed into Inline Classes when the Valhalla project will be released. This is the case for example of the Optional class or wrappers on primitives.<\/p>\n<p>Starting from Java 16, the use of these classes in a way incompatible with inline classes will generate warnings: use of constructors (which are deprecated), synchronization, incorrect use of the == or the !=.<\/p>\n<h2>Performance<\/h2>\n<p>Many intrinsics have been added to the JVM:<\/p>\n<ul><li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8250902\" rel=\"noopener\" target=\"_blank\">JDK-8250902<\/a> : MD5 intrinsic.<\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8248188\" rel=\"noopener\" target=\"_blank\">JDK-8248188<\/a> : Base64 intrinsic. <\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8173585\" rel=\"noopener\" target=\"_blank\">JDK-8173585<\/a> : Intrinsic pour StringLatin1.indexOf(char).<\/li>\n\n<li>Dedicated intrinsics for AArch64 (already present on other platforms): <a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8173585\" rel=\"noopener\" target=\"_blank\">JDK-8173585<\/a>, <a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8173585\" rel=\"noopener\" target=\"_blank\">JDK-8173585<\/a>, <a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8173585\" rel=\"noopener\" target=\"_blank\">JDK-8173585<\/a>.<\/li>\n<\/ul>\n<h2>Startup time<\/h2>\n<p>Java 16 has seen its share of JVM startup time optimizations. Claes Redestad, one of the Oracle engineers working on the subject, has written a rather interesting article which takes up the different optimizations of the JVM startup time since Java 8 and asks the question of the optimizations still to be done for Java 17: <a href=\"https:\/\/cl4es.github.io\/2020\/12\/06\/Towards-OpenJDK-17.html\" rel=\"noopener\" target=\"_blank\">Towards OpenJDK 17<\/a>.<\/p>\n<p>Release after release, the JVM startup time has been almost halved since Java 8 (after a significant increase in Java 9 following the introduction of modules). Knowing that a JVM starts in less than 40ms, Claes wonders if it is still necessary to work on this subject?<\/p>\n<p>As for Java 16, we can note, among other things, many improvements in the CDS functionality:<\/p>\n<ul><li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8244778\" rel=\"noopener\" target=\"_blank\">JDK-8244778<\/a> : Archive full module graph in CDS<\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8247536\" rel=\"noopener\" target=\"_blank\">JDK-8247536<\/a> : Support for pre-generated java.lang.invoke classes in CDS static archive<\/li>\n\n<li><a href=\"https:\/\/bugs.openjdk.java.net\/browse\/JDK-8247666\" rel=\"noopener\" target=\"_blank\">JDK-8247666<\/a> : Support Lambda proxy classes in static CDS archive<\/li>\n<\/ul>\n<p>CDS &#8211; Class Data Sharing, allows to save in an archive the classes metadata when the JVM is launched, in order to reuse them during successive launches, thus optimizing the JVM startup time.\nYou can find more information in my article <a href=\"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/quarkus-jlink-et-application-class-data-sharing-appcds\/\" rel=\"noopener\" target=\"_blank\">QUARKUS, JLINK AND APPLICATION CLASS DATA SHARING (APPCDS)<\/a>.<\/p>\n<p>The JVM contains a default archive with the metadata of certain classes from JDK, so changes to the CDS functionality automatically benefit to everyone.<\/p>","protected":false},"excerpt":{"rendered":"<p>Now that Java 16 is features complete (Rampdown Phase Two at the day of writing), it\u2019s time to walk throught all the functionalities that brings to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who wants to read the others, here are the links : Java 15,, Java 14, Java 13, Java 12, Java 11,\u00a0Java 10,\u00a0and\u00a0Java 9. This new version counts no less than 17&#8230;<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-16-quoi-de-neuf\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[11,191,163],"class_list":["post-1215","post","type-post","status-publish","format-standard","hentry","category-informatique","tag-java","tag-java16","tag-whatsnew"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":856,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-next\/","url_meta":{"origin":1215,"position":0},"title":"Java.Next","author":"admin","date":"Wednesday October 31st, 2018","format":false,"excerpt":"Ma premi\u00e8re contribution au blog de Zenika est un article qui parle du futur (ou du pr\u00e9sent) de Java et des changement pour les d\u00e9veloppeurs des version 9, 10 et 11. La gouvernance de Java y est aussi abord\u00e9. Cet article reprend et r\u00e9sume les articles que j'ai pr\u00e9c\u00e9dement \u00e9crit\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":829,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-11-quoi-de-neuf\/","url_meta":{"origin":1215,"position":1},"title":"Java 11  : what\u2019s new ?","author":"admin","date":"Monday October  1st, 2018","format":false,"excerpt":"Now that Java 11 is out, it is time to look at the new features that this version brings to us, developers. This article is part of a series on what\u2019s new on the last versions of Java, for those who wants to read the others, here are the links\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":712,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/demarrage-jvm-8-vs-9\/","url_meta":{"origin":1215,"position":2},"title":"D\u00e9marrage JVM 8 vs 9","author":"admin","date":"Thursday August 31st, 2017","format":false,"excerpt":"Introduction En parcourant la mailing liste d'open JDK (core-lib-dev) j'ai vu plusieurs threads de mail \u00e0 propos d'optimisation de temps de d\u00e9marrage et d'occupation m\u00e9moire d'une JVM \"minimale\". Ce travail a \u00e9t\u00e9 r\u00e9alis\u00e9 en grande partie par Claes Redestad (Oracle) lors du d\u00e9veloppement de Java 9. J'ai donc d\u00e9cid\u00e9 de\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":722,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-10-quoi-de-neuf\/","url_meta":{"origin":1215,"position":3},"title":"Java 10 : what&#8217;s new ?","author":"admin","date":"Monday March 26th, 2018","format":false,"excerpt":"Now that java 10 is out, it's time to look at all the new functionalities of this version. Like my previous article on Java 9, I will focus on the changes that will impact developers that uses Java leaving aside the changes that are internal\/very small\/on rarely used API. The\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1839,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-vers-une-integrite-par-defaut-de-la-jvm\/","url_meta":{"origin":1215,"position":4},"title":"Java: towards JVM integrity by default","author":"admin","date":"Tuesday February  4th, 2025","format":false,"excerpt":"This article first appeared in Programmez! Hors s\u00e9rie #16 (in french only). The Java Virtual Machine (JVM) is an execution environment that enables programs written in Java (or other languages compiled into Java bytecode) to run on different operating systems and hardware architectures. From the begining, the JVM was designed\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1112,"url":"https:\/\/www.loicmathieu.fr\/wordpress\/informatique\/java-15-quoi-de-neuf\/","url_meta":{"origin":1215,"position":5},"title":"Java 15 : what&#8217;s new ?","author":"admin","date":"Thursday July  2nd, 2020","format":false,"excerpt":"Now that Java 15 is features complete (Rampdown Phase One at the day of writing), it\u2019s time to walk throught all it\u2019s functionalities that brings to us, developers, this new version. This article is part of a series on what\u2019s new on the last versions of Java, for those who\u2026","rel":"","context":"In &quot;informatique&quot;","block_context":{"text":"informatique","link":"https:\/\/www.loicmathieu.fr\/wordpress\/category\/informatique\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts\/1215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/comments?post=1215"}],"version-history":[{"count":0,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/posts\/1215\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/media?parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/categories?post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.loicmathieu.fr\/wordpress\/wp-json\/wp\/v2\/tags?post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}