prefetch instruction in JVM/JAVA(JVM/JAVA 中的预取指令)
问题描述
是否有 Java 语言或 JVM 中的软件预取指令,例如 __builtin_prefetch 在 GCC 中可用
Is there any software prefetching instructions in Java language or JVM, like __builtin_prefetch which is available in GCC
推荐答案
Hotspot JVM 实际上确实支持预取!
它将 Unsafe.prefetchRead()
和 Unsafe.prefetchWrite()
方法视为内在函数,并将它们编译为相应的 CPU 指令.
One interesting thing is that Hotspot JVM actually does support prefetch!
It treats Unsafe.prefetchRead()
and Unsafe.prefetchWrite()
methods as intrinsics and compiles them into corresponding CPU instructions.
很遗憾,sun.misc.Unsafe
没有声明此类方法.但是,如果您将以下方法添加到 Unsafe.java,重新编译它并替换 rt.jar 中的 Unsafe.class(或仅添加 -Xbootclasspath/p
JVM 参数),您将能够使用预取内在函数在您的应用程序中.
Unfortunately, sun.misc.Unsafe
does not declare such methods. But, if you add the following methods to Unsafe.java, recompile it and replace Unsafe.class inside rt.jar (or just add -Xbootclasspath/p
JVM argument) you would be able to use prefetch intrinsics in your application.
public native void prefetchRead(Object o, long offset);
public native void prefetchWrite(Object o, long offset);
public static native void prefetchReadStatic(Object o, long offset);
public static native void prefetchWriteStatic(Object o, long offset);
我怀疑这对实际应用程序有多大帮助,但如果您想使用它,我可以提供更多详细信息.
这是 JDK 8 的已编译补丁,可启用预取方法:下载
I doubt this could help much in real applications, but if you'd like to play with it, I can provide more details.
Here is a compiled patch to JDK 8 that enables prefetch methods: download
使用示例:
long[] array = new long[100*1024*1024];
// ...
sun.misc.Unsafe.prefetchReadStatic(array, 50*1024*1024);
更新
Unsafe.prefetch*
内部函数已完全删除 在 JDK 9 中:
Unsafe.prefetch*
intrinsics are completely removed in JDK 9:
注意读/写预取支持是作为实验实现的看看 JDK 库代码是否可以使用它来获得性能优势.但是,实验结果并不表明这是值得.因此没有相应的预取sun.misc.Unsafe 中的本机方法声明.
Note read/write prefetch support was implemented as an experiment to see if JDK library code could use it for performance advantages. However, the results of the experiment did not indicate this was worthwhile. As a consequence there are no corresponding prefetch native method declarations in sun.misc.Unsafe.
这篇关于JVM/JAVA 中的预取指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JVM/JAVA 中的预取指令
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01