Oop Maps 在 Hotspot VM 中的确切含义是什么

2022-01-16 00:00:00 jvm java jvm-hotspot

我从一些文档中了解到,Hotspot VM 利用称为 Oop Maps 的数据结构来管理 VM 中的所有 OOP.我的问题是,这个 Oop Map 数据结构是什么时候生成的?在编译时还是运行时?任何有关此的详细文件都将受到欢迎.谢谢各位.

I read from some documents that Hotspot VM utilizes a data structure called Oop Maps to manage all OOPs in VM. My question is that when does this Oop Map data structure generated? At compile time or runtime? Any further detailed documents regarding to this will be more than welcomed. Thank you guys.

推荐答案

OopMap 是一种记录对象引用 (OOP) 在 Java 堆栈上的位置的结构.它的主要目的是在 Java 堆栈上查找 GC 根,并在对象在堆内移动时更新引用.

OopMap is a structure that records where object references (OOPs) are located on the Java stack. Its primary purpose is to find GC roots on Java stacks and to update the references whenever objects are moved within the Heap.

OopMap 共有三种:

There are three kinds of OopMaps:

  1. 用于解释方法的OopMaps.它们是通过分析字节码流来延迟计算的,即当 GC 发生时.最好的参考是源代码(有很多注释),见 generateOopMap.cpp.InterpreterOopMap 存储在 OopMapCache.
  2. 用于JIT 编译的方法 的OopMaps.它们在 JIT 编译期间生成并与编译后的代码一起保存,以便 VM 可以通过指令地址快速找到堆栈位置和保存对象引用的寄存器.
  3. OopMaps 用于生成的共享运行时存根.这些映射由开发人员(这些运行时存根的作者)手动构建.
  1. OopMaps for interpreted methods. They are computed lazily, i.e. when GC happens, by analyzing bytecode flow. The best reference is the source code (with lots of comments), see generateOopMap.cpp. InterpreterOopMaps are stored in OopMapCache.
  2. OopMaps for JIT-compiled methods. They are generated during JIT-compilation and kept along with the compiled code so that VM can quickly find by instruction address the stack locations and the registers where the object references are held.
  3. OopMaps for generated shared runtime stubs. These maps are constructed manually by the developers - authors of these runtime stubs.

在 GC 期间,JVM 遍历所有线程堆栈.每个堆栈都被解析为堆栈帧流.这些帧要么是解释的,要么是编译的,要么是存根的.解释帧包含有关 Java 方法和 bci(字节码索引)的信息.OopMapCache 帮助找到与给定方法和 bci 对应的 OopMap.编译帧的方法是通过指令地址查找发现的.

During GC JVM walks through all thread stacks. Each stack is parsed as a stream of stack frames. The frames are either interpreted or compiled or stubs. Interpreted frames contain information about Java method and bci (bytecode index). OopMapCache helps to find an OopMap corresponding to the given method and bci. The method of a compiled frame is discovered by instruction address lookup.

相关文章