Java 10 Performance Improvements – Java 10的性能改进

最后修改: 2018年 5月 16日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

In this quick tutorial, we will discuss the performance improvements that come along with the latest Java 10 release.

在这个快速教程中,我们将讨论最新的Java 10版本所带来的性能改进。

These improvements apply to all applications running under JDK 10, with no need for any code changes to leverage them.

这些改进适用于所有在JDK 10下运行的应用程序,不需要修改任何代码就可以利用它们。

2. Parallel Full GC for G1

2.G1的平行全面GC

The G1 garbage collector is the default one since JDK 9. However, the full GC for G1 used a single threaded mark-sweep-compact algorithm.

G1垃圾收集器是自JDK 9以来默认的垃圾收集器。然而,G1的完整GC使用了一个单线程的标记-扫荡-紧凑算法。

This has been changed to the parallel mark-sweep-compact algorithm in Java 10 effectively reducing the stop-the-world time during full GC.

在Java 10中,这已经被改变为并行标记-扫描-紧凑算法,有效地减少了完全GC期间的停止-世界时间。

3. Application Class-Data Sharing

3.应用类-数据共享

Class-Data Sharing, introduced in JDK 5, allows a set of classes to be pre-processed into a shared archive file that can then be memory-mapped at runtime to reduce startup time which can also reduce dynamic memory footprint when multiple JVMs share the same archive file.

JDK 5中引入的类数据共享允许将一组类预处理成一个共享的归档文件,然后在运行时进行内存映射,以减少启动时间,当多个JVM共享同一个归档文件时,也可以减少动态内存的占用。

CDS only allowed the bootstrap class loader, limiting the feature to system classes only. Application CDS (AppCDS) extends CDS to allow the built-in system class loader (a.k.a., the “app class loader”), the built-in platform class loader, and custom class loaders to load archived classes. This makes it possible to use the feature for application classes.

CDS只允许bootstrap类加载器,将该功能仅限制在系统类上。应用CDS(AppCDS)扩展了CDS,允许内置系统类加载器(又称 “应用类加载器”)、内置平台类加载器和自定义类加载器加载存档类。这使得应用类的使用功能成为可能。

We can use the following steps to make use of this feature:

我们可以使用以下步骤来利用这一功能。

1. Get the list of classes to archive

1.获取要存档的班级列表

The following command will dump the classes loaded by the HelloWorld application into hello.lst:

下面的命令将把由HelloWorld应用程序加载的类转储到hello.lst

$ java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=hello.lst \ 
    -cp hello.jar HelloWorld

2. Create the AppCDS archive

2.创建AppCDS档案

Following command creates hello.js a using the hello.lst as input:

下面的命令使用hello.lst作为输入,创建hello.js a

$ java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=hello.lst \
    -XX:SharedArchiveFile=hello.jsa -cp hello.jar

3. Use the AppCDS archive

3.使用AppCDS档案

Following command starts the HelloWorld application with hello.jsa as input:

以下命令以hello.jsa为输入启动HelloWorld应用程序。

$ java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa \
    -cp hello.jar HelloWorld

AppCDS was a commercial feature in Oracle JDK for JDK 8 and JDK 9. Now it is open sourced and made publicly available.

AppCDS是Oracle JDK 8和JDK 9中的一个商业功能。 现在它已经开源并公开提供了。

4. Experimental Java-Based JIT Compiler

4.实验性的基于Java的JIT编译器

Graal is a dynamic compiler written in Java that integrates with the HotSpot JVM; it’s focused on high performance and extensibility. It’s also the basis of the experimental Ahead-of-Time (AOT) compiler introduced in JDK 9.

Graal是一个用Java编写的动态编译器,与HotSpot JVM集成;它专注于高性能和可扩展性。它也是JDK 9中引入的实验性超前(AOT)编译器的基础。

JDK 10 enables the Graal compiler, to be used as an experimental JIT compiler on the Linux/x64 platform.

JDK 10使Graal编译器可以作为Linux/x64平台上的实验性JIT编译器使用。

To enable Graal as the JIT compiler, use the following options on the java command line:

要启用Graal作为JIT编译器,请在java命令行中使用以下选项。

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

Note that this is an experimental feature and we may not necessarily get better performance than the existing JIT compilers.

请注意,这是一个实验性的功能,我们不一定能得到比现有JIT编译器更好的性能。

5. Conclusion

5.结论

In this quick article, we focused on and explored the performance improvement features in Java 10.

在这篇快速的文章中,我们重点关注并探讨了Java 10中的性能改进功能。

Next »

New Features in Java 10

« Previous

Java 10 LocalVariable Type-Inference