VisualVM OQL: how to search for primitive float values rather than actual Float instances?

爱⌒轻易说出口 提交于 2019-12-06 12:04:23

A primitive value exists only as a field in the structure it's a part of (or directly on the stack). Because it isn't an object, it can't be referenced. Try something like the following:

select v from Vector v where v.x == 1.0 || v.y == 1.0 || v.z == 1.0

If you want to examine all float fields in all objects, it should be possible to use OQL's reflection capabilities to do so, using something like the following:

select filter(heap.objects(), function(it) {
  var cls = classof(it);
  while (cls) {
    for (var i = 0; i < cls.fields.length; i++) {
      var field = cls.fields[i];
      if (field.signature == 'F' && it[field.name] == 0.0)
        return true;
      }
    cls = cls.superclass;
  }
  return false;
})

However, while this works correctly using jhat, it doesn't work in my version of VisualVM (1.6.0_22), because cls.fields seems to improperly return a list of static fields rather than instance fields.

It's also very slow, taking 10 seconds to search a 1MB heap dump. It's probably possible to optimize the code and also speed things up by only searching a limited set of classes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!