AES-NI intrinsic默认启用吗?

时间:2022-12-25 17:19:24

Oracle has this to say about Java 8 with regards to AES-NI:

关于AES-NI, Oracle对Java 8有如下看法:

Hardware intrinsics were added to use Advanced Encryption Standard (AES). The UseAES and UseAESIntrinsics flags are available to enable the hardware-based AES intrinsics for Intel hardware. The hardware must be 2010 or newer Westmere hardware. For example, to enable hardware AES, use the following flags:

增加了硬件特性以使用高级加密标准(AES)。UseAES和useaesintrinsic标志可用来为Intel硬件启用基于硬件的AES intrinsic。硬件必须是2010年或更新的Westmere硬件。例如,要启用硬件AES,请使用以下标志:

-XX:+UseAES -XX:+UseAESIntrinsics

To disable hardware AES use the following flags:

要禁用硬件AES,请使用以下标志:

-XX:-UseAES -XX:-UseAESIntrinsics

But it does not indicate if AES intrinsics are enabled by default (for processors that support it). So the question is simple: if the processor supports AES-NI, are AES intrinsics used?

但是它并不表示AES intrinsic是否被启用(对于支持它的处理器)。所以问题很简单:如果处理器支持AES- ni,是否使用了AES intrinsic ?

Bonus question: is there any way to test if AES-NI is being used? I guess you can guess based on performance, but that's not an optimal or sure fire way of testing.

附加问题:是否有办法测试是否使用了AES-NI ?我猜你可以根据性能进行猜测,但这并不是最优或最可靠的测试方法。


For readerS that are not familiar with AES-NI intrinsics: it's replacing byte code with pre-compiled machine code, using the AES-NI instruction set. This happens by the JVM, so it does not show up in the API of the Java runtime or bytecode.

对于不熟悉AES-NI intrinsic的读者来说:它使用AES-NI指令集,用预编译的机器代码替换字节代码。

2 个解决方案

#1


31  

The flag has a default of true and it will be set to false if the detection fails, so you can simply use +PrintFlagsFinal to see if it is used:

这个标志的默认值是true,如果检测失败,它将被设置为false,所以您可以使用+PrintFlagsFinal来查看它是否被使用:

My Laptop without AES-NI:

我的笔记本电脑没有AES-NI:

C:\>"C:\Program Files\Java\jdk1.7.0_51\bin\java" -XX:+PrintFlagsFinal -version | find "UseAES"
     bool UseAES                                    = false           {product}
     bool UseAESIntrinsics                          = false           {product}
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Same on Desktop with AES-NI:

与AES-NI相同的是:

C:\>"C:\Program Files\Java\jdk7\bin\java" -XX:+PrintFlagsFinal -version | find "AES"
     bool UseAES                                    = true            {product}
     bool UseAESIntrinsics                          = true            {product}

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

C:\>"C:\Program Files (x86)\Java\jre7\bin\java" -XX:+PrintFlagsFinal -version | find "AES"
     bool UseAES                                    = true            {product}
     bool UseAESIntrinsics                          = true            {product}

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

So, it works for both x64 and i686 (WOW64) with recent Java 7. The feature was introduced with https://bugs.openjdk.java.net/browse/JDK-7184394 and backported to 7u40 and 7u45.

因此,它对于x64和i686 (WOW64)都适用于最近的Java 7。该特性是通过https://bugs.openjdk.java.net/browse/JDK-7184394引入的,并向后移植到7u40和7u45。


Important: AES-NI may only be available on the server VM.

重要提示:AES-NI可能只在服务器VM上可用。

This was acknowledged by Oracle after a bug report was filed. This vital piece of information was missing when they created the featues list of Java 8 where it was introduced (it later got backported to 7 as well). The server VM can be explicitly choosen by providing the -server option on the java or javaw command line.

在提交错误报告后,Oracle承认了这一点。当他们创建Java 8的特性列表时,这个重要的信息丢失了(它后来也被反向移植到7)。可以通过在java或javaw命令行上提供-server选项显式地选择服务器VM。

#2


4  

Can't comment (stupid SO rules more than 50 credits required!). This mailthread from openjdk says, all AES intrinsics are enabled by default. Although I'm not certain how much of the Oracle core VM code shares with openjdk. If you read the whole thread, they also discuss about challenges on 32-bit VMs, that probably explains your problem with your second test run.

