本文介绍了比JVMTI GetTag更快地获取对象标签的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用异步事件探查器和gperftools进行性能分析时,我注意到jvmti->GetTag在我的代理的结果中显示了很多内容.当我检查它的实现方式时,在jvmitTagMap.cpp的源代码中发现了以下内容:

When profiling with async profiler and gperftools I noticed that jvmti->GetTag shows up quite a lot in the results for my agent. When I checked how it is implemented I found the following in the source of jvmitTagMap.cpp:

jlong JvmtiTagMap::get_tag(jobject object) {
  MutexLocker ml(lock());

  // resolve the object
  oop o = JNIHandles::resolve_non_null(object);

  // for Classes get the tag from the klassOop
  return tag_for(this, klassOop_if_java_lang_Class(o));
}
  1. 尽管我的测试中只有一个真正处于负载状态的线程,但似乎一旦我添加更多线程并大量使用GetTag,它的扩展规模甚至会减少.
  1. Although my test only had one thread that was really under load it seems that this will scale even less once I add more threads and make heavy use of GetTag.

我想使用标签将ID分配给某些对象,并在我的jvmti代理中使用它.有什么更快的想法可以实现吗? (据我所知)无法使用对象标头来解决这个问题.

I wanted to use the tag to assign an id to certain objects and use it in my jvmti agent. Any ideas for a faster way accomplish that? Messing with the object header obvioulsy is not an option (to my knowledge).

注意:大多数事情应该在C端完成,因为我不希望Java代理以任何方式干扰应用程序.通过干涉,我什至表示诸如更改某些中央对象/类(例如,如java.lang.StringCoding)的内部状态或导致某些类被加载等之类的事情

NOTE: Most things should be done on C side as I do not want my Java agent to interfer with the application in any way. By interfer I even mean things like changing internal state of some central objects / classes (like java.lang.StringCoding for example), or leading to some classes being loaded, etc

GetTag已经在当前的JVMTI代理中大量使用,因此我正在寻找一种更快的方法来获取标签或实现我自己的机制,同时又站在C端.

GetTag is already used heavily throughout the current JVMTI agent, so I am looking for a faster way to get the tag or implement my own mechanism while staying on C side.

推荐答案

使用C语言中的Java对象时,您基本上会受到JNI和JVMTI函数的限制.而且它们确实有不可避免的开销.

When you work with Java objects from C, you are basically limited by JNI and JVMTI functions. And they do have inevitable overhead.

恐怕没有其他合法方法可以从本地代理访问Java对象.特别是,处理裸露的循环是非法的-这只是一个原始指针,由于对象可以移动,它随时可能变得无效.

I'm afraid there are no other legal ways to access Java objects from a native agent. In particular, dealing with naked oop is illegal - this is just a raw pointer which may become invalid at any time because the objects can move.

JVM可以使用oop,甚至可以将对象地址用作JvmtiTagMap中的键,只要它在移动对象时更新相应的oop.而且HotSpot JVM确实做到了这一点,请参见 JvmtiTagMap :: do_weak_oops .

JVM, however, can work with oops and even use the object address as a key in JvmtiTagMap as long as it updates the corresponding oops whenever the objects are moved. And HotSpot JVM indeed does this, see JvmtiTagMap::do_weak_oops.

这篇关于比JVMTI GetTag更快地获取对象标签的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 06:38