VisualVM OQL:如何搜索原始浮点值而不是实际的浮点数实例? [英] VisualVM OQL: how to search for primitive float values rather than actual Float instances?

查看:239
本文介绍了VisualVM OQL:如何搜索原始浮点值而不是实际的浮点数实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何搜索匹配特定数字的所有原始浮点值。

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

执行以下操作时:

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

仅找到Float类实例。我正在探索的应用程序使用的不同包装器不仅仅是Float(例如,Vectors),它使用原始浮点值作为我需要搜索的字段。

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.

我将如何完成这个?

以下内容返回未找到浮动错误:

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

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


推荐答案

原始值仅作为结构中的字段存在(或直接在堆栈上)。因为它不是对象,所以不能引用它。尝试以下内容:

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






如果你想检查所有在所有对象中浮动字段, 可以使用OQL的反射功能来执行此操作,使用以下内容:


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;
})

但是,虽然这可以正常使用jhat,但它在我的VisualVM版本(1.6.0_22)中不起作用,因为cls.fields似乎不正确地返回静态字段列表而不是实例字段。

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.

它也很慢,需要10秒才能搜索1MB堆转储。通过只搜索一组有限的类,可能可以优化代码并加快速度。

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.

这篇关于VisualVM OQL:如何搜索原始浮点值而不是实际的浮点数实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