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

随声附和 提交于 2019-12-23 01:25:17

问题


I am wondering how one can search for all primitive float values that match a certain number.

When doing something like:

select n from java.lang.Float n where n.value == 1.00

Only the Float class instances are being found. The application I am exploring is using different wrappers than just Float (eg. Vectors) that use primitive float values as fields for which I need to search.

How would I accomplish this?

The following returns a "float is not found error":

select n from float n where n.value == 1.00

回答1:


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.



来源:https://stackoverflow.com/questions/5021988/visualvm-oql-how-to-search-for-primitive-float-values-rather-than-actual-float

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