Java 语言个性系列
- Java5 的新个性
- Java6 的新个性
- Java7 的新个性
- Java8 的新个性
- Java9 的新个性
- Java10 的新个性
- Java11 的新个性
- Java12 的新个性
- Java13 的新个性
- Java14 的新个性
- Java15 的新个性
- Java16 的新个性
- Java17 的新个性
序
本文次要讲述一下 Java16 的新个性
版本号
java -version
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+36-2231)
OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
从 version 信息能够看出是 build 16+36
个性列表
JEP 338: Vector API (Incubator)
提供了 jdk.incubator.vector 来用于矢量计算,实例如下
static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_256;
void vectorComputation(float[] a, float[] b, float[] c) {for (int i = 0; i < a.length; i += SPECIES.length()) {var m = SPECIES.indexInRange(i, a.length);
// FloatVector va, vb, vc;
var va = FloatVector.fromArray(SPECIES, a, i, m);
var vb = FloatVector.fromArray(SPECIES, b, i, m);
var vc = va.mul(va).
add(vb.mul(vb)).
neg();
vc.intoArray(c, i, m);
}
}
JEP 347: Enable C++14 Language Features
在 JDK C++ 的源码中容许应用 C ++14 的语言个性
JEP 357: Migrate from Mercurial to Git
OpenJDK 源码的版本控制从 Mercurial (hg) 迁徙到 git
JEP 369: Migrate to GitHub
将 OpenJDK 源码的版本控制迁徙到 github 上
JEP 376: ZGC: Concurrent Thread-Stack Processing
实现了并发 thread-stack 解决来升高 GC safepoints 的累赘
JEP 380: Unix-Domain Socket Channels
对 socket channel 及 server socket channel 的 api 提供对 unix domain socket 的反对
JEP 386: Alpine Linux Port
将 glibc 的 jdk 移植到应用 musl 的 alpine linux 上
JEP 387: Elastic Metaspace
反对不再应用的 class metadata 偿还内存给操作系统,升高内存占用
JEP 388: Windows/AArch64 Port
移植 JDK 到 Windows/AArch64
JEP 389: Foreign Linker API (Incubator)
提供 jdk.incubator.foreign 来简化 native code 的调用
JEP 390: Warnings for Value-Based Classes
提供 @jdk.internal.ValueBased 来用于标注作为 value-based 的类,实例如下
@jdk.internal.ValueBased
public final class SomeVbc {public SomeVbc() {}
final String ref = "String";
void abuseVbc() {synchronized(ref) { // OK
synchronized (this) {// WARN}
}
}
}
final class AuxilliaryAbuseOfVbc {void abuseVbc(SomeVbc vbc) {synchronized(this) { // OK
synchronized (vbc) {// WARN}
}
}
}
JEP 392: Packaging Tool
jpackage 在 JDK14 引入,JDK15 作为 incubating 工具,在 JDK16 转正,从
jdk.incubator.jpackage
转为jdk.jpackage
。它反对 Linux: deb and rpm、macOS: pkg and dmg、Windows: msi and exe
JEP 393: Foreign-Memory Access API (Third Incubator)
Foreign-Memory Access API 在 JDK14 首次引入作为 incubating API,在 JDK15 处于第二轮 incubating,在 JDK16 处于第三轮 incubating
JEP 394: Pattern Matching for instanceof
instanceof 的模式匹配在 JDK14 作为 preview,在 JDK15 作为第二轮的 preview,在 JDK16 转正
JEP 395: Records
Record 类型在 JDK14 作为 preview,在 JDK15 处于第二轮 preview,在 JDK16 转正
JEP 396: Strongly Encapsulate JDK Internals by Default
对外部的 api 进行更多的封装,激励开发者从应用外部的办法迁徙到规范的 API,然而
sun.misc.Unsafe
还是持续保留
JEP 397: Sealed Classes (Second Preview)
Sealed Classes 在 JDK15 作为 preview 引入,在 JDK16 作为第二轮 preview
细项解读
下面列出的是大方面的个性,除此之外还有一些 api 的更新及废除,次要见 JDK 16 Release Notes,这里举几个例子。
增加项
- Add InvocationHandler::invokeDefault Method for Proxy’s Default Method Support (JDK-8159746)
给 InvocationHandler 增加 invokeDefault 办法
- Day Period Support Added to java.time Formats (JDK-8247781)
java.time 反对 Day Period
- Add Stream.toList() Method (JDK-8180352) (JDK-8180352)
Stream 新增 toList 办法
- Concurrently Uncommit Memory in G1 (JDK-8236926)
针对 G1 提供了并发偿还内存给操作系统
移除项
- Removal of Experimental Features AOT and Graal JIT (JDK-8255616)
移除 jaotc 工具
- Deprecated Tracing Flags Are Obsolete and Must Be Replaced With Unified Logging Equivalents (JDK-8256718)
应用
-Xlog:class+load=info
代替-XX:+TraceClassLoading
;应用-Xlog:class+unload=info
代替-XX:+TraceClassUnloading
;应用-Xlog:exceptions=info
代替-XX:+TraceExceptions
废除项
- Terminally Deprecated ThreadGroup stop, destroy, isDestroyed, setDaemon and isDaemon (JDK-8256643)
废除 ThreadGroup 的 stop, destroy, isDestroyed, setDaemon, isDaemon 办法
- Deprecated the java.security.cert APIs That Represent DNs as Principal or String Objects (JDK-8241003)
废除了 java.security.cert.X509Certificate 的 getIssuerDN()、getSubjectDN()办法
已知问题
- Incomplete Support for Unix Domain Sockets in Windows 2019 Server (JDK-8259014)
Unix Domain Sockets 对 Windows 2019 Server 的反对还不欠缺
- TreeMap.computeIfAbsent Mishandles Existing Entries Whose Values Are null (JDK-8259622)
TreeMap.computeIfAbsent 办法针对 null 的解决与标准有偏差
其余事项
- Enhanced Support of Proxy Class (JDK-8236862)
对 Proxy Class 进行了加强,反对
jdk.serialProxyInterfaceLimit
属性
- Support Supplementary Characters in String Case Insensitive Operations (JDK-8248655)
对 compareToIgnoreCase、equalsIgnoreCase、regionMatches 办法的 Case Insensitive 语义进行了加强
- HttpClient.newHttpClient and HttpClient.Builder.build Might Throw UncheckedIOException (JDK-8248006)
HttpClient.newHttpClient 及 HttpClient.Builder.build 办法可能抛出 UncheckedIOException
- The Default HttpClient Implementation Returns Cancelable Futures (JDK-8245462)
默认的 HttpClient 实现返回 Cancelable Futures
小结
Java16 次要有如下几个个性
- JEP 338: Vector API (Incubator)
- JEP 347: Enable C++14 Language Features
- JEP 357: Migrate from Mercurial to Git
- JEP 369: Migrate to GitHub
- JEP 376: ZGC: Concurrent Thread-Stack Processing
- JEP 380: Unix-Domain Socket Channels
- JEP 386: Alpine Linux Port
- JEP 387: Elastic Metaspace
- JEP 388: Windows/AArch64 Port
- JEP 389: Foreign Linker API (Incubator)
- JEP 390: Warnings for Value-Based Classes
- JEP 392: Packaging Tool
- JEP 393: Foreign-Memory Access API (Third Incubator)
- JEP 394: Pattern Matching for instanceof
- JEP 395: Records
- JEP 396: Strongly Encapsulate JDK Internals by Default
- JEP 397: Sealed Classes (Second Preview)
doc
- JDK 16 Features
- JDK 16 Release Notes
- Oracle JDK 16 Release Notes
- Java SE deprecated-list
- The Arrival of Java 16
- Java 16 and IntelliJ IDEA