gpt4 book ai didi

java - 如何从 jvmti 中的 jobject 获取类名

转载 作者:行者123 更新时间:2023-12-01 21:45:21 27 4
gpt4 key购买 nike

我正在尝试从 jvmti 中的 jobject 获取类名,我尝试了 get

(*jvmti)->GetClassSignature(jvmti, object_klass, &signature, &generic);

对于这样的代码

public static void main(String arg[]) throws Exception {
Set<String> names = new HashSet<>();
names.add("foo");
names.add("bar");
System.out.println(names);
}

我正在跟踪 jvmti 中对象的所有分配,我没有得到 java.util.HashSet在这个钩子(Hook)中

我得到了一堆

Ljava/lang/String;     Ljava/lang/Object;Ljava/io/Serializable;Ljava/lang/Comparable<Ljava/lang/String;>;Ljava/lang/CharSequence;
Ljava/lang/reflect/Method; (null)

和其他一些类(class),但我没有看到 new HashSet<>初始化

最佳答案

我想你正在尝试 VMObjectAlloc JVMTI 通知。对于 Java 代码中进行的分配,不会发送此通知。 JVMTI 规范中描述了此行为:

Sent when ... the allocation is not detectable by other intrumentation mechanisms. Generally object allocation should be detected by instrumenting the bytecodes of allocating methods.

...

Cases where this event would not be generated:

  • Allocation due to bytecodes - for example, the new and newarray VM instructions
  • Allocation due to JNI function calls - for example, AllocObject
  • Allocations during VM initialization
  • VM internal objects
<小时/>

This answer解释如何在 Java 中跟踪对象分配。

关于java - 如何从 jvmti 中的 jobject 获取类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36070397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com