我是 C 和 C++ 的初学者,我不太了解如何使用 JVMTI。我想获取java对象的物理内存位置(十六进制)。是否可以?我不想得到诸如“从这个探查器等获取它”之类的答案...... 到目前为止,我在 Linux 终端中使用这个命令:
java -showversion -agentpath:../CPrg/DLL/bin/Debug/libDLL.so SimpleMemAlloc
libDLL.so 是我使用 c 创建的库,我在其中使用 java 应用程序运行它。它确实有效,它与我的代码一起运行,但我不知道如何获取我想要的数据。
例如,我正在使用这个简单的代码:
public class SimpleMemAlloc{
Object [] oarray = new Object[10000];
public static void main(String args []){
Object [] o= new Object[100];
for (int i= 0; i<100; i++){
o[i] = new Integer [10000];
}
}
}
我想获取我创建的每个新整数数组的内存位置(0x...)... 如果我使用 jvmti 获得一个很好的示例代码,我将非常高兴
最佳答案
如果对象不覆盖 hashCode()
,则默认实现会以整数形式返回对象的内部地址。同样,这可能不是最好的方法。
This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.
了解更多信息click here
关于java - 如何使用 JVMTI 获取 java 对象的内存地址(不是哈希码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8659377/