VisualVM OQL:如何搜索原始浮点值而不是实际的浮点实例?

发布于 2024-10-17 21:23:39 字数 322 浏览 3 评论 0原文

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

当执行以下操作时:

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

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

我将如何实现这个目标?

以下返回“找不到浮动错误”:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情域 2024-10-24 21:23:39

原始值仅作为其所属结构中的字段存在(或直接存在于堆栈中)。因为它不是一个对象,所以不能被引用。尝试如下操作:

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

如果您想检查所有对象中的所有浮点字段,应该可以使用 OQL 的反射功能来执行此操作,使用如下所示的操作:

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 似乎不正确地返回静态字段列表而不是实例字段。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文