不能评论(笨蛋,所以要求超过50学分!)openjdk的这个mailthread说,所有AES intrinsic都是默认启用的。虽然我不确定有多少Oracle核心VM代码与openjdk共享。如果您阅读了整个线程,它们还讨论了32位vm上的挑战,这可能解释了第二次测试运行时的问题。

  • Regarding your test (sorry, can't comment), don't you think the differences in the CPUs make a big difference? Core i7's are quadcore and have better clock speeds in general. Wouldn't that have made a difference ? I guess that shift from 21s (core i5, 32bitVM, AES-NI off) to 8s (core i7, 64bitVM, AES-NI off) is the difference between i5 and i7.
  • 关于您的测试(对不起,不能评论),您不认为cpu的差异有很大的不同吗?核心i7是四核,一般有更好的时钟速度。这不会有什么不同吗?我想从21 (core i5, 32bitVM, AES-NI off)到8s (core i7, 64bitVM, AES-NI off)的变化是i5和i7的区别。
  • The improvement from 8s to 3s, although not 7 fold, is indeed worth a 'Yipes'! :)
  • 从8秒提高到3秒,虽然不是7倍,但确实值1秒!:)
  • Regarding the detection mechanism - there doesn't seem to be a straightforward way. JVM throws a warning "AES intrinsics not available on this CPU" if you enabled the flags, and if it cannot find AES support - as per this bug report.
  • 关于检测机制——似乎没有一个简单的方法。如果您启用了标志,并且如果它找不到AES支持,那么JVM会抛出一个警告“AES intrinsic not available on this CPU”——如这个bug报告所示。

#1


31  

The flag has a default of true and it will be set to false if the detection fails, so you can simply use +PrintFlagsFinal to see if it is used:

这个标志的默认值是true,如果检测失败,它将被设置为false,所以您可以使用+PrintFlagsFinal来查看它是否被使用:

My Laptop without AES-NI:

我的笔记本电脑没有AES-NI:

C:\>"C:\Program Files\Java\jdk1.7.0_51\bin\java" -XX:+PrintFlagsFinal -version | find "UseAES"
     bool UseAES                                    = false           {product}
     bool UseAESIntrinsics                          = false           {product}
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Same on Desktop with AES-NI:

与AES-NI相同的是:

C:\>"C:\Program Files\Java\jdk7\bin\java" -XX:+PrintFlagsFinal -version | find "AES"
     bool UseAES                                    = true            {product}
     bool UseAESIntrinsics                          = true            {product}

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

C:\>"C:\Program Files (x86)\Java\jre7\bin\java" -XX:+PrintFlagsFinal -version | find "AES"
     bool UseAES                                    = true            {product}
     bool UseAESIntrinsics                          = true            {product}

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

So, it works for both x64 and i686 (WOW64) with recent Java 7. The feature was introduced with https://bugs.openjdk.java.net/browse/JDK-7184394 and backported to 7u40 and 7u45.

因此,它对于x64和i686 (WOW64)都适用于最近的Java 7。该特性是通过https://bugs.openjdk.java.net/browse/JDK-7184394引入的,并向后移植到7u40和7u45。


Important: AES-NI may only be available on the server VM.

重要提示:AES-NI可能只在服务器VM上可用。

This was acknowledged by Oracle after a bug report was filed. This vital piece of information was missing when they created the featues list of Java 8 where it was introduced (it later got backported to 7 as well). The server VM can be explicitly choosen by providing the -server option on the java or javaw command line.

在提交错误报告后,Oracle承认了这一点。当他们创建Java 8的特性列表时,这个重要的信息丢失了(它后来也被反向移植到7)。可以通过在java或javaw命令行上提供-server选项显式地选择服务器VM。

#2


4  

Can't comment (stupid SO rules more than 50 credits required!). This mailthread from openjdk says, all AES intrinsics are enabled by default. Although I'm not certain how much of the Oracle core VM code shares with openjdk. If you read the whole thread, they also discuss about challenges on 32-bit VMs, that probably explains your problem with your second test run.

不能评论(笨蛋,所以要求超过50学分!)openjdk的这个mailthread说,所有AES intrinsic都是默认启用的。虽然我不确定有多少Oracle核心VM代码与openjdk共享。如果您阅读了整个线程,它们还讨论了32位vm上的挑战,这可能解释了第二次测试运行时的问题。

  • Regarding your test (sorry, can't comment), don't you think the differences in the CPUs make a big difference? Core i7's are quadcore and have better clock speeds in general. Wouldn't that have made a difference ? I guess that shift from 21s (core i5, 32bitVM, AES-NI off) to 8s (core i7, 64bitVM, AES-NI off) is the difference between i5 and i7.
  • 关于您的测试(对不起,不能评论),您不认为cpu的差异有很大的不同吗?核心i7是四核,一般有更好的时钟速度。这不会有什么不同吗?我想从21 (core i5, 32bitVM, AES-NI off)到8s (core i7, 64bitVM, AES-NI off)的变化是i5和i7的区别。
  • The improvement from 8s to 3s, although not 7 fold, is indeed worth a 'Yipes'! :)
  • 从8秒提高到3秒,虽然不是7倍,但确实值1秒!:)
  • Regarding the detection mechanism - there doesn't seem to be a straightforward way. JVM throws a warning "AES intrinsics not available on this CPU" if you enabled the flags, and if it cannot find AES support - as per this bug report.
  • 关于检测机制——似乎没有一个简单的方法。如果您启用了标志,并且如果它找不到AES支持,那么JVM会抛出一个警告“AES intrinsic not available on this CPU”——如这个bug报告所示。